1
0
Fork 0
mirror of https://github.com/git/git.git synced 2024-11-01 14:57:52 +01:00
git/builtin
Jeff King 0e9f62dab9 interpret_branch_name: allow callers to restrict expansions
The interpret_branch_name() function converts names like
@{-1} and @{upstream} into branch names. The expanded ref
names are not fully qualified, and may be outside of the
refs/heads/ namespace (e.g., "@" expands to "HEAD", and
"@{upstream}" is likely to be in "refs/remotes/").

This is OK for callers like dwim_ref() which are primarily
interested in resolving the resulting name, no matter where
it is. But callers like "git branch" treat the result as a
branch name in refs/heads/.  When we expand to a ref outside
that namespace, the results are very confusing (e.g., "git
branch @" tries to create refs/heads/HEAD, which is
nonsense).

Callers can't know from the returned string how the
expansion happened (e.g., did the user really ask for a
branch named "HEAD", or did we do a bogus expansion?). One
fix would be to return some out-parameters describing the
types of expansion that occurred. This has the benefit that
the caller can generate precise error messages ("I
understood @{upstream} to mean origin/master, but that is a
remote tracking branch, so you cannot create it as a local
name").

However, out-parameters make the function interface somewhat
cumbersome. Instead, let's do the opposite: let the caller
tell us which elements to expand. That's easier to pass in,
and none of the callers give more precise error messages
than "@{upstream} isn't a valid branch name" anyway (which
should be sufficient).

The strbuf_branchname() function needs a similar parameter,
as most of the callers access interpret_branch_name()
through it.

We can break the callers down into two groups:

  1. Callers that are happy with any kind of ref in the
     result. We pass "0" here, so they continue to work
     without restrictions. This includes merge_name(),
     the reflog handling in add_pending_object_with_path(),
     and substitute_branch_name(). This last is what powers
     dwim_ref().

  2. Callers that have funny corner cases (mostly in
     git-branch and git-checkout). These need to make use of
     the new parameter, but I've left them as "0" in this
     patch, and will address them individually in follow-on
     patches.

Signed-off-by: Jeff King <peff@peff.net>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2017-03-02 11:05:04 -08:00
..
add.c add: modify already added files when --chmod is given 2016-09-15 12:13:54 -07:00
am.c am: change safe_to_abort()'s not rewinding error into a warning 2016-12-08 09:09:44 -08:00
annotate.c
apply.c Convert read_mmblob to take struct object_id. 2016-09-07 12:59:42 -07:00
archive.c archive: read local configuration 2016-11-22 13:55:20 -08:00
bisect--helper.c
blame.c Merge branch 'jk/blame-fixes' into maint 2017-01-31 13:32:07 -08:00
branch.c interpret_branch_name: allow callers to restrict expansions 2017-03-02 11:05:04 -08:00
bundle.c
cat-file.c Merge branch 'jk/pack-objects-optim-mru' 2016-10-10 14:03:47 -07:00
check-attr.c
check-ignore.c
check-mailmap.c
check-ref-format.c
checkout-index.c introduce CHECKOUT_INIT 2016-09-22 13:42:18 -07:00
checkout.c interpret_branch_name: allow callers to restrict expansions 2017-03-02 11:05:04 -08:00
clean.c
clone.c Merge branch 'jk/clone-copy-alternates-fix' into maint 2016-10-28 09:01:14 -07:00
column.c
commit-tree.c builtin/commit-tree: convert to struct object_id 2016-09-07 12:59:43 -07:00
commit.c Merge branch 'ak/commit-only-allow-empty' into maint 2017-01-17 15:11:03 -08:00
config.c i18n: config: mark error message for translation 2016-09-15 13:17:32 -07:00
count-objects.c alternates: use fspathcmp to detect duplicates 2016-10-10 13:52:37 -07:00
credential.c
describe.c use QSORT 2016-09-29 15:42:18 -07:00
diff-files.c diff: run arguments through precompose_argv 2016-05-13 14:35:49 -07:00
diff-index.c diff: run arguments through precompose_argv 2016-05-13 14:35:49 -07:00
diff-tree.c Merge branch 'ar/diff-args-osx-precompose' into maint 2016-06-06 14:27:35 -07:00
diff.c Merge branch 'jk/setup-sequence-update' 2016-09-21 15:15:24 -07:00
fast-export.c use QSORT 2016-09-29 15:42:18 -07:00
fetch-pack.c Merge branch 'nd/shallow-deepen' 2016-10-10 14:03:50 -07:00
fetch.c Merge branch 'jt/fetch-no-redundant-tag-fetch-map' into maint 2017-01-17 15:19:09 -08:00
fmt-merge-msg.c remove unnecessary check before QSORT 2016-09-29 15:42:18 -07:00
for-each-ref.c
fsck.c alternates: use a separate scratch space 2016-10-10 13:52:36 -07:00
gc.c auto gc: don't write bitmaps for incremental repacks 2016-12-29 13:45:35 -08:00
get-tar-commit-id.c
grep.c cache: convert struct cache_entry to use struct object_id 2016-09-07 12:59:42 -07:00
hash-object.c hash-object: always try to set up the git repository 2016-09-13 15:45:45 -07:00
help.c Merge branch 'js/no-html-bypass-on-windows' into maint 2016-09-08 21:35:55 -07:00
index-pack.c index-pack: skip collision check when not in repository 2016-12-16 13:57:19 -08:00
init-db.c Merge branch 'nd/init-core-worktree-in-multi-worktree-world' 2016-10-03 13:30:35 -07:00
interpret-trailers.c Merge branch 'jk/parseopt-string-list' into jk/string-list-static-init 2016-06-13 10:37:48 -07:00
log.c Merge branch 'jt/format-patch-rfc' 2016-09-26 16:09:17 -07:00
ls-files.c Merge branch 'bw/ls-files-recurse-submodules' 2016-10-26 13:14:44 -07:00
ls-remote.c
ls-tree.c
mailinfo.c mailinfo: read local configuration 2016-11-22 13:13:16 -08:00
mailsplit.c mailsplit: support unescaping mboxrd messages 2016-06-06 11:14:43 -07:00
merge-base.c merge-base: handle --fork-point without reflog 2016-10-12 14:30:16 -07:00
merge-file.c
merge-index.c cache: convert struct cache_entry to use struct object_id 2016-09-07 12:59:42 -07:00
merge-ours.c
merge-recursive.c i18n: merge-recursive: mark verbose message for translation 2016-09-15 13:17:32 -07:00
merge-tree.c
merge.c interpret_branch_name: allow callers to restrict expansions 2017-03-02 11:05:04 -08:00
mktag.c
mktree.c use QSORT 2016-09-29 15:42:18 -07:00
mv.c Merge branch 'rs/copy-array' into maint 2016-10-11 14:18:32 -07:00
name-rev.c use QSORT 2016-09-29 15:42:18 -07:00
notes.c notes: spell first word of error messages in lowercase 2016-09-15 13:17:32 -07:00
pack-objects.c compression: unify pack.compression configuration parsing 2016-11-15 21:16:22 -08:00
pack-redundant.c
pack-refs.c
patch-id.c Merge branch 'rs/patch-id-use-skip-prefix' 2016-06-03 14:38:03 -07:00
prune-packed.c
prune.c
pull.c Merge branch 'jc/pull-rebase-ff' into maint 2017-01-17 15:11:05 -08:00
push.c Merge branch 'jc/push-default-explicit' into maint 2017-01-17 15:11:07 -08:00
read-tree.c cache: convert struct cache_entry to use struct object_id 2016-09-07 12:59:42 -07:00
receive-pack.c Merge branch 'ls/filter-process' 2016-10-31 13:15:21 -07:00
reflog.c
remote-ext.c pkt-line: rename packet_write() to packet_write_fmt() 2016-10-17 11:36:50 -07:00
remote-fd.c
remote.c use QSORT 2016-09-29 15:42:18 -07:00
repack.c repack: die on incremental + write-bitmap-index 2016-12-29 13:45:37 -08:00
replace.c
rerere.c
reset.c Merge branch 'js/reset-usage' into maint 2016-10-28 09:01:22 -07:00
rev-list.c rev-list: use hdr_termination instead of a always using a newline 2016-10-20 14:44:37 -07:00
rev-parse.c Merge branch 'jk/rev-parse-symbolic-parents-fix' into maint 2017-01-17 14:49:26 -08:00
revert.c sequencer: get rid of the subcommand field 2016-10-21 09:32:34 -07:00
rm.c builtin/rm: convert to use struct object_id 2016-09-07 12:59:42 -07:00
send-pack.c
shortlog.c use QSORT, part 2 2016-09-29 20:40:23 -07:00
show-branch.c show-branch: use QSORT 2016-10-03 12:46:47 -07:00
show-ref.c
stripspace.c stripspace: respect repository config 2016-11-21 11:00:38 -08:00
submodule--helper.c Merge branch 'sb/submodule-ignore-trailing-slash' 2016-10-27 14:58:49 -07:00
symbolic-ref.c symbolic-ref -d: do not allow removal of HEAD 2016-09-02 09:01:38 -07:00
tag.c
unpack-file.c
unpack-objects.c unpack-objects: add --max-input-size=<size> option 2016-08-24 12:31:05 -07:00
update-index.c Merge branch 'tg/add-chmod+x-fix' into maint 2016-09-29 16:49:47 -07:00
update-ref.c
update-server-info.c
upload-archive.c archive: read local configuration 2016-11-22 13:55:20 -08:00
var.c
verify-commit.c
verify-pack.c
verify-tag.c
worktree.c worktree list: keep the list sorted 2016-11-28 13:18:51 -08:00
write-tree.c