summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKaartic Sivaraam <kaartic.sivaraam@gmail.com>2017-12-01 05:59:33 (GMT)
committerJunio C Hamano <gitster@pobox.com>2017-12-07 23:06:46 (GMT)
commit255073ca59de7cd293e4a9d6c12831b6e505c37e (patch)
tree5ec00e5c15979825d0e878e1f0a765defc257d2d
parenta48ebe9724b01e53f23e2a44a85f52237aaf5c34 (diff)
downloadgit-255073ca59de7cd293e4a9d6c12831b6e505c37e.zip
git-255073ca59de7cd293e4a9d6c12831b6e505c37e.tar.gz
git-255073ca59de7cd293e4a9d6c12831b6e505c37e.tar.bz2
builtin/branch: strip refs/heads/ using skip_prefix
Instead of hard-coding the offset strlen("refs/heads/") to skip the prefix "refs/heads/" use the skip_prefix() function which is more communicative and verifies that the string actually starts with that prefix. Signed-off-by: Kaartic Sivaraam <kaartic.sivaraam@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
-rw-r--r--builtin/branch.c15
1 files changed, 11 insertions, 4 deletions
diff --git a/builtin/branch.c b/builtin/branch.c
index ca9d8ab..196d5fe 100644
--- a/builtin/branch.c
+++ b/builtin/branch.c
@@ -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;
int clobber_head_ok;
@@ -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);
@@ -508,10 +515,10 @@ static void copy_or_rename_branch(const char *oldname, const char *newname, int
if (recovery) {
if (copy)
warning(_("Created a copy of a misnamed branch '%s'"),
- oldref.buf + 11);
+ 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
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"));