summaryrefslogtreecommitdiff
path: root/refs.c
diff options
context:
space:
mode:
authorJunio C Hamano <gitster@pobox.com>2015-08-03 17:41:31 (GMT)
committerJunio C Hamano <gitster@pobox.com>2015-08-03 17:41:31 (GMT)
commit0533a9b70cc768438a817103f02c51bc4f52bf45 (patch)
tree1d69e2fd8a639c2ec1c45957c8f4c0b5e02f35a1 /refs.c
parenta94594dcf7522652363773c06e1ff617914dffe8 (diff)
parent501cf47cddfbf8040b6f9b8ac06d13094a70f729 (diff)
downloadgit-0533a9b70cc768438a817103f02c51bc4f52bf45.zip
git-0533a9b70cc768438a817103f02c51bc4f52bf45.tar.gz
git-0533a9b70cc768438a817103f02c51bc4f52bf45.tar.bz2
Merge branch 'mh/reporting-broken-refs-from-for-each-ref' into maint
"git for-each-ref" reported "missing object" for 0{40} when it encounters a broken ref. The lack of object whose name is 0{40} is not the problem; the ref being broken is. * mh/reporting-broken-refs-from-for-each-ref: read_loose_refs(): treat NULL_SHA1 loose references as broken read_loose_refs(): simplify function logic for-each-ref: report broken references correctly t6301: new tests of for-each-ref error handling
Diffstat (limited to 'refs.c')
-rw-r--r--refs.c29
1 files changed, 22 insertions, 7 deletions
diff --git a/refs.c b/refs.c
index 67d6745..305bb54 100644
--- a/refs.c
+++ b/refs.c
@@ -1374,19 +1374,34 @@ static void read_loose_refs(const char *dirname, struct ref_dir *dir)
create_dir_entry(refs, refname.buf,
refname.len, 1));
} else {
+ int read_ok;
+
if (*refs->name) {
hashclr(sha1);
flag = 0;
- if (resolve_gitlink_ref(refs->name, refname.buf, sha1) < 0) {
- hashclr(sha1);
- flag |= REF_ISBROKEN;
- }
- } else if (read_ref_full(refname.buf,
- RESOLVE_REF_READING,
- sha1, &flag)) {
+ read_ok = !resolve_gitlink_ref(refs->name,
+ refname.buf, sha1);
+ } else {
+ read_ok = !read_ref_full(refname.buf,
+ RESOLVE_REF_READING,
+ sha1, &flag);
+ }
+
+ if (!read_ok) {
hashclr(sha1);
flag |= REF_ISBROKEN;
+ } else if (is_null_sha1(sha1)) {
+ /*
+ * It is so astronomically unlikely
+ * that NULL_SHA1 is the SHA-1 of an
+ * actual object that we consider its
+ * appearance in a loose reference
+ * file to be repo corruption
+ * (probably due to a software bug).
+ */
+ flag |= REF_ISBROKEN;
}
+
if (check_refname_format(refname.buf,
REFNAME_ALLOW_ONELEVEL)) {
hashclr(sha1);