gitweb: Move git_get_last_activity subroutine earlier
[git/mingw.git] / builtin-symbolic-ref.c
blob1d3a5e229ae1a16211671e7591a7544af98721f8
1 #include "builtin.h"
2 #include "cache.h"
4 static const char git_symbolic_ref_usage[] =
5 "git-symbolic-ref name [ref]";
7 static void check_symref(const char *HEAD)
9 unsigned char sha1[20];
10 const char *git_HEAD = xstrdup(git_path("%s", HEAD));
11 const char *git_refs_heads_master = resolve_ref(git_HEAD, sha1, 0);
12 if (git_refs_heads_master) {
13 /* we want to strip the .git/ part */
14 int pfxlen = strlen(git_HEAD) - strlen(HEAD);
15 puts(git_refs_heads_master + pfxlen);
17 else
18 die("No such ref: %s", HEAD);
21 int cmd_symbolic_ref(int argc, const char **argv, const char *prefix)
23 git_config(git_default_config);
24 switch (argc) {
25 case 2:
26 check_symref(argv[1]);
27 break;
28 case 3:
29 create_symref(xstrdup(git_path("%s", argv[1])), argv[2]);
30 break;
31 default:
32 usage(git_symbolic_ref_usage);
34 return 0;