Teach git-update-index about gitlinks
[gitweb.git] / builtin-reflog.c
index bfb169ac04a3bddbe7afe79efc25e5ef3de59319..4c39f1da98e5e690f28f5145a1ab5dba790da68d 100644 (file)
@@ -13,7 +13,7 @@
  */
 
 static const char reflog_expire_usage[] =
-"git-reflog expire [--verbose] [--dry-run] [--stale-fix] [--expire=<time>] [--expire-unreachable=<time>] [--all] <refs>...";
+"git-reflog (show|expire) [--verbose] [--dry-run] [--stale-fix] [--expire=<time>] [--expire-unreachable=<time>] [--all] <refs>...";
 
 static unsigned long default_reflog_expire;
 static unsigned long default_reflog_expire_unreachable;
@@ -52,18 +52,18 @@ static int tree_is_complete(const unsigned char *sha1)
        if (tree->object.flags & INCOMPLETE)
                return 0;
 
-       desc.buf = tree->buffer;
-       desc.size = tree->size;
-       if (!desc.buf) {
-               char type[20];
-               void *data = read_sha1_file(sha1, type, &desc.size);
+       if (!tree->buffer) {
+               enum object_type type;
+               unsigned long size;
+               void *data = read_sha1_file(sha1, &type, &size);
                if (!data) {
                        tree->object.flags |= INCOMPLETE;
                        return 0;
                }
-               desc.buf = data;
                tree->buffer = data;
+               tree->size = size;
        }
+       init_tree_desc(&desc, tree->buffer, tree->size);
        complete = 1;
        while (tree_entry(&desc, &entry)) {
                if (!has_sha1_file(entry.sha1) ||
@@ -215,8 +215,8 @@ static int expire_reflog_ent(unsigned char *osha1, unsigned char *nsha1,
                        old = lookup_commit_reference_gently(osha1, 1);
                if (!new && !is_null_sha1(nsha1))
                        new = lookup_commit_reference_gently(nsha1, 1);
-               if ((old && !in_merge_bases(old, cb->ref_commit)) ||
-                   (new && !in_merge_bases(new, cb->ref_commit)))
+               if ((old && !in_merge_bases(old, &cb->ref_commit, 1)) ||
+                   (new && !in_merge_bases(new, &cb->ref_commit, 1)))
                        goto prune;
        }
 
@@ -321,9 +321,9 @@ static int cmd_reflog_expire(int argc, const char **argv, const char *prefix)
                const char *arg = argv[i];
                if (!strcmp(arg, "--dry-run") || !strcmp(arg, "-n"))
                        cb.dry_run = 1;
-               else if (!strncmp(arg, "--expire=", 9))
+               else if (!prefixcmp(arg, "--expire="))
                        cb.expire_total = approxidate(arg + 9);
-               else if (!strncmp(arg, "--expire-unreachable=", 21))
+               else if (!prefixcmp(arg, "--expire-unreachable="))
                        cb.expire_unreachable = approxidate(arg + 21);
                else if (!strcmp(arg, "--stale-fix"))
                        cb.stalefix = 1;
@@ -372,10 +372,16 @@ static const char reflog_usage[] =
 
 int cmd_reflog(int argc, const char **argv, const char *prefix)
 {
-       if (argc < 2)
-               usage(reflog_usage);
-       else if (!strcmp(argv[1], "expire"))
+       /* With no command, we default to showing it. */
+       if (argc < 2 || *argv[1] == '-')
+               return cmd_log_reflog(argc, argv, prefix);
+
+       if (!strcmp(argv[1], "show"))
+               return cmd_log_reflog(argc - 1, argv + 1, prefix);
+
+       if (!strcmp(argv[1], "expire"))
                return cmd_reflog_expire(argc - 1, argv + 1, prefix);
-       else
-               usage(reflog_usage);
+
+       /* Not a recognized reflog command..*/
+       usage(reflog_usage);
 }