]> git.ipfire.org Git - thirdparty/git.git/commitdiff
Merge branch 'ks/branch-cleanup'
authorJunio C Hamano <gitster@pobox.com>
Wed, 27 Dec 2017 19:16:25 +0000 (11:16 -0800)
committerJunio C Hamano <gitster@pobox.com>
Wed, 27 Dec 2017 19:16:25 +0000 (11:16 -0800)
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

1  2 
branch.c
branch.h
builtin/branch.c
builtin/checkout.c

diff --cc branch.c
index fe1e1c3676b26a4f35feaf8137700b25916ad5ee,bd607ae979f6c0a1b93ee89a0facdd818ea64e64..2672054f0b5423cd09010302285935650435f1dc
+++ 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 be5e5d13083a98e57e834d81afe5450f11202130,f66536a10c9ec3d8dd6c148968364a5f7e3996a3..473d0a93e910d8f053e6e8c919e430048a3033a0
+++ b/branch.h
   *
   *   - 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
index af95ad2192004ad3a712c15f1e50356daadb7c86,196d5fe9b5e2a9859d34fb2d55fcb11da68aa712..8dcc2ed058be6e653f885e48c9aa5f465a5f9749
@@@ -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)
Simple merge