1
0
mirror of https://github.com/git/git.git synced 2024-11-20 03:33:57 +01:00
git/builtin-symbolic-ref.c
Linus Torvalds ed378ec7e8 Make ref resolution saner
The old code used to totally mix up the notion of a ref-name and the path
that that ref was associated with.  That was not only horribly ugly (a
number of users got the path, and then wanted to try to turn it back into
a ref-name again), but it fundamnetally doesn't work at all once we do any
setup where a ref doesn't have a 1:1 relationship with a particular
pathname.

This fixes things up so that we use the ref-name throughout, and only
turn it into a pathname once we actually look it up in the filesystem.
That makes a lot of things much clearer and more straightforward.

Signed-off-by: Linus Torvalds <torvalds@osdl.org>
Signed-off-by: Junio C Hamano <junkio@cox.net>
2006-09-17 19:09:11 -07:00

32 lines
615 B
C

#include "builtin.h"
#include "cache.h"
static const char git_symbolic_ref_usage[] =
"git-symbolic-ref name [ref]";
static void check_symref(const char *HEAD)
{
unsigned char sha1[20];
const char *refs_heads_master = resolve_ref("HEAD", sha1, 0);
if (!refs_heads_master)
die("No such ref: %s", HEAD);
puts(refs_heads_master);
}
int cmd_symbolic_ref(int argc, const char **argv, const char *prefix)
{
git_config(git_default_config);
switch (argc) {
case 2:
check_symref(argv[1]);
break;
case 3:
create_symref(argv[1], argv[2]);
break;
default:
usage(git_symbolic_ref_usage);
}
return 0;
}