Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
Re: [jgit-dev] InMemoryRepository and HEAD reference

On Tue, Mar 19, 2013 at 3:49 PM, Alex Blewitt <alex.blewitt@xxxxxxxxx> wrote:
> On 18 Mar 2013, at 23:02, Alex Blewitt wrote:
>
> On 18 Mar 2013, at 22:33, Shawn Pearce wrote:
>
> This also has to be in the ids RefList. That is the contract you broke.
>
>
> Thanks, I'll try that out and verify it works when that happens.
>
> Alex
>
>
> This worked:
>
> •   protected RefCache scanAllRefs() throws IOException {
> •                         RefList.Builder<Ref> ids = new
> RefList.Builder<Ref>();
> •                         RefList.Builder<Ref> sym = new
> RefList.Builder<Ref>();
> •                         for (Ref ref : refs.values()) {
> if(ref.getName().equals("refs/heads/master")) {
>  SymbolicRef HEAD = new SymbolicRef("HEAD",ref);
>  sym.add(HEAD);
>  ids.add(HEAD);
> } •                                 if (ref.isSymbolic())
> •                                         sym.add(ref);
> •                                 ids.add(ref);
> •                         }
> •                         ids.sort();
> •                         sym.sort();
> •                         return new RefCache(ids.toRefList(),
> sym.toRefList());
> •                 }
>
> Would it be worth storing the 'default branch' in a config property of the
> project? That way, the code could be more generic and be part of the
> InMemory example of DFS. Say, something like:
>
> branch_default = cfg.getString("dfs",null,"branch.default");
> if(branch_default != null && branch_default.equals(ref.getName())) {
>   sym.add(HEAD);
>   ids.add(HEAD);
> }
>
> Should this be part of the DFS implementation anyway, or should it be
> handled higher up?

Its not part of a config. It should be what
DfsRepository.create(boolean) does. That should write out HEAD as a
symbolic reference to refs/heads/master, similar to the way
FileRepository.create() does that. IIRC this is a bug in the
DfsRepository implementation. The Google subclass does this itself and
I don't recall why:

  updateRef(Constants.HEAD).link("refs/heads/master");


Back to the top