From a31dca0393fefae894b7a155ae24000107bcc383 Mon Sep 17 00:00:00 2001 From: Junio C Hamano Date: Sat, 21 Mar 2009 14:19:53 -0700 Subject: check-ref-format --branch: give Porcelain a way to grok branch shorthand The command may not be the best place to add this new feature, but $ git check-ref-format --branch "@{-1}" allows Porcelains to figure out what branch you were on before the last branch switching. Signed-off-by: Junio C Hamano --- builtin-check-ref-format.c | 10 ++++++++++ 1 file changed, 10 insertions(+) (limited to 'builtin-check-ref-format.c') diff --git a/builtin-check-ref-format.c b/builtin-check-ref-format.c index 701de439ae..39db6cbe47 100644 --- a/builtin-check-ref-format.c +++ b/builtin-check-ref-format.c @@ -5,9 +5,19 @@ #include "cache.h" #include "refs.h" #include "builtin.h" +#include "strbuf.h" int cmd_check_ref_format(int argc, const char **argv, const char *prefix) { + 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)) + die("'%s' is not a valid branch name", argv[2]); + printf("%s\n", sb.buf + 11); + exit(0); + } if (argc != 2) usage("git check-ref-format refname"); return !!check_ref_format(argv[1]); -- cgit v1.2.1 From a2fab531bbb00ff64335906e22854365be2eb5c7 Mon Sep 17 00:00:00 2001 From: Junio C Hamano Date: Sat, 21 Mar 2009 14:35:51 -0700 Subject: strbuf_check_branch_ref(): a helper to check a refname for a branch 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 --- builtin-check-ref-format.c | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) (limited to 'builtin-check-ref-format.c') diff --git a/builtin-check-ref-format.c b/builtin-check-ref-format.c index 39db6cbe47..f9381e07ea 100644 --- a/builtin-check-ref-format.c +++ b/builtin-check-ref-format.c @@ -11,9 +11,8 @@ int cmd_check_ref_format(int argc, const char **argv, const char *prefix) { 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); -- cgit v1.2.1