-static int get_short_sha1(char *name, unsigned char *sha1)
-{
- int i;
- char canonical[40];
- unsigned char res[20];
-
- memset(res, 0, 20);
- memset(canonical, 'x', 40);
- for (i = 0;;i++) {
- unsigned char c = name[i];
- unsigned char val;
- if (!c || i > 40)
- break;
- if (c >= '0' && c <= '9')
- val = c - '0';
- else if (c >= 'a' && c <= 'f')
- val = c - 'a' + 10;
- else if (c >= 'A' && c <='F') {
- val = c - 'A' + 10;
- c -= 'A' - 'a';
- }
- else
- return -1;
- canonical[i] = c;
- if (!(i & 1))
- val <<= 4;
- res[i >> 1] |= val;
- }
- if (i < 4)
- return -1;
- if (find_short_object_filename(i, canonical, sha1))
- return 0;
- if (find_short_packed_object(i, res, sha1))
- return 0;
- return -1;
-}
-
-/*
- * This is like "get_sha1()", except it allows "sha1 expressions",
- * notably "xyz^" for "parent of xyz"
- */
-static int get_extended_sha1(char *name, unsigned char *sha1)
-{
- int parent, ret;
- int len = strlen(name);
-
- parent = 1;
- if (len > 2 && name[len-1] >= '0' && name[len-1] <= '9') {
- parent = name[len-1] - '0';
- len--;
- }
- if (len > 1 && name[len-1] == '^') {
- name[len-1] = 0;
- ret = get_parent(name, sha1, parent);
- name[len-1] = '^';
- if (!ret)
- return 0;
- }
- ret = get_sha1(name, sha1);
- if (!ret)
- return 0;
- return get_short_sha1(name, sha1);
-}
-
-static void show_default(void)