[
Date Prev][
Date Next][
Thread Prev][
Thread Next][
Date Index][
Thread Index]
[
List Home]
Re: [jgit-dev] Bug in TreeWalk.forPath (?)
|
> You are missing something.
Thanks for the answer. However, I am afraid that this is not the case, see below:
>> String repo = "/home/gousiosg/test"; //Clone of
>> git://github.com/schacon/ruby-git.git
>> Repository local = new FileRepository(repo);
>> FileMode a = null, b = null;
>> RevWalk rw = new RevWalk(local);
>> ObjectId treeId =
>> local.resolve("5df04c8b946ef9c1f31bf8e722a9262b512c1928");
>>
>> RevTree tree = rw.parseTree(treeId);
>> final TreeWalk walk = new TreeWalk(local);
>> walk.setRecursive(false);
>
> Here you have disabled recursive walking. This means the TreeWalk will
> only scan the top level tree, and will *not* dive into subdirectories.
5df04... is not a commit id but a tree id, which points to test/files/ in version b18bca3b853dee6a7bc... which I am also using for the forPath() method initialisation below
macbook:ruby-git gousiosg$ git ls-tree 5df04c8b946ef9c1f31bf8e722a9262b512c1928
100644 blob 3f1679d5fdccd9ea5a61bef7f964ee46617cb5c5 index
040000 tree 84b4d1f7f675ea752e9edcb5ff515f3c12602ec8 working.git
040000 tree e8bd03b163f82fba4560c11839d49361a78dec85 working
With the above piece of code I am starting a treewalk and rooting it to tree id 5df04... I actually copied this piece of code from JGit's CLI LsTree.java IIRC.
>> walk.addTree(tree);
>>
>> while (walk.next()) {
>> String pathstr = walk.getPathString();
>> if (pathstr.equals("working")) {
>
> Here you have matched an item in the top level tree that is named
> "working". This is *not* test/files/working, this is just plain old
> working. Which happens to be a TREE:
There is no "working" top level directory in the revision (b18bca3b...) I am working with. See
https://github.com/schacon/ruby-git/tree/b18bca3b853dee6a7bc86f09921aa3b1ee3f3d7b
>> assertEquals(a, FileMode.TREE);
>>
>> RevCommit c =
>> rw.parseCommit(local.resolve("b18bca3b853dee6a7bc86f09921aa3b1ee3f3d7b"));
>> TreeWalk tw = TreeWalk.forPath(local, "tests/files/working",
>> c.getTree());
>
> This is a file called "working", in the "files" subdirectory, of the
> "tests" subdirectory of the top level. Because you handed a path with
> / in it, TreeWalk.forPath setRecursive(true) automatically and was
> able to dive into the "tests" subdirectory when it was found, and then
> the "files" subdirectory, and then found "working" as a file and
> returned it.
It is actually a directory, see the git output above and this:
https://github.com/schacon/ruby-git/tree/b18bca3b853dee6a7bc86f09921aa3b1ee3f3d7b/tests/files
G