git/list[1] front-page[2] threads[3] people[4] search[5] about
 

Re: problem using jgit

From
Shawn O. Pearce <spearce@spearce.org>
Date
Jul 22, 2008, 16:58 UTC
Message-ID
<20080722165831.GA11173@spearce.org>
In-Reply-To
<488482A2.4000601@gmail.com>
Marek Zawirski <marek.zawirski@gmail.com> wrote:
Show 5 quoted lines
> Marek Zawirski wrote:
>> Stephen Bannasch wrote:
>>> I've setup a simple test class that integrates jgit to clone a git  
>>> repository. However I'm getting a NullPointerError when  
>>> RevWalk.parseAny ends up producing a null object id.
...
Show 5 quoted lines
> It's caused by 14a630c3: Cached modification times for symbolic refs too
> Changes introduced by this patch made Repository#getAllRefs() including  
> Ref objects with null ObjectId in case of unresolvable (invalid?) HEAD  
> symbolic ref, and null Ref for HEAD  when it doesn't exist. Previous  
> behavior was just not including such refs in result.

My intention here was that if a ref cannot be resolved, it should not be reported. So Ref.getObjectId should never return null, and it should also never return an ObjectId for which the object does not exist in the Repository's object database(s). (Though that can happen in the face of repository corruption, but lets not go there just yet).

So IMHO the RefDatabase code is _wrong_ for returning HEAD with a null objectId.

Now this case can happen if HEAD points at a stillborn branch. This is easily reproduced in any repository, e.g. just do:

	git symbolic-ref HEAD refs/heads/`date`

You'll wind up on a branch which doesn't exist. In this case HEAD shouldn't be reported back from RefDatabase, it doesn't exist, as branch `date` does not exist either.

-- 
Shawn.
Previous: Marek ZawirskiNext: Marek Zawirski
Message 6 of 8 in “problem using jgit”
  1. Stephen BannaschJul 21, 2008
  2. Marek ZawirskiJul 21, 2008
  3. Marek ZawirskiJul 21, 2008
  4. Stephen BannaschJul 21, 2008
  5. Marek ZawirskiJul 22, 2008
  6. Shawn O. PearceJul 22, 2008
  7. Marek ZawirskiJul 25, 2008
  8. Shawn O. PearceJul 27, 2008

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.