diff options
author | Russell Belfer <rb@github.com> | 2013-07-22 11:01:19 -0700 |
---|---|---|
committer | Russell Belfer <rb@github.com> | 2013-07-22 11:01:19 -0700 |
commit | b71071313f4800840ecc48cb18e5cedec8ef250e (patch) | |
tree | 4a565ee90a594ba18ad9e52f38edfffb1366c7fd /src/refdb_fs.c | |
parent | 1cd9dc29b7105cb33959d15ab670a085f5a1445b (diff) | |
download | libgit2-b71071313f4800840ecc48cb18e5cedec8ef250e.tar.gz |
git_reference_next_name must match git_reference_next
The git_reference_next API silently skips invalid references when
scanning the loose refs. The git_reference_next_name API should
skip the same ones even though it isn't creating the reference
object.
This adds a test with a an invalid loose reference and makes sure
that both APIs skip the same entries and generate the same results.
Diffstat (limited to 'src/refdb_fs.c')
-rw-r--r-- | src/refdb_fs.c | 16 |
1 files changed, 13 insertions, 3 deletions
diff --git a/src/refdb_fs.c b/src/refdb_fs.c index b9e283ac5..2f1a5b26c 100644 --- a/src/refdb_fs.c +++ b/src/refdb_fs.c @@ -452,6 +452,9 @@ static int loose_lookup( git_buf ref_file = GIT_BUF_INIT; int error = 0; + if (out) + *out = NULL; + error = reference_read(&ref_file, NULL, backend->path, ref_name, NULL); if (error < 0) @@ -465,15 +468,17 @@ static int loose_lookup( goto done; } - *out = git_reference__alloc_symbolic(ref_name, target); + if (out) + *out = git_reference__alloc_symbolic(ref_name, target); } else { if ((error = loose_parse_oid(&oid, ref_name, &ref_file)) < 0) goto done; - *out = git_reference__alloc(ref_name, &oid, NULL); + if (out) + *out = git_reference__alloc(ref_name, &oid, NULL); } - if (*out == NULL) + if (out && *out == NULL) error = -1; done: @@ -679,6 +684,11 @@ static int refdb_fs_backend__iterator_next_name( if (git_strmap_exists(packfile, path)) continue; + if (loose_lookup(NULL, backend, path) != 0) { + giterr_clear(); + continue; + } + *out = path; return 0; } |