static struct ref_list *get_packed_refs(const char *submodule) { const char *packed_refs_file; struct cached_refs *refs; if (submodule) { packed_refs_file = git_path_submodule(submodule, "packed-refs"); refs = &submodule_refs; free_ref_list(refs->packed); } else { packed_refs_file = git_path("packed-refs"); refs = &cached_refs; } if (!refs->did_packed || submodule) { printf("Openning %s\n", packed_refs_file); FILE *f = fopen(packed_refs_file, "r"); refs->packed = NULL; if (f) { read_packed_refs(f, refs); fclose(f); } refs->did_packed = 1; } return refs->packed; }
static int resolve_gitlink_packed_ref(char *name, int pathlen, const char *refname, unsigned char *result) { FILE *f; struct cached_refs refs; struct ref_list *ref; int retval; strcpy(name + pathlen, "packed-refs"); f = fopen(name, "r"); if (!f) return -1; read_packed_refs(f, &refs); fclose(f); ref = refs.packed; retval = -1; while (ref) { if (!strcmp(ref->name, refname)) { retval = 0; memcpy(result, ref->sha1, 20); break; } ref = ref->next; } free_ref_list(refs.packed); return retval; }
static struct ref_list *get_packed_refs(void) { if (!cached_refs.did_packed) { FILE *f = fopen(git_path("packed-refs"), "r"); cached_refs.packed = NULL; if (f) { read_packed_refs(f, &cached_refs); fclose(f); } cached_refs.did_packed = 1; } return cached_refs.packed; }