Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
[jgit-dev] Re: synchronize patches

Matthias Sohn <matthias.sohn@xxxxxxxxxxxxxx> wrote:
> 2010/7/7 Dariusz Luksza <dariusz.luksza@xxxxxxxxx>
> 
> > On Wed, Jul 7, 2010 at 12:44 AM, Dariusz Luksza
> > <dariusz.luksza@xxxxxxxxx> wrote:
> > > On Wed, Jul 7, 2010 at 12:32 AM, Matthias Sohn
> > > <matthias.sohn@xxxxxxxxxxxxxx> wrote:
> > >> Another hint: I saw you are using Tree in some places, Shawn mentioned
> > >> here
> > http://egit.eclipse.org/r/#patch,unified,825,4,org.eclipse.jgit/src/org/eclipse/jgit/dircache/DirCacheCheckout.java
> > >> that we want to get rid of Tree, according to Shawn instead RevTree
> > should
> > >> be used.
> > >
> > > Thanks, I'll change it.
> >
> > Migration from Tree to RevTree wouldn't be so easy as I think of it.
> > These two classes has different inheritance tree and API eg. in
> > RevTree there are no methods that allows me to check and obtain child
> > blob or tree.
> >
> 
> Shawn could you provide some hints here ?

Right, so a RevTree has no information about the contents of
the tree.  It just knows the ObjectId of it, and also can track
some flags that we use during the various graph coloring algorithms.

With a RevTree the only way to see its contents is to use a TreeWalk
and iterate through it:

  RevTree theTree = ...;
  TreeWalk tw = new TreeWalk(repository);
  tw.reset();
  tw.addTree(theTree);

  while (tw.next())
    ... use the current entry ...

If you need a single specific name, you can use TreeWalk.forPath()
to make the TreeWalk and have it jump to the target path.  If you
need just a couple of names, you can make your own TreeWalk and
set a PathFilterGroup with setFilter.


Long story short, Tree is incredibly slow compared to TreeWalk.

Dealing with findBlob vs. findTree is messy, and leads to tons of
confusing code.  And you have to do all of the join logic yourself
when there are multiple trees involved at once.  TreeWalk solves
all of that, and magically provides D/F detection (when required)
with NameConflictTreeWalk.

DirCache is slower for editing a single tree than Tree is, but it
has a lot more power, so I'm somewhat willing to make the tradeoff
there, as writing is somewhat less frequent than reading.

Tree and its realted classes are on my list of things-that-must-die.

-- 
Shawn.


Back to the top