aboutsummaryrefslogtreecommitdiff
path: root/builtin-show-ref.c
diff options
context:
space:
mode:
authorJunio C Hamano <junkio@cox.net>2006-11-19 13:22:44 -0800
committerJunio C Hamano <junkio@cox.net>2006-11-19 18:45:44 -0800
commitcf0adba7885342e1bbcf0689fece9d13e39784b4 (patch)
treec6559d40439c8e28fb0634292738e00693deb88e /builtin-show-ref.c
parentef06b91804ff5a626e265c6d9080bbc0e7924e88 (diff)
downloadgit-cf0adba7885342e1bbcf0689fece9d13e39784b4.tar.gz
git-cf0adba7885342e1bbcf0689fece9d13e39784b4.tar.xz
Store peeled refs in packed-refs file.
This would speed up "show-ref -d" in a repository with mostly packed tags. Signed-off-by: Junio C Hamano <junkio@cox.net>
Diffstat (limited to 'builtin-show-ref.c')
-rw-r--r--builtin-show-ref.c36
1 files changed, 27 insertions, 9 deletions
diff --git a/builtin-show-ref.c b/builtin-show-ref.c
index 06ec400d7..9ae3d0854 100644
--- a/builtin-show-ref.c
+++ b/builtin-show-ref.c
@@ -13,6 +13,7 @@ static int show_ref(const char *refname, const unsigned char *sha1, int flag, vo
{
struct object *obj;
const char *hex;
+ unsigned char peeled[20];
if (tags_only || heads_only) {
int match;
@@ -44,12 +45,15 @@ static int show_ref(const char *refname, const unsigned char *sha1, int flag, vo
match:
found_match++;
- obj = parse_object(sha1);
- if (!obj) {
- if (quiet)
- return 0;
- die("git-show-ref: bad ref %s (%s)", refname, sha1_to_hex(sha1));
- }
+
+ /* This changes the semantics slightly that even under quiet we
+ * detect and return error if the repository is corrupt and
+ * ref points at a nonexistent object.
+ */
+ if (!has_sha1_file(sha1))
+ die("git-show-ref: bad ref %s (%s)", refname,
+ sha1_to_hex(sha1));
+
if (quiet)
return 0;
@@ -58,11 +62,25 @@ match:
printf("%s\n", hex);
else
printf("%s %s\n", hex, refname);
- if (deref_tags && obj->type == OBJ_TAG) {
- obj = deref_tag(obj, refname, 0);
- hex = find_unique_abbrev(obj->sha1, abbrev);
+
+ if (!deref_tags)
+ return 0;
+
+ if ((flag & REF_ISPACKED) && !peel_ref(refname, peeled)) {
+ hex = find_unique_abbrev(peeled, abbrev);
printf("%s %s^{}\n", hex, refname);
}
+ else {
+ obj = parse_object(sha1);
+ if (!obj)
+ die("git-show-ref: bad ref %s (%s)", refname,
+ sha1_to_hex(sha1));
+ if (obj->type == OBJ_TAG) {
+ obj = deref_tag(obj, refname, 0);
+ hex = find_unique_abbrev(obj->sha1, abbrev);
+ printf("%s %s^{}\n", hex, refname);
+ }
+ }
return 0;
}