Merge "RevWalk: Avoid unnecessary re-parsing of commit bodies"

This commit is contained in:
Chris Aniszczyk 2011-02-14 18:14:59 -05:00 committed by Code Review
commit cb2a22a9a5
13 changed files with 121 additions and 2 deletions

View File

@ -312,5 +312,10 @@ public boolean include(RevWalk walker, RevCommit cmit)
IncorrectObjectTypeException, IOException { IncorrectObjectTypeException, IOException {
return true; return true;
} }
@Override
public boolean requiresCommitBody() {
return false;
}
} }
} }

View File

@ -81,6 +81,10 @@ public RevFilter clone() {
return this; return this;
} }
@Override
public boolean requiresCommitBody() {
return true;
}
}; };
// Do an initial run through the walk // Do an initial run through the walk

View File

@ -136,7 +136,8 @@ RevCommit next() throws MissingObjectException,
if ((c.flags & UNINTERESTING) != 0) if ((c.flags & UNINTERESTING) != 0)
produce = false; produce = false;
else { else {
c.parseBody(walker); if (filter.requiresCommitBody())
c.parseBody(walker);
produce = filter.include(walker, c); produce = filter.include(walker, c);
} }

View File

@ -230,6 +230,11 @@ public boolean include(final RevWalk walker, final RevCommit c)
return false; return false;
} }
@Override
public boolean requiresCommitBody() {
return false;
}
private void updateFollowFilter(ObjectId[] trees) private void updateFollowFilter(ObjectId[] trees)
throws MissingObjectException, IncorrectObjectTypeException, throws MissingObjectException, IncorrectObjectTypeException,
CorruptObjectException, IOException { CorruptObjectException, IOException {

View File

@ -120,9 +120,13 @@ private static class Binary extends AndRevFilter {
private final RevFilter b; private final RevFilter b;
private final boolean requiresCommitBody;
Binary(final RevFilter one, final RevFilter two) { Binary(final RevFilter one, final RevFilter two) {
a = one; a = one;
b = two; b = two;
requiresCommitBody = a.requiresCommitBody()
|| b.requiresCommitBody();
} }
@Override @Override
@ -132,6 +136,11 @@ public boolean include(final RevWalk walker, final RevCommit c)
return a.include(walker, c) && b.include(walker, c); return a.include(walker, c) && b.include(walker, c);
} }
@Override
public boolean requiresCommitBody() {
return requiresCommitBody;
}
@Override @Override
public RevFilter clone() { public RevFilter clone() {
return new Binary(a.clone(), b.clone()); return new Binary(a.clone(), b.clone());
@ -146,8 +155,15 @@ public String toString() {
private static class List extends AndRevFilter { private static class List extends AndRevFilter {
private final RevFilter[] subfilters; private final RevFilter[] subfilters;
private final boolean requiresCommitBody;
List(final RevFilter[] list) { List(final RevFilter[] list) {
subfilters = list; subfilters = list;
boolean rcb = false;
for (RevFilter filter : subfilters)
rcb |= filter.requiresCommitBody();
requiresCommitBody = rcb;
} }
@Override @Override
@ -161,6 +177,11 @@ public boolean include(final RevWalk walker, final RevCommit c)
return true; return true;
} }
@Override
public boolean requiresCommitBody() {
return requiresCommitBody;
}
@Override @Override
public RevFilter clone() { public RevFilter clone() {
final RevFilter[] s = new RevFilter[subfilters.length]; final RevFilter[] s = new RevFilter[subfilters.length];

View File

@ -134,6 +134,11 @@ public RevFilter clone() {
return this; return this;
} }
@Override
public boolean requiresCommitBody() {
return false;
}
private static class Before extends CommitTimeRevFilter { private static class Before extends CommitTimeRevFilter {
Before(final long ts) { Before(final long ts) {
super(ts); super(ts);

View File

@ -81,6 +81,11 @@ public boolean include(final RevWalk walker, final RevCommit c)
return !a.include(walker, c); return !a.include(walker, c);
} }
@Override
public boolean requiresCommitBody() {
return a.requiresCommitBody();
}
@Override @Override
public RevFilter clone() { public RevFilter clone() {
return new NotRevFilter(a.clone()); return new NotRevFilter(a.clone());

View File

@ -118,9 +118,13 @@ private static class Binary extends OrRevFilter {
private final RevFilter b; private final RevFilter b;
private final boolean requiresCommitBody;
Binary(final RevFilter one, final RevFilter two) { Binary(final RevFilter one, final RevFilter two) {
a = one; a = one;
b = two; b = two;
requiresCommitBody = a.requiresCommitBody()
|| b.requiresCommitBody();
} }
@Override @Override
@ -130,6 +134,11 @@ public boolean include(final RevWalk walker, final RevCommit c)
return a.include(walker, c) || b.include(walker, c); return a.include(walker, c) || b.include(walker, c);
} }
@Override
public boolean requiresCommitBody() {
return requiresCommitBody;
}
@Override @Override
public RevFilter clone() { public RevFilter clone() {
return new Binary(a.clone(), b.clone()); return new Binary(a.clone(), b.clone());
@ -144,8 +153,15 @@ public String toString() {
private static class List extends OrRevFilter { private static class List extends OrRevFilter {
private final RevFilter[] subfilters; private final RevFilter[] subfilters;
private final boolean requiresCommitBody;
List(final RevFilter[] list) { List(final RevFilter[] list) {
subfilters = list; subfilters = list;
boolean rcb = false;
for (RevFilter filter : subfilters)
rcb |= filter.requiresCommitBody();
requiresCommitBody = rcb;
} }
@Override @Override
@ -159,6 +175,11 @@ public boolean include(final RevWalk walker, final RevCommit c)
return false; return false;
} }
@Override
public boolean requiresCommitBody() {
return requiresCommitBody;
}
@Override @Override
public RevFilter clone() { public RevFilter clone() {
final RevFilter[] s = new RevFilter[subfilters.length]; final RevFilter[] s = new RevFilter[subfilters.length];

View File

@ -131,6 +131,11 @@ public boolean include(final RevWalk walker, final RevCommit cmit)
return compiledPattern.reset(text(cmit)).matches(); return compiledPattern.reset(text(cmit)).matches();
} }
@Override
public boolean requiresCommitBody() {
return true;
}
/** /**
* Obtain the raw text to match against. * Obtain the raw text to match against.
* *

View File

@ -107,6 +107,11 @@ public RevFilter clone() {
return this; return this;
} }
@Override
public boolean requiresCommitBody() {
return false;
}
@Override @Override
public String toString() { public String toString() {
return "ALL"; return "ALL";
@ -127,6 +132,11 @@ public RevFilter clone() {
return this; return this;
} }
@Override
public boolean requiresCommitBody() {
return false;
}
@Override @Override
public String toString() { public String toString() {
return "NONE"; return "NONE";
@ -147,6 +157,11 @@ public RevFilter clone() {
return this; return this;
} }
@Override
public boolean requiresCommitBody() {
return false;
}
@Override @Override
public String toString() { public String toString() {
return "NO_MERGES"; return "NO_MERGES";
@ -174,6 +189,11 @@ public RevFilter clone() {
return this; return this;
} }
@Override
public boolean requiresCommitBody() {
return false;
}
@Override @Override
public String toString() { public String toString() {
return "MERGE_BASE"; return "MERGE_BASE";
@ -189,6 +209,12 @@ public RevFilter negate() {
return NotRevFilter.create(this); return NotRevFilter.create(this);
} }
/** @return true if the filter needs the commit body to be parsed. */
public boolean requiresCommitBody() {
// Assume true to be backward compatible with prior behavior.
return true;
}
/** /**
* Determine if the supplied commit should be included in results. * Determine if the supplied commit should be included in results.
* *
@ -196,7 +222,8 @@ public RevFilter negate() {
* the active walker this filter is being invoked from within. * the active walker this filter is being invoked from within.
* @param cmit * @param cmit
* the commit currently being tested. The commit has been parsed * the commit currently being tested. The commit has been parsed
* and its body is available for inspection. * and its body is available for inspection only if the filter
* returns true from {@link #requiresCommitBody()}.
* @return true to include this commit in the results; false to have this * @return true to include this commit in the results; false to have this
* commit be omitted entirely from the results. * commit be omitted entirely from the results.
* @throws StopWalkException * @throws StopWalkException

View File

@ -144,6 +144,11 @@ public boolean include(final RevWalk walker, final RevCommit c)
IOException { IOException {
return c.hasAll(flags); return c.hasAll(flags);
} }
@Override
public boolean requiresCommitBody() {
return false;
}
} }
private static class HasAny extends RevFlagFilter { private static class HasAny extends RevFlagFilter {
@ -157,5 +162,10 @@ public boolean include(final RevWalk walker, final RevCommit c)
IOException { IOException {
return c.hasAny(flags); return c.hasAny(flags);
} }
@Override
public boolean requiresCommitBody() {
return false;
}
} }
} }

View File

@ -104,6 +104,11 @@ public boolean include(final RevWalk walker, final RevCommit cmit)
return pattern.match(text(cmit)) >= 0; return pattern.match(text(cmit)) >= 0;
} }
@Override
public boolean requiresCommitBody() {
return true;
}
/** /**
* Obtain the raw text to match against. * Obtain the raw text to match against.
* *

View File

@ -599,6 +599,11 @@ public boolean include(final RevWalk walker, final RevCommit c) {
} }
return !remoteKnowsIsCommon; return !remoteKnowsIsCommon;
} }
@Override
public boolean requiresCommitBody() {
return false;
}
}); });
} }