From: Junio C Hamano Date: Wed, 27 Dec 2017 19:16:25 +0000 (-0800) Subject: Merge branch 'ks/branch-cleanup' X-Git-Tag: v2.16.0-rc0~30 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=0faff988eed719c53daf470cf0a88c26d0e83525;p=thirdparty%2Fgit.git Merge branch 'ks/branch-cleanup' Code clean-up. * ks/branch-cleanup: builtin/branch: strip refs/heads/ using skip_prefix branch: update warning message shown when copying a misnamed branch branch: group related arguments of create_branch() branch: improve documentation and naming of create_branch() parameters --- 0faff988eed719c53daf470cf0a88c26d0e83525 diff --cc branch.c index fe1e1c3676,bd607ae979..2672054f0b --- a/branch.c +++ b/branch.c @@@ -258,9 -242,9 +258,9 @@@ void create_branch(const char *name, co if (track == BRANCH_TRACK_EXPLICIT || track == BRANCH_TRACK_OVERRIDE) explicit_tracking = 1; - if ((track == BRANCH_TRACK_OVERRIDE || clobber_head) - if (validate_new_branchname(name, &ref, force, - track == BRANCH_TRACK_OVERRIDE || - clobber_head_ok)) { ++ if ((track == BRANCH_TRACK_OVERRIDE || clobber_head_ok) + ? validate_branchname(name, &ref) + : validate_new_branchname(name, &ref, force)) { if (!force) dont_change_ref = 1; else diff --cc branch.h index be5e5d1308,f66536a10c..473d0a93e9 --- a/branch.h +++ b/branch.h @@@ -13,29 -13,38 +13,35 @@@ * * - force enables overwriting an existing (non-head) branch * + * - clobber_head_ok allows the currently checked out (hence existing) + * branch to be overwritten; without 'force', it has no effect. + * * - reflog creates a reflog for the branch * + * - quiet suppresses tracking information + * * - track causes the new branch to be configured to merge the remote branch * that start_name is a tracking branch for (if any). + * */ void create_branch(const char *name, const char *start_name, - int force, int reflog, - int clobber_head, int quiet, enum branch_track track); + int force, int clobber_head_ok, + int reflog, int quiet, enum branch_track track); /* - * Validates that the requested branch may be created, returning the - * interpreted ref in ref, force indicates whether (non-head) branches - * may be overwritten. A non-zero return value indicates that the force - * parameter was non-zero and the branch already exists. - * - * Contrary to all of the above, when attr_only is 1, the caller is - * not interested in verifying if it is Ok to update the named - * branch to point at a potentially different commit. It is merely - * asking if it is OK to change some attribute for the named branch - * (e.g. tracking upstream). - * - * NEEDSWORK: This needs to be split into two separate functions in the - * longer run for sanity. - * + * Check if 'name' can be a valid name for a branch; die otherwise. + * Return 1 if the named branch already exists; return 0 otherwise. + * Fill ref with the full refname for the branch. + */ +extern int validate_branchname(const char *name, struct strbuf *ref); + +/* + * Check if a branch 'name' can be created as a new branch; die otherwise. + * 'force' can be used when it is OK for the named branch already exists. + * Return 1 if the named branch already exists; return 0 otherwise. + * Fill ref with the full refname for the branch. */ -int validate_new_branchname(const char *name, struct strbuf *ref, int force, int attr_only); +extern int validate_new_branchname(const char *name, struct strbuf *ref, int force); /* * Remove information about the state of working on the current diff --cc builtin/branch.c index af95ad2192,196d5fe9b5..8dcc2ed058 --- a/builtin/branch.c +++ b/builtin/branch.c @@@ -462,7 -462,10 +462,9 @@@ static void copy_or_rename_branch(cons { struct strbuf oldref = STRBUF_INIT, newref = STRBUF_INIT, logmsg = STRBUF_INIT; struct strbuf oldsection = STRBUF_INIT, newsection = STRBUF_INIT; + const char *interpreted_oldname = NULL; + const char *interpreted_newname = NULL; int recovery = 0; - int clobber_head_ok; if (!oldname) { if (copy)