make got_ref_open() search on-disk refs before packed-refs
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63
diff --git a/lib/reference.c b/lib/reference.c
index 978e204..419ffd3 100644
--- a/lib/reference.c
+++ b/lib/reference.c
@@ -294,13 +294,28 @@ got_ref_open(struct got_reference **ref, struct got_repository *repo,
*ref = NULL;
+ path_refs = get_refs_dir_path(repo, refname);
+ if (path_refs == NULL) {
+ err = got_error_from_errno();
+ goto done;
+ }
+
if (!well_known) {
char *packed_refs_path;
FILE *f;
+ /* Search on-disk refs before packed refs! */
+ for (i = 0; i < nitems(subdirs); i++) {
+ err = open_ref(ref, path_refs, subdirs[i], refname);
+ if (err || *ref)
+ goto done;
+ }
+
packed_refs_path = got_repo_get_path_packed_refs(repo);
- if (packed_refs_path == NULL)
- return got_error_from_errno();
+ if (packed_refs_path == NULL) {
+ err = got_error_from_errno();
+ goto done;
+ }
f = fopen(packed_refs_path, "rb");
free(packed_refs_path);
@@ -313,26 +328,12 @@ got_ref_open(struct got_reference **ref, struct got_repository *repo,
}
}
- path_refs = get_refs_dir_path(repo, refname);
- if (path_refs == NULL) {
- err = got_error_from_errno();
- goto done;
- }
-
- if (!well_known) {
- for (i = 0; i < nitems(subdirs); i++) {
- err = open_ref(ref, path_refs, subdirs[i], refname);
- if (err || *ref)
- goto done;
- }
- }
-
err = open_ref(ref, path_refs, "", refname);
if (err)
goto done;
+done:
if (*ref == NULL)
err = got_error_not_ref(refname);
-done:
free(path_refs);
return err;
}