2 * GIT - The information manager from hell
10 static const char builtin_check_ref_format_usage[] =
11 "git check-ref-format [--print] <refname>\n"
12 " or: git check-ref-format --branch <branchname-shorthand>";
15 * Replace each run of adjacent slashes in src with a single slash,
16 * and write the result to dst.
18 * This function is similar to normalize_path_copy(), but stripped down
19 * to meet check_ref_format's simpler needs.
21 static void collapse_slashes(char *dst, const char *src)
26 while ((ch = *src++) != '\0') {
27 if (prev == '/' && ch == prev)
36 static int check_ref_format_branch(const char *arg)
38 struct strbuf sb = STRBUF_INIT;
40 if (strbuf_check_branch_ref(&sb, arg))
41 die("'%s' is not a valid branch name", arg);
42 printf("%s\n", sb.buf + 11);
46 static int check_ref_format_print(const char *arg)
48 char *refname = xmalloc(strlen(arg) + 1);
50 if (check_ref_format(arg))
52 collapse_slashes(refname, arg);
53 printf("%s\n", refname);
57 int cmd_check_ref_format(int argc, const char **argv, const char *prefix)
59 if (argc == 2 && !strcmp(argv[1], "-h"))
60 usage(builtin_check_ref_format_usage);
62 if (argc == 3 && !strcmp(argv[1], "--branch"))
63 return check_ref_format_branch(argv[2]);
64 if (argc == 3 && !strcmp(argv[1], "--print"))
65 return check_ref_format_print(argv[2]);
67 usage(builtin_check_ref_format_usage);
68 return !!check_ref_format(argv[1]);