Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
Re: [jgit-dev] Transient poopies after JGit commit

I wasn't using DirCacheEditor earlier because it didn't seem finished to me since PathEdit is abstract with only two concrete subclasses: DeletePath and DeleteTree.

So, I made an AddPath subclass of PathEdit, changed my commit code to use a DirCacheEditor and AddPath, and tested it out but there are still problems.  AddPath uses its own private DirCacheEntry to store metadata and my test code sets lastModified and length.  Now, commits only contain new files, not modified files even though I added an AddPath to the DirCacheEditor for every file (new, modified, or old) -- the same was true for an earlier test that only set fileMode in apply().  Also, there seems to be an inconsistency in the commmit because when I use gitk to check it, the contents of my new file appears in the diff area when I choose "Patch" but the file appears to be empty when I choose "Tree".

Anyway, here's the AddPath class.  As an officer of my company, I disclaim any and all rights to the following AddPath class:

* Add a single file entry to the index.
public static final class AddPath extends PathEdit {
DirCacheEntry cached;

* Create a new add command by path name.
* @param entryPath
*            path of the file within the repository.
public AddPath(final String entryPath) {
cached = new DirCacheEntry(entryPath);

* Create a new add command for an existing entry instance.
* @param ent
*            entry instance to add. Only the path of this entry is
*            actually considered during command evaluation.
public AddPath(final DirCacheEntry ent) {
cached = new DirCacheEntry(ent.path);

* Configure entry with cached metadata
* @see org.eclipse.jgit.dircache.DirCacheEditor.PathEdit#apply(org.eclipse.jgit.dircache.DirCacheEntry)
public void apply(final DirCacheEntry ent) {

And here is the updated section of my commit test code (the if-clause for using a dircache instead of a gitindex) -- note that pathsDo executes its block for every project file (i.e. not directories and not files in the .git subtree):

dircache = DirCache.lock(repository)
val editor = dircache.editor

pathsDo(repoPath, _.getName != ".git") {f =>
val subpath = f.getAbsolutePath.substring(repoPathLen)
var entry = dircache.getEntry(subpath)

if (entry == null) entry = new DirCacheEntry(subpath)
editor.add(new AddPath(entry))
commit.setTree(repository.mapTree(dircache.writeTree(new ObjectWriter(repository))))

On Mon, Feb 22, 2010 at 6:56 AM, Shawn O. Pearce <spearce@xxxxxxxxxxx> wrote:
Bill Burdick <bill.burdick@xxxxxxxxx> wrote:
> OK, I'm trying to use DirCache, but I must not be using it properly.  I have
> a boolean in my script to switch between using GitIndex and DirCache.
>  GitIndex behaves like I would expect, but when I use DirCache to do two
> commits (after edits), the second one adds a commit to the list and updates
> the head like you would expect, but it appears to change the tree in the
> first commit and leaves the new commit empty.  Here is the if-clause that
> chooses between GitIndex and DirCache.  After that, I'm attaching the entire
> (updated) script.

You shouldn't use a builder like this.  Instead you need to use
an editor.

Back to the top