path: root/builtin-symbolic-ref.c
diff options
authorLinus Torvalds <>2006-09-12 03:17:35 (GMT)
committerJunio C Hamano <>2006-09-18 02:09:11 (GMT)
commited378ec7e85fd2c5cfcc7bd64b454236357fdd97 (patch)
tree76a1666618aff73fd9184a533273b1e083858a6d /builtin-symbolic-ref.c
parentb37a562a1097af7403c649a5f903a93acaf279e8 (diff)
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 <> Signed-off-by: Junio C Hamano <>
Diffstat (limited to 'builtin-symbolic-ref.c')
1 files changed, 5 insertions, 9 deletions
diff --git a/builtin-symbolic-ref.c b/builtin-symbolic-ref.c
index 1d3a5e2..6f18db8 100644
--- a/builtin-symbolic-ref.c
+++ b/builtin-symbolic-ref.c
@@ -7,15 +7,11 @@ static const char git_symbolic_ref_usage[] =
static void check_symref(const char *HEAD)
unsigned char sha1[20];
- const char *git_HEAD = xstrdup(git_path("%s", HEAD));
- const char *git_refs_heads_master = resolve_ref(git_HEAD, sha1, 0);
- if (git_refs_heads_master) {
- /* we want to strip the .git/ part */
- int pfxlen = strlen(git_HEAD) - strlen(HEAD);
- puts(git_refs_heads_master + pfxlen);
- }
- else
+ 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)
@@ -26,7 +22,7 @@ int cmd_symbolic_ref(int argc, const char **argv, const char *prefix)
case 3:
- create_symref(xstrdup(git_path("%s", argv[1])), argv[2]);
+ create_symref(argv[1], argv[2]);