+ if (found == 1)
+ memcpy(sha1, found_sha1, 20);
+ return found;
+}
+
+#define SHORT_NAME_NOT_FOUND (-1)
+#define SHORT_NAME_AMBIGUOUS (-2)
+
+static int find_unique_short_object(int len, char *canonical,
+ unsigned char *res, unsigned char *sha1)
+{
+ int has_unpacked, has_packed;
+ unsigned char unpacked_sha1[20], packed_sha1[20];
+
+ has_unpacked = find_short_object_filename(len, canonical, unpacked_sha1);
+ has_packed = find_short_packed_object(len, res, packed_sha1);
+ if (!has_unpacked && !has_packed)
+ return SHORT_NAME_NOT_FOUND;
+ if (1 < has_unpacked || 1 < has_packed)
+ return SHORT_NAME_AMBIGUOUS;
+ if (has_unpacked != has_packed) {
+ memcpy(sha1, (has_packed ? packed_sha1 : unpacked_sha1), 20);
+ return 0;
+ }
+ /* Both have unique ones -- do they match? */
+ if (memcmp(packed_sha1, unpacked_sha1, 20))
+ return SHORT_NAME_AMBIGUOUS;
+ memcpy(sha1, packed_sha1, 20);