Junio C Hamano | 4264dc1 | 2006-12-19 00:23:12 -0800 | [diff] [blame] | 1 | #include "cache.h" |
| 2 | #include "builtin.h" |
| 3 | #include "commit.h" |
| 4 | #include "refs.h" |
| 5 | #include "dir.h" |
Junio C Hamano | 8d8b9f6 | 2006-12-22 00:46:33 -0800 | [diff] [blame] | 6 | #include "tree-walk.h" |
Junio C Hamano | 1389d9d | 2007-01-06 02:16:19 -0800 | [diff] [blame] | 7 | #include "diff.h" |
| 8 | #include "revision.h" |
| 9 | #include "reachable.h" |
| 10 | |
| 11 | /* |
| 12 | * reflog expire |
| 13 | */ |
| 14 | |
| 15 | static const char reflog_expire_usage[] = |
Stephan Beyer | 1b1dd23 | 2008-07-13 15:36:15 +0200 | [diff] [blame] | 16 | "git reflog (show|expire) [--verbose] [--dry-run] [--stale-fix] [--expire=<time>] [--expire-unreachable=<time>] [--all] <refs>..."; |
Brandon Casey | 3c386aa | 2008-02-22 15:08:59 -0600 | [diff] [blame] | 17 | static const char reflog_delete_usage[] = |
Stephan Beyer | 1b1dd23 | 2008-07-13 15:36:15 +0200 | [diff] [blame] | 18 | "git reflog delete [--verbose] [--dry-run] [--rewrite] [--updateref] <refs>..."; |
Junio C Hamano | 4264dc1 | 2006-12-19 00:23:12 -0800 | [diff] [blame] | 19 | |
Junio C Hamano | 4aec56d | 2006-12-27 01:47:57 -0800 | [diff] [blame] | 20 | static unsigned long default_reflog_expire; |
| 21 | static unsigned long default_reflog_expire_unreachable; |
| 22 | |
Junio C Hamano | 1389d9d | 2007-01-06 02:16:19 -0800 | [diff] [blame] | 23 | struct cmd_reflog_expire_cb { |
| 24 | struct rev_info revs; |
| 25 | int dry_run; |
| 26 | int stalefix; |
Brandon Casey | 2b81fab | 2008-02-22 12:56:50 -0600 | [diff] [blame] | 27 | int rewrite; |
Brandon Casey | 55f1056 | 2008-02-22 13:04:12 -0600 | [diff] [blame] | 28 | int updateref; |
Junio C Hamano | 1389d9d | 2007-01-06 02:16:19 -0800 | [diff] [blame] | 29 | int verbose; |
| 30 | unsigned long expire_total; |
| 31 | unsigned long expire_unreachable; |
Johannes Schindelin | 552cecc | 2007-10-17 02:50:45 +0100 | [diff] [blame] | 32 | int recno; |
Junio C Hamano | 1389d9d | 2007-01-06 02:16:19 -0800 | [diff] [blame] | 33 | }; |
| 34 | |
Junio C Hamano | 4264dc1 | 2006-12-19 00:23:12 -0800 | [diff] [blame] | 35 | struct expire_reflog_cb { |
| 36 | FILE *newlog; |
| 37 | const char *ref; |
| 38 | struct commit *ref_commit; |
Junio C Hamano | 1389d9d | 2007-01-06 02:16:19 -0800 | [diff] [blame] | 39 | struct cmd_reflog_expire_cb *cmd; |
Brandon Casey | 2b81fab | 2008-02-22 12:56:50 -0600 | [diff] [blame] | 40 | unsigned char last_kept_sha1[20]; |
Junio C Hamano | 4264dc1 | 2006-12-19 00:23:12 -0800 | [diff] [blame] | 41 | }; |
| 42 | |
Junio C Hamano | bda3a31 | 2008-01-25 23:53:05 -0800 | [diff] [blame] | 43 | struct collected_reflog { |
| 44 | unsigned char sha1[20]; |
| 45 | char reflog[FLEX_ARRAY]; |
| 46 | }; |
| 47 | struct collect_reflog_cb { |
| 48 | struct collected_reflog **e; |
| 49 | int alloc; |
| 50 | int nr; |
| 51 | }; |
| 52 | |
Junio C Hamano | cd1f9c3 | 2007-01-06 22:32:41 -0800 | [diff] [blame] | 53 | #define INCOMPLETE (1u<<10) |
| 54 | #define STUDYING (1u<<11) |
Junio Hamano | 494fbfe | 2009-03-30 21:34:14 -0700 | [diff] [blame] | 55 | #define REACHABLE (1u<<12) |
Junio C Hamano | cd1f9c3 | 2007-01-06 22:32:41 -0800 | [diff] [blame] | 56 | |
Junio C Hamano | 8d8b9f6 | 2006-12-22 00:46:33 -0800 | [diff] [blame] | 57 | static int tree_is_complete(const unsigned char *sha1) |
| 58 | { |
| 59 | struct tree_desc desc; |
Junio C Hamano | cd1f9c3 | 2007-01-06 22:32:41 -0800 | [diff] [blame] | 60 | struct name_entry entry; |
| 61 | int complete; |
| 62 | struct tree *tree; |
Junio C Hamano | 8d8b9f6 | 2006-12-22 00:46:33 -0800 | [diff] [blame] | 63 | |
Junio C Hamano | cd1f9c3 | 2007-01-06 22:32:41 -0800 | [diff] [blame] | 64 | tree = lookup_tree(sha1); |
| 65 | if (!tree) |
Junio C Hamano | 8d8b9f6 | 2006-12-22 00:46:33 -0800 | [diff] [blame] | 66 | return 0; |
Junio C Hamano | cd1f9c3 | 2007-01-06 22:32:41 -0800 | [diff] [blame] | 67 | if (tree->object.flags & SEEN) |
| 68 | return 1; |
| 69 | if (tree->object.flags & INCOMPLETE) |
| 70 | return 0; |
Junio C Hamano | 8d8b9f6 | 2006-12-22 00:46:33 -0800 | [diff] [blame] | 71 | |
Linus Torvalds | 6fda5e5 | 2007-03-21 10:08:25 -0700 | [diff] [blame] | 72 | if (!tree->buffer) { |
Nicolas Pitre | 21666f1 | 2007-02-26 14:55:59 -0500 | [diff] [blame] | 73 | enum object_type type; |
Linus Torvalds | 6fda5e5 | 2007-03-21 10:08:25 -0700 | [diff] [blame] | 74 | unsigned long size; |
| 75 | void *data = read_sha1_file(sha1, &type, &size); |
Junio C Hamano | cd1f9c3 | 2007-01-06 22:32:41 -0800 | [diff] [blame] | 76 | if (!data) { |
| 77 | tree->object.flags |= INCOMPLETE; |
Junio C Hamano | 8d8b9f6 | 2006-12-22 00:46:33 -0800 | [diff] [blame] | 78 | return 0; |
| 79 | } |
Junio C Hamano | cd1f9c3 | 2007-01-06 22:32:41 -0800 | [diff] [blame] | 80 | tree->buffer = data; |
Linus Torvalds | 6fda5e5 | 2007-03-21 10:08:25 -0700 | [diff] [blame] | 81 | tree->size = size; |
Junio C Hamano | 8d8b9f6 | 2006-12-22 00:46:33 -0800 | [diff] [blame] | 82 | } |
Linus Torvalds | 6fda5e5 | 2007-03-21 10:08:25 -0700 | [diff] [blame] | 83 | init_tree_desc(&desc, tree->buffer, tree->size); |
Junio C Hamano | cd1f9c3 | 2007-01-06 22:32:41 -0800 | [diff] [blame] | 84 | complete = 1; |
| 85 | while (tree_entry(&desc, &entry)) { |
| 86 | if (!has_sha1_file(entry.sha1) || |
| 87 | (S_ISDIR(entry.mode) && !tree_is_complete(entry.sha1))) { |
| 88 | tree->object.flags |= INCOMPLETE; |
| 89 | complete = 0; |
| 90 | } |
| 91 | } |
| 92 | free(tree->buffer); |
| 93 | tree->buffer = NULL; |
Junio C Hamano | 8d8b9f6 | 2006-12-22 00:46:33 -0800 | [diff] [blame] | 94 | |
Junio C Hamano | cd1f9c3 | 2007-01-06 22:32:41 -0800 | [diff] [blame] | 95 | if (complete) |
| 96 | tree->object.flags |= SEEN; |
| 97 | return complete; |
| 98 | } |
Junio C Hamano | 1389d9d | 2007-01-06 02:16:19 -0800 | [diff] [blame] | 99 | |
| 100 | static int commit_is_complete(struct commit *commit) |
| 101 | { |
| 102 | struct object_array study; |
| 103 | struct object_array found; |
| 104 | int is_incomplete = 0; |
| 105 | int i; |
| 106 | |
| 107 | /* early return */ |
| 108 | if (commit->object.flags & SEEN) |
| 109 | return 1; |
| 110 | if (commit->object.flags & INCOMPLETE) |
| 111 | return 0; |
| 112 | /* |
| 113 | * Find all commits that are reachable and are not marked as |
| 114 | * SEEN. Then make sure the trees and blobs contained are |
| 115 | * complete. After that, mark these commits also as SEEN. |
| 116 | * If some of the objects that are needed to complete this |
| 117 | * commit are missing, mark this commit as INCOMPLETE. |
| 118 | */ |
| 119 | memset(&study, 0, sizeof(study)); |
| 120 | memset(&found, 0, sizeof(found)); |
| 121 | add_object_array(&commit->object, NULL, &study); |
| 122 | add_object_array(&commit->object, NULL, &found); |
| 123 | commit->object.flags |= STUDYING; |
| 124 | while (study.nr) { |
| 125 | struct commit *c; |
| 126 | struct commit_list *parent; |
| 127 | |
| 128 | c = (struct commit *)study.objects[--study.nr].item; |
| 129 | if (!c->object.parsed && !parse_object(c->object.sha1)) |
| 130 | c->object.flags |= INCOMPLETE; |
| 131 | |
| 132 | if (c->object.flags & INCOMPLETE) { |
| 133 | is_incomplete = 1; |
| 134 | break; |
| 135 | } |
| 136 | else if (c->object.flags & SEEN) |
| 137 | continue; |
| 138 | for (parent = c->parents; parent; parent = parent->next) { |
| 139 | struct commit *p = parent->item; |
| 140 | if (p->object.flags & STUDYING) |
| 141 | continue; |
| 142 | p->object.flags |= STUDYING; |
| 143 | add_object_array(&p->object, NULL, &study); |
| 144 | add_object_array(&p->object, NULL, &found); |
| 145 | } |
| 146 | } |
| 147 | if (!is_incomplete) { |
Junio C Hamano | cd1f9c3 | 2007-01-06 22:32:41 -0800 | [diff] [blame] | 148 | /* |
| 149 | * make sure all commits in "found" array have all the |
Junio C Hamano | 1389d9d | 2007-01-06 02:16:19 -0800 | [diff] [blame] | 150 | * necessary objects. |
| 151 | */ |
Junio C Hamano | cd1f9c3 | 2007-01-06 22:32:41 -0800 | [diff] [blame] | 152 | for (i = 0; i < found.nr; i++) { |
Junio C Hamano | 1389d9d | 2007-01-06 02:16:19 -0800 | [diff] [blame] | 153 | struct commit *c = |
| 154 | (struct commit *)found.objects[i].item; |
Junio C Hamano | cd1f9c3 | 2007-01-06 22:32:41 -0800 | [diff] [blame] | 155 | if (!tree_is_complete(c->tree->object.sha1)) { |
Junio C Hamano | 1389d9d | 2007-01-06 02:16:19 -0800 | [diff] [blame] | 156 | is_incomplete = 1; |
Junio C Hamano | cd1f9c3 | 2007-01-06 22:32:41 -0800 | [diff] [blame] | 157 | c->object.flags |= INCOMPLETE; |
| 158 | } |
Junio C Hamano | 1389d9d | 2007-01-06 02:16:19 -0800 | [diff] [blame] | 159 | } |
| 160 | if (!is_incomplete) { |
| 161 | /* mark all found commits as complete, iow SEEN */ |
| 162 | for (i = 0; i < found.nr; i++) |
| 163 | found.objects[i].item->flags |= SEEN; |
| 164 | } |
| 165 | } |
| 166 | /* clear flags from the objects we traversed */ |
| 167 | for (i = 0; i < found.nr; i++) |
| 168 | found.objects[i].item->flags &= ~STUDYING; |
| 169 | if (is_incomplete) |
| 170 | commit->object.flags |= INCOMPLETE; |
Junio C Hamano | cd1f9c3 | 2007-01-06 22:32:41 -0800 | [diff] [blame] | 171 | else { |
| 172 | /* |
| 173 | * If we come here, we have (1) traversed the ancestry chain |
| 174 | * from the "commit" until we reach SEEN commits (which are |
| 175 | * known to be complete), and (2) made sure that the commits |
| 176 | * encountered during the above traversal refer to trees that |
| 177 | * are complete. Which means that we know *all* the commits |
| 178 | * we have seen during this process are complete. |
| 179 | */ |
| 180 | for (i = 0; i < found.nr; i++) |
| 181 | found.objects[i].item->flags |= SEEN; |
| 182 | } |
Junio C Hamano | 1389d9d | 2007-01-06 02:16:19 -0800 | [diff] [blame] | 183 | /* free object arrays */ |
| 184 | free(study.objects); |
| 185 | free(found.objects); |
| 186 | return !is_incomplete; |
| 187 | } |
| 188 | |
Junio C Hamano | 4264dc1 | 2006-12-19 00:23:12 -0800 | [diff] [blame] | 189 | static int keep_entry(struct commit **it, unsigned char *sha1) |
| 190 | { |
Junio C Hamano | 8d8b9f6 | 2006-12-22 00:46:33 -0800 | [diff] [blame] | 191 | struct commit *commit; |
| 192 | |
Junio C Hamano | 4264dc1 | 2006-12-19 00:23:12 -0800 | [diff] [blame] | 193 | if (is_null_sha1(sha1)) |
| 194 | return 1; |
Junio C Hamano | 8d8b9f6 | 2006-12-22 00:46:33 -0800 | [diff] [blame] | 195 | commit = lookup_commit_reference_gently(sha1, 1); |
| 196 | if (!commit) |
| 197 | return 0; |
| 198 | |
Junio C Hamano | 1389d9d | 2007-01-06 02:16:19 -0800 | [diff] [blame] | 199 | /* |
| 200 | * Make sure everything in this commit exists. |
| 201 | * |
| 202 | * We have walked all the objects reachable from the refs |
| 203 | * and cache earlier. The commits reachable by this commit |
| 204 | * must meet SEEN commits -- and then we should mark them as |
| 205 | * SEEN as well. |
| 206 | */ |
| 207 | if (!commit_is_complete(commit)) |
Junio C Hamano | 8d8b9f6 | 2006-12-22 00:46:33 -0800 | [diff] [blame] | 208 | return 0; |
| 209 | *it = commit; |
| 210 | return 1; |
Junio C Hamano | 4264dc1 | 2006-12-19 00:23:12 -0800 | [diff] [blame] | 211 | } |
| 212 | |
Linus Torvalds | 666e07e | 2009-03-31 09:45:22 -0700 | [diff] [blame] | 213 | static int unreachable(struct expire_reflog_cb *cb, struct commit *commit, unsigned char *sha1) |
| 214 | { |
| 215 | /* |
| 216 | * We may or may not have the commit yet - if not, look it |
| 217 | * up using the supplied sha1. |
| 218 | */ |
| 219 | if (!commit) { |
| 220 | if (is_null_sha1(sha1)) |
| 221 | return 0; |
| 222 | |
| 223 | commit = lookup_commit_reference_gently(sha1, 1); |
| 224 | |
| 225 | /* Not a commit -- keep it */ |
| 226 | if (!commit) |
| 227 | return 0; |
| 228 | } |
| 229 | |
| 230 | /* Reachable from the current ref? Don't prune. */ |
Junio Hamano | 494fbfe | 2009-03-30 21:34:14 -0700 | [diff] [blame] | 231 | if (commit->object.flags & REACHABLE) |
| 232 | return 0; |
Linus Torvalds | 666e07e | 2009-03-31 09:45:22 -0700 | [diff] [blame] | 233 | if (in_merge_bases(commit, &cb->ref_commit, 1)) |
| 234 | return 0; |
| 235 | |
| 236 | /* We can't reach it - prune it. */ |
| 237 | return 1; |
| 238 | } |
| 239 | |
Junio Hamano | 494fbfe | 2009-03-30 21:34:14 -0700 | [diff] [blame] | 240 | static void mark_reachable(struct commit *commit, unsigned long expire_limit) |
| 241 | { |
| 242 | /* |
Michael J Gruber | b18cc5a | 2009-04-22 23:15:56 +0200 | [diff] [blame] | 243 | * We need to compute whether the commit on either side of a reflog |
Junio Hamano | 494fbfe | 2009-03-30 21:34:14 -0700 | [diff] [blame] | 244 | * entry is reachable from the tip of the ref for all entries. |
| 245 | * Mark commits that are reachable from the tip down to the |
Mike Ralphson | 3ea3c21 | 2009-04-17 19:13:30 +0100 | [diff] [blame] | 246 | * time threshold first; we know a commit marked thusly is |
Junio Hamano | 494fbfe | 2009-03-30 21:34:14 -0700 | [diff] [blame] | 247 | * reachable from the tip without running in_merge_bases() |
| 248 | * at all. |
| 249 | */ |
| 250 | struct commit_list *pending = NULL; |
| 251 | |
| 252 | commit_list_insert(commit, &pending); |
| 253 | while (pending) { |
| 254 | struct commit_list *entry = pending; |
| 255 | struct commit_list *parent; |
| 256 | pending = entry->next; |
| 257 | commit = entry->item; |
| 258 | free(entry); |
| 259 | if (commit->object.flags & REACHABLE) |
| 260 | continue; |
| 261 | if (parse_commit(commit)) |
| 262 | continue; |
| 263 | commit->object.flags |= REACHABLE; |
| 264 | if (commit->date < expire_limit) |
| 265 | continue; |
| 266 | parent = commit->parents; |
| 267 | while (parent) { |
| 268 | commit = parent->item; |
| 269 | parent = parent->next; |
| 270 | if (commit->object.flags & REACHABLE) |
| 271 | continue; |
| 272 | commit_list_insert(commit, &pending); |
| 273 | } |
| 274 | } |
| 275 | } |
| 276 | |
Junio C Hamano | 4264dc1 | 2006-12-19 00:23:12 -0800 | [diff] [blame] | 277 | static int expire_reflog_ent(unsigned char *osha1, unsigned char *nsha1, |
Johannes Schindelin | 883d60f | 2007-01-08 01:59:54 +0100 | [diff] [blame] | 278 | const char *email, unsigned long timestamp, int tz, |
| 279 | const char *message, void *cb_data) |
Junio C Hamano | 4264dc1 | 2006-12-19 00:23:12 -0800 | [diff] [blame] | 280 | { |
| 281 | struct expire_reflog_cb *cb = cb_data; |
Junio C Hamano | 4264dc1 | 2006-12-19 00:23:12 -0800 | [diff] [blame] | 282 | struct commit *old, *new; |
| 283 | |
Junio C Hamano | 1389d9d | 2007-01-06 02:16:19 -0800 | [diff] [blame] | 284 | if (timestamp < cb->cmd->expire_total) |
Junio C Hamano | 4264dc1 | 2006-12-19 00:23:12 -0800 | [diff] [blame] | 285 | goto prune; |
| 286 | |
Brandon Casey | 2b81fab | 2008-02-22 12:56:50 -0600 | [diff] [blame] | 287 | if (cb->cmd->rewrite) |
| 288 | osha1 = cb->last_kept_sha1; |
| 289 | |
Junio C Hamano | 9bbaa6c | 2007-01-11 19:56:43 -0800 | [diff] [blame] | 290 | old = new = NULL; |
Junio C Hamano | 1389d9d | 2007-01-06 02:16:19 -0800 | [diff] [blame] | 291 | if (cb->cmd->stalefix && |
| 292 | (!keep_entry(&old, osha1) || !keep_entry(&new, nsha1))) |
Junio C Hamano | 4264dc1 | 2006-12-19 00:23:12 -0800 | [diff] [blame] | 293 | goto prune; |
| 294 | |
Junio C Hamano | 9bbaa6c | 2007-01-11 19:56:43 -0800 | [diff] [blame] | 295 | if (timestamp < cb->cmd->expire_unreachable) { |
| 296 | if (!cb->ref_commit) |
| 297 | goto prune; |
Linus Torvalds | 666e07e | 2009-03-31 09:45:22 -0700 | [diff] [blame] | 298 | if (unreachable(cb, old, osha1) || unreachable(cb, new, nsha1)) |
Junio C Hamano | 9bbaa6c | 2007-01-11 19:56:43 -0800 | [diff] [blame] | 299 | goto prune; |
| 300 | } |
Junio C Hamano | 4264dc1 | 2006-12-19 00:23:12 -0800 | [diff] [blame] | 301 | |
Johannes Schindelin | 552cecc | 2007-10-17 02:50:45 +0100 | [diff] [blame] | 302 | if (cb->cmd->recno && --(cb->cmd->recno) == 0) |
| 303 | goto prune; |
| 304 | |
Johannes Schindelin | 883d60f | 2007-01-08 01:59:54 +0100 | [diff] [blame] | 305 | if (cb->newlog) { |
| 306 | char sign = (tz < 0) ? '-' : '+'; |
| 307 | int zone = (tz < 0) ? (-tz) : tz; |
| 308 | fprintf(cb->newlog, "%s %s %s %lu %c%04d\t%s", |
| 309 | sha1_to_hex(osha1), sha1_to_hex(nsha1), |
| 310 | email, timestamp, sign, zone, |
| 311 | message); |
Brandon Casey | 2b81fab | 2008-02-22 12:56:50 -0600 | [diff] [blame] | 312 | hashcpy(cb->last_kept_sha1, nsha1); |
Johannes Schindelin | 883d60f | 2007-01-08 01:59:54 +0100 | [diff] [blame] | 313 | } |
Junio C Hamano | 1389d9d | 2007-01-06 02:16:19 -0800 | [diff] [blame] | 314 | if (cb->cmd->verbose) |
Johannes Schindelin | 883d60f | 2007-01-08 01:59:54 +0100 | [diff] [blame] | 315 | printf("keep %s", message); |
Junio C Hamano | 4264dc1 | 2006-12-19 00:23:12 -0800 | [diff] [blame] | 316 | return 0; |
| 317 | prune: |
Junio C Hamano | 1389d9d | 2007-01-06 02:16:19 -0800 | [diff] [blame] | 318 | if (!cb->newlog || cb->cmd->verbose) |
Johannes Schindelin | 883d60f | 2007-01-08 01:59:54 +0100 | [diff] [blame] | 319 | printf("%sprune %s", cb->newlog ? "" : "would ", message); |
Junio C Hamano | 4264dc1 | 2006-12-19 00:23:12 -0800 | [diff] [blame] | 320 | return 0; |
| 321 | } |
| 322 | |
Junio C Hamano | 4264dc1 | 2006-12-19 00:23:12 -0800 | [diff] [blame] | 323 | static int expire_reflog(const char *ref, const unsigned char *sha1, int unused, void *cb_data) |
| 324 | { |
| 325 | struct cmd_reflog_expire_cb *cmd = cb_data; |
| 326 | struct expire_reflog_cb cb; |
| 327 | struct ref_lock *lock; |
Nicolas Pitre | 9a13f0b | 2007-01-26 17:26:05 -0500 | [diff] [blame] | 328 | char *log_file, *newlog_path = NULL; |
Junio C Hamano | 4264dc1 | 2006-12-19 00:23:12 -0800 | [diff] [blame] | 329 | int status = 0; |
| 330 | |
Junio C Hamano | 4264dc1 | 2006-12-19 00:23:12 -0800 | [diff] [blame] | 331 | memset(&cb, 0, sizeof(cb)); |
Junio C Hamano | 3cb22b8 | 2008-06-15 23:48:46 -0700 | [diff] [blame] | 332 | |
| 333 | /* |
| 334 | * we take the lock for the ref itself to prevent it from |
Junio C Hamano | 4264dc1 | 2006-12-19 00:23:12 -0800 | [diff] [blame] | 335 | * getting updated. |
| 336 | */ |
Sven Verdoolaege | 68db31c | 2007-05-09 12:33:20 +0200 | [diff] [blame] | 337 | lock = lock_any_ref_for_update(ref, sha1, 0); |
Junio C Hamano | 4264dc1 | 2006-12-19 00:23:12 -0800 | [diff] [blame] | 338 | if (!lock) |
| 339 | return error("cannot lock ref '%s'", ref); |
Alex Riesen | a4f34cb | 2008-10-27 11:22:09 +0100 | [diff] [blame] | 340 | log_file = git_pathdup("logs/%s", ref); |
Nicolas Pitre | 9a13f0b | 2007-01-26 17:26:05 -0500 | [diff] [blame] | 341 | if (!file_exists(log_file)) |
Junio C Hamano | 4264dc1 | 2006-12-19 00:23:12 -0800 | [diff] [blame] | 342 | goto finish; |
| 343 | if (!cmd->dry_run) { |
Alex Riesen | a4f34cb | 2008-10-27 11:22:09 +0100 | [diff] [blame] | 344 | newlog_path = git_pathdup("logs/%s.lock", ref); |
Junio C Hamano | 4264dc1 | 2006-12-19 00:23:12 -0800 | [diff] [blame] | 345 | cb.newlog = fopen(newlog_path, "w"); |
| 346 | } |
| 347 | |
| 348 | cb.ref_commit = lookup_commit_reference_gently(sha1, 1); |
Junio C Hamano | 4264dc1 | 2006-12-19 00:23:12 -0800 | [diff] [blame] | 349 | cb.ref = ref; |
Junio C Hamano | 1389d9d | 2007-01-06 02:16:19 -0800 | [diff] [blame] | 350 | cb.cmd = cmd; |
Junio Hamano | 494fbfe | 2009-03-30 21:34:14 -0700 | [diff] [blame] | 351 | if (cb.ref_commit) |
| 352 | mark_reachable(cb.ref_commit, cmd->expire_total); |
Junio C Hamano | 4264dc1 | 2006-12-19 00:23:12 -0800 | [diff] [blame] | 353 | for_each_reflog_ent(ref, expire_reflog_ent, &cb); |
Junio Hamano | 494fbfe | 2009-03-30 21:34:14 -0700 | [diff] [blame] | 354 | if (cb.ref_commit) |
| 355 | clear_commit_marks(cb.ref_commit, REACHABLE); |
Junio C Hamano | 4264dc1 | 2006-12-19 00:23:12 -0800 | [diff] [blame] | 356 | finish: |
| 357 | if (cb.newlog) { |
Brandon Casey | 4cd883d | 2008-02-22 12:47:08 -0600 | [diff] [blame] | 358 | if (fclose(cb.newlog)) { |
Junio C Hamano | 4264dc1 | 2006-12-19 00:23:12 -0800 | [diff] [blame] | 359 | status |= error("%s: %s", strerror(errno), |
| 360 | newlog_path); |
Brandon Casey | 4cd883d | 2008-02-22 12:47:08 -0600 | [diff] [blame] | 361 | unlink(newlog_path); |
Brandon Casey | 55f1056 | 2008-02-22 13:04:12 -0600 | [diff] [blame] | 362 | } else if (cmd->updateref && |
| 363 | (write_in_full(lock->lock_fd, |
| 364 | sha1_to_hex(cb.last_kept_sha1), 40) != 40 || |
Jim Meyering | 2b7ca83 | 2009-09-12 10:54:32 +0200 | [diff] [blame^] | 365 | write_str_in_full(lock->lock_fd, "\n") != 1 || |
Brandon Casey | 55f1056 | 2008-02-22 13:04:12 -0600 | [diff] [blame] | 366 | close_ref(lock) < 0)) { |
| 367 | status |= error("Couldn't write %s", |
| 368 | lock->lk->filename); |
| 369 | unlink(newlog_path); |
Brandon Casey | 4cd883d | 2008-02-22 12:47:08 -0600 | [diff] [blame] | 370 | } else if (rename(newlog_path, log_file)) { |
Junio C Hamano | 4264dc1 | 2006-12-19 00:23:12 -0800 | [diff] [blame] | 371 | status |= error("cannot rename %s to %s", |
Nicolas Pitre | 9a13f0b | 2007-01-26 17:26:05 -0500 | [diff] [blame] | 372 | newlog_path, log_file); |
Junio C Hamano | 4264dc1 | 2006-12-19 00:23:12 -0800 | [diff] [blame] | 373 | unlink(newlog_path); |
Brandon Casey | 55f1056 | 2008-02-22 13:04:12 -0600 | [diff] [blame] | 374 | } else if (cmd->updateref && commit_ref(lock)) { |
| 375 | status |= error("Couldn't set %s", lock->ref_name); |
Pierre Habouzit | 336d09d | 2008-06-15 23:37:42 +0200 | [diff] [blame] | 376 | } else { |
| 377 | adjust_shared_perm(log_file); |
Junio C Hamano | 4264dc1 | 2006-12-19 00:23:12 -0800 | [diff] [blame] | 378 | } |
| 379 | } |
| 380 | free(newlog_path); |
Nicolas Pitre | 9a13f0b | 2007-01-26 17:26:05 -0500 | [diff] [blame] | 381 | free(log_file); |
Junio C Hamano | 4264dc1 | 2006-12-19 00:23:12 -0800 | [diff] [blame] | 382 | unlock_ref(lock); |
| 383 | return status; |
| 384 | } |
| 385 | |
Junio C Hamano | bda3a31 | 2008-01-25 23:53:05 -0800 | [diff] [blame] | 386 | static int collect_reflog(const char *ref, const unsigned char *sha1, int unused, void *cb_data) |
| 387 | { |
| 388 | struct collected_reflog *e; |
| 389 | struct collect_reflog_cb *cb = cb_data; |
| 390 | size_t namelen = strlen(ref); |
| 391 | |
| 392 | e = xmalloc(sizeof(*e) + namelen + 1); |
| 393 | hashcpy(e->sha1, sha1); |
| 394 | memcpy(e->reflog, ref, namelen + 1); |
| 395 | ALLOC_GROW(cb->e, cb->nr + 1, cb->alloc); |
| 396 | cb->e[cb->nr++] = e; |
| 397 | return 0; |
| 398 | } |
| 399 | |
Junio C Hamano | 3cb22b8 | 2008-06-15 23:48:46 -0700 | [diff] [blame] | 400 | static struct reflog_expire_cfg { |
| 401 | struct reflog_expire_cfg *next; |
| 402 | unsigned long expire_total; |
| 403 | unsigned long expire_unreachable; |
| 404 | size_t len; |
| 405 | char pattern[FLEX_ARRAY]; |
| 406 | } *reflog_expire_cfg, **reflog_expire_cfg_tail; |
| 407 | |
| 408 | static struct reflog_expire_cfg *find_cfg_ent(const char *pattern, size_t len) |
| 409 | { |
| 410 | struct reflog_expire_cfg *ent; |
| 411 | |
| 412 | if (!reflog_expire_cfg_tail) |
| 413 | reflog_expire_cfg_tail = &reflog_expire_cfg; |
| 414 | |
| 415 | for (ent = reflog_expire_cfg; ent; ent = ent->next) |
| 416 | if (ent->len == len && |
| 417 | !memcmp(ent->pattern, pattern, len)) |
| 418 | return ent; |
| 419 | |
| 420 | ent = xcalloc(1, (sizeof(*ent) + len)); |
| 421 | memcpy(ent->pattern, pattern, len); |
| 422 | ent->len = len; |
| 423 | *reflog_expire_cfg_tail = ent; |
| 424 | reflog_expire_cfg_tail = &(ent->next); |
| 425 | return ent; |
| 426 | } |
| 427 | |
| 428 | static int parse_expire_cfg_value(const char *var, const char *value, unsigned long *expire) |
| 429 | { |
| 430 | if (!value) |
| 431 | return config_error_nonbool(var); |
| 432 | if (!strcmp(value, "never") || !strcmp(value, "false")) { |
| 433 | *expire = 0; |
| 434 | return 0; |
| 435 | } |
| 436 | *expire = approxidate(value); |
| 437 | return 0; |
| 438 | } |
| 439 | |
| 440 | /* expiry timer slot */ |
| 441 | #define EXPIRE_TOTAL 01 |
| 442 | #define EXPIRE_UNREACH 02 |
| 443 | |
Johannes Schindelin | ef90d6d | 2008-05-14 18:46:53 +0100 | [diff] [blame] | 444 | static int reflog_expire_config(const char *var, const char *value, void *cb) |
Junio C Hamano | 4aec56d | 2006-12-27 01:47:57 -0800 | [diff] [blame] | 445 | { |
Junio C Hamano | 3cb22b8 | 2008-06-15 23:48:46 -0700 | [diff] [blame] | 446 | const char *lastdot = strrchr(var, '.'); |
| 447 | unsigned long expire; |
| 448 | int slot; |
| 449 | struct reflog_expire_cfg *ent; |
| 450 | |
| 451 | if (!lastdot || prefixcmp(var, "gc.")) |
| 452 | return git_default_config(var, value, cb); |
| 453 | |
| 454 | if (!strcmp(lastdot, ".reflogexpire")) { |
| 455 | slot = EXPIRE_TOTAL; |
| 456 | if (parse_expire_cfg_value(var, value, &expire)) |
| 457 | return -1; |
| 458 | } else if (!strcmp(lastdot, ".reflogexpireunreachable")) { |
| 459 | slot = EXPIRE_UNREACH; |
| 460 | if (parse_expire_cfg_value(var, value, &expire)) |
| 461 | return -1; |
| 462 | } else |
| 463 | return git_default_config(var, value, cb); |
| 464 | |
| 465 | if (lastdot == var + 2) { |
| 466 | switch (slot) { |
| 467 | case EXPIRE_TOTAL: |
| 468 | default_reflog_expire = expire; |
| 469 | break; |
| 470 | case EXPIRE_UNREACH: |
| 471 | default_reflog_expire_unreachable = expire; |
| 472 | break; |
| 473 | } |
Junio C Hamano | 4f342b9 | 2008-02-11 10:50:06 -0800 | [diff] [blame] | 474 | return 0; |
| 475 | } |
Junio C Hamano | 3cb22b8 | 2008-06-15 23:48:46 -0700 | [diff] [blame] | 476 | |
| 477 | ent = find_cfg_ent(var + 3, lastdot - (var+3)); |
| 478 | if (!ent) |
| 479 | return -1; |
| 480 | switch (slot) { |
| 481 | case EXPIRE_TOTAL: |
| 482 | ent->expire_total = expire; |
| 483 | break; |
| 484 | case EXPIRE_UNREACH: |
| 485 | ent->expire_unreachable = expire; |
| 486 | break; |
Junio C Hamano | 4f342b9 | 2008-02-11 10:50:06 -0800 | [diff] [blame] | 487 | } |
Junio C Hamano | 3cb22b8 | 2008-06-15 23:48:46 -0700 | [diff] [blame] | 488 | return 0; |
| 489 | } |
| 490 | |
| 491 | static void set_reflog_expiry_param(struct cmd_reflog_expire_cb *cb, int slot, const char *ref) |
| 492 | { |
| 493 | struct reflog_expire_cfg *ent; |
| 494 | |
| 495 | if (slot == (EXPIRE_TOTAL|EXPIRE_UNREACH)) |
| 496 | return; /* both given explicitly -- nothing to tweak */ |
| 497 | |
| 498 | for (ent = reflog_expire_cfg; ent; ent = ent->next) { |
| 499 | if (!fnmatch(ent->pattern, ref, 0)) { |
| 500 | if (!(slot & EXPIRE_TOTAL)) |
| 501 | cb->expire_total = ent->expire_total; |
| 502 | if (!(slot & EXPIRE_UNREACH)) |
| 503 | cb->expire_unreachable = ent->expire_unreachable; |
| 504 | return; |
| 505 | } |
| 506 | } |
| 507 | |
Junio C Hamano | 60bce2b | 2008-06-28 22:24:49 -0700 | [diff] [blame] | 508 | /* |
| 509 | * If unconfigured, make stash never expire |
| 510 | */ |
| 511 | if (!strcmp(ref, "refs/stash")) { |
| 512 | if (!(slot & EXPIRE_TOTAL)) |
| 513 | cb->expire_total = 0; |
| 514 | if (!(slot & EXPIRE_UNREACH)) |
| 515 | cb->expire_unreachable = 0; |
| 516 | return; |
| 517 | } |
| 518 | |
Junio C Hamano | 3cb22b8 | 2008-06-15 23:48:46 -0700 | [diff] [blame] | 519 | /* Nothing matched -- use the default value */ |
| 520 | if (!(slot & EXPIRE_TOTAL)) |
| 521 | cb->expire_total = default_reflog_expire; |
| 522 | if (!(slot & EXPIRE_UNREACH)) |
| 523 | cb->expire_unreachable = default_reflog_expire_unreachable; |
Junio C Hamano | 4aec56d | 2006-12-27 01:47:57 -0800 | [diff] [blame] | 524 | } |
| 525 | |
Junio C Hamano | 4264dc1 | 2006-12-19 00:23:12 -0800 | [diff] [blame] | 526 | static int cmd_reflog_expire(int argc, const char **argv, const char *prefix) |
| 527 | { |
| 528 | struct cmd_reflog_expire_cb cb; |
| 529 | unsigned long now = time(NULL); |
| 530 | int i, status, do_all; |
Junio C Hamano | 3cb22b8 | 2008-06-15 23:48:46 -0700 | [diff] [blame] | 531 | int explicit_expiry = 0; |
Junio C Hamano | 4264dc1 | 2006-12-19 00:23:12 -0800 | [diff] [blame] | 532 | |
Johannes Schindelin | ef90d6d | 2008-05-14 18:46:53 +0100 | [diff] [blame] | 533 | git_config(reflog_expire_config, NULL); |
Junio C Hamano | 4aec56d | 2006-12-27 01:47:57 -0800 | [diff] [blame] | 534 | |
Junio C Hamano | 4264dc1 | 2006-12-19 00:23:12 -0800 | [diff] [blame] | 535 | save_commit_buffer = 0; |
| 536 | do_all = status = 0; |
| 537 | memset(&cb, 0, sizeof(cb)); |
Junio C Hamano | 4aec56d | 2006-12-27 01:47:57 -0800 | [diff] [blame] | 538 | |
| 539 | if (!default_reflog_expire_unreachable) |
| 540 | default_reflog_expire_unreachable = now - 30 * 24 * 3600; |
| 541 | if (!default_reflog_expire) |
| 542 | default_reflog_expire = now - 90 * 24 * 3600; |
| 543 | cb.expire_total = default_reflog_expire; |
| 544 | cb.expire_unreachable = default_reflog_expire_unreachable; |
Junio C Hamano | 4264dc1 | 2006-12-19 00:23:12 -0800 | [diff] [blame] | 545 | |
| 546 | for (i = 1; i < argc; i++) { |
| 547 | const char *arg = argv[i]; |
| 548 | if (!strcmp(arg, "--dry-run") || !strcmp(arg, "-n")) |
| 549 | cb.dry_run = 1; |
Junio C Hamano | 3cb22b8 | 2008-06-15 23:48:46 -0700 | [diff] [blame] | 550 | else if (!prefixcmp(arg, "--expire=")) { |
Junio C Hamano | 4264dc1 | 2006-12-19 00:23:12 -0800 | [diff] [blame] | 551 | cb.expire_total = approxidate(arg + 9); |
Junio C Hamano | 3cb22b8 | 2008-06-15 23:48:46 -0700 | [diff] [blame] | 552 | explicit_expiry |= EXPIRE_TOTAL; |
| 553 | } |
| 554 | else if (!prefixcmp(arg, "--expire-unreachable=")) { |
Junio C Hamano | 4264dc1 | 2006-12-19 00:23:12 -0800 | [diff] [blame] | 555 | cb.expire_unreachable = approxidate(arg + 21); |
Junio C Hamano | 3cb22b8 | 2008-06-15 23:48:46 -0700 | [diff] [blame] | 556 | explicit_expiry |= EXPIRE_UNREACH; |
| 557 | } |
Junio C Hamano | 1389d9d | 2007-01-06 02:16:19 -0800 | [diff] [blame] | 558 | else if (!strcmp(arg, "--stale-fix")) |
| 559 | cb.stalefix = 1; |
Brandon Casey | 2b81fab | 2008-02-22 12:56:50 -0600 | [diff] [blame] | 560 | else if (!strcmp(arg, "--rewrite")) |
| 561 | cb.rewrite = 1; |
Brandon Casey | 55f1056 | 2008-02-22 13:04:12 -0600 | [diff] [blame] | 562 | else if (!strcmp(arg, "--updateref")) |
| 563 | cb.updateref = 1; |
Junio C Hamano | 4264dc1 | 2006-12-19 00:23:12 -0800 | [diff] [blame] | 564 | else if (!strcmp(arg, "--all")) |
| 565 | do_all = 1; |
Junio C Hamano | 1389d9d | 2007-01-06 02:16:19 -0800 | [diff] [blame] | 566 | else if (!strcmp(arg, "--verbose")) |
| 567 | cb.verbose = 1; |
Junio C Hamano | 4264dc1 | 2006-12-19 00:23:12 -0800 | [diff] [blame] | 568 | else if (!strcmp(arg, "--")) { |
| 569 | i++; |
| 570 | break; |
| 571 | } |
| 572 | else if (arg[0] == '-') |
| 573 | usage(reflog_expire_usage); |
| 574 | else |
| 575 | break; |
| 576 | } |
Junio C Hamano | 3cb22b8 | 2008-06-15 23:48:46 -0700 | [diff] [blame] | 577 | |
| 578 | /* |
| 579 | * We can trust the commits and objects reachable from refs |
| 580 | * even in older repository. We cannot trust what's reachable |
| 581 | * from reflog if the repository was pruned with older git. |
| 582 | */ |
Junio C Hamano | 1389d9d | 2007-01-06 02:16:19 -0800 | [diff] [blame] | 583 | if (cb.stalefix) { |
| 584 | init_revisions(&cb.revs, prefix); |
| 585 | if (cb.verbose) |
| 586 | printf("Marking reachable objects..."); |
| 587 | mark_reachable_objects(&cb.revs, 0); |
| 588 | if (cb.verbose) |
| 589 | putchar('\n'); |
| 590 | } |
| 591 | |
Junio C Hamano | bda3a31 | 2008-01-25 23:53:05 -0800 | [diff] [blame] | 592 | if (do_all) { |
| 593 | struct collect_reflog_cb collected; |
| 594 | int i; |
| 595 | |
| 596 | memset(&collected, 0, sizeof(collected)); |
| 597 | for_each_reflog(collect_reflog, &collected); |
| 598 | for (i = 0; i < collected.nr; i++) { |
| 599 | struct collected_reflog *e = collected.e[i]; |
Junio C Hamano | 3cb22b8 | 2008-06-15 23:48:46 -0700 | [diff] [blame] | 600 | set_reflog_expiry_param(&cb, explicit_expiry, e->reflog); |
Junio C Hamano | bda3a31 | 2008-01-25 23:53:05 -0800 | [diff] [blame] | 601 | status |= expire_reflog(e->reflog, e->sha1, 0, &cb); |
| 602 | free(e); |
| 603 | } |
| 604 | free(collected.e); |
| 605 | } |
| 606 | |
Pieter de Bie | 90fb46e | 2008-08-10 22:22:21 +0200 | [diff] [blame] | 607 | for (; i < argc; i++) { |
| 608 | char *ref; |
Junio C Hamano | 4264dc1 | 2006-12-19 00:23:12 -0800 | [diff] [blame] | 609 | unsigned char sha1[20]; |
Pieter de Bie | 90fb46e | 2008-08-10 22:22:21 +0200 | [diff] [blame] | 610 | if (!dwim_log(argv[i], strlen(argv[i]), sha1, &ref)) { |
| 611 | status |= error("%s points nowhere!", argv[i]); |
Junio C Hamano | 4264dc1 | 2006-12-19 00:23:12 -0800 | [diff] [blame] | 612 | continue; |
| 613 | } |
Junio C Hamano | 3cb22b8 | 2008-06-15 23:48:46 -0700 | [diff] [blame] | 614 | set_reflog_expiry_param(&cb, explicit_expiry, ref); |
Junio C Hamano | 4264dc1 | 2006-12-19 00:23:12 -0800 | [diff] [blame] | 615 | status |= expire_reflog(ref, sha1, 0, &cb); |
| 616 | } |
| 617 | return status; |
| 618 | } |
| 619 | |
Johannes Schindelin | 552cecc | 2007-10-17 02:50:45 +0100 | [diff] [blame] | 620 | static int count_reflog_ent(unsigned char *osha1, unsigned char *nsha1, |
| 621 | const char *email, unsigned long timestamp, int tz, |
| 622 | const char *message, void *cb_data) |
| 623 | { |
| 624 | struct cmd_reflog_expire_cb *cb = cb_data; |
| 625 | if (!cb->expire_total || timestamp < cb->expire_total) |
| 626 | cb->recno++; |
| 627 | return 0; |
| 628 | } |
| 629 | |
| 630 | static int cmd_reflog_delete(int argc, const char **argv, const char *prefix) |
| 631 | { |
| 632 | struct cmd_reflog_expire_cb cb; |
| 633 | int i, status = 0; |
| 634 | |
Johannes Schindelin | 552cecc | 2007-10-17 02:50:45 +0100 | [diff] [blame] | 635 | memset(&cb, 0, sizeof(cb)); |
| 636 | |
| 637 | for (i = 1; i < argc; i++) { |
Brandon Casey | 3c386aa | 2008-02-22 15:08:59 -0600 | [diff] [blame] | 638 | const char *arg = argv[i]; |
| 639 | if (!strcmp(arg, "--dry-run") || !strcmp(arg, "-n")) |
| 640 | cb.dry_run = 1; |
Brandon Casey | 2b81fab | 2008-02-22 12:56:50 -0600 | [diff] [blame] | 641 | else if (!strcmp(arg, "--rewrite")) |
| 642 | cb.rewrite = 1; |
Brandon Casey | 55f1056 | 2008-02-22 13:04:12 -0600 | [diff] [blame] | 643 | else if (!strcmp(arg, "--updateref")) |
| 644 | cb.updateref = 1; |
Brandon Casey | 3c386aa | 2008-02-22 15:08:59 -0600 | [diff] [blame] | 645 | else if (!strcmp(arg, "--verbose")) |
| 646 | cb.verbose = 1; |
| 647 | else if (!strcmp(arg, "--")) { |
| 648 | i++; |
| 649 | break; |
| 650 | } |
| 651 | else if (arg[0] == '-') |
| 652 | usage(reflog_delete_usage); |
| 653 | else |
| 654 | break; |
| 655 | } |
| 656 | |
| 657 | if (argc - i < 1) |
| 658 | return error("Nothing to delete?"); |
| 659 | |
| 660 | for ( ; i < argc; i++) { |
Johannes Schindelin | 552cecc | 2007-10-17 02:50:45 +0100 | [diff] [blame] | 661 | const char *spec = strstr(argv[i], "@{"); |
| 662 | unsigned char sha1[20]; |
| 663 | char *ep, *ref; |
| 664 | int recno; |
| 665 | |
| 666 | if (!spec) { |
Brandon Casey | cb97cc9 | 2008-01-04 19:11:37 -0600 | [diff] [blame] | 667 | status |= error("Not a reflog: %s", argv[i]); |
Johannes Schindelin | 552cecc | 2007-10-17 02:50:45 +0100 | [diff] [blame] | 668 | continue; |
| 669 | } |
| 670 | |
Junio C Hamano | 55beff4 | 2008-08-10 23:21:25 -0700 | [diff] [blame] | 671 | if (!dwim_log(argv[i], spec - argv[i], sha1, &ref)) { |
| 672 | status |= error("no reflog for '%s'", argv[i]); |
Johannes Schindelin | 552cecc | 2007-10-17 02:50:45 +0100 | [diff] [blame] | 673 | continue; |
| 674 | } |
| 675 | |
| 676 | recno = strtoul(spec + 2, &ep, 10); |
| 677 | if (*ep == '}') { |
| 678 | cb.recno = -recno; |
| 679 | for_each_reflog_ent(ref, count_reflog_ent, &cb); |
| 680 | } else { |
| 681 | cb.expire_total = approxidate(spec + 2); |
| 682 | for_each_reflog_ent(ref, count_reflog_ent, &cb); |
| 683 | cb.expire_total = 0; |
| 684 | } |
| 685 | |
| 686 | status |= expire_reflog(ref, sha1, 0, &cb); |
| 687 | free(ref); |
| 688 | } |
| 689 | return status; |
| 690 | } |
| 691 | |
Junio C Hamano | 1389d9d | 2007-01-06 02:16:19 -0800 | [diff] [blame] | 692 | /* |
| 693 | * main "reflog" |
| 694 | */ |
| 695 | |
Junio C Hamano | 4264dc1 | 2006-12-19 00:23:12 -0800 | [diff] [blame] | 696 | static const char reflog_usage[] = |
Matthieu Moy | e77095e | 2009-08-05 17:36:28 +0200 | [diff] [blame] | 697 | "git reflog [ show | expire | delete ]"; |
Junio C Hamano | 4264dc1 | 2006-12-19 00:23:12 -0800 | [diff] [blame] | 698 | |
| 699 | int cmd_reflog(int argc, const char **argv, const char *prefix) |
| 700 | { |
Linus Torvalds | cf39f54 | 2007-02-08 09:51:56 -0800 | [diff] [blame] | 701 | /* With no command, we default to showing it. */ |
| 702 | if (argc < 2 || *argv[1] == '-') |
| 703 | return cmd_log_reflog(argc, argv, prefix); |
| 704 | |
| 705 | if (!strcmp(argv[1], "show")) |
| 706 | return cmd_log_reflog(argc - 1, argv + 1, prefix); |
| 707 | |
| 708 | if (!strcmp(argv[1], "expire")) |
Junio C Hamano | 4264dc1 | 2006-12-19 00:23:12 -0800 | [diff] [blame] | 709 | return cmd_reflog_expire(argc - 1, argv + 1, prefix); |
Linus Torvalds | cf39f54 | 2007-02-08 09:51:56 -0800 | [diff] [blame] | 710 | |
Johannes Schindelin | 552cecc | 2007-10-17 02:50:45 +0100 | [diff] [blame] | 711 | if (!strcmp(argv[1], "delete")) |
| 712 | return cmd_reflog_delete(argc - 1, argv + 1, prefix); |
| 713 | |
Linus Torvalds | cf39f54 | 2007-02-08 09:51:56 -0800 | [diff] [blame] | 714 | /* Not a recognized reflog command..*/ |
| 715 | usage(reflog_usage); |
Junio C Hamano | 4264dc1 | 2006-12-19 00:23:12 -0800 | [diff] [blame] | 716 | } |