2 * GIT - The information manager from hell
11 * Replace each run of adjacent slashes in src with a single slash,
12 * and write the result to dst.
14 * This function is similar to normalize_path_copy(), but stripped down
15 * to meet check_ref_format's simpler needs.
17 static void collapse_slashes(char *dst
, const char *src
)
22 while ((ch
= *src
++) != '\0') {
23 if (prev
== '/' && ch
== prev
)
32 int cmd_check_ref_format(int argc
, const char **argv
, const char *prefix
)
34 if (argc
== 2 && !strcmp(argv
[1], "-h"))
35 usage(builtin_check_ref_format_usage
);
37 if (argc
== 3 && !strcmp(argv
[1], "--branch")) {
38 struct strbuf sb
= STRBUF_INIT
;
40 if (strbuf_check_branch_ref(&sb
, argv
[2]))
41 die("'%s' is not a valid branch name", argv
[2]);
42 printf("%s\n", sb
.buf
+ 11);
45 if (argc
== 3 && !strcmp(argv
[1], "--print")) {
46 char *refname
= xmalloc(strlen(argv
[2]) + 1);
48 if (check_ref_format(argv
[2]))
50 collapse_slashes(refname
, argv
[2]);
51 printf("%s\n", refname
);
55 usage("git check-ref-format refname");
56 return !!check_ref_format(argv
[1]);