aboutsummaryrefslogtreecommitdiffstats
path: root/org.eclipse.jgit/src/org/eclipse
diff options
context:
space:
mode:
authorRobin Rosenberg <robin.rosenberg@dewire.com>2012-09-23 15:18:19 +0200
committerRobin Rosenberg <robin.rosenberg@dewire.com>2012-09-23 15:18:19 +0200
commit094df5a916db6060fa7f7d8c1f61cc0b970a9433 (patch)
treede195e4acbe03874e73b0130df05c74dab708b5b /org.eclipse.jgit/src/org/eclipse
parent78c865942849de420592bb822e9e1fd85cc95ade (diff)
downloadjgit-094df5a916db6060fa7f7d8c1f61cc0b970a9433.tar.gz
jgit-094df5a916db6060fa7f7d8c1f61cc0b970a9433.zip
Allow @ in branch names and tighten syntax checking
Valid refs are defined by git-check-ref-format(1). In addition we will not try to perform a lookup of an invalid ref name in Repository.resolve(). Reported by R Shapiro in the Eclipse JGit Forum. Change-Id: I0b098eec9ecb98a9ce16b1cfb476729aaf2fb190
Diffstat (limited to 'org.eclipse.jgit/src/org/eclipse')
-rw-r--r--org.eclipse.jgit/src/org/eclipse/jgit/lib/Repository.java40
1 files changed, 33 insertions, 7 deletions
diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/lib/Repository.java b/org.eclipse.jgit/src/org/eclipse/jgit/lib/Repository.java
index 16f8cdfef7..76f5378179 100644
--- a/org.eclipse.jgit/src/org/eclipse/jgit/lib/Repository.java
+++ b/org.eclipse.jgit/src/org/eclipse/jgit/lib/Repository.java
@@ -429,7 +429,12 @@ public abstract class Repository {
case '^':
if (rev == null) {
if (name == null)
- name = new String(revChars, done, i);
+ if (done == 0)
+ name = new String(revChars, done, i);
+ else {
+ done = i + 1;
+ break;
+ }
rev = parseSimple(rw, name);
name = null;
if (rev == null)
@@ -471,7 +476,7 @@ public abstract class Repository {
rev = commit.getParent(pnum - 1);
}
i = j - 1;
- done = i;
+ done = j;
break;
case '{':
int k;
@@ -512,7 +517,6 @@ public abstract class Repository {
} else
throw new IncorrectObjectTypeException(rev,
Constants.TYPE_COMMIT);
-
}
} else {
rev = rw.peel(rev);
@@ -526,11 +530,17 @@ public abstract class Repository {
throw new IncorrectObjectTypeException(rev,
Constants.TYPE_COMMIT);
}
+ done = i + 1;
break;
case '~':
if (rev == null) {
if (name == null)
- name = new String(revChars, done, i);
+ if (done == 0)
+ name = new String(revChars, done, i);
+ else {
+ done = i + 1;
+ break;
+ }
rev = parseSimple(rw, name);
name = null;
if (rev == null)
@@ -568,10 +578,13 @@ public abstract class Repository {
--dist;
}
i = l - 1;
+ done = l;
break;
case '@':
if (rev != null)
throw new RevisionSyntaxException(revstr);
+ if (i + 1 < revChars.length && revChars[i + 1] != '{')
+ continue;
int m;
String time = null;
for (m = i + 2; m < revChars.length; ++m) {
@@ -588,6 +601,8 @@ public abstract class Repository {
// Currently checked out branch, HEAD if
// detached
name = Constants.HEAD;
+ if (!Repository.isValidRefName("x/" + name))
+ throw new RevisionSyntaxException(revstr);
Ref ref = getRef(name);
name = null;
if (ref == null)
@@ -636,6 +651,8 @@ public abstract class Repository {
name = new String(revChars, done, i);
if (name.equals(""))
name = Constants.HEAD;
+ if (!Repository.isValidRefName("x/" + name))
+ throw new RevisionSyntaxException(revstr);
Ref ref = getRef(name);
name = null;
if (ref == null)
@@ -680,7 +697,11 @@ public abstract class Repository {
return rev.copy();
if (name != null)
return name;
+ if (rev == null && done == revstr.length())
+ return null;
name = revstr.substring(done);
+ if (!Repository.isValidRefName("x/" + name))
+ throw new RevisionSyntaxException(revstr);
if (getRef(name) != null)
return name;
return resolveSimple(name);
@@ -709,9 +730,11 @@ public abstract class Repository {
if (ObjectId.isId(revstr))
return ObjectId.fromString(revstr);
- Ref r = getRefDatabase().getRef(revstr);
- if (r != null)
- return r.getObjectId();
+ if (Repository.isValidRefName("x/" + revstr)) {
+ Ref r = getRefDatabase().getRef(revstr);
+ if (r != null)
+ return r.getObjectId();
+ }
if (AbbreviatedObjectId.isId(revstr))
return resolveAbbreviation(revstr);
@@ -1132,6 +1155,8 @@ public abstract class Repository {
case '/':
if (i == 0 || i == len - 1)
return false;
+ if (p == '/')
+ return false;
components++;
break;
case '{':
@@ -1141,6 +1166,7 @@ public abstract class Repository {
case '~': case '^': case ':':
case '?': case '[': case '*':
case '\\':
+ case '\u007F':
return false;
}
p = c;