Code

Set permissions of each new file before "cvs add"ing it.
[git.git] / builtin-show-ref.c
index 06ec400d7f3f2e589111a561a6b18da067a02f1f..073979855b30b72363ed8116288b7bbbb2f0ff74 100644 (file)
@@ -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,10 +62,26 @@ 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);
-               printf("%s %s^{}\n", hex, refname);
+
+       if (!deref_tags)
+               return 0;
+
+       if ((flag & REF_ISPACKED) && !peel_ref(refname, peeled)) {
+               if (!is_null_sha1(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;
 }