From cfbe22f03f9be1f3bbbd33240dcb127099d4346e Mon Sep 17 00:00:00 2001 From: Jonathan Nieder Date: Thu, 5 Aug 2010 22:36:07 -0500 Subject: check-ref-format: handle subcommands in separate functions The code for each subcommand should be easier to read and manipulate this way. Signed-off-by: Jonathan Nieder Signed-off-by: Junio C Hamano --- builtin/check-ref-format.c | 42 +++++++++++++++++++++++++----------------- 1 file changed, 25 insertions(+), 17 deletions(-) diff --git a/builtin/check-ref-format.c b/builtin/check-ref-format.c index b106c65d80..8707ee935a 100644 --- a/builtin/check-ref-format.c +++ b/builtin/check-ref-format.c @@ -33,28 +33,36 @@ static void collapse_slashes(char *dst, const char *src) *dst = '\0'; } +static int check_ref_format_branch(const char *arg) +{ + struct strbuf sb = STRBUF_INIT; + + if (strbuf_check_branch_ref(&sb, arg)) + die("'%s' is not a valid branch name", arg); + printf("%s\n", sb.buf + 11); + return 0; +} + +static int check_ref_format_print(const char *arg) +{ + char *refname = xmalloc(strlen(arg) + 1); + + if (check_ref_format(arg)) + return 1; + collapse_slashes(refname, arg); + printf("%s\n", refname); + return 0; +} + int cmd_check_ref_format(int argc, const char **argv, const char *prefix) { if (argc == 2 && !strcmp(argv[1], "-h")) usage(builtin_check_ref_format_usage); - if (argc == 3 && !strcmp(argv[1], "--branch")) { - struct strbuf sb = STRBUF_INIT; - - 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); - } - if (argc == 3 && !strcmp(argv[1], "--print")) { - char *refname = xmalloc(strlen(argv[2]) + 1); - - if (check_ref_format(argv[2])) - exit(1); - collapse_slashes(refname, argv[2]); - printf("%s\n", refname); - exit(0); - } + if (argc == 3 && !strcmp(argv[1], "--branch")) + return check_ref_format_branch(argv[2]); + if (argc == 3 && !strcmp(argv[1], "--print")) + return check_ref_format_print(argv[2]); if (argc != 2) usage(builtin_check_ref_format_usage); return !!check_ref_format(argv[1]); -- cgit v1.2.3 ce6fcb'/>
AgeCommit message (Expand)AuthorFilesLines
2025-09-18Documentation: trace: historgram-design: Separate sched_waking histogram sect...Bagas Sanjaya1-1/+3
2025-09-18Documentation: trace: histogram-design: Trim trailing vertices in diagram exp...Bagas Sanjaya1-81/+81
2025-09-18Documentation: trace: histogram: Fix histogram trigger subsection number orderBagas Sanjaya1-17/+17
2025-09-18docs: driver-api: fix spelling of "buses".Marneni PoornaChandu13-22/+22
2025-09-18Documentation: fbcon: Use admonition directivesBagas Sanjaya1-12/+16
2025-09-18Documentation: fbcon: Reindent 8th step of attach/detach/unloadBagas Sanjaya1-5/+5
2025-09-18Documentation: fbcon: Add boot options and attach/detach/unload section headingsBagas Sanjaya1-1/+3
2025-09-18docs: filesystems: sysfs: add remaining top level sysfs directory descriptionsAlex Tran1-1/+15
2025-09-18docs: filesystems: sysfs: clarify symlink destinations in dev and bus/devices...Alex Tran1-2/+2
2025-09-18docs: filesystems: sysfs: remove top level sysfs net directoryAlex Tran1-1/+0
2025-09-18docs: maintainer: Fix ambiguous subheading formattingThorsten Blum1-0/+2
2025-09-18docs: kdoc: a few more dump_typedef() tweaksJonathan Corbet1-9/+11
2025-09-18docs: kdoc: remove redundant comment stripping in dump_typedef()Jonathan Corbet1-3/+0
2025-09-18docs: kdoc: remove some dead code in dump_typedef()Jonathan Corbet1-5/+0
2025-09-18docs: kdoc: final dump_function() cleanupsJonathan Corbet1-17/+13
2025-09-18docs: kdoc: consolidate some of the macro-processing logicJonathan Corbet1-23/+20
2025-09-18docs: kdoc: Simplify the dump_function() prototype regexesJonathan Corbet1-10/+10
2025-09-18docs: kdoc: remove a useless empty capture groupJonathan Corbet1-2/+2
2025-09-18docs: kdoc: remove a couple of spurious regex charactersJonathan Corbet1-1/+1
2025-09-18doc: kdoc: unify transform handlingJonathan Corbet1-31/+34
2025-09-18docs: kdoc: move the function transform patterns out of dump_function()Jonathan Corbet1-43/+35
2025-09-18docs: kdoc: remove a single-use variableJonathan Corbet1-3/+1
2025-09-18docs: kdoc: tighten up the push_parameter() no-type caseJonathan Corbet1-24/+20
2025-09-18docs: kdoc: trim __cacheline_group_* with the other annotationsJonathan Corbet1-6/+1
2025-09-16docs: Pull LKMM documentation into dev-tools bookAkira Yokosawa18-0/+192
2025-09-16docs: w1: ds2482: fix typo in busesAkiyoshi Kurita1-1/+1
2025-09-16Documentation: staging: fix spelling error in remoteproc.rstTaimoor Zaeem1-1/+1
2025-09-15docs: kdoc: handle the obsolescensce of docutils.ErrorString()Jonathan Corbet3-4/+10
2025-09-15docs: update the guidance for Link: tagsJonathan Corbet2-32/+3
2025-09-09Documentation: update maintainer-pgp-guide for latest best practicesKonstantin Ryabitsev1-83/+75
2025-09-09docs: submitting-patches: adjust Fixes definition slightlyJakub Kicinski1-2/+2
2025-09-09docs: add tools/docs/gen-redirects.pyVegard Nossum3-2/+61