From: Kaartic Sivaraam <kaartic.sivaraam@gmail.com>
To: Eric Sunshine <sunshine@sunshineco.com>
Cc: Git mailing list <git@vger.kernel.org>,
Junio C Hamano <gitster@pobox.com>,
Stefan Beller <sbeller@google.com>
Subject: [PATCH v3 4/4] builtin/branch: strip refs/heads/ using skip_prefix
Date: Wed, 22 Nov 2017 00:47:08 +0530 [thread overview]
Message-ID: <20171121191708.7662-1-kaartic.sivaraam@gmail.com> (raw)
In-Reply-To: <CAPig+cSGu-+6Bw3YBzMwzxO8vKt7jdf9xgtr9FUdOAQpXzi2rQ@mail.gmail.com>
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>
---
Changes in v3:
- Update commit message
- Removed superfluous comment
builtin/branch.c | 13 +++++++++----
1 file changed, 9 insertions(+), 4 deletions(-)
diff --git a/builtin/branch.c b/builtin/branch.c
index ca9d8abd0..4ad3b228b 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,9 @@ static void copy_or_rename_branch(const char *oldname, const char *newname, int
reject_rebase_or_bisect_branch(oldref.buf);
+ skip_prefix(oldref.buf, "refs/heads/", &interpreted_oldname);
+ skip_prefix(newref.buf, "refs/heads/", &interpreted_newname);
+
if (copy)
strbuf_addf(&logmsg, "Branch: copied %s to %s",
oldref.buf, newref.buf);
@@ -508,10 +513,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 +525,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"));
--
2.15.0.345.gf926f18f3
prev parent reply other threads:[~2017-11-21 19:17 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2017-11-21 14:18 [PATCH v2 4/4] builtin/branch: strip refs/heads/ using skip_prefix Kaartic Sivaraam
2017-11-21 18:38 ` Eric Sunshine
2017-11-21 19:12 ` Kaartic Sivaraam
2017-11-21 19:22 ` Eric Sunshine
2017-11-22 2:09 ` Junio C Hamano
2017-11-22 17:45 ` Kaartic Sivaraam
2017-11-21 19:17 ` Kaartic Sivaraam [this message]
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20171121191708.7662-1-kaartic.sivaraam@gmail.com \
--to=kaartic.sivaraam@gmail.com \
--cc=git@vger.kernel.org \
--cc=gitster@pobox.com \
--cc=sbeller@google.com \
--cc=sunshine@sunshineco.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).