15 static const char reflog_expire_usage
[] =
16 "git reflog expire [--verbose] [--dry-run] [--stale-fix] [--expire=<time>] [--expire-unreachable=<time>] [--all] <refs>...";
17 static const char reflog_delete_usage
[] =
18 "git reflog delete [--verbose] [--dry-run] [--rewrite] [--updateref] <refs>...";
20 static unsigned long default_reflog_expire
;
21 static unsigned long default_reflog_expire_unreachable
;
23 enum expire_reflog_flags
{
24 EXPIRE_REFLOGS_DRY_RUN
= 1 << 0,
25 EXPIRE_REFLOGS_UPDATE_REF
= 1 << 1,
26 EXPIRE_REFLOGS_VERBOSE
= 1 << 2,
27 EXPIRE_REFLOGS_REWRITE
= 1 << 3
30 struct cmd_reflog_expire_cb
{
33 unsigned long expire_total
;
34 unsigned long expire_unreachable
;
38 struct expire_reflog_policy_cb
{
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 expire_reflog_cb
{
55 unsigned char last_kept_sha1
[20];
58 struct collected_reflog
{
59 unsigned char sha1
[20];
60 char reflog
[FLEX_ARRAY
];
63 struct collect_reflog_cb
{
64 struct collected_reflog
**e
;
69 #define INCOMPLETE (1u<<10)
70 #define STUDYING (1u<<11)
71 #define REACHABLE (1u<<12)
73 static int tree_is_complete(const unsigned char *sha1
)
75 struct tree_desc desc
;
76 struct name_entry entry
;
80 tree
= lookup_tree(sha1
);
83 if (tree
->object
.flags
& SEEN
)
85 if (tree
->object
.flags
& INCOMPLETE
)
89 enum object_type type
;
91 void *data
= read_sha1_file(sha1
, &type
, &size
);
93 tree
->object
.flags
|= INCOMPLETE
;
99 init_tree_desc(&desc
, tree
->buffer
, tree
->size
);
101 while (tree_entry(&desc
, &entry
)) {
102 if (!has_sha1_file(entry
.sha1
) ||
103 (S_ISDIR(entry
.mode
) && !tree_is_complete(entry
.sha1
))) {
104 tree
->object
.flags
|= INCOMPLETE
;
108 free_tree_buffer(tree
);
111 tree
->object
.flags
|= SEEN
;
115 static int commit_is_complete(struct commit
*commit
)
117 struct object_array study
;
118 struct object_array found
;
119 int is_incomplete
= 0;
123 if (commit
->object
.flags
& SEEN
)
125 if (commit
->object
.flags
& INCOMPLETE
)
128 * Find all commits that are reachable and are not marked as
129 * SEEN. Then make sure the trees and blobs contained are
130 * complete. After that, mark these commits also as SEEN.
131 * If some of the objects that are needed to complete this
132 * commit are missing, mark this commit as INCOMPLETE.
134 memset(&study
, 0, sizeof(study
));
135 memset(&found
, 0, sizeof(found
));
136 add_object_array(&commit
->object
, NULL
, &study
);
137 add_object_array(&commit
->object
, NULL
, &found
);
138 commit
->object
.flags
|= STUDYING
;
141 struct commit_list
*parent
;
143 c
= (struct commit
*)study
.objects
[--study
.nr
].item
;
144 if (!c
->object
.parsed
&& !parse_object(c
->object
.sha1
))
145 c
->object
.flags
|= INCOMPLETE
;
147 if (c
->object
.flags
& INCOMPLETE
) {
151 else if (c
->object
.flags
& SEEN
)
153 for (parent
= c
->parents
; parent
; parent
= parent
->next
) {
154 struct commit
*p
= parent
->item
;
155 if (p
->object
.flags
& STUDYING
)
157 p
->object
.flags
|= STUDYING
;
158 add_object_array(&p
->object
, NULL
, &study
);
159 add_object_array(&p
->object
, NULL
, &found
);
162 if (!is_incomplete
) {
164 * make sure all commits in "found" array have all the
167 for (i
= 0; i
< found
.nr
; i
++) {
169 (struct commit
*)found
.objects
[i
].item
;
170 if (!tree_is_complete(c
->tree
->object
.sha1
)) {
172 c
->object
.flags
|= INCOMPLETE
;
175 if (!is_incomplete
) {
176 /* mark all found commits as complete, iow SEEN */
177 for (i
= 0; i
< found
.nr
; i
++)
178 found
.objects
[i
].item
->flags
|= SEEN
;
181 /* clear flags from the objects we traversed */
182 for (i
= 0; i
< found
.nr
; i
++)
183 found
.objects
[i
].item
->flags
&= ~STUDYING
;
185 commit
->object
.flags
|= INCOMPLETE
;
188 * If we come here, we have (1) traversed the ancestry chain
189 * from the "commit" until we reach SEEN commits (which are
190 * known to be complete), and (2) made sure that the commits
191 * encountered during the above traversal refer to trees that
192 * are complete. Which means that we know *all* the commits
193 * we have seen during this process are complete.
195 for (i
= 0; i
< found
.nr
; i
++)
196 found
.objects
[i
].item
->flags
|= SEEN
;
198 /* free object arrays */
201 return !is_incomplete
;
204 static int keep_entry(struct commit
**it
, unsigned char *sha1
)
206 struct commit
*commit
;
208 if (is_null_sha1(sha1
))
210 commit
= lookup_commit_reference_gently(sha1
, 1);
215 * Make sure everything in this commit exists.
217 * We have walked all the objects reachable from the refs
218 * and cache earlier. The commits reachable by this commit
219 * must meet SEEN commits -- and then we should mark them as
222 if (!commit_is_complete(commit
))
229 * Starting from commits in the cb->mark_list, mark commits that are
230 * reachable from them. Stop the traversal at commits older than
231 * the expire_limit and queue them back, so that the caller can call
232 * us again to restart the traversal with longer expire_limit.
234 static void mark_reachable(struct expire_reflog_policy_cb
*cb
)
236 struct commit
*commit
;
237 struct commit_list
*pending
;
238 unsigned long expire_limit
= cb
->mark_limit
;
239 struct commit_list
*leftover
= NULL
;
241 for (pending
= cb
->mark_list
; pending
; pending
= pending
->next
)
242 pending
->item
->object
.flags
&= ~REACHABLE
;
244 pending
= cb
->mark_list
;
246 struct commit_list
*entry
= pending
;
247 struct commit_list
*parent
;
248 pending
= entry
->next
;
249 commit
= entry
->item
;
251 if (commit
->object
.flags
& REACHABLE
)
253 if (parse_commit(commit
))
255 commit
->object
.flags
|= REACHABLE
;
256 if (commit
->date
< expire_limit
) {
257 commit_list_insert(commit
, &leftover
);
260 commit
->object
.flags
|= REACHABLE
;
261 parent
= commit
->parents
;
263 commit
= parent
->item
;
264 parent
= parent
->next
;
265 if (commit
->object
.flags
& REACHABLE
)
267 commit_list_insert(commit
, &pending
);
270 cb
->mark_list
= leftover
;
273 static int unreachable(struct expire_reflog_policy_cb
*cb
, struct commit
*commit
, unsigned char *sha1
)
276 * We may or may not have the commit yet - if not, look it
277 * up using the supplied sha1.
280 if (is_null_sha1(sha1
))
283 commit
= lookup_commit_reference_gently(sha1
, 1);
285 /* Not a commit -- keep it */
290 /* Reachable from the current ref? Don't prune. */
291 if (commit
->object
.flags
& REACHABLE
)
294 if (cb
->mark_list
&& cb
->mark_limit
) {
295 cb
->mark_limit
= 0; /* dig down to the root */
299 return !(commit
->object
.flags
& REACHABLE
);
303 * Return true iff the specified reflog entry should be expired.
305 static int should_expire_reflog_ent(unsigned char *osha1
, unsigned char *nsha1
,
306 const char *email
, unsigned long timestamp
, int tz
,
307 const char *message
, void *cb_data
)
309 struct expire_reflog_policy_cb
*cb
= cb_data
;
310 struct commit
*old
, *new;
312 if (timestamp
< cb
->cmd
->expire_total
)
316 if (cb
->cmd
->stalefix
&&
317 (!keep_entry(&old
, osha1
) || !keep_entry(&new, nsha1
)))
320 if (timestamp
< cb
->cmd
->expire_unreachable
) {
321 if (cb
->unreachable_expire_kind
== UE_ALWAYS
)
323 if (unreachable(cb
, old
, osha1
) || unreachable(cb
, new, nsha1
))
327 if (cb
->cmd
->recno
&& --(cb
->cmd
->recno
) == 0)
333 static int expire_reflog_ent(unsigned char *osha1
, unsigned char *nsha1
,
334 const char *email
, unsigned long timestamp
, int tz
,
335 const char *message
, void *cb_data
)
337 struct expire_reflog_cb
*cb
= cb_data
;
338 struct expire_reflog_policy_cb
*policy_cb
= cb
->policy_cb
;
340 if (cb
->flags
& EXPIRE_REFLOGS_REWRITE
)
341 osha1
= cb
->last_kept_sha1
;
343 if (should_expire_reflog_ent(osha1
, nsha1
, email
, timestamp
, tz
,
344 message
, policy_cb
)) {
346 printf("would prune %s", message
);
347 else if (cb
->flags
& EXPIRE_REFLOGS_VERBOSE
)
348 printf("prune %s", message
);
351 char sign
= (tz
< 0) ? '-' : '+';
352 int zone
= (tz
< 0) ? (-tz
) : tz
;
353 fprintf(cb
->newlog
, "%s %s %s %lu %c%04d\t%s",
354 sha1_to_hex(osha1
), sha1_to_hex(nsha1
),
355 email
, timestamp
, sign
, zone
,
357 hashcpy(cb
->last_kept_sha1
, nsha1
);
359 if (cb
->flags
& EXPIRE_REFLOGS_VERBOSE
)
360 printf("keep %s", message
);
365 static int push_tip_to_list(const char *refname
, const unsigned char *sha1
,
366 int flags
, void *cb_data
)
368 struct commit_list
**list
= cb_data
;
369 struct commit
*tip_commit
;
370 if (flags
& REF_ISSYMREF
)
372 tip_commit
= lookup_commit_reference_gently(sha1
, 1);
375 commit_list_insert(tip_commit
, list
);
379 static void reflog_expiry_prepare(const char *refname
,
380 const unsigned char *sha1
,
381 struct expire_reflog_policy_cb
*cb
)
383 if (!cb
->cmd
->expire_unreachable
|| !strcmp(refname
, "HEAD")) {
384 cb
->tip_commit
= NULL
;
385 cb
->unreachable_expire_kind
= UE_HEAD
;
387 cb
->tip_commit
= lookup_commit_reference_gently(sha1
, 1);
389 cb
->unreachable_expire_kind
= UE_ALWAYS
;
391 cb
->unreachable_expire_kind
= UE_NORMAL
;
394 if (cb
->cmd
->expire_unreachable
<= cb
->cmd
->expire_total
)
395 cb
->unreachable_expire_kind
= UE_ALWAYS
;
397 cb
->mark_list
= NULL
;
399 if (cb
->unreachable_expire_kind
!= UE_ALWAYS
) {
400 if (cb
->unreachable_expire_kind
== UE_HEAD
) {
401 struct commit_list
*elem
;
402 for_each_ref(push_tip_to_list
, &cb
->tips
);
403 for (elem
= cb
->tips
; elem
; elem
= elem
->next
)
404 commit_list_insert(elem
->item
, &cb
->mark_list
);
406 commit_list_insert(cb
->tip_commit
, &cb
->mark_list
);
408 cb
->mark_limit
= cb
->cmd
->expire_total
;
413 static void reflog_expiry_cleanup(struct expire_reflog_policy_cb
*cb
)
415 if (cb
->unreachable_expire_kind
!= UE_ALWAYS
) {
416 if (cb
->unreachable_expire_kind
== UE_HEAD
) {
417 struct commit_list
*elem
;
418 for (elem
= cb
->tips
; elem
; elem
= elem
->next
)
419 clear_commit_marks(elem
->item
, REACHABLE
);
420 free_commit_list(cb
->tips
);
422 clear_commit_marks(cb
->tip_commit
, REACHABLE
);
427 static int expire_reflog(const char *refname
, const unsigned char *sha1
,
428 unsigned int flags
, struct cmd_reflog_expire_cb
*cmd
)
430 static struct lock_file reflog_lock
;
431 struct expire_reflog_cb cb
;
432 struct expire_reflog_policy_cb policy_cb
;
433 struct ref_lock
*lock
;
437 memset(&cb
, 0, sizeof(cb
));
438 memset(&policy_cb
, 0, sizeof(policy_cb
));
440 cb
.policy_cb
= &policy_cb
;
443 * The reflog file is locked by holding the lock on the
444 * reference itself, plus we might need to update the
445 * reference if --updateref was specified:
447 lock
= lock_any_ref_for_update(refname
, sha1
, 0, NULL
);
449 return error("cannot lock ref '%s'", refname
);
450 if (!reflog_exists(refname
)) {
455 log_file
= git_pathdup("logs/%s", refname
);
456 if (!(flags
& EXPIRE_REFLOGS_DRY_RUN
)) {
458 * Even though holding $GIT_DIR/logs/$reflog.lock has
459 * no locking implications, we use the lock_file
460 * machinery here anyway because it does a lot of the
461 * work we need, including cleaning up if the program
462 * exits unexpectedly.
464 if (hold_lock_file_for_update(&reflog_lock
, log_file
, 0) < 0) {
465 struct strbuf err
= STRBUF_INIT
;
466 unable_to_lock_message(log_file
, errno
, &err
);
467 error("%s", err
.buf
);
468 strbuf_release(&err
);
471 cb
.newlog
= fdopen_lock_file(&reflog_lock
, "w");
473 error("cannot fdopen %s (%s)",
474 reflog_lock
.filename
.buf
, strerror(errno
));
481 reflog_expiry_prepare(refname
, sha1
, &policy_cb
);
482 for_each_reflog_ent(refname
, expire_reflog_ent
, &cb
);
483 reflog_expiry_cleanup(&policy_cb
);
485 if (!(flags
& EXPIRE_REFLOGS_DRY_RUN
)) {
486 if (close_lock_file(&reflog_lock
)) {
487 status
|= error("couldn't write %s: %s", log_file
,
489 } else if ((flags
& EXPIRE_REFLOGS_UPDATE_REF
) &&
490 (write_in_full(lock
->lock_fd
,
491 sha1_to_hex(cb
.last_kept_sha1
), 40) != 40 ||
492 write_str_in_full(lock
->lock_fd
, "\n") != 1 ||
493 close_ref(lock
) < 0)) {
494 status
|= error("couldn't write %s",
495 lock
->lk
->filename
.buf
);
496 rollback_lock_file(&reflog_lock
);
497 } else if (commit_lock_file(&reflog_lock
)) {
498 status
|= error("unable to commit reflog '%s' (%s)",
499 log_file
, strerror(errno
));
500 } else if ((flags
& EXPIRE_REFLOGS_UPDATE_REF
) && commit_ref(lock
)) {
501 status
|= error("couldn't set %s", lock
->ref_name
);
509 rollback_lock_file(&reflog_lock
);
515 static int collect_reflog(const char *ref
, const unsigned char *sha1
, int unused
, void *cb_data
)
517 struct collected_reflog
*e
;
518 struct collect_reflog_cb
*cb
= cb_data
;
519 size_t namelen
= strlen(ref
);
521 e
= xmalloc(sizeof(*e
) + namelen
+ 1);
522 hashcpy(e
->sha1
, sha1
);
523 memcpy(e
->reflog
, ref
, namelen
+ 1);
524 ALLOC_GROW(cb
->e
, cb
->nr
+ 1, cb
->alloc
);
529 static struct reflog_expire_cfg
{
530 struct reflog_expire_cfg
*next
;
531 unsigned long expire_total
;
532 unsigned long expire_unreachable
;
534 char pattern
[FLEX_ARRAY
];
535 } *reflog_expire_cfg
, **reflog_expire_cfg_tail
;
537 static struct reflog_expire_cfg
*find_cfg_ent(const char *pattern
, size_t len
)
539 struct reflog_expire_cfg
*ent
;
541 if (!reflog_expire_cfg_tail
)
542 reflog_expire_cfg_tail
= &reflog_expire_cfg
;
544 for (ent
= reflog_expire_cfg
; ent
; ent
= ent
->next
)
545 if (ent
->len
== len
&&
546 !memcmp(ent
->pattern
, pattern
, len
))
549 ent
= xcalloc(1, (sizeof(*ent
) + len
));
550 memcpy(ent
->pattern
, pattern
, len
);
552 *reflog_expire_cfg_tail
= ent
;
553 reflog_expire_cfg_tail
= &(ent
->next
);
557 static int parse_expire_cfg_value(const char *var
, const char *value
, unsigned long *expire
)
560 return config_error_nonbool(var
);
561 if (parse_expiry_date(value
, expire
))
562 return error(_("%s' for '%s' is not a valid timestamp"),
567 /* expiry timer slot */
568 #define EXPIRE_TOTAL 01
569 #define EXPIRE_UNREACH 02
571 static int reflog_expire_config(const char *var
, const char *value
, void *cb
)
573 const char *pattern
, *key
;
575 unsigned long expire
;
577 struct reflog_expire_cfg
*ent
;
579 if (parse_config_key(var
, "gc", &pattern
, &pattern_len
, &key
) < 0)
580 return git_default_config(var
, value
, cb
);
582 if (!strcmp(key
, "reflogexpire")) {
584 if (parse_expire_cfg_value(var
, value
, &expire
))
586 } else if (!strcmp(key
, "reflogexpireunreachable")) {
587 slot
= EXPIRE_UNREACH
;
588 if (parse_expire_cfg_value(var
, value
, &expire
))
591 return git_default_config(var
, value
, cb
);
596 default_reflog_expire
= expire
;
599 default_reflog_expire_unreachable
= expire
;
605 ent
= find_cfg_ent(pattern
, pattern_len
);
610 ent
->expire_total
= expire
;
613 ent
->expire_unreachable
= expire
;
619 static void set_reflog_expiry_param(struct cmd_reflog_expire_cb
*cb
, int slot
, const char *ref
)
621 struct reflog_expire_cfg
*ent
;
623 if (slot
== (EXPIRE_TOTAL
|EXPIRE_UNREACH
))
624 return; /* both given explicitly -- nothing to tweak */
626 for (ent
= reflog_expire_cfg
; ent
; ent
= ent
->next
) {
627 if (!wildmatch(ent
->pattern
, ref
, 0, NULL
)) {
628 if (!(slot
& EXPIRE_TOTAL
))
629 cb
->expire_total
= ent
->expire_total
;
630 if (!(slot
& EXPIRE_UNREACH
))
631 cb
->expire_unreachable
= ent
->expire_unreachable
;
637 * If unconfigured, make stash never expire
639 if (!strcmp(ref
, "refs/stash")) {
640 if (!(slot
& EXPIRE_TOTAL
))
641 cb
->expire_total
= 0;
642 if (!(slot
& EXPIRE_UNREACH
))
643 cb
->expire_unreachable
= 0;
647 /* Nothing matched -- use the default value */
648 if (!(slot
& EXPIRE_TOTAL
))
649 cb
->expire_total
= default_reflog_expire
;
650 if (!(slot
& EXPIRE_UNREACH
))
651 cb
->expire_unreachable
= default_reflog_expire_unreachable
;
654 static int cmd_reflog_expire(int argc
, const char **argv
, const char *prefix
)
656 struct cmd_reflog_expire_cb cb
;
657 unsigned long now
= time(NULL
);
658 int i
, status
, do_all
;
659 int explicit_expiry
= 0;
660 unsigned int flags
= 0;
662 default_reflog_expire_unreachable
= now
- 30 * 24 * 3600;
663 default_reflog_expire
= now
- 90 * 24 * 3600;
664 git_config(reflog_expire_config
, NULL
);
666 save_commit_buffer
= 0;
668 memset(&cb
, 0, sizeof(cb
));
670 cb
.expire_total
= default_reflog_expire
;
671 cb
.expire_unreachable
= default_reflog_expire_unreachable
;
673 for (i
= 1; i
< argc
; i
++) {
674 const char *arg
= argv
[i
];
675 if (!strcmp(arg
, "--dry-run") || !strcmp(arg
, "-n"))
676 flags
|= EXPIRE_REFLOGS_DRY_RUN
;
677 else if (starts_with(arg
, "--expire=")) {
678 if (parse_expiry_date(arg
+ 9, &cb
.expire_total
))
679 die(_("'%s' is not a valid timestamp"), arg
);
680 explicit_expiry
|= EXPIRE_TOTAL
;
682 else if (starts_with(arg
, "--expire-unreachable=")) {
683 if (parse_expiry_date(arg
+ 21, &cb
.expire_unreachable
))
684 die(_("'%s' is not a valid timestamp"), arg
);
685 explicit_expiry
|= EXPIRE_UNREACH
;
687 else if (!strcmp(arg
, "--stale-fix"))
689 else if (!strcmp(arg
, "--rewrite"))
690 flags
|= EXPIRE_REFLOGS_REWRITE
;
691 else if (!strcmp(arg
, "--updateref"))
692 flags
|= EXPIRE_REFLOGS_UPDATE_REF
;
693 else if (!strcmp(arg
, "--all"))
695 else if (!strcmp(arg
, "--verbose"))
696 flags
|= EXPIRE_REFLOGS_VERBOSE
;
697 else if (!strcmp(arg
, "--")) {
701 else if (arg
[0] == '-')
702 usage(reflog_expire_usage
);
708 * We can trust the commits and objects reachable from refs
709 * even in older repository. We cannot trust what's reachable
710 * from reflog if the repository was pruned with older git.
713 init_revisions(&cb
.revs
, prefix
);
714 if (flags
& EXPIRE_REFLOGS_VERBOSE
)
715 printf("Marking reachable objects...");
716 mark_reachable_objects(&cb
.revs
, 0, 0, NULL
);
717 if (flags
& EXPIRE_REFLOGS_VERBOSE
)
722 struct collect_reflog_cb collected
;
725 memset(&collected
, 0, sizeof(collected
));
726 for_each_reflog(collect_reflog
, &collected
);
727 for (i
= 0; i
< collected
.nr
; i
++) {
728 struct collected_reflog
*e
= collected
.e
[i
];
729 set_reflog_expiry_param(&cb
, explicit_expiry
, e
->reflog
);
730 status
|= expire_reflog(e
->reflog
, e
->sha1
, flags
, &cb
);
736 for (; i
< argc
; i
++) {
738 unsigned char sha1
[20];
739 if (!dwim_log(argv
[i
], strlen(argv
[i
]), sha1
, &ref
)) {
740 status
|= error("%s points nowhere!", argv
[i
]);
743 set_reflog_expiry_param(&cb
, explicit_expiry
, ref
);
744 status
|= expire_reflog(ref
, sha1
, flags
, &cb
);
749 static int count_reflog_ent(unsigned char *osha1
, unsigned char *nsha1
,
750 const char *email
, unsigned long timestamp
, int tz
,
751 const char *message
, void *cb_data
)
753 struct cmd_reflog_expire_cb
*cb
= cb_data
;
754 if (!cb
->expire_total
|| timestamp
< cb
->expire_total
)
759 static int cmd_reflog_delete(int argc
, const char **argv
, const char *prefix
)
761 struct cmd_reflog_expire_cb cb
;
763 unsigned int flags
= 0;
765 memset(&cb
, 0, sizeof(cb
));
767 for (i
= 1; i
< argc
; i
++) {
768 const char *arg
= argv
[i
];
769 if (!strcmp(arg
, "--dry-run") || !strcmp(arg
, "-n"))
770 flags
|= EXPIRE_REFLOGS_DRY_RUN
;
771 else if (!strcmp(arg
, "--rewrite"))
772 flags
|= EXPIRE_REFLOGS_REWRITE
;
773 else if (!strcmp(arg
, "--updateref"))
774 flags
|= EXPIRE_REFLOGS_UPDATE_REF
;
775 else if (!strcmp(arg
, "--verbose"))
776 flags
|= EXPIRE_REFLOGS_VERBOSE
;
777 else if (!strcmp(arg
, "--")) {
781 else if (arg
[0] == '-')
782 usage(reflog_delete_usage
);
788 return error("Nothing to delete?");
790 for ( ; i
< argc
; i
++) {
791 const char *spec
= strstr(argv
[i
], "@{");
792 unsigned char sha1
[20];
797 status
|= error("Not a reflog: %s", argv
[i
]);
801 if (!dwim_log(argv
[i
], spec
- argv
[i
], sha1
, &ref
)) {
802 status
|= error("no reflog for '%s'", argv
[i
]);
806 recno
= strtoul(spec
+ 2, &ep
, 10);
809 for_each_reflog_ent(ref
, count_reflog_ent
, &cb
);
811 cb
.expire_total
= approxidate(spec
+ 2);
812 for_each_reflog_ent(ref
, count_reflog_ent
, &cb
);
816 status
|= expire_reflog(ref
, sha1
, flags
, &cb
);
826 static const char reflog_usage
[] =
827 "git reflog [ show | expire | delete ]";
829 int cmd_reflog(int argc
, const char **argv
, const char *prefix
)
831 if (argc
> 1 && !strcmp(argv
[1], "-h"))
834 /* With no command, we default to showing it. */
835 if (argc
< 2 || *argv
[1] == '-')
836 return cmd_log_reflog(argc
, argv
, prefix
);
838 if (!strcmp(argv
[1], "show"))
839 return cmd_log_reflog(argc
- 1, argv
+ 1, prefix
);
841 if (!strcmp(argv
[1], "expire"))
842 return cmd_reflog_expire(argc
- 1, argv
+ 1, prefix
);
844 if (!strcmp(argv
[1], "delete"))
845 return cmd_reflog_delete(argc
- 1, argv
+ 1, prefix
);
847 return cmd_log_reflog(argc
, argv
, prefix
);