Make --stdin option to "log" family read also pathspecs
[git/vmiklos.git] / builtin-check-ref-format.c
blobe3e7bdf52f0b1f597e6cfd3affcf75f41f183d75
1 /*
2 * GIT - The information manager from hell
3 */
5 #include "cache.h"
6 #include "refs.h"
7 #include "builtin.h"
8 #include "strbuf.h"
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)
19 char ch;
20 char prev = '\0';
22 while ((ch = *src++) != '\0') {
23 if (prev == '/' && ch == prev)
24 continue;
26 *dst++ = ch;
27 prev = ch;
29 *dst = '\0';
32 int cmd_check_ref_format(int argc, const char **argv, const char *prefix)
34 if (argc == 3 && !strcmp(argv[1], "--branch")) {
35 struct strbuf sb = STRBUF_INIT;
37 if (strbuf_check_branch_ref(&sb, argv[2]))
38 die("'%s' is not a valid branch name", argv[2]);
39 printf("%s\n", sb.buf + 11);
40 exit(0);
42 if (argc == 3 && !strcmp(argv[1], "--print")) {
43 char *refname = xmalloc(strlen(argv[2]) + 1);
45 if (check_ref_format(argv[2]))
46 exit(1);
47 collapse_slashes(refname, argv[2]);
48 printf("%s\n", refname);
49 exit(0);
51 if (argc != 2)
52 usage("git check-ref-format refname");
53 return !!check_ref_format(argv[1]);