ids)
throws MissingObjectException, JGitInternalException {
for (ObjectId id : ids)
add(id);
return this;
}
/**
* Add a ref prefix to the set that results must match.
*
* If an object matches multiple refs equally well, the first matching ref
* added with {@link #addRef(Ref)} is preferred, or else the first matching
* prefix added by {@link #addPrefix(String)}.
*
* @param prefix
* prefix to add; see {@link RefDatabase#getRefs(String)}
* @return {@code this}
*/
public NameRevCommand addPrefix(String prefix) {
checkCallable();
prefixes.add(prefix);
return this;
}
/**
* Add all annotated tags under {@code refs/tags/} to the set that all results
* must match.
*
* Calls {@link #addRef(Ref)}; see that method for a note on matching
* priority.
*
* @return {@code this}
* @throws JGitInternalException
* a low-level exception of JGit has occurred. The original
* exception can be retrieved by calling
* {@link Exception#getCause()}.
*/
public NameRevCommand addAnnotatedTags() {
checkCallable();
if (refs == null)
refs = new ArrayList<>();
try {
for (Ref ref : repo.getRefDatabase().getRefs(Constants.R_TAGS).values()) {
ObjectId id = ref.getObjectId();
if (id != null && (walk.parseAny(id) instanceof RevTag))
addRef(ref);
}
} catch (IOException e) {
throw new JGitInternalException(e.getMessage(), e);
}
return this;
}
/**
* Add a ref to the set that all results must match.
*
* If an object matches multiple refs equally well, the first matching ref
* added with {@link #addRef(Ref)} is preferred, or else the first matching
* prefix added by {@link #addPrefix(String)}.
*
* @param ref
* ref to add.
* @return {@code this}
*/
public NameRevCommand addRef(Ref ref) {
checkCallable();
if (refs == null)
refs = new ArrayList<>();
refs.add(ref);
return this;
}
NameRevCommand setMergeCost(int cost) {
mergeCost = cost;
return this;
}
private void addPrefixes(Map nonCommits,
FIFORevQueue pending) throws IOException {
if (!prefixes.isEmpty()) {
for (String prefix : prefixes)
addPrefix(prefix, nonCommits, pending);
} else if (refs == null)
addPrefix(Constants.R_REFS, nonCommits, pending);
}
private void addPrefix(String prefix, Map nonCommits,
FIFORevQueue pending) throws IOException {
for (Ref ref : repo.getRefDatabase().getRefs(prefix).values())
addRef(ref, nonCommits, pending);
}
private void addRef(Ref ref, Map nonCommits,
FIFORevQueue pending) throws IOException {
if (ref.getObjectId() == null)
return;
RevObject o = walk.parseAny(ref.getObjectId());
while (o instanceof RevTag) {
RevTag t = (RevTag) o;
nonCommits.put(o, ref.getName());
o = t.getObject();
walk.parseHeaders(o);
}
if (o instanceof NameRevCommit) {
NameRevCommit c = (NameRevCommit) o;
if (c.tip == null)
c.tip = ref.getName();
pending.add(c);
} else if (!nonCommits.containsKey(o))
nonCommits.put(o, ref.getName());
}
private int minCommitTime() throws IOException {
int min = Integer.MAX_VALUE;
for (ObjectId id : revs) {
RevObject o = walk.parseAny(id);
while (o instanceof RevTag) {
o = ((RevTag) o).getObject();
walk.parseHeaders(o);
}
if (o instanceof RevCommit) {
RevCommit c = (RevCommit) o;
if (c.getCommitTime() < min)
min = c.getCommitTime();
}
}
return min;
}
private long compare(String leftTip, long leftCost, String rightTip, long rightCost) {
long c = leftCost - rightCost;
if (c != 0 || prefixes.isEmpty())
return c;
int li = -1;
int ri = -1;
for (int i = 0; i < prefixes.size(); i++) {
String prefix = prefixes.get(i);
if (li < 0 && leftTip.startsWith(prefix))
li = i;
if (ri < 0 && rightTip.startsWith(prefix))
ri = i;
}
// Don't tiebreak if prefixes are the same, in order to prefer first-parent
// paths.
return li - ri;
}
private static String simplify(String refName) {
if (refName.startsWith(Constants.R_HEADS))
return refName.substring(Constants.R_HEADS.length());
if (refName.startsWith(Constants.R_TAGS))
return refName.substring(Constants.R_TAGS.length());
if (refName.startsWith(Constants.R_REFS))
return refName.substring(Constants.R_REFS.length());
return refName;
}
}