From: "Adam W. Hawks" <awhawks@writeme.com>
To: git@vger.kernel.org
Subject: [ JGIT ] incompatiblity found in DirCache
Date: Wed, 09 Sep 2009 14:55:39 -0400 [thread overview]
Message-ID: <4AA7FA2B.4090707@writeme.com> (raw)
When using the DirCache interface to the index you can create a invalid/corrupt tree for git 1.6.5.
The problem seems to be you can add a path to the index that starts with a "/" and DirCache creates a entry with a mode but no path.
This causes git 1.6.5 to fail with a corrupt tree.
The following code will create the problem
import java.io.File;
import java.io.IOException;
import java.util.Calendar;
import java.util.Date;
import java.util.TimeZone;
import org.spearce.jgit.dircache.DirCache;
import org.spearce.jgit.dircache.DirCacheBuilder;
import org.spearce.jgit.dircache.DirCacheEntry;
import org.spearce.jgit.lib.Commit;
import org.spearce.jgit.lib.FileMode;
import org.spearce.jgit.lib.ObjectId;
import org.spearce.jgit.lib.ObjectWriter;
import org.spearce.jgit.lib.PersonIdent;
import org.spearce.jgit.lib.RefUpdate;
import org.spearce.jgit.lib.Repository;
import org.spearce.jgit.lib.RefUpdate.Result;
public class BuildTest
{
private Repository db;
public static void main(String[] args)
{
BuildTest bt = new BuildTest();
bt.doit();
}
public void doit()
{
Date when = Calendar.getInstance().getTime();
File gitDir = new File("gitProblem/.git");
gitDir.mkdirs();
try
{
db = new Repository(gitDir);
db.create(true);
DirCache dirc = DirCache.newInCore();
DirCacheBuilder dcb = dirc.builder();
byte[] data = "Some File data".getBytes();
ObjectWriter ow = new ObjectWriter(db);
ObjectId dataId = ow.writeBlob(data);
DirCacheEntry newEntry = new DirCacheEntry("/someDir/someFile");
newEntry.setAssumeValid(false);
newEntry.setFileMode(FileMode.REGULAR_FILE);
newEntry.setLastModified(when.getTime());
newEntry.setLength(data.length);
newEntry.setObjectId(dataId);
dcb.add(newEntry );
dcb.finish();
dirc = dcb.getDirCache();
PersonIdent pi = new PersonIdent("someonw","someone@somewhere",when,TimeZone.getDefault());
ObjectId tree = dirc.writeTree(new ObjectWriter(db));
Commit commit = new Commit(db);
commit.setAuthor(pi);
commit.setCommitter(pi);
commit.setMessage("This causes a corrupt tree");
commit.setTreeId(tree);
commit.commit();
ObjectId cid = commit.getCommitId();
RefUpdate ru = db.updateRef("refs/heads/master");
ru.setExpectedOldObjectId(ObjectId.zeroId());
ru.setNewObjectId(cid);
ru.setRefLogIdent(pi);
ru.setRefLogMessage("some reflog message", true);
Result result = ru.update();
System.out.println("Result = "+result.toString());
}
catch (IOException e)
{
System.out.println(e);
e.printStackTrace();
System.exit(1);
}
}
}
next reply other threads:[~2009-09-09 18:56 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2009-09-09 18:55 Adam W. Hawks [this message]
2009-09-09 21:11 ` [ JGIT ] incompatiblity found in DirCache Robin Rosenberg
2009-09-11 15:05 ` Shawn O. Pearce
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
List information: http://vger.kernel.org/majordomo-info.html
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=4AA7FA2B.4090707@writeme.com \
--to=awhawks@writeme.com \
--cc=git@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
Code repositories for project(s) associated with this public inbox
https://80x24.org/mirrors/git.git
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).