t0301: fixes for windows compatibility
[git/debian.git] / builtin / reflog.c
blob09541d1c80483c1a20802ba34a747a1674811165
1 #include "builtin.h"
2 #include "config.h"
3 #include "lockfile.h"
4 #include "object-store.h"
5 #include "repository.h"
6 #include "commit.h"
7 #include "refs.h"
8 #include "dir.h"
9 #include "tree-walk.h"
10 #include "diff.h"
11 #include "revision.h"
12 #include "reachable.h"
13 #include "worktree.h"
15 /* NEEDSWORK: switch to using parse_options */
16 static const char reflog_expire_usage[] =
17 N_("git reflog expire [--expire=<time>] "
18 "[--expire-unreachable=<time>] "
19 "[--rewrite] [--updateref] [--stale-fix] [--dry-run | -n] "
20 "[--verbose] [--all] <refs>...");
21 static const char reflog_delete_usage[] =
22 N_("git reflog delete [--rewrite] [--updateref] "
23 "[--dry-run | -n] [--verbose] <refs>...");
24 static const char reflog_exists_usage[] =
25 N_("git reflog exists <ref>");
27 static timestamp_t default_reflog_expire;
28 static timestamp_t default_reflog_expire_unreachable;
30 struct cmd_reflog_expire_cb {
31 struct rev_info revs;
32 int stalefix;
33 timestamp_t expire_total;
34 timestamp_t expire_unreachable;
35 int recno;
38 struct expire_reflog_policy_cb {
39 enum {
40 UE_NORMAL,
41 UE_ALWAYS,
42 UE_HEAD
43 } unreachable_expire_kind;
44 struct commit_list *mark_list;
45 unsigned long mark_limit;
46 struct cmd_reflog_expire_cb cmd;
47 struct commit *tip_commit;
48 struct commit_list *tips;
51 struct collected_reflog {
52 struct object_id oid;
53 char reflog[FLEX_ARRAY];
56 struct collect_reflog_cb {
57 struct collected_reflog **e;
58 int alloc;
59 int nr;
60 struct worktree *wt;
63 /* Remember to update object flag allocation in object.h */
64 #define INCOMPLETE (1u<<10)
65 #define STUDYING (1u<<11)
66 #define REACHABLE (1u<<12)
68 static int tree_is_complete(const struct object_id *oid)
70 struct tree_desc desc;
71 struct name_entry entry;
72 int complete;
73 struct tree *tree;
75 tree = lookup_tree(the_repository, oid);
76 if (!tree)
77 return 0;
78 if (tree->object.flags & SEEN)
79 return 1;
80 if (tree->object.flags & INCOMPLETE)
81 return 0;
83 if (!tree->buffer) {
84 enum object_type type;
85 unsigned long size;
86 void *data = read_object_file(oid, &type, &size);
87 if (!data) {
88 tree->object.flags |= INCOMPLETE;
89 return 0;
91 tree->buffer = data;
92 tree->size = size;
94 init_tree_desc(&desc, tree->buffer, tree->size);
95 complete = 1;
96 while (tree_entry(&desc, &entry)) {
97 if (!has_object_file(&entry.oid) ||
98 (S_ISDIR(entry.mode) && !tree_is_complete(&entry.oid))) {
99 tree->object.flags |= INCOMPLETE;
100 complete = 0;
103 free_tree_buffer(tree);
105 if (complete)
106 tree->object.flags |= SEEN;
107 return complete;
110 static int commit_is_complete(struct commit *commit)
112 struct object_array study;
113 struct object_array found;
114 int is_incomplete = 0;
115 int i;
117 /* early return */
118 if (commit->object.flags & SEEN)
119 return 1;
120 if (commit->object.flags & INCOMPLETE)
121 return 0;
123 * Find all commits that are reachable and are not marked as
124 * SEEN. Then make sure the trees and blobs contained are
125 * complete. After that, mark these commits also as SEEN.
126 * If some of the objects that are needed to complete this
127 * commit are missing, mark this commit as INCOMPLETE.
129 memset(&study, 0, sizeof(study));
130 memset(&found, 0, sizeof(found));
131 add_object_array(&commit->object, NULL, &study);
132 add_object_array(&commit->object, NULL, &found);
133 commit->object.flags |= STUDYING;
134 while (study.nr) {
135 struct commit *c;
136 struct commit_list *parent;
138 c = (struct commit *)object_array_pop(&study);
139 if (!c->object.parsed && !parse_object(the_repository, &c->object.oid))
140 c->object.flags |= INCOMPLETE;
142 if (c->object.flags & INCOMPLETE) {
143 is_incomplete = 1;
144 break;
146 else if (c->object.flags & SEEN)
147 continue;
148 for (parent = c->parents; parent; parent = parent->next) {
149 struct commit *p = parent->item;
150 if (p->object.flags & STUDYING)
151 continue;
152 p->object.flags |= STUDYING;
153 add_object_array(&p->object, NULL, &study);
154 add_object_array(&p->object, NULL, &found);
157 if (!is_incomplete) {
159 * make sure all commits in "found" array have all the
160 * necessary objects.
162 for (i = 0; i < found.nr; i++) {
163 struct commit *c =
164 (struct commit *)found.objects[i].item;
165 if (!tree_is_complete(get_commit_tree_oid(c))) {
166 is_incomplete = 1;
167 c->object.flags |= INCOMPLETE;
170 if (!is_incomplete) {
171 /* mark all found commits as complete, iow SEEN */
172 for (i = 0; i < found.nr; i++)
173 found.objects[i].item->flags |= SEEN;
176 /* clear flags from the objects we traversed */
177 for (i = 0; i < found.nr; i++)
178 found.objects[i].item->flags &= ~STUDYING;
179 if (is_incomplete)
180 commit->object.flags |= INCOMPLETE;
181 else {
183 * If we come here, we have (1) traversed the ancestry chain
184 * from the "commit" until we reach SEEN commits (which are
185 * known to be complete), and (2) made sure that the commits
186 * encountered during the above traversal refer to trees that
187 * are complete. Which means that we know *all* the commits
188 * we have seen during this process are complete.
190 for (i = 0; i < found.nr; i++)
191 found.objects[i].item->flags |= SEEN;
193 /* free object arrays */
194 object_array_clear(&study);
195 object_array_clear(&found);
196 return !is_incomplete;
199 static int keep_entry(struct commit **it, struct object_id *oid)
201 struct commit *commit;
203 if (is_null_oid(oid))
204 return 1;
205 commit = lookup_commit_reference_gently(the_repository, oid, 1);
206 if (!commit)
207 return 0;
210 * Make sure everything in this commit exists.
212 * We have walked all the objects reachable from the refs
213 * and cache earlier. The commits reachable by this commit
214 * must meet SEEN commits -- and then we should mark them as
215 * SEEN as well.
217 if (!commit_is_complete(commit))
218 return 0;
219 *it = commit;
220 return 1;
224 * Starting from commits in the cb->mark_list, mark commits that are
225 * reachable from them. Stop the traversal at commits older than
226 * the expire_limit and queue them back, so that the caller can call
227 * us again to restart the traversal with longer expire_limit.
229 static void mark_reachable(struct expire_reflog_policy_cb *cb)
231 struct commit_list *pending;
232 timestamp_t expire_limit = cb->mark_limit;
233 struct commit_list *leftover = NULL;
235 for (pending = cb->mark_list; pending; pending = pending->next)
236 pending->item->object.flags &= ~REACHABLE;
238 pending = cb->mark_list;
239 while (pending) {
240 struct commit_list *parent;
241 struct commit *commit = pop_commit(&pending);
242 if (commit->object.flags & REACHABLE)
243 continue;
244 if (parse_commit(commit))
245 continue;
246 commit->object.flags |= REACHABLE;
247 if (commit->date < expire_limit) {
248 commit_list_insert(commit, &leftover);
249 continue;
251 commit->object.flags |= REACHABLE;
252 parent = commit->parents;
253 while (parent) {
254 commit = parent->item;
255 parent = parent->next;
256 if (commit->object.flags & REACHABLE)
257 continue;
258 commit_list_insert(commit, &pending);
261 cb->mark_list = leftover;
264 static int unreachable(struct expire_reflog_policy_cb *cb, struct commit *commit, struct object_id *oid)
267 * We may or may not have the commit yet - if not, look it
268 * up using the supplied sha1.
270 if (!commit) {
271 if (is_null_oid(oid))
272 return 0;
274 commit = lookup_commit_reference_gently(the_repository, oid,
277 /* Not a commit -- keep it */
278 if (!commit)
279 return 0;
282 /* Reachable from the current ref? Don't prune. */
283 if (commit->object.flags & REACHABLE)
284 return 0;
286 if (cb->mark_list && cb->mark_limit) {
287 cb->mark_limit = 0; /* dig down to the root */
288 mark_reachable(cb);
291 return !(commit->object.flags & REACHABLE);
295 * Return true iff the specified reflog entry should be expired.
297 static int should_expire_reflog_ent(struct object_id *ooid, struct object_id *noid,
298 const char *email, timestamp_t timestamp, int tz,
299 const char *message, void *cb_data)
301 struct expire_reflog_policy_cb *cb = cb_data;
302 struct commit *old_commit, *new_commit;
304 if (timestamp < cb->cmd.expire_total)
305 return 1;
307 old_commit = new_commit = NULL;
308 if (cb->cmd.stalefix &&
309 (!keep_entry(&old_commit, ooid) || !keep_entry(&new_commit, noid)))
310 return 1;
312 if (timestamp < cb->cmd.expire_unreachable) {
313 if (cb->unreachable_expire_kind == UE_ALWAYS)
314 return 1;
315 if (unreachable(cb, old_commit, ooid) || unreachable(cb, new_commit, noid))
316 return 1;
319 if (cb->cmd.recno && --(cb->cmd.recno) == 0)
320 return 1;
322 return 0;
325 static int push_tip_to_list(const char *refname, const struct object_id *oid,
326 int flags, void *cb_data)
328 struct commit_list **list = cb_data;
329 struct commit *tip_commit;
330 if (flags & REF_ISSYMREF)
331 return 0;
332 tip_commit = lookup_commit_reference_gently(the_repository, oid, 1);
333 if (!tip_commit)
334 return 0;
335 commit_list_insert(tip_commit, list);
336 return 0;
339 static int is_head(const char *refname)
341 switch (ref_type(refname)) {
342 case REF_TYPE_OTHER_PSEUDOREF:
343 case REF_TYPE_MAIN_PSEUDOREF:
344 if (parse_worktree_ref(refname, NULL, NULL, &refname))
345 BUG("not a worktree ref: %s", refname);
346 break;
347 default:
348 break;
350 return !strcmp(refname, "HEAD");
353 static void reflog_expiry_prepare(const char *refname,
354 const struct object_id *oid,
355 void *cb_data)
357 struct expire_reflog_policy_cb *cb = cb_data;
359 if (!cb->cmd.expire_unreachable || is_head(refname)) {
360 cb->tip_commit = NULL;
361 cb->unreachable_expire_kind = UE_HEAD;
362 } else {
363 cb->tip_commit = lookup_commit_reference_gently(the_repository,
364 oid, 1);
365 if (!cb->tip_commit)
366 cb->unreachable_expire_kind = UE_ALWAYS;
367 else
368 cb->unreachable_expire_kind = UE_NORMAL;
371 if (cb->cmd.expire_unreachable <= cb->cmd.expire_total)
372 cb->unreachable_expire_kind = UE_ALWAYS;
374 cb->mark_list = NULL;
375 cb->tips = NULL;
376 if (cb->unreachable_expire_kind != UE_ALWAYS) {
377 if (cb->unreachable_expire_kind == UE_HEAD) {
378 struct commit_list *elem;
380 for_each_ref(push_tip_to_list, &cb->tips);
381 for (elem = cb->tips; elem; elem = elem->next)
382 commit_list_insert(elem->item, &cb->mark_list);
383 } else {
384 commit_list_insert(cb->tip_commit, &cb->mark_list);
386 cb->mark_limit = cb->cmd.expire_total;
387 mark_reachable(cb);
391 static void reflog_expiry_cleanup(void *cb_data)
393 struct expire_reflog_policy_cb *cb = cb_data;
395 if (cb->unreachable_expire_kind != UE_ALWAYS) {
396 if (cb->unreachable_expire_kind == UE_HEAD) {
397 struct commit_list *elem;
398 for (elem = cb->tips; elem; elem = elem->next)
399 clear_commit_marks(elem->item, REACHABLE);
400 free_commit_list(cb->tips);
401 } else {
402 clear_commit_marks(cb->tip_commit, REACHABLE);
407 static int collect_reflog(const char *ref, const struct object_id *oid, int unused, void *cb_data)
409 struct collected_reflog *e;
410 struct collect_reflog_cb *cb = cb_data;
411 struct strbuf newref = STRBUF_INIT;
414 * Avoid collecting the same shared ref multiple times because
415 * they are available via all worktrees.
417 if (!cb->wt->is_current && ref_type(ref) == REF_TYPE_NORMAL)
418 return 0;
420 strbuf_worktree_ref(cb->wt, &newref, ref);
421 FLEX_ALLOC_STR(e, reflog, newref.buf);
422 strbuf_release(&newref);
424 oidcpy(&e->oid, oid);
425 ALLOC_GROW(cb->e, cb->nr + 1, cb->alloc);
426 cb->e[cb->nr++] = e;
427 return 0;
430 static struct reflog_expire_cfg {
431 struct reflog_expire_cfg *next;
432 timestamp_t expire_total;
433 timestamp_t expire_unreachable;
434 char pattern[FLEX_ARRAY];
435 } *reflog_expire_cfg, **reflog_expire_cfg_tail;
437 static struct reflog_expire_cfg *find_cfg_ent(const char *pattern, size_t len)
439 struct reflog_expire_cfg *ent;
441 if (!reflog_expire_cfg_tail)
442 reflog_expire_cfg_tail = &reflog_expire_cfg;
444 for (ent = reflog_expire_cfg; ent; ent = ent->next)
445 if (!strncmp(ent->pattern, pattern, len) &&
446 ent->pattern[len] == '\0')
447 return ent;
449 FLEX_ALLOC_MEM(ent, pattern, pattern, len);
450 *reflog_expire_cfg_tail = ent;
451 reflog_expire_cfg_tail = &(ent->next);
452 return ent;
455 /* expiry timer slot */
456 #define EXPIRE_TOTAL 01
457 #define EXPIRE_UNREACH 02
459 static int reflog_expire_config(const char *var, const char *value, void *cb)
461 const char *pattern, *key;
462 size_t pattern_len;
463 timestamp_t expire;
464 int slot;
465 struct reflog_expire_cfg *ent;
467 if (parse_config_key(var, "gc", &pattern, &pattern_len, &key) < 0)
468 return git_default_config(var, value, cb);
470 if (!strcmp(key, "reflogexpire")) {
471 slot = EXPIRE_TOTAL;
472 if (git_config_expiry_date(&expire, var, value))
473 return -1;
474 } else if (!strcmp(key, "reflogexpireunreachable")) {
475 slot = EXPIRE_UNREACH;
476 if (git_config_expiry_date(&expire, var, value))
477 return -1;
478 } else
479 return git_default_config(var, value, cb);
481 if (!pattern) {
482 switch (slot) {
483 case EXPIRE_TOTAL:
484 default_reflog_expire = expire;
485 break;
486 case EXPIRE_UNREACH:
487 default_reflog_expire_unreachable = expire;
488 break;
490 return 0;
493 ent = find_cfg_ent(pattern, pattern_len);
494 if (!ent)
495 return -1;
496 switch (slot) {
497 case EXPIRE_TOTAL:
498 ent->expire_total = expire;
499 break;
500 case EXPIRE_UNREACH:
501 ent->expire_unreachable = expire;
502 break;
504 return 0;
507 static void set_reflog_expiry_param(struct cmd_reflog_expire_cb *cb, int slot, const char *ref)
509 struct reflog_expire_cfg *ent;
511 if (slot == (EXPIRE_TOTAL|EXPIRE_UNREACH))
512 return; /* both given explicitly -- nothing to tweak */
514 for (ent = reflog_expire_cfg; ent; ent = ent->next) {
515 if (!wildmatch(ent->pattern, ref, 0)) {
516 if (!(slot & EXPIRE_TOTAL))
517 cb->expire_total = ent->expire_total;
518 if (!(slot & EXPIRE_UNREACH))
519 cb->expire_unreachable = ent->expire_unreachable;
520 return;
525 * If unconfigured, make stash never expire
527 if (!strcmp(ref, "refs/stash")) {
528 if (!(slot & EXPIRE_TOTAL))
529 cb->expire_total = 0;
530 if (!(slot & EXPIRE_UNREACH))
531 cb->expire_unreachable = 0;
532 return;
535 /* Nothing matched -- use the default value */
536 if (!(slot & EXPIRE_TOTAL))
537 cb->expire_total = default_reflog_expire;
538 if (!(slot & EXPIRE_UNREACH))
539 cb->expire_unreachable = default_reflog_expire_unreachable;
542 static int cmd_reflog_expire(int argc, const char **argv, const char *prefix)
544 struct expire_reflog_policy_cb cb;
545 timestamp_t now = time(NULL);
546 int i, status, do_all, all_worktrees = 1;
547 int explicit_expiry = 0;
548 unsigned int flags = 0;
550 default_reflog_expire_unreachable = now - 30 * 24 * 3600;
551 default_reflog_expire = now - 90 * 24 * 3600;
552 git_config(reflog_expire_config, NULL);
554 save_commit_buffer = 0;
555 do_all = status = 0;
556 memset(&cb, 0, sizeof(cb));
558 cb.cmd.expire_total = default_reflog_expire;
559 cb.cmd.expire_unreachable = default_reflog_expire_unreachable;
561 for (i = 1; i < argc; i++) {
562 const char *arg = argv[i];
564 if (!strcmp(arg, "--dry-run") || !strcmp(arg, "-n"))
565 flags |= EXPIRE_REFLOGS_DRY_RUN;
566 else if (skip_prefix(arg, "--expire=", &arg)) {
567 if (parse_expiry_date(arg, &cb.cmd.expire_total))
568 die(_("'%s' is not a valid timestamp"), arg);
569 explicit_expiry |= EXPIRE_TOTAL;
571 else if (skip_prefix(arg, "--expire-unreachable=", &arg)) {
572 if (parse_expiry_date(arg, &cb.cmd.expire_unreachable))
573 die(_("'%s' is not a valid timestamp"), arg);
574 explicit_expiry |= EXPIRE_UNREACH;
576 else if (!strcmp(arg, "--stale-fix"))
577 cb.cmd.stalefix = 1;
578 else if (!strcmp(arg, "--rewrite"))
579 flags |= EXPIRE_REFLOGS_REWRITE;
580 else if (!strcmp(arg, "--updateref"))
581 flags |= EXPIRE_REFLOGS_UPDATE_REF;
582 else if (!strcmp(arg, "--all"))
583 do_all = 1;
584 else if (!strcmp(arg, "--single-worktree"))
585 all_worktrees = 0;
586 else if (!strcmp(arg, "--verbose"))
587 flags |= EXPIRE_REFLOGS_VERBOSE;
588 else if (!strcmp(arg, "--")) {
589 i++;
590 break;
592 else if (arg[0] == '-')
593 usage(_(reflog_expire_usage));
594 else
595 break;
599 * We can trust the commits and objects reachable from refs
600 * even in older repository. We cannot trust what's reachable
601 * from reflog if the repository was pruned with older git.
603 if (cb.cmd.stalefix) {
604 repo_init_revisions(the_repository, &cb.cmd.revs, prefix);
605 cb.cmd.revs.do_not_die_on_missing_tree = 1;
606 cb.cmd.revs.ignore_missing = 1;
607 cb.cmd.revs.ignore_missing_links = 1;
608 if (flags & EXPIRE_REFLOGS_VERBOSE)
609 printf(_("Marking reachable objects..."));
610 mark_reachable_objects(&cb.cmd.revs, 0, 0, NULL);
611 if (flags & EXPIRE_REFLOGS_VERBOSE)
612 putchar('\n');
615 if (do_all) {
616 struct collect_reflog_cb collected;
617 struct worktree **worktrees, **p;
618 int i;
620 memset(&collected, 0, sizeof(collected));
621 worktrees = get_worktrees();
622 for (p = worktrees; *p; p++) {
623 if (!all_worktrees && !(*p)->is_current)
624 continue;
625 collected.wt = *p;
626 refs_for_each_reflog(get_worktree_ref_store(*p),
627 collect_reflog, &collected);
629 free_worktrees(worktrees);
630 for (i = 0; i < collected.nr; i++) {
631 struct collected_reflog *e = collected.e[i];
632 set_reflog_expiry_param(&cb.cmd, explicit_expiry, e->reflog);
633 status |= reflog_expire(e->reflog, &e->oid, flags,
634 reflog_expiry_prepare,
635 should_expire_reflog_ent,
636 reflog_expiry_cleanup,
637 &cb);
638 free(e);
640 free(collected.e);
643 for (; i < argc; i++) {
644 char *ref;
645 struct object_id oid;
646 if (!dwim_log(argv[i], strlen(argv[i]), &oid, &ref)) {
647 status |= error(_("%s points nowhere!"), argv[i]);
648 continue;
650 set_reflog_expiry_param(&cb.cmd, explicit_expiry, ref);
651 status |= reflog_expire(ref, &oid, flags,
652 reflog_expiry_prepare,
653 should_expire_reflog_ent,
654 reflog_expiry_cleanup,
655 &cb);
657 return status;
660 static int count_reflog_ent(struct object_id *ooid, struct object_id *noid,
661 const char *email, timestamp_t timestamp, int tz,
662 const char *message, void *cb_data)
664 struct expire_reflog_policy_cb *cb = cb_data;
665 if (!cb->cmd.expire_total || timestamp < cb->cmd.expire_total)
666 cb->cmd.recno++;
667 return 0;
670 static int cmd_reflog_delete(int argc, const char **argv, const char *prefix)
672 struct expire_reflog_policy_cb cb;
673 int i, status = 0;
674 unsigned int flags = 0;
676 memset(&cb, 0, sizeof(cb));
678 for (i = 1; i < argc; i++) {
679 const char *arg = argv[i];
680 if (!strcmp(arg, "--dry-run") || !strcmp(arg, "-n"))
681 flags |= EXPIRE_REFLOGS_DRY_RUN;
682 else if (!strcmp(arg, "--rewrite"))
683 flags |= EXPIRE_REFLOGS_REWRITE;
684 else if (!strcmp(arg, "--updateref"))
685 flags |= EXPIRE_REFLOGS_UPDATE_REF;
686 else if (!strcmp(arg, "--verbose"))
687 flags |= EXPIRE_REFLOGS_VERBOSE;
688 else if (!strcmp(arg, "--")) {
689 i++;
690 break;
692 else if (arg[0] == '-')
693 usage(_(reflog_delete_usage));
694 else
695 break;
698 if (argc - i < 1)
699 return error(_("no reflog specified to delete"));
701 for ( ; i < argc; i++) {
702 const char *spec = strstr(argv[i], "@{");
703 struct object_id oid;
704 char *ep, *ref;
705 int recno;
707 if (!spec) {
708 status |= error(_("not a reflog: %s"), argv[i]);
709 continue;
712 if (!dwim_log(argv[i], spec - argv[i], &oid, &ref)) {
713 status |= error(_("no reflog for '%s'"), argv[i]);
714 continue;
717 recno = strtoul(spec + 2, &ep, 10);
718 if (*ep == '}') {
719 cb.cmd.recno = -recno;
720 for_each_reflog_ent(ref, count_reflog_ent, &cb);
721 } else {
722 cb.cmd.expire_total = approxidate(spec + 2);
723 for_each_reflog_ent(ref, count_reflog_ent, &cb);
724 cb.cmd.expire_total = 0;
727 status |= reflog_expire(ref, &oid, flags,
728 reflog_expiry_prepare,
729 should_expire_reflog_ent,
730 reflog_expiry_cleanup,
731 &cb);
732 free(ref);
734 return status;
737 static int cmd_reflog_exists(int argc, const char **argv, const char *prefix)
739 int i, start = 0;
741 for (i = 1; i < argc; i++) {
742 const char *arg = argv[i];
743 if (!strcmp(arg, "--")) {
744 i++;
745 break;
747 else if (arg[0] == '-')
748 usage(_(reflog_exists_usage));
749 else
750 break;
753 start = i;
755 if (argc - start != 1)
756 usage(_(reflog_exists_usage));
758 if (check_refname_format(argv[start], REFNAME_ALLOW_ONELEVEL))
759 die(_("invalid ref format: %s"), argv[start]);
760 return !reflog_exists(argv[start]);
764 * main "reflog"
767 static const char reflog_usage[] =
768 N_("git reflog [ show | expire | delete | exists ]");
770 int cmd_reflog(int argc, const char **argv, const char *prefix)
772 if (argc > 1 && !strcmp(argv[1], "-h"))
773 usage(_(reflog_usage));
775 /* With no command, we default to showing it. */
776 if (argc < 2 || *argv[1] == '-')
777 return cmd_log_reflog(argc, argv, prefix);
779 if (!strcmp(argv[1], "show"))
780 return cmd_log_reflog(argc - 1, argv + 1, prefix);
782 if (!strcmp(argv[1], "expire"))
783 return cmd_reflog_expire(argc - 1, argv + 1, prefix);
785 if (!strcmp(argv[1], "delete"))
786 return cmd_reflog_delete(argc - 1, argv + 1, prefix);
788 if (!strcmp(argv[1], "exists"))
789 return cmd_reflog_exists(argc - 1, argv + 1, prefix);
791 return cmd_log_reflog(argc, argv, prefix);