Browse Source

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
maint
Junio C Hamano 7 years ago
parent
commit
0faff988ee
  1. 4
      branch.c
  2. 10
      branch.h
  3. 19
      builtin/branch.c
  4. 2
      builtin/checkout.c

4
branch.c

@ -244,7 +244,7 @@ N_("\n" @@ -244,7 +244,7 @@ N_("\n"
"\"git push -u\" to set the upstream config as you push.");

void create_branch(const char *name, const char *start_name,
int force, int reflog, int clobber_head,
int force, int clobber_head_ok, int reflog,
int quiet, enum branch_track track)
{
struct commit *commit;
@ -258,7 +258,7 @@ void create_branch(const char *name, const char *start_name, @@ -258,7 +258,7 @@ void create_branch(const char *name, const char *start_name,
if (track == BRANCH_TRACK_EXPLICIT || track == BRANCH_TRACK_OVERRIDE)
explicit_tracking = 1;

if ((track == BRANCH_TRACK_OVERRIDE || clobber_head)
if ((track == BRANCH_TRACK_OVERRIDE || clobber_head_ok)
? validate_branchname(name, &ref)
: validate_new_branchname(name, &ref, force)) {
if (!force)

10
branch.h

@ -13,14 +13,20 @@ @@ -13,14 +13,20 @@
*
* - 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);

/*
* Check if 'name' can be a valid name for a branch; die otherwise.

19
builtin/branch.c

@ -462,6 +462,8 @@ static void copy_or_rename_branch(const char *oldname, const char *newname, int @@ -462,6 +462,8 @@ static void copy_or_rename_branch(const char *oldname, const char *newname, int
{
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;

if (!oldname) {
@ -493,6 +495,11 @@ static void copy_or_rename_branch(const char *oldname, const char *newname, int @@ -493,6 +495,11 @@ static void copy_or_rename_branch(const char *oldname, const char *newname, int

reject_rebase_or_bisect_branch(oldref.buf);

if (!skip_prefix(oldref.buf, "refs/heads/", &interpreted_oldname) ||
!skip_prefix(newref.buf, "refs/heads/", &interpreted_newname)) {
die("BUG: expected prefix missing for refs");
}

if (copy)
strbuf_addf(&logmsg, "Branch: copied %s to %s",
oldref.buf, newref.buf);
@ -507,11 +514,11 @@ static void copy_or_rename_branch(const char *oldname, const char *newname, int @@ -507,11 +514,11 @@ static void copy_or_rename_branch(const char *oldname, const char *newname, int

if (recovery) {
if (copy)
warning(_("Copied a misnamed branch '%s' away"),
oldref.buf + 11);
warning(_("Created a copy of a misnamed branch '%s'"),
interpreted_oldname);
else
warning(_("Renamed a misnamed branch '%s' away"),
oldref.buf + 11);
interpreted_oldname);
}

if (!copy &&
@ -520,9 +527,9 @@ static void copy_or_rename_branch(const char *oldname, const char *newname, int @@ -520,9 +527,9 @@ static void copy_or_rename_branch(const char *oldname, const char *newname, int

strbuf_release(&logmsg);

strbuf_addf(&oldsection, "branch.%s", oldref.buf + 11);
strbuf_addf(&oldsection, "branch.%s", interpreted_oldname);
strbuf_release(&oldref);
strbuf_addf(&newsection, "branch.%s", newref.buf + 11);
strbuf_addf(&newsection, "branch.%s", interpreted_newname);
strbuf_release(&newref);
if (!copy && git_config_rename_section(oldsection.buf, newsection.buf) < 0)
die(_("Branch is renamed, but update of config-file failed"));
@ -806,7 +813,7 @@ int cmd_branch(int argc, const char **argv, const char *prefix) @@ -806,7 +813,7 @@ int cmd_branch(int argc, const char **argv, const char *prefix)
die(_("the '--set-upstream' option is no longer supported. Please use '--track' or '--set-upstream-to' instead."));

create_branch(argv[0], (argc == 2) ? argv[1] : head,
force, reflog, 0, quiet, track);
force, 0, reflog, quiet, track);

} else
usage_with_options(builtin_branch_usage, options);

2
builtin/checkout.c

@ -647,8 +647,8 @@ static void update_refs_for_switch(const struct checkout_opts *opts, @@ -647,8 +647,8 @@ static void update_refs_for_switch(const struct checkout_opts *opts,
else
create_branch(opts->new_branch, new->name,
opts->new_branch_force ? 1 : 0,
opts->new_branch_log,
opts->new_branch_force ? 1 : 0,
opts->new_branch_log,
opts->quiet,
opts->track);
new->name = opts->new_branch;

Loading…
Cancel
Save