summary | shortlog | log | commit | commitdiff | tree
raw | patch | inline | side by side (parent: 03d3aad)
raw | patch | inline | side by side (parent: 03d3aad)
author | Junio C Hamano <gitster@pobox.com> | |
Sat, 21 Mar 2009 21:35:51 +0000 (14:35 -0700) | ||
committer | Junio C Hamano <gitster@pobox.com> | |
Mon, 23 Mar 2009 06:52:11 +0000 (23:52 -0700) |
This allows a common calling sequence
strbuf_branchname(&ref, name);
strbuf_splice(&ref, 0, 0, "refs/heads/", 11);
if (check_ref_format(ref.buf))
die(...);
to be refactored into
if (strbuf_check_branch_ref(&ref, name))
die(...);
Signed-off-by: Junio C Hamano <gitster@pobox.com>
strbuf_branchname(&ref, name);
strbuf_splice(&ref, 0, 0, "refs/heads/", 11);
if (check_ref_format(ref.buf))
die(...);
to be refactored into
if (strbuf_check_branch_ref(&ref, name))
die(...);
Signed-off-by: Junio C Hamano <gitster@pobox.com>
branch.c | patch | blob | history | |
builtin-branch.c | patch | blob | history | |
builtin-check-ref-format.c | patch | blob | history | |
builtin-checkout.c | patch | blob | history | |
strbuf.c | patch | blob | history | |
strbuf.h | patch | blob | history |
diff --git a/branch.c b/branch.c
index 558f092701f7aa797a0b38a48f67fef6f0218f9c..62030af4b51abbfb9c488dbf018770f3b3606789 100644 (file)
--- a/branch.c
+++ b/branch.c
struct strbuf ref = STRBUF_INIT;
int forcing = 0;
- strbuf_branchname(&ref, name);
- strbuf_splice(&ref, 0, 0, "refs/heads/", 11);
-
- if (check_ref_format(ref.buf))
+ if (strbuf_check_branch_ref(&ref, name))
die("'%s' is not a valid branch name.", name);
if (resolve_ref(ref.buf, sha1, 1, NULL)) {
diff --git a/builtin-branch.c b/builtin-branch.c
index 0df82bf96d7f06426ac0ff89f3410714257c20fd..afeed68cfd7482c40a276c00ef3b7bfd09433950 100644 (file)
--- a/builtin-branch.c
+++ b/builtin-branch.c
@@ -468,14 +468,10 @@ static void rename_branch(const char *oldname, const char *newname, int force)
if (!oldname)
die("cannot rename the current branch while not on any.");
- strbuf_branchname(&oldref, oldname);
- strbuf_splice(&oldref, 0, 0, "refs/heads/", 11);
- if (check_ref_format(oldref.buf))
+ if (strbuf_check_branch_ref(&oldref, oldname))
die("Invalid branch name: '%s'", oldname);
- strbuf_branchname(&newref, newname);
- strbuf_splice(&newref, 0, 0, "refs/heads/", 11);
- if (check_ref_format(newref.buf))
+ if (strbuf_check_branch_ref(&newref, newname))
die("Invalid branch name: '%s'", newname);
if (resolve_ref(newref.buf, sha1, 1, NULL) && !force)
index 39db6cbe47d77f84bd2d1d8d98942be89aaa1bf7..f9381e07eaeda673e91ef6250eca4027c5ba0278 100644 (file)
{
if (argc == 3 && !strcmp(argv[1], "--branch")) {
struct strbuf sb = STRBUF_INIT;
- strbuf_branchname(&sb, argv[2]);
- strbuf_splice(&sb, 0, 0, "refs/heads/", 11);
- if (check_ref_format(sb.buf))
+
+ if (strbuf_check_branch_ref(&sb, argv[2]))
die("'%s' is not a valid branch name", argv[2]);
printf("%s\n", sb.buf + 11);
exit(0);
diff --git a/builtin-checkout.c b/builtin-checkout.c
index b2680466d86a0456c01dfb900c30571b5a2cba4a..66df0c072cba89e74af26a767a6fa9b65d5449ef 100644 (file)
--- a/builtin-checkout.c
+++ b/builtin-checkout.c
if (opts.new_branch) {
struct strbuf buf = STRBUF_INIT;
- strbuf_addstr(&buf, "refs/heads/");
- strbuf_addstr(&buf, opts.new_branch);
+ if (strbuf_check_branch_ref(&buf, opts.new_branch))
+ die("git checkout: we do not like '%s' as a branch name.",
+ opts.new_branch);
if (!get_sha1(buf.buf, rev))
die("git checkout: branch %s already exists", opts.new_branch);
- if (check_ref_format(buf.buf))
- die("git checkout: we do not like '%s' as a branch name.", opts.new_branch);
strbuf_release(&buf);
}
diff --git a/strbuf.c b/strbuf.c
index a60b0ad67d22b02f81cc44acd38b9b8ac3744af3..a88496030b7053a543173c299bd9f54b923db2ec 100644 (file)
--- a/strbuf.c
+++ b/strbuf.c
#include "cache.h"
+#include "refs.h"
int prefixcmp(const char *str, const char *prefix)
{
strbuf_add(sb, name, len);
return len;
}
+
+int strbuf_check_branch_ref(struct strbuf *sb, const char *name)
+{
+ strbuf_branchname(sb, name);
+ strbuf_splice(sb, 0, 0, "refs/heads/", 11);
+ return check_ref_format(sb->buf);
+}
diff --git a/strbuf.h b/strbuf.h
index 68923e1908560641aed9592c4ed3afd6cfd73717..9ee908a3ec5d4d5329385bc10cdd676f703c0c1f 100644 (file)
--- a/strbuf.h
+++ b/strbuf.h
extern int launch_editor(const char *path, struct strbuf *buffer, const char *const *env);
extern int strbuf_branchname(struct strbuf *sb, const char *name);
+extern int strbuf_check_branch_ref(struct strbuf *sb, const char *name);
#endif /* STRBUF_H */