summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJunio C Hamano <junkio@cox.net>2006-02-03 07:48:36 (GMT)
committerJunio C Hamano <junkio@cox.net>2006-02-03 07:49:44 (GMT)
commit0601dbe1784901a43289ff1575d3b8db33a191e1 (patch)
treecc8dadcf4d7aa1b3f97138f88e7714dbf9c55e3f
parent46dc941246af6e845eb7835afdb8cd20eed835b7 (diff)
downloadgit-0601dbe1784901a43289ff1575d3b8db33a191e1.zip
git-0601dbe1784901a43289ff1575d3b8db33a191e1.tar.gz
git-0601dbe1784901a43289ff1575d3b8db33a191e1.tar.bz2
get_sha1_1: allow octopus^12 to be properly parsed.
We probably thought anybody who does more than 9 parents in an Octopus is insane when this was initially done, but there is no inherent reason to limit the number of independent topic branches that happen to mature at the same time. Our commit-tree allows up to 16 already, so at least we should prepare to handle what we can produce, if only to be consistent. Signed-off-by: Junio C Hamano <junkio@cox.net>
-rw-r--r--sha1_name.c39
1 files changed, 16 insertions, 23 deletions
diff --git a/sha1_name.c b/sha1_name.c
index ba0747c..fa85d8a 100644
--- a/sha1_name.c
+++ b/sha1_name.c
@@ -388,43 +388,36 @@ static int peel_onion(const char *name, int len, unsigned char *sha1)
static int get_sha1_1(const char *name, int len, unsigned char *sha1)
{
- int parent, ret;
+ int ret, has_suffix;
const char *cp;
- /* foo^[0-9] or foo^ (== foo^1); we do not do more than 9 parents. */
- if (len > 2 && name[len-2] == '^' &&
- name[len-1] >= '0' && name[len-1] <= '9') {
- parent = name[len-1] - '0';
- len -= 2;
- }
- else if (len > 1 && name[len-1] == '^') {
- parent = 1;
- len--;
- } else
- parent = -1;
-
- if (parent >= 0)
- return get_parent(name, len, sha1, parent);
-
/* "name~3" is "name^^^",
- * "name~12" is "name^^^^^^^^^^^^", and
* "name~" and "name~0" are name -- not "name^0"!
+ * "name^" is not "name^0"; it is "name^1".
*/
- parent = 0;
+ has_suffix = 0;
for (cp = name + len - 1; name <= cp; cp--) {
int ch = *cp;
if ('0' <= ch && ch <= '9')
continue;
- if (ch != '~')
- parent = -1;
+ if (ch == '~' || ch == '^')
+ has_suffix = ch;
break;
}
- if (!parent && *cp == '~') {
+
+ if (has_suffix) {
+ int num = 0;
int len1 = cp - name;
cp++;
while (cp < name + len)
- parent = parent * 10 + *cp++ - '0';
- return get_nth_ancestor(name, len1, sha1, parent);
+ num = num * 10 + *cp++ - '0';
+ if (has_suffix == '^') {
+ if (!num && len1 == len - 1)
+ num = 1;
+ return get_parent(name, len1, sha1, num);
+ }
+ /* else if (has_suffix == '~') -- goes without saying */
+ return get_nth_ancestor(name, len1, sha1, num);
}
ret = peel_onion(name, len, sha1);