git-commit-vandalism/builtin
Jeff King e6dbffa67b peel_ref: do not return a null sha1
The idea of the peel_ref function is to dereference tag
objects recursively until we hit a non-tag, and return the
sha1. Conceptually, it should return 0 if it is successful
(and fill in the sha1), or -1 if there was nothing to peel.

However, the current behavior is much more confusing. For a
regular loose ref, the behavior is as described above. But
there is an optimization to reuse the peeled-ref value for a
ref that came from a packed-refs file. If we have such a
ref, we return its peeled value, even if that peeled value
is null (indicating that we know the ref definitely does
_not_ peel).

It might seem like such information is useful to the caller,
who would then know not to bother loading and trying to peel
the object. Except that they should not bother loading and
trying to peel the object _anyway_, because that fallback is
already handled by peel_ref. In other words, the whole point
of calling this function is that it handles those details
internally, and you either get a sha1, or you know that it
is not peel-able.

This patch catches the null sha1 case internally and
converts it into a -1 return value (i.e., there is nothing
to peel). This simplifies callers, which do not need to
bother checking themselves.

Two callers are worth noting:

  - in pack-objects, a comment indicates that there is a
    difference between non-peelable tags and unannotated
    tags. But that is not the case (before or after this
    patch). Whether you get a null sha1 has to do with
    internal details of how peel_ref operated.

  - in show-ref, if peel_ref returns a failure, the caller
    tries to decide whether to try peeling manually based on
    whether the REF_ISPACKED flag is set. But this doesn't
    make any sense. If the flag is set, that does not
    necessarily mean the ref came from a packed-refs file
    with the "peeled" extension. But it doesn't matter,
    because even if it didn't, there's no point in trying to
    peel it ourselves, as peel_ref would already have done
    so. In other words, the fallback peeling is guaranteed
    to fail.

Signed-off-by: Jeff King <peff@peff.net>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2012-10-04 20:34:28 -07:00
..
add.c Merge branch 'ar/clone-honor-umask-at-top' into maint 2012-07-22 13:04:05 -07:00
annotate.c
apply.c Merge branch 'maint-1.7.11' into maint 2012-09-12 14:08:05 -07:00
archive.c
bisect--helper.c
blame.c Merge branch 'jc/maint-blame-no-such-path' into maint 2012-09-24 12:40:02 -07:00
branch.c
bundle.c
cat-file.c Merge branch 'maint-1.7.11' into maint 2012-09-10 15:31:06 -07:00
check-attr.c Add missing -z to git check-attr usage text for consistency with man page 2012-09-17 13:45:32 -07:00
check-ref-format.c
checkout-index.c
checkout.c Sync with 1.7.11.6 2012-09-11 11:23:54 -07:00
clean.c
clone.c Merge branch 'ar/clone-honor-umask-at-top' into maint 2012-07-22 13:04:05 -07:00
column.c
commit-tree.c Merge branch 'kk/maint-commit-tree' 2012-07-23 20:55:54 -07:00
commit.c split_ident_line(): make best effort when parsing author/committer line 2012-08-31 14:54:18 -07:00
config.c Merge branch 'jk/config-warn-on-inaccessible-paths' into maint 2012-09-18 14:24:06 -07:00
count-objects.c
credential.c
describe.c peel_ref: do not return a null sha1 2012-10-04 20:34:28 -07:00
diff-files.c
diff-index.c
diff-tree.c
diff.c Merge branch 'tr/void-diff-setup-done' into maint-1.7.11 2012-09-11 10:53:40 -07:00
fast-export.c
fetch-pack.c fetch-pack: mention server version with verbose output 2012-08-13 21:56:05 -07:00
fetch.c Merge branch 'dj/fetch-all-tags' into maint 2012-09-24 12:39:21 -07:00
fmt-merge-msg.c
for-each-ref.c for-each-ref: Fix sort with multiple keys 2012-08-21 14:42:12 -07:00
fsck.c
gc.c
grep.c Merge branch 'jc/maint-log-grep-all-match-1' into maint 2012-09-29 22:30:56 -07:00
hash-object.c
help.c
index-pack.c
init-db.c
log.c Merge branch 'mz/cherry-pick-cmdline-order' into maint 2012-09-14 21:24:18 -07:00
ls-files.c
ls-remote.c ls-remote: document the '--get-url' option 2012-09-07 10:58:35 -07:00
ls-tree.c
mailinfo.c Merge branch 'jc/maint-mailinfo-mime-attr' into maint 2012-09-29 22:30:48 -07:00
mailsplit.c
merge-base.c
merge-file.c
merge-index.c
merge-ours.c
merge-recursive.c
merge-tree.c
merge.c Merge branch 'tr/void-diff-setup-done' into maint-1.7.11 2012-09-11 10:53:40 -07:00
mktag.c
mktree.c
mv.c
name-rev.c
notes.c
pack-objects.c peel_ref: do not return a null sha1 2012-10-04 20:34:28 -07:00
pack-redundant.c
pack-refs.c
patch-id.c
prune-packed.c
prune.c prune.c: only print informational message in show_only or verbose mode 2012-08-07 15:01:37 -07:00
push.c
read-tree.c
receive-pack.c Merge branch 'jc/capabilities' into maint 2012-09-11 11:06:45 -07:00
reflog.c
remote-ext.c
remote-fd.c
remote.c remote: prefer subcommand name 'remove' to 'rm' 2012-09-06 13:23:22 -07:00
replace.c Convert many resolve_ref() calls to read_ref*() and ref_exists() 2011-11-13 12:21:06 -08:00
rerere.c
reset.c
rev-list.c
rev-parse.c Merge branch 'maint-1.7.11' into maint 2012-09-12 14:08:05 -07:00
revert.c cherry-pick/revert: respect order of revisions to pick 2012-08-30 14:00:23 -07:00
rm.c
send-pack.c do not send client agent unless server does first 2012-08-10 12:35:13 -07:00
shortlog.c
show-branch.c
show-ref.c peel_ref: do not return a null sha1 2012-10-04 20:34:28 -07:00
stripspace.c
symbolic-ref.c
tag.c
tar-tree.c
unpack-file.c
unpack-objects.c
update-index.c
update-ref.c
update-server-info.c
upload-archive.c
var.c
verify-pack.c
verify-tag.c
write-tree.c