-struct seen {
- unsigned char sha1[20];
- char tag[10];
- unsigned needed;
-};
-
-static struct needs *needs;
-static struct seen *seen;
-
-static int nr_seen, alloc_seen, nr_needs, alloc_needs;
-
-/*
- * These two functions build up a graph in memory about
- * what objects we've referenced, and found, and types..
- */
-static int compare_seen(const void *s1, const void *s2)
-{
- return memcmp(s1, s2, 20);
-}
-
-static int lookup_seen(unsigned char *sha1, char *tag)
-{
- int first = 0, last = nr_seen;
-
- while (last > first) {
- int next = (last + first) / 2;
- struct seen *s = seen + next;
- int cmp = memcmp(sha1, s->sha1, 20);
-
- if (cmp < 0) {
- last = next;
- continue;
- }
- if (cmp > 0) {
- first = next+1;
- continue;
- }
- if (strcmp(tag, s->tag))
- break;
- s->needed++;
- return 1;
- }
- return 0;
-}