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>
Junio C Hamano committed
Feb 2, 2006 at 23:48 UTC
0601dbe1784901a43289ff1575d3b8db33a191e1
1 file changed
+16
-23
sha1_name.c
+16
-23
@@ -388,43 +388,36 @@ static int peel_onion(const char *name, int len, unsigned char *sha1)
388
389
static int get_sha1_1(const char *name, int len, unsigned char *sha1)
390
{
391
- int parent, ret;
391
+ int ret, has_suffix;
392
const char *cp;
393
394
- /* foo^[0-9] or foo^ (== foo^1); we do not do more than 9 parents. */
395
- if (len > 2 && name[len-2] == '^' &&
396
- name[len-1] >= '0' && name[len-1] <= '9') {
397
- parent = name[len-1] - '0';
398
- len -= 2;
399
- }
400
- else if (len > 1 && name[len-1] == '^') {
401
- parent = 1;
402
- len--;
403
- } else
404
- parent = -1;
405
-
406
- if (parent >= 0)
407
- return get_parent(name, len, sha1, parent);
408
-
394
/* "name~3" is "name^^^",
410
- * "name~12" is "name^^^^^^^^^^^^", and
395
* "name~" and "name~0" are name -- not "name^0"!
396
+ * "name^" is not "name^0"; it is "name^1".
397
*/
413
- parent = 0;
398
+ has_suffix = 0;
399
for (cp = name + len - 1; name <= cp; cp--) {
400
int ch = *cp;
401
if ('0' <= ch && ch <= '9')
402
continue;
418
- if (ch != '~')
419
- parent = -1;
403
+ if (ch == '~' || ch == '^')
404
+ has_suffix = ch;
405
break;
406
}
422
- if (!parent && *cp == '~') {
407
+
408
+ if (has_suffix) {
409
+ int num = 0;
410
int len1 = cp - name;
411
cp++;
412
while (cp < name + len)
426
- parent = parent * 10 + *cp++ - '0';
427
- return get_nth_ancestor(name, len1, sha1, parent);
413
+ num = num * 10 + *cp++ - '0';
414
+ if (has_suffix == '^') {
415
+ if (!num && len1 == len - 1)
416
+ num = 1;
417
+ return get_parent(name, len1, sha1, num);
418
+ }
419
+ /* else if (has_suffix == '~') -- goes without saying */
420
+ return get_nth_ancestor(name, len1, sha1, num);
421
}
422
423
ret = peel_onion(name, len, sha1);