summary | shortlog | log | commit | commitdiff | tree
raw | patch | inline | side by side (parent: 431b196)
raw | patch | inline | side by side (parent: 431b196)
author | Junio C Hamano <gitster@pobox.com> | |
Sat, 21 Mar 2009 20:17:30 +0000 (13:17 -0700) | ||
committer | Junio C Hamano <gitster@pobox.com> | |
Mon, 23 Mar 2009 06:44:08 +0000 (23:44 -0700) |
The function takes a user-supplied string that is supposed to be a branch
name, and puts it in a strbuf after expanding possible shorthand notation.
A handful of open coded sequence to do this in the existing code have been
changed to use this helper function.
Signed-off-by: Junio C Hamano <gitster@pobox.com>
name, and puts it in a strbuf after expanding possible shorthand notation.
A handful of open coded sequence to do this in the existing code have been
changed to use this helper function.
Signed-off-by: Junio C Hamano <gitster@pobox.com>
branch.c | patch | blob | history | |
builtin-branch.c | patch | blob | history | |
builtin-checkout.c | patch | blob | history | |
builtin-merge.c | patch | blob | history | |
strbuf.c | patch | blob | history | |
strbuf.h | patch | blob | history |
diff --git a/branch.c b/branch.c
index 313bcf16342a956a4f4521c6835bfb382c449da6..558f092701f7aa797a0b38a48f67fef6f0218f9c 100644 (file)
--- a/branch.c
+++ b/branch.c
char *real_ref, msg[PATH_MAX + 20];
struct strbuf ref = STRBUF_INIT;
int forcing = 0;
- int len;
- len = strlen(name);
- if (interpret_branch_name(name, &ref) != len) {
- strbuf_reset(&ref);
- strbuf_add(&ref, name, len);
- }
+ strbuf_branchname(&ref, name);
strbuf_splice(&ref, 0, 0, "refs/heads/", 11);
if (check_ref_format(ref.buf))
diff --git a/builtin-branch.c b/builtin-branch.c
index cacd7daae7ce3ccb2171a557a52705473d7ff665..7452db13c89f0d025700949605e983087df85961 100644 (file)
--- a/builtin-branch.c
+++ b/builtin-branch.c
die("Couldn't look up commit object for HEAD");
}
for (i = 0; i < argc; i++, strbuf_release(&bname)) {
- int len = strlen(argv[i]);
-
- if (interpret_branch_name(argv[i], &bname) != len)
- strbuf_add(&bname, argv[i], len);
-
+ strbuf_branchname(&bname, argv[i]);
if (kinds == REF_LOCAL_BRANCH && !strcmp(head, bname.buf)) {
error("Cannot delete the branch '%s' "
"which you are currently on.", bname.buf);
diff --git a/builtin-checkout.c b/builtin-checkout.c
index a8d9d97da202952eda503f28e006737ff34c7d5b..b2680466d86a0456c01dfb900c30571b5a2cba4a 100644 (file)
--- a/builtin-checkout.c
+++ b/builtin-checkout.c
static void setup_branch_path(struct branch_info *branch)
{
struct strbuf buf = STRBUF_INIT;
- int ret;
- if ((ret = interpret_branch_name(branch->name, &buf))
- && ret == strlen(branch->name)) {
+ strbuf_branchname(&buf, branch->name);
+ if (strcmp(buf.buf, branch->name))
branch->name = xstrdup(buf.buf);
- strbuf_splice(&buf, 0, 0, "refs/heads/", 11);
- } else {
- strbuf_addstr(&buf, "refs/heads/");
- strbuf_addstr(&buf, branch->name);
- }
+ strbuf_splice(&buf, 0, 0, "refs/heads/", 11);
branch->path = strbuf_detach(&buf, NULL);
}
diff --git a/builtin-merge.c b/builtin-merge.c
index e94ea7c35f73bd5e939cab93cf860039a757f9a9..6a51823a55502766bee74dfd0a3857a8330a0f75 100644 (file)
--- a/builtin-merge.c
+++ b/builtin-merge.c
const char *ptr;
int len, early;
- len = strlen(remote);
- if (interpret_branch_name(remote, &bname) == len)
- remote = bname.buf;
+ strbuf_branchname(&bname, remote);
+ remote = bname.buf;
memset(branch_head, 0, sizeof(branch_head));
remote_head = peel_to_type(remote, 0, NULL, OBJ_COMMIT);
diff --git a/strbuf.c b/strbuf.c
index bfbd81632e8d2e5584c4eeac0d17aa4b4c2525d8..a60b0ad67d22b02f81cc44acd38b9b8ac3744af3 100644 (file)
--- a/strbuf.c
+++ b/strbuf.c
return len;
}
+
+int strbuf_branchname(struct strbuf *sb, const char *name)
+{
+ int len = strlen(name);
+ if (interpret_branch_name(name, sb) == len)
+ return 0;
+ strbuf_add(sb, name, len);
+ return len;
+}
diff --git a/strbuf.h b/strbuf.h
index 89bd36e15a541e268117ff023afc6a43137cdd6e..68923e1908560641aed9592c4ed3afd6cfd73717 100644 (file)
--- a/strbuf.h
+++ b/strbuf.h
extern void stripspace(struct strbuf *buf, int skip_comments);
extern int launch_editor(const char *path, struct strbuf *buffer, const char *const *env);
+extern int strbuf_branchname(struct strbuf *sb, const char *name);
+
#endif /* STRBUF_H */