Code

Use fixed-size integers for .idx file I/O
[git.git] / builtin-symbolic-ref.c
1 #include "builtin.h"
2 #include "cache.h"
3 #include "refs.h"
5 static const char git_symbolic_ref_usage[] =
6 "git-symbolic-ref [-q] name [ref]";
8 static void check_symref(const char *HEAD, int quiet)
9 {
10         unsigned char sha1[20];
11         int flag;
12         const char *refs_heads_master = resolve_ref(HEAD, sha1, 0, &flag);
14         if (!refs_heads_master)
15                 die("No such ref: %s", HEAD);
16         else if (!(flag & REF_ISSYMREF)) {
17                 if (!quiet)
18                         die("ref %s is not a symbolic ref", HEAD);
19                 else
20                         exit(1);
21         }
22         puts(refs_heads_master);
23 }
25 int cmd_symbolic_ref(int argc, const char **argv, const char *prefix)
26 {
27         int quiet = 0;
29         git_config(git_default_config);
31         while (1 < argc) {
32                 const char *arg = argv[1];
33                 if (arg[0] != '-')
34                         break;
35                 else if (!strcmp("-q", arg))
36                         quiet = 1;
37                 else if (!strcmp("--", arg)) {
38                         argc--;
39                         argv++;
40                         break;
41                 }
42                 else
43                         die("unknown option %s", arg);
44                 argc--;
45                 argv++;
46         }
48         switch (argc) {
49         case 2:
50                 check_symref(argv[1], quiet);
51                 break;
52         case 3:
53                 create_symref(argv[1], argv[2]);
54                 break;
55         default:
56                 usage(git_symbolic_ref_usage);
57         }
58         return 0;
59 }