RevWalkUtils: add progress callback to findBranchesReachableFrom
Offer a version of findBranchesReachableFrom method with progress monitor callback. This is required to allow UI clients to cancel long running operations and show progress. Bug: 547642 Change-Id: I31d1de54dbaa6ffb11e03da4c447963e8defa1d0 Signed-off-by: Andrey Loskutov <loskutov@gmx.de>
This commit is contained in:
parent
76c867d62a
commit
e57a37e767
|
@ -625,6 +625,7 @@ rewinding=Rewinding to commit {0}
|
||||||
s3ActionDeletion=Deletion
|
s3ActionDeletion=Deletion
|
||||||
s3ActionReading=Reading
|
s3ActionReading=Reading
|
||||||
s3ActionWriting=Writing
|
s3ActionWriting=Writing
|
||||||
|
searchForReachableBranches=Finding reachable branches
|
||||||
searchForReuse=Finding sources
|
searchForReuse=Finding sources
|
||||||
searchForSizes=Getting sizes
|
searchForSizes=Getting sizes
|
||||||
secondsAgo={0} seconds ago
|
secondsAgo={0} seconds ago
|
||||||
|
|
|
@ -686,6 +686,7 @@ public static JGitText get() {
|
||||||
/***/ public String s3ActionDeletion;
|
/***/ public String s3ActionDeletion;
|
||||||
/***/ public String s3ActionReading;
|
/***/ public String s3ActionReading;
|
||||||
/***/ public String s3ActionWriting;
|
/***/ public String s3ActionWriting;
|
||||||
|
/***/ public String searchForReachableBranches;
|
||||||
/***/ public String searchForReuse;
|
/***/ public String searchForReuse;
|
||||||
/***/ public String searchForSizes;
|
/***/ public String searchForSizes;
|
||||||
/***/ public String secondsAgo;
|
/***/ public String secondsAgo;
|
||||||
|
|
|
@ -50,6 +50,9 @@
|
||||||
|
|
||||||
import org.eclipse.jgit.errors.IncorrectObjectTypeException;
|
import org.eclipse.jgit.errors.IncorrectObjectTypeException;
|
||||||
import org.eclipse.jgit.errors.MissingObjectException;
|
import org.eclipse.jgit.errors.MissingObjectException;
|
||||||
|
import org.eclipse.jgit.internal.JGitText;
|
||||||
|
import org.eclipse.jgit.lib.NullProgressMonitor;
|
||||||
|
import org.eclipse.jgit.lib.ProgressMonitor;
|
||||||
import org.eclipse.jgit.lib.Ref;
|
import org.eclipse.jgit.lib.Ref;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -153,15 +156,51 @@ public static List<Ref> findBranchesReachableFrom(RevCommit commit,
|
||||||
RevWalk revWalk, Collection<Ref> refs)
|
RevWalk revWalk, Collection<Ref> refs)
|
||||||
throws MissingObjectException, IncorrectObjectTypeException,
|
throws MissingObjectException, IncorrectObjectTypeException,
|
||||||
IOException {
|
IOException {
|
||||||
|
return findBranchesReachableFrom(commit, revWalk, refs,
|
||||||
|
NullProgressMonitor.INSTANCE);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Find the list of branches a given commit is reachable from when following
|
||||||
|
* parents.
|
||||||
|
* <p>
|
||||||
|
* Note that this method calls
|
||||||
|
* {@link org.eclipse.jgit.revwalk.RevWalk#reset()} at the beginning.
|
||||||
|
* <p>
|
||||||
|
* In order to improve performance this method assumes clock skew among
|
||||||
|
* committers is never larger than 24 hours.
|
||||||
|
*
|
||||||
|
* @param commit
|
||||||
|
* the commit we are looking at
|
||||||
|
* @param revWalk
|
||||||
|
* The RevWalk to be used.
|
||||||
|
* @param refs
|
||||||
|
* the set of branches we want to see reachability from
|
||||||
|
* @param monitor
|
||||||
|
* the callback for progress and cancellation
|
||||||
|
* @return the list of branches a given commit is reachable from
|
||||||
|
* @throws org.eclipse.jgit.errors.MissingObjectException
|
||||||
|
* @throws org.eclipse.jgit.errors.IncorrectObjectTypeException
|
||||||
|
* @throws java.io.IOException
|
||||||
|
* @since 5.4
|
||||||
|
*/
|
||||||
|
public static List<Ref> findBranchesReachableFrom(RevCommit commit,
|
||||||
|
RevWalk revWalk, Collection<Ref> refs, ProgressMonitor monitor)
|
||||||
|
throws MissingObjectException, IncorrectObjectTypeException,
|
||||||
|
IOException {
|
||||||
|
|
||||||
// Make sure commit is from the same RevWalk
|
// Make sure commit is from the same RevWalk
|
||||||
commit = revWalk.parseCommit(commit.getId());
|
commit = revWalk.parseCommit(commit.getId());
|
||||||
revWalk.reset();
|
revWalk.reset();
|
||||||
List<Ref> result = new ArrayList<>();
|
List<Ref> result = new ArrayList<>();
|
||||||
|
monitor.beginTask(JGitText.get().searchForReachableBranches,
|
||||||
|
refs.size());
|
||||||
final int SKEW = 24*3600; // one day clock skew
|
final int SKEW = 24*3600; // one day clock skew
|
||||||
|
|
||||||
for (Ref ref : refs) {
|
for (Ref ref : refs) {
|
||||||
|
if (monitor.isCancelled())
|
||||||
|
return result;
|
||||||
|
monitor.update(1);
|
||||||
RevObject maybehead = revWalk.parseAny(ref.getObjectId());
|
RevObject maybehead = revWalk.parseAny(ref.getObjectId());
|
||||||
if (!(maybehead instanceof RevCommit))
|
if (!(maybehead instanceof RevCommit))
|
||||||
continue;
|
continue;
|
||||||
|
@ -176,6 +215,7 @@ public static List<Ref> findBranchesReachableFrom(RevCommit commit,
|
||||||
if (revWalk.isMergedInto(commit, headCommit))
|
if (revWalk.isMergedInto(commit, headCommit))
|
||||||
result.add(ref);
|
result.add(ref);
|
||||||
}
|
}
|
||||||
|
monitor.endTask();
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue