use of org.eclipse.jgit.revwalk.RevTag in project gitiles by GerritCodeReview.
the class RevisionParser method parse.
Result parse(String path) throws IOException {
if (path.startsWith("/")) {
path = path.substring(1);
}
try (RevWalk walk = new RevWalk(repo)) {
Revision oldRevision = null;
StringBuilder b = new StringBuilder();
boolean first = true;
for (String part : PathUtil.SPLITTER.split(path)) {
if (part.isEmpty()) {
// No valid revision contains empty segments.
return null;
}
if (!first) {
b.append('/');
}
if (oldRevision == null) {
int dots = part.indexOf("..");
int firstParent = part.indexOf("^!");
if (dots == 0 || firstParent == 0) {
return null;
} else if (dots > 0) {
b.append(part, 0, dots);
String oldName = b.toString();
if (!isValidRevision(oldName)) {
return null;
}
RevObject old = resolve(oldName, walk);
if (old == null) {
return null;
}
oldRevision = Revision.peel(oldName, old, walk);
part = part.substring(dots + 2);
b = new StringBuilder();
} else if (firstParent > 0) {
if (firstParent != part.length() - 2) {
return null;
}
b.append(part, 0, part.length() - 2);
String name = b.toString();
if (!isValidRevision(name)) {
return null;
}
RevObject obj = resolve(name, walk);
if (obj == null) {
return null;
}
while (obj instanceof RevTag) {
obj = ((RevTag) obj).getObject();
walk.parseHeaders(obj);
}
if (!(obj instanceof RevCommit)) {
// Not a commit, ^! is invalid.
return null;
}
RevCommit c = (RevCommit) obj;
if (c.getParentCount() > 0) {
oldRevision = Revision.peeled(name + "^", c.getParent(0));
} else {
oldRevision = Revision.NULL;
}
Result result = new Result(Revision.peeled(name, c), oldRevision, path.substring(name.length() + 2));
return isVisible(walk, result) ? result : null;
}
}
b.append(part);
String name = b.toString();
if (!isValidRevision(name)) {
return null;
}
RevObject obj = resolve(name, walk);
if (obj != null) {
int pathStart;
if (oldRevision == null) {
// foo
pathStart = name.length();
} else {
// foo..bar (foo may be empty)
pathStart = oldRevision.getName().length() + 2 + name.length();
}
Result result = new Result(Revision.peel(name, obj, walk), oldRevision, path.substring(pathStart));
return isVisible(walk, result) ? result : null;
}
first = false;
}
return null;
}
}
use of org.eclipse.jgit.revwalk.RevTag in project gitiles by GerritCodeReview.
the class TimeCache method getTime.
Long getTime(final RevWalk walk, final ObjectId id) throws IOException {
try {
return cache.get(id, () -> {
RevObject o = walk.parseAny(id);
while (o instanceof RevTag) {
RevTag tag = (RevTag) o;
PersonIdent ident = tag.getTaggerIdent();
if (ident != null) {
return ident.getWhen().getTime() / 1000;
}
o = tag.getObject();
walk.parseHeaders(o);
}
if (o.getType() == Constants.OBJ_COMMIT) {
return Long.valueOf(((RevCommit) o).getCommitTime());
}
return Long.MIN_VALUE;
});
} catch (ExecutionException e) {
Throwables.throwIfInstanceOf(e.getCause(), IOException.class);
throw new IOException(e);
}
}
use of org.eclipse.jgit.revwalk.RevTag in project gerrit by GerritCodeReview.
the class ListTags method createTagInfo.
public static TagInfo createTagInfo(PermissionBackend.ForRef perm, Ref ref, RevWalk rw) throws MissingObjectException, IOException {
RevObject object = rw.parseAny(ref.getObjectId());
boolean canDelete = perm.testOrFalse(RefPermission.DELETE);
if (object instanceof RevTag) {
// Annotated or signed tag
RevTag tag = (RevTag) object;
PersonIdent tagger = tag.getTaggerIdent();
return new TagInfo(ref.getName(), tag.getName(), tag.getObject().getName(), tag.getFullMessage().trim(), tagger != null ? CommonConverters.toGitPerson(tag.getTaggerIdent()) : null, canDelete);
}
// Lightweight tag
return new TagInfo(ref.getName(), ref.getObjectId().getName(), canDelete);
}
use of org.eclipse.jgit.revwalk.RevTag in project gitiles by GerritCodeReview.
the class RevisionParserTest method parseTag.
@Test
public void parseTag() throws Exception {
RevCommit master = repo.branch("master").commit().create();
RevTag masterTag = repo.update("refs/tags/master-tag", repo.tag("master-tag", master));
RevTag masterTagTag = repo.update("refs/tags/master-tag-tag", repo.tag("master-tag-tag", master));
assertThat(parser.parse("master-tag")).isEqualTo(new Result(new Revision("master-tag", masterTag, OBJ_TAG, master, OBJ_COMMIT)));
assertThat(parser.parse("master-tag-tag")).isEqualTo(new Result(new Revision("master-tag-tag", masterTagTag, OBJ_TAG, master, OBJ_COMMIT)));
RevBlob blob = repo.update("refs/tags/blob", repo.blob("blob"));
RevTag blobTag = repo.update("refs/tags/blob-tag", repo.tag("blob-tag", blob));
assertThat(parser.parse("blob")).isEqualTo(new Result(Revision.peeled("blob", blob)));
assertThat(parser.parse("blob-tag")).isEqualTo(new Result(new Revision("blob-tag", blobTag, OBJ_TAG, blob, OBJ_BLOB)));
}
use of org.eclipse.jgit.revwalk.RevTag in project gitiles by GerritCodeReview.
the class TimeCacheTest method taggedTagTime.
@Test
public void taggedTagTime() throws Exception {
repo.tick(2);
RevTag tag = repo.tag("tag", repo.commit().create());
repo.tick(-1);
RevTag tagTag = repo.tag("tagtag", tag);
assertThat(getTime(tag)).isEqualTo(start + 3);
assertThat(getTime(tagTag)).isEqualTo(start + 2);
}
Aggregations