Linus Torvalds | ae56354 | 2006-02-25 16:19:46 -0800 | [diff] [blame] | 1 | #include "cache.h" |
Stefan Beller | cbd53a2 | 2018-05-15 16:42:15 -0700 | [diff] [blame] | 2 | #include "object-store.h" |
Linus Torvalds | ae56354 | 2006-02-25 16:19:46 -0800 | [diff] [blame] | 3 | #include "tag.h" |
| 4 | #include "blob.h" |
| 5 | #include "tree.h" |
| 6 | #include "commit.h" |
Linus Torvalds | a4a88b2 | 2006-02-28 11:24:00 -0800 | [diff] [blame] | 7 | #include "diff.h" |
Linus Torvalds | ae56354 | 2006-02-25 16:19:46 -0800 | [diff] [blame] | 8 | #include "refs.h" |
| 9 | #include "revision.h" |
Stefan Beller | 23a3f0c | 2018-04-11 17:21:09 -0700 | [diff] [blame] | 10 | #include "repository.h" |
Adam Simpkins | 7fefda5 | 2008-05-04 03:36:54 -0700 | [diff] [blame] | 11 | #include "graph.h" |
Junio C Hamano | 8ecae9b | 2006-09-17 15:43:40 -0700 | [diff] [blame] | 12 | #include "grep.h" |
Johannes Schindelin | 8860fd4 | 2007-01-11 11:47:48 +0100 | [diff] [blame] | 13 | #include "reflog-walk.h" |
Junio C Hamano | d7a17ca | 2007-04-09 03:40:38 -0700 | [diff] [blame] | 14 | #include "patch-ids.h" |
Junio C Hamano | f35f560 | 2008-04-03 02:12:06 -0700 | [diff] [blame] | 15 | #include "decorate.h" |
Linus Torvalds | 78892e3 | 2008-11-03 11:25:46 -0800 | [diff] [blame] | 16 | #include "log-tree.h" |
Thomas Rast | 894a9d3 | 2010-03-12 18:04:26 +0100 | [diff] [blame] | 17 | #include "string-list.h" |
Thomas Rast | 12da1d1 | 2013-03-28 17:47:32 +0100 | [diff] [blame] | 18 | #include "line-log.h" |
Antoine Pelisse | d72fbe8 | 2013-01-05 22:26:45 +0100 | [diff] [blame] | 19 | #include "mailmap.h" |
Thomas Rast | 53d00b3 | 2013-07-31 22:13:20 +0200 | [diff] [blame] | 20 | #include "commit-slab.h" |
Nguyễn Thái Ngọc Duy | 429bb40 | 2014-01-24 20:40:28 +0700 | [diff] [blame] | 21 | #include "dir.h" |
Jeff King | 4fe1021 | 2014-10-16 20:44:23 -0400 | [diff] [blame] | 22 | #include "cache-tree.h" |
Antoine Delaite | cb46d63 | 2015-06-29 17:40:30 +0200 | [diff] [blame] | 23 | #include "bisect.h" |
Jonathan Tan | 150e300 | 2017-08-18 15:20:36 -0700 | [diff] [blame] | 24 | #include "packfile.h" |
Nguyễn Thái Ngọc Duy | be489d0 | 2017-08-23 19:36:52 +0700 | [diff] [blame] | 25 | #include "worktree.h" |
Jeff King | 7fa3c2a | 2017-09-20 16:36:59 -0400 | [diff] [blame] | 26 | #include "argv-array.h" |
Derrick Stolee | 6404355 | 2018-07-20 16:33:04 +0000 | [diff] [blame] | 27 | #include "commit-reach.h" |
Derrick Stolee | f0d9cc4 | 2018-11-01 13:46:20 +0000 | [diff] [blame] | 28 | #include "commit-graph.h" |
Derrick Stolee | b454241 | 2018-11-01 13:46:22 +0000 | [diff] [blame] | 29 | #include "prio-queue.h" |
Derrick Stolee | d5d2e93 | 2019-01-16 10:25:59 -0800 | [diff] [blame] | 30 | #include "hashmap.h" |
Linus Torvalds | ae56354 | 2006-02-25 16:19:46 -0800 | [diff] [blame] | 31 | |
Linus Torvalds | cdcefbc | 2007-11-03 11:11:10 -0700 | [diff] [blame] | 32 | volatile show_early_output_fn_t show_early_output; |
| 33 | |
Antoine Delaite | cb46d63 | 2015-06-29 17:40:30 +0200 | [diff] [blame] | 34 | static const char *term_bad; |
| 35 | static const char *term_good; |
| 36 | |
Nguyễn Thái Ngọc Duy | 87be252 | 2018-05-19 07:28:24 +0200 | [diff] [blame] | 37 | implement_shared_commit_slab(revision_sources, char *); |
| 38 | |
Jeff King | de1e67d | 2016-02-11 17:28:36 -0500 | [diff] [blame] | 39 | void show_object_with_name(FILE *out, struct object *obj, const char *name) |
Linus Torvalds | ae56354 | 2006-02-25 16:19:46 -0800 | [diff] [blame] | 40 | { |
Jeff King | de1e67d | 2016-02-11 17:28:36 -0500 | [diff] [blame] | 41 | const char *p; |
Junio C Hamano | 91f1751 | 2011-08-17 14:30:34 -0700 | [diff] [blame] | 42 | |
brian m. carlson | f2fd076 | 2015-11-10 02:22:28 +0000 | [diff] [blame] | 43 | fprintf(out, "%s ", oid_to_hex(&obj->oid)); |
Jeff King | f9fb9d0 | 2016-02-11 17:24:18 -0500 | [diff] [blame] | 44 | for (p = name; *p && *p != '\n'; p++) |
| 45 | fputc(*p, out); |
Junio C Hamano | beba25a | 2011-08-17 14:30:35 -0700 | [diff] [blame] | 46 | fputc('\n', out); |
Junio C Hamano | 91f1751 | 2011-08-17 14:30:34 -0700 | [diff] [blame] | 47 | } |
| 48 | |
Linus Torvalds | ae56354 | 2006-02-25 16:19:46 -0800 | [diff] [blame] | 49 | static void mark_blob_uninteresting(struct blob *blob) |
| 50 | { |
Martin Koegler | c1ee901 | 2008-02-18 21:47:54 +0100 | [diff] [blame] | 51 | if (!blob) |
| 52 | return; |
Linus Torvalds | ae56354 | 2006-02-25 16:19:46 -0800 | [diff] [blame] | 53 | if (blob->object.flags & UNINTERESTING) |
| 54 | return; |
| 55 | blob->object.flags |= UNINTERESTING; |
| 56 | } |
| 57 | |
Nguyễn Thái Ngọc Duy | b3c7eef | 2018-09-21 17:57:39 +0200 | [diff] [blame] | 58 | static void mark_tree_contents_uninteresting(struct repository *r, |
| 59 | struct tree *tree) |
Linus Torvalds | ae56354 | 2006-02-25 16:19:46 -0800 | [diff] [blame] | 60 | { |
Linus Torvalds | f75e53e | 2006-05-29 12:20:14 -0700 | [diff] [blame] | 61 | struct tree_desc desc; |
Linus Torvalds | 4c068a9 | 2006-05-30 09:45:45 -0700 | [diff] [blame] | 62 | struct name_entry entry; |
Linus Torvalds | ae56354 | 2006-02-25 16:19:46 -0800 | [diff] [blame] | 63 | |
Jeff King | a5411df | 2018-05-11 14:00:55 -0400 | [diff] [blame] | 64 | if (parse_tree_gently(tree, 1) < 0) |
Linus Torvalds | ae56354 | 2006-02-25 16:19:46 -0800 | [diff] [blame] | 65 | return; |
Linus Torvalds | f75e53e | 2006-05-29 12:20:14 -0700 | [diff] [blame] | 66 | |
Linus Torvalds | 6fda5e5 | 2007-03-21 10:08:25 -0700 | [diff] [blame] | 67 | init_tree_desc(&desc, tree->buffer, tree->size); |
Linus Torvalds | 4c068a9 | 2006-05-30 09:45:45 -0700 | [diff] [blame] | 68 | while (tree_entry(&desc, &entry)) { |
Linus Torvalds | 4d1012c | 2007-11-11 23:35:23 +0000 | [diff] [blame] | 69 | switch (object_type(entry.mode)) { |
| 70 | case OBJ_TREE: |
brian m. carlson | ea82b2a | 2019-01-15 00:39:44 +0000 | [diff] [blame] | 71 | mark_tree_uninteresting(r, lookup_tree(r, &entry.oid)); |
Linus Torvalds | 4d1012c | 2007-11-11 23:35:23 +0000 | [diff] [blame] | 72 | break; |
| 73 | case OBJ_BLOB: |
brian m. carlson | ea82b2a | 2019-01-15 00:39:44 +0000 | [diff] [blame] | 74 | mark_blob_uninteresting(lookup_blob(r, &entry.oid)); |
Linus Torvalds | 4d1012c | 2007-11-11 23:35:23 +0000 | [diff] [blame] | 75 | break; |
| 76 | default: |
| 77 | /* Subproject commit - not in this repository */ |
| 78 | break; |
| 79 | } |
Linus Torvalds | ae56354 | 2006-02-25 16:19:46 -0800 | [diff] [blame] | 80 | } |
Linus Torvalds | f75e53e | 2006-05-29 12:20:14 -0700 | [diff] [blame] | 81 | |
| 82 | /* |
| 83 | * We don't care about the tree any more |
| 84 | * after it has been marked uninteresting. |
| 85 | */ |
Jeff King | 6e454b9 | 2013-06-05 18:37:39 -0400 | [diff] [blame] | 86 | free_tree_buffer(tree); |
Linus Torvalds | ae56354 | 2006-02-25 16:19:46 -0800 | [diff] [blame] | 87 | } |
| 88 | |
Nguyễn Thái Ngọc Duy | b3c7eef | 2018-09-21 17:57:39 +0200 | [diff] [blame] | 89 | void mark_tree_uninteresting(struct repository *r, struct tree *tree) |
Junio C Hamano | 2ac5e44 | 2014-01-15 15:38:01 -0800 | [diff] [blame] | 90 | { |
Stefan Naewe | a2678df | 2015-12-05 16:27:24 +0100 | [diff] [blame] | 91 | struct object *obj; |
Junio C Hamano | 2ac5e44 | 2014-01-15 15:38:01 -0800 | [diff] [blame] | 92 | |
| 93 | if (!tree) |
| 94 | return; |
Stefan Naewe | a2678df | 2015-12-05 16:27:24 +0100 | [diff] [blame] | 95 | |
| 96 | obj = &tree->object; |
Junio C Hamano | 2ac5e44 | 2014-01-15 15:38:01 -0800 | [diff] [blame] | 97 | if (obj->flags & UNINTERESTING) |
| 98 | return; |
| 99 | obj->flags |= UNINTERESTING; |
Nguyễn Thái Ngọc Duy | b3c7eef | 2018-09-21 17:57:39 +0200 | [diff] [blame] | 100 | mark_tree_contents_uninteresting(r, tree); |
Linus Torvalds | ae56354 | 2006-02-25 16:19:46 -0800 | [diff] [blame] | 101 | } |
| 102 | |
Derrick Stolee | d5d2e93 | 2019-01-16 10:25:59 -0800 | [diff] [blame] | 103 | struct path_and_oids_entry { |
| 104 | struct hashmap_entry ent; |
| 105 | char *path; |
| 106 | struct oidset trees; |
| 107 | }; |
| 108 | |
| 109 | static int path_and_oids_cmp(const void *hashmap_cmp_fn_data, |
| 110 | const struct path_and_oids_entry *e1, |
| 111 | const struct path_and_oids_entry *e2, |
| 112 | const void *keydata) |
| 113 | { |
| 114 | return strcmp(e1->path, e2->path); |
| 115 | } |
| 116 | |
| 117 | static void paths_and_oids_init(struct hashmap *map) |
| 118 | { |
| 119 | hashmap_init(map, (hashmap_cmp_fn) path_and_oids_cmp, NULL, 0); |
| 120 | } |
| 121 | |
| 122 | static void paths_and_oids_clear(struct hashmap *map) |
| 123 | { |
| 124 | struct hashmap_iter iter; |
| 125 | struct path_and_oids_entry *entry; |
| 126 | hashmap_iter_init(map, &iter); |
| 127 | |
| 128 | while ((entry = (struct path_and_oids_entry *)hashmap_iter_next(&iter))) { |
| 129 | oidset_clear(&entry->trees); |
| 130 | free(entry->path); |
| 131 | } |
| 132 | |
| 133 | hashmap_free(map, 1); |
| 134 | } |
| 135 | |
| 136 | static void paths_and_oids_insert(struct hashmap *map, |
| 137 | const char *path, |
| 138 | const struct object_id *oid) |
| 139 | { |
| 140 | int hash = strhash(path); |
| 141 | struct path_and_oids_entry key; |
| 142 | struct path_and_oids_entry *entry; |
| 143 | |
| 144 | hashmap_entry_init(&key, hash); |
| 145 | |
| 146 | /* use a shallow copy for the lookup */ |
| 147 | key.path = (char *)path; |
| 148 | oidset_init(&key.trees, 0); |
| 149 | |
| 150 | if (!(entry = (struct path_and_oids_entry *)hashmap_get(map, &key, NULL))) { |
| 151 | entry = xcalloc(1, sizeof(struct path_and_oids_entry)); |
| 152 | hashmap_entry_init(entry, hash); |
| 153 | entry->path = xstrdup(key.path); |
| 154 | oidset_init(&entry->trees, 16); |
| 155 | hashmap_put(map, entry); |
| 156 | } |
| 157 | |
| 158 | oidset_insert(&entry->trees, oid); |
| 159 | } |
| 160 | |
| 161 | static void add_children_by_path(struct repository *r, |
| 162 | struct tree *tree, |
| 163 | struct hashmap *map) |
| 164 | { |
| 165 | struct tree_desc desc; |
| 166 | struct name_entry entry; |
| 167 | |
| 168 | if (!tree) |
| 169 | return; |
| 170 | |
| 171 | if (parse_tree_gently(tree, 1) < 0) |
| 172 | return; |
| 173 | |
| 174 | init_tree_desc(&desc, tree->buffer, tree->size); |
| 175 | while (tree_entry(&desc, &entry)) { |
| 176 | switch (object_type(entry.mode)) { |
| 177 | case OBJ_TREE: |
Junio C Hamano | 5fda343 | 2019-02-06 22:05:24 -0800 | [diff] [blame] | 178 | paths_and_oids_insert(map, entry.path, &entry.oid); |
Derrick Stolee | d5d2e93 | 2019-01-16 10:25:59 -0800 | [diff] [blame] | 179 | |
| 180 | if (tree->object.flags & UNINTERESTING) { |
Junio C Hamano | 5fda343 | 2019-02-06 22:05:24 -0800 | [diff] [blame] | 181 | struct tree *child = lookup_tree(r, &entry.oid); |
Derrick Stolee | d5d2e93 | 2019-01-16 10:25:59 -0800 | [diff] [blame] | 182 | if (child) |
| 183 | child->object.flags |= UNINTERESTING; |
| 184 | } |
| 185 | break; |
| 186 | case OBJ_BLOB: |
| 187 | if (tree->object.flags & UNINTERESTING) { |
Junio C Hamano | 5fda343 | 2019-02-06 22:05:24 -0800 | [diff] [blame] | 188 | struct blob *child = lookup_blob(r, &entry.oid); |
Derrick Stolee | d5d2e93 | 2019-01-16 10:25:59 -0800 | [diff] [blame] | 189 | if (child) |
| 190 | child->object.flags |= UNINTERESTING; |
| 191 | } |
| 192 | break; |
| 193 | default: |
| 194 | /* Subproject commit - not in this repository */ |
| 195 | break; |
| 196 | } |
| 197 | } |
| 198 | |
| 199 | free_tree_buffer(tree); |
| 200 | } |
| 201 | |
Derrick Stolee | f1f5de4 | 2019-01-16 10:25:58 -0800 | [diff] [blame] | 202 | void mark_trees_uninteresting_sparse(struct repository *r, |
| 203 | struct oidset *trees) |
| 204 | { |
Derrick Stolee | d5d2e93 | 2019-01-16 10:25:59 -0800 | [diff] [blame] | 205 | unsigned has_interesting = 0, has_uninteresting = 0; |
| 206 | struct hashmap map; |
| 207 | struct hashmap_iter map_iter; |
| 208 | struct path_and_oids_entry *entry; |
Derrick Stolee | f1f5de4 | 2019-01-16 10:25:58 -0800 | [diff] [blame] | 209 | struct object_id *oid; |
| 210 | struct oidset_iter iter; |
| 211 | |
| 212 | oidset_iter_init(trees, &iter); |
Derrick Stolee | d5d2e93 | 2019-01-16 10:25:59 -0800 | [diff] [blame] | 213 | while ((!has_interesting || !has_uninteresting) && |
| 214 | (oid = oidset_iter_next(&iter))) { |
Derrick Stolee | f1f5de4 | 2019-01-16 10:25:58 -0800 | [diff] [blame] | 215 | struct tree *tree = lookup_tree(r, oid); |
| 216 | |
| 217 | if (!tree) |
| 218 | continue; |
| 219 | |
Derrick Stolee | d5d2e93 | 2019-01-16 10:25:59 -0800 | [diff] [blame] | 220 | if (tree->object.flags & UNINTERESTING) |
| 221 | has_uninteresting = 1; |
| 222 | else |
| 223 | has_interesting = 1; |
Derrick Stolee | f1f5de4 | 2019-01-16 10:25:58 -0800 | [diff] [blame] | 224 | } |
Derrick Stolee | d5d2e93 | 2019-01-16 10:25:59 -0800 | [diff] [blame] | 225 | |
| 226 | /* Do not walk unless we have both types of trees. */ |
| 227 | if (!has_uninteresting || !has_interesting) |
| 228 | return; |
| 229 | |
| 230 | paths_and_oids_init(&map); |
| 231 | |
| 232 | oidset_iter_init(trees, &iter); |
| 233 | while ((oid = oidset_iter_next(&iter))) { |
| 234 | struct tree *tree = lookup_tree(r, oid); |
| 235 | add_children_by_path(r, tree, &map); |
| 236 | } |
| 237 | |
| 238 | hashmap_iter_init(&map, &map_iter); |
| 239 | while ((entry = hashmap_iter_next(&map_iter))) |
| 240 | mark_trees_uninteresting_sparse(r, &entry->trees); |
| 241 | |
| 242 | paths_and_oids_clear(&map); |
Derrick Stolee | f1f5de4 | 2019-01-16 10:25:58 -0800 | [diff] [blame] | 243 | } |
| 244 | |
Jeff King | 43fc643 | 2018-05-11 14:02:27 -0400 | [diff] [blame] | 245 | struct commit_stack { |
| 246 | struct commit **items; |
| 247 | size_t nr, alloc; |
| 248 | }; |
| 249 | #define COMMIT_STACK_INIT { NULL, 0, 0 } |
| 250 | |
| 251 | static void commit_stack_push(struct commit_stack *stack, struct commit *commit) |
| 252 | { |
| 253 | ALLOC_GROW(stack->items, stack->nr + 1, stack->alloc); |
| 254 | stack->items[stack->nr++] = commit; |
| 255 | } |
| 256 | |
| 257 | static struct commit *commit_stack_pop(struct commit_stack *stack) |
| 258 | { |
| 259 | return stack->nr ? stack->items[--stack->nr] : NULL; |
| 260 | } |
| 261 | |
| 262 | static void commit_stack_clear(struct commit_stack *stack) |
| 263 | { |
| 264 | FREE_AND_NULL(stack->items); |
| 265 | stack->nr = stack->alloc = 0; |
| 266 | } |
| 267 | |
Jeff King | 8702b30 | 2018-05-11 14:03:15 -0400 | [diff] [blame] | 268 | static void mark_one_parent_uninteresting(struct commit *commit, |
| 269 | struct commit_stack *pending) |
| 270 | { |
| 271 | struct commit_list *l; |
| 272 | |
| 273 | if (commit->object.flags & UNINTERESTING) |
| 274 | return; |
| 275 | commit->object.flags |= UNINTERESTING; |
| 276 | |
| 277 | /* |
| 278 | * Normally we haven't parsed the parent |
| 279 | * yet, so we won't have a parent of a parent |
| 280 | * here. However, it may turn out that we've |
| 281 | * reached this commit some other way (where it |
| 282 | * wasn't uninteresting), in which case we need |
| 283 | * to mark its parents recursively too.. |
| 284 | */ |
| 285 | for (l = commit->parents; l; l = l->next) |
| 286 | commit_stack_push(pending, l->item); |
| 287 | } |
| 288 | |
Linus Torvalds | ae56354 | 2006-02-25 16:19:46 -0800 | [diff] [blame] | 289 | void mark_parents_uninteresting(struct commit *commit) |
| 290 | { |
Jeff King | 43fc643 | 2018-05-11 14:02:27 -0400 | [diff] [blame] | 291 | struct commit_stack pending = COMMIT_STACK_INIT; |
| 292 | struct commit_list *l; |
Nguyễn Thái Ngọc Duy | 941ba8d | 2012-01-14 19:19:53 +0700 | [diff] [blame] | 293 | |
| 294 | for (l = commit->parents; l; l = l->next) |
Jeff King | 8702b30 | 2018-05-11 14:03:15 -0400 | [diff] [blame] | 295 | mark_one_parent_uninteresting(l->item, &pending); |
Linus Torvalds | ae56354 | 2006-02-25 16:19:46 -0800 | [diff] [blame] | 296 | |
Jeff King | 8702b30 | 2018-05-11 14:03:15 -0400 | [diff] [blame] | 297 | while (pending.nr > 0) |
| 298 | mark_one_parent_uninteresting(commit_stack_pop(&pending), |
| 299 | &pending); |
Nguyễn Thái Ngọc Duy | 941ba8d | 2012-01-14 19:19:53 +0700 | [diff] [blame] | 300 | |
Jeff King | 43fc643 | 2018-05-11 14:02:27 -0400 | [diff] [blame] | 301 | commit_stack_clear(&pending); |
Linus Torvalds | ae56354 | 2006-02-25 16:19:46 -0800 | [diff] [blame] | 302 | } |
| 303 | |
Jeff King | 2073949 | 2014-10-15 18:43:19 -0400 | [diff] [blame] | 304 | static void add_pending_object_with_path(struct rev_info *revs, |
Michael Haggerty | ff5f5f2 | 2013-05-25 11:08:07 +0200 | [diff] [blame] | 305 | struct object *obj, |
Jeff King | 2073949 | 2014-10-15 18:43:19 -0400 | [diff] [blame] | 306 | const char *name, unsigned mode, |
| 307 | const char *path) |
Martin Koegler | bb6c2fb | 2007-04-22 18:43:59 +0200 | [diff] [blame] | 308 | { |
Junio C Hamano | cc243c3 | 2011-05-18 18:08:09 -0700 | [diff] [blame] | 309 | if (!obj) |
| 310 | return; |
Linus Torvalds | aa27e46 | 2007-02-27 16:22:52 -0800 | [diff] [blame] | 311 | if (revs->no_walk && (obj->flags & UNINTERESTING)) |
Linus Torvalds | f222abd | 2009-07-13 14:41:12 -0700 | [diff] [blame] | 312 | revs->no_walk = 0; |
Junio C Hamano | 105e473 | 2010-01-26 13:48:28 -0800 | [diff] [blame] | 313 | if (revs->reflog_info && obj->type == OBJ_COMMIT) { |
| 314 | struct strbuf buf = STRBUF_INIT; |
Jeff King | 0e9f62d | 2017-03-02 03:23:01 -0500 | [diff] [blame] | 315 | int len = interpret_branch_name(name, 0, &buf, 0); |
Junio C Hamano | 105e473 | 2010-01-26 13:48:28 -0800 | [diff] [blame] | 316 | |
| 317 | if (0 < len && name[len] && buf.len) |
| 318 | strbuf_addstr(&buf, name + len); |
Jeff King | d08565b | 2017-07-07 05:14:07 -0400 | [diff] [blame] | 319 | add_reflog_for_walk(revs->reflog_info, |
| 320 | (struct commit *)obj, |
| 321 | buf.buf[0] ? buf.buf: name); |
Junio C Hamano | 105e473 | 2010-01-26 13:48:28 -0800 | [diff] [blame] | 322 | strbuf_release(&buf); |
Jeff King | d08565b | 2017-07-07 05:14:07 -0400 | [diff] [blame] | 323 | return; /* do not add the commit itself */ |
Junio C Hamano | 105e473 | 2010-01-26 13:48:28 -0800 | [diff] [blame] | 324 | } |
Jeff King | 2073949 | 2014-10-15 18:43:19 -0400 | [diff] [blame] | 325 | add_object_array_with_path(obj, name, &revs->pending, mode, path); |
| 326 | } |
| 327 | |
| 328 | static void add_pending_object_with_mode(struct rev_info *revs, |
| 329 | struct object *obj, |
| 330 | const char *name, unsigned mode) |
| 331 | { |
| 332 | add_pending_object_with_path(revs, obj, name, mode, NULL); |
Linus Torvalds | ae56354 | 2006-02-25 16:19:46 -0800 | [diff] [blame] | 333 | } |
| 334 | |
Michael Haggerty | ff5f5f2 | 2013-05-25 11:08:07 +0200 | [diff] [blame] | 335 | void add_pending_object(struct rev_info *revs, |
| 336 | struct object *obj, const char *name) |
Junio C Hamano | 2d93b9f | 2007-06-08 02:24:58 -0700 | [diff] [blame] | 337 | { |
| 338 | add_pending_object_with_mode(revs, obj, name, S_IFINVALID); |
| 339 | } |
| 340 | |
Junio C Hamano | 3384a2d | 2007-12-11 10:09:04 -0800 | [diff] [blame] | 341 | void add_head_to_pending(struct rev_info *revs) |
| 342 | { |
brian m. carlson | 654b9a9 | 2017-05-06 22:10:27 +0000 | [diff] [blame] | 343 | struct object_id oid; |
Junio C Hamano | 3384a2d | 2007-12-11 10:09:04 -0800 | [diff] [blame] | 344 | struct object *obj; |
brian m. carlson | 654b9a9 | 2017-05-06 22:10:27 +0000 | [diff] [blame] | 345 | if (get_oid("HEAD", &oid)) |
Junio C Hamano | 3384a2d | 2007-12-11 10:09:04 -0800 | [diff] [blame] | 346 | return; |
Nguyễn Thái Ngọc Duy | b3c7eef | 2018-09-21 17:57:39 +0200 | [diff] [blame] | 347 | obj = parse_object(revs->repo, &oid); |
Junio C Hamano | 3384a2d | 2007-12-11 10:09:04 -0800 | [diff] [blame] | 348 | if (!obj) |
| 349 | return; |
| 350 | add_pending_object(revs, obj, "HEAD"); |
| 351 | } |
| 352 | |
Michael Haggerty | ff5f5f2 | 2013-05-25 11:08:07 +0200 | [diff] [blame] | 353 | static struct object *get_reference(struct rev_info *revs, const char *name, |
brian m. carlson | 654b9a9 | 2017-05-06 22:10:27 +0000 | [diff] [blame] | 354 | const struct object_id *oid, |
Michael Haggerty | ff5f5f2 | 2013-05-25 11:08:07 +0200 | [diff] [blame] | 355 | unsigned int flags) |
Linus Torvalds | ae56354 | 2006-02-25 16:19:46 -0800 | [diff] [blame] | 356 | { |
| 357 | struct object *object; |
| 358 | |
Jonathan Tan | ec0c579 | 2018-12-04 14:42:38 -0800 | [diff] [blame] | 359 | /* |
| 360 | * If the repository has commit graphs, repo_parse_commit() avoids |
| 361 | * reading the object buffer, so use it whenever possible. |
| 362 | */ |
| 363 | if (oid_object_info(revs->repo, oid, NULL) == OBJ_COMMIT) { |
| 364 | struct commit *c = lookup_commit(revs->repo, oid); |
| 365 | if (!repo_parse_commit(revs->repo, c)) |
| 366 | object = (struct object *) c; |
| 367 | else |
| 368 | object = NULL; |
| 369 | } else { |
| 370 | object = parse_object(revs->repo, oid); |
| 371 | } |
| 372 | |
Junio C Hamano | cc243c3 | 2011-05-18 18:08:09 -0700 | [diff] [blame] | 373 | if (!object) { |
| 374 | if (revs->ignore_missing) |
| 375 | return object; |
Jonathan Tan | df11e19 | 2017-12-08 15:27:15 +0000 | [diff] [blame] | 376 | if (revs->exclude_promisor_objects && is_promisor_object(oid)) |
| 377 | return NULL; |
Linus Torvalds | ae56354 | 2006-02-25 16:19:46 -0800 | [diff] [blame] | 378 | die("bad object %s", name); |
Junio C Hamano | cc243c3 | 2011-05-18 18:08:09 -0700 | [diff] [blame] | 379 | } |
Linus Torvalds | cd2bdc5 | 2006-04-14 16:52:13 -0700 | [diff] [blame] | 380 | object->flags |= flags; |
| 381 | return object; |
| 382 | } |
| 383 | |
brian m. carlson | a58a1b0 | 2017-05-06 22:10:26 +0000 | [diff] [blame] | 384 | void add_pending_oid(struct rev_info *revs, const char *name, |
| 385 | const struct object_id *oid, unsigned int flags) |
René Scharfe | 26c3177 | 2011-10-01 17:43:52 +0200 | [diff] [blame] | 386 | { |
brian m. carlson | 654b9a9 | 2017-05-06 22:10:27 +0000 | [diff] [blame] | 387 | struct object *object = get_reference(revs, name, oid, flags); |
René Scharfe | 26c3177 | 2011-10-01 17:43:52 +0200 | [diff] [blame] | 388 | add_pending_object(revs, object, name); |
| 389 | } |
| 390 | |
Michael Haggerty | ff5f5f2 | 2013-05-25 11:08:07 +0200 | [diff] [blame] | 391 | static struct commit *handle_commit(struct rev_info *revs, |
Jeff King | 2073949 | 2014-10-15 18:43:19 -0400 | [diff] [blame] | 392 | struct object_array_entry *entry) |
Linus Torvalds | cd2bdc5 | 2006-04-14 16:52:13 -0700 | [diff] [blame] | 393 | { |
Jeff King | 2073949 | 2014-10-15 18:43:19 -0400 | [diff] [blame] | 394 | struct object *object = entry->item; |
| 395 | const char *name = entry->name; |
| 396 | const char *path = entry->path; |
| 397 | unsigned int mode = entry->mode; |
Linus Torvalds | cd2bdc5 | 2006-04-14 16:52:13 -0700 | [diff] [blame] | 398 | unsigned long flags = object->flags; |
Linus Torvalds | ae56354 | 2006-02-25 16:19:46 -0800 | [diff] [blame] | 399 | |
| 400 | /* |
| 401 | * Tag object? Look what it points to.. |
| 402 | */ |
Linus Torvalds | 1974632 | 2006-07-11 20:45:31 -0700 | [diff] [blame] | 403 | while (object->type == OBJ_TAG) { |
Linus Torvalds | ae56354 | 2006-02-25 16:19:46 -0800 | [diff] [blame] | 404 | struct tag *tag = (struct tag *) object; |
Linus Torvalds | cd2bdc5 | 2006-04-14 16:52:13 -0700 | [diff] [blame] | 405 | if (revs->tag_objects && !(flags & UNINTERESTING)) |
Linus Torvalds | ae56354 | 2006-02-25 16:19:46 -0800 | [diff] [blame] | 406 | add_pending_object(revs, object, tag->tag); |
Martin Koegler | 9684afd | 2008-02-18 21:48:01 +0100 | [diff] [blame] | 407 | if (!tag->tagged) |
| 408 | die("bad tag"); |
Nguyễn Thái Ngọc Duy | b3c7eef | 2018-09-21 17:57:39 +0200 | [diff] [blame] | 409 | object = parse_object(revs->repo, &tag->tagged->oid); |
Junio C Hamano | aeeae1b | 2009-01-27 23:19:30 -0800 | [diff] [blame] | 410 | if (!object) { |
Jeff King | a3ba6bf | 2017-05-20 04:30:25 -0400 | [diff] [blame] | 411 | if (revs->ignore_missing_links || (flags & UNINTERESTING)) |
Junio C Hamano | aeeae1b | 2009-01-27 23:19:30 -0800 | [diff] [blame] | 412 | return NULL; |
Jonathan Tan | dc0a13f | 2018-07-12 17:03:06 -0700 | [diff] [blame] | 413 | if (revs->exclude_promisor_objects && |
| 414 | is_promisor_object(&tag->tagged->oid)) |
| 415 | return NULL; |
brian m. carlson | f2fd076 | 2015-11-10 02:22:28 +0000 | [diff] [blame] | 416 | die("bad object %s", oid_to_hex(&tag->tagged->oid)); |
Junio C Hamano | aeeae1b | 2009-01-27 23:19:30 -0800 | [diff] [blame] | 417 | } |
Junio C Hamano | a743528 | 2014-01-15 12:26:13 -0800 | [diff] [blame] | 418 | object->flags |= flags; |
Jeff King | 2073949 | 2014-10-15 18:43:19 -0400 | [diff] [blame] | 419 | /* |
| 420 | * We'll handle the tagged object by looping or dropping |
| 421 | * through to the non-tag handlers below. Do not |
Jeff King | 728350b | 2015-12-17 01:47:07 -0500 | [diff] [blame] | 422 | * propagate path data from the tag's pending entry. |
Jeff King | 2073949 | 2014-10-15 18:43:19 -0400 | [diff] [blame] | 423 | */ |
Jeff King | 2073949 | 2014-10-15 18:43:19 -0400 | [diff] [blame] | 424 | path = NULL; |
| 425 | mode = 0; |
Linus Torvalds | ae56354 | 2006-02-25 16:19:46 -0800 | [diff] [blame] | 426 | } |
| 427 | |
| 428 | /* |
| 429 | * Commit object? Just return it, we'll do all the complex |
| 430 | * reachability crud. |
| 431 | */ |
Linus Torvalds | 1974632 | 2006-07-11 20:45:31 -0700 | [diff] [blame] | 432 | if (object->type == OBJ_COMMIT) { |
Linus Torvalds | ae56354 | 2006-02-25 16:19:46 -0800 | [diff] [blame] | 433 | struct commit *commit = (struct commit *)object; |
Nguyễn Thái Ngọc Duy | 87be252 | 2018-05-19 07:28:24 +0200 | [diff] [blame] | 434 | |
Linus Torvalds | ae56354 | 2006-02-25 16:19:46 -0800 | [diff] [blame] | 435 | if (parse_commit(commit) < 0) |
| 436 | die("unable to parse commit %s", name); |
Linus Torvalds | d9a8368 | 2006-02-27 08:54:36 -0800 | [diff] [blame] | 437 | if (flags & UNINTERESTING) { |
Linus Torvalds | ae56354 | 2006-02-25 16:19:46 -0800 | [diff] [blame] | 438 | mark_parents_uninteresting(commit); |
Derrick Stolee | 1b4d882 | 2019-05-21 09:14:38 -0400 | [diff] [blame] | 439 | |
| 440 | if (!revs->topo_order || !generation_numbers_enabled(the_repository)) |
| 441 | revs->limited = 1; |
Linus Torvalds | d9a8368 | 2006-02-27 08:54:36 -0800 | [diff] [blame] | 442 | } |
Nguyễn Thái Ngọc Duy | 87be252 | 2018-05-19 07:28:24 +0200 | [diff] [blame] | 443 | if (revs->sources) { |
| 444 | char **slot = revision_sources_at(revs->sources, commit); |
| 445 | |
| 446 | if (!*slot) |
| 447 | *slot = xstrdup(name); |
| 448 | } |
Linus Torvalds | ae56354 | 2006-02-25 16:19:46 -0800 | [diff] [blame] | 449 | return commit; |
| 450 | } |
| 451 | |
| 452 | /* |
Mike Ralphson | 3ea3c21 | 2009-04-17 19:13:30 +0100 | [diff] [blame] | 453 | * Tree object? Either mark it uninteresting, or add it |
Linus Torvalds | ae56354 | 2006-02-25 16:19:46 -0800 | [diff] [blame] | 454 | * to the list of objects to look at later.. |
| 455 | */ |
Linus Torvalds | 1974632 | 2006-07-11 20:45:31 -0700 | [diff] [blame] | 456 | if (object->type == OBJ_TREE) { |
Linus Torvalds | ae56354 | 2006-02-25 16:19:46 -0800 | [diff] [blame] | 457 | struct tree *tree = (struct tree *)object; |
| 458 | if (!revs->tree_objects) |
| 459 | return NULL; |
| 460 | if (flags & UNINTERESTING) { |
Nguyễn Thái Ngọc Duy | b3c7eef | 2018-09-21 17:57:39 +0200 | [diff] [blame] | 461 | mark_tree_contents_uninteresting(revs->repo, tree); |
Linus Torvalds | ae56354 | 2006-02-25 16:19:46 -0800 | [diff] [blame] | 462 | return NULL; |
| 463 | } |
Jeff King | 2073949 | 2014-10-15 18:43:19 -0400 | [diff] [blame] | 464 | add_pending_object_with_path(revs, object, name, mode, path); |
Linus Torvalds | ae56354 | 2006-02-25 16:19:46 -0800 | [diff] [blame] | 465 | return NULL; |
| 466 | } |
| 467 | |
| 468 | /* |
| 469 | * Blob object? You know the drill by now.. |
| 470 | */ |
Linus Torvalds | 1974632 | 2006-07-11 20:45:31 -0700 | [diff] [blame] | 471 | if (object->type == OBJ_BLOB) { |
Linus Torvalds | ae56354 | 2006-02-25 16:19:46 -0800 | [diff] [blame] | 472 | if (!revs->blob_objects) |
| 473 | return NULL; |
Junio C Hamano | a743528 | 2014-01-15 12:26:13 -0800 | [diff] [blame] | 474 | if (flags & UNINTERESTING) |
Linus Torvalds | ae56354 | 2006-02-25 16:19:46 -0800 | [diff] [blame] | 475 | return NULL; |
Jeff King | 2073949 | 2014-10-15 18:43:19 -0400 | [diff] [blame] | 476 | add_pending_object_with_path(revs, object, name, mode, path); |
Linus Torvalds | ae56354 | 2006-02-25 16:19:46 -0800 | [diff] [blame] | 477 | return NULL; |
| 478 | } |
| 479 | die("%s is unknown object", name); |
| 480 | } |
| 481 | |
Jeff King | b6e8a3b | 2015-04-17 18:11:04 -0400 | [diff] [blame] | 482 | static int everybody_uninteresting(struct commit_list *orig, |
| 483 | struct commit **interesting_cache) |
Linus Torvalds | a4a88b2 | 2006-02-28 11:24:00 -0800 | [diff] [blame] | 484 | { |
| 485 | struct commit_list *list = orig; |
Jeff King | b6e8a3b | 2015-04-17 18:11:04 -0400 | [diff] [blame] | 486 | |
| 487 | if (*interesting_cache) { |
| 488 | struct commit *commit = *interesting_cache; |
| 489 | if (!(commit->object.flags & UNINTERESTING)) |
| 490 | return 0; |
| 491 | } |
| 492 | |
Linus Torvalds | a4a88b2 | 2006-02-28 11:24:00 -0800 | [diff] [blame] | 493 | while (list) { |
| 494 | struct commit *commit = list->item; |
| 495 | list = list->next; |
| 496 | if (commit->object.flags & UNINTERESTING) |
| 497 | continue; |
Stefan Beller | ae40ebd | 2015-06-26 12:40:19 -0700 | [diff] [blame] | 498 | |
| 499 | *interesting_cache = commit; |
Linus Torvalds | a4a88b2 | 2006-02-28 11:24:00 -0800 | [diff] [blame] | 500 | return 0; |
| 501 | } |
| 502 | return 1; |
| 503 | } |
| 504 | |
Junio C Hamano | 0a4ba7f | 2007-03-14 13:12:18 -0700 | [diff] [blame] | 505 | /* |
Kevin Bracey | 4d82660 | 2013-05-16 18:32:39 +0300 | [diff] [blame] | 506 | * A definition of "relevant" commit that we can use to simplify limited graphs |
| 507 | * by eliminating side branches. |
| 508 | * |
| 509 | * A "relevant" commit is one that is !UNINTERESTING (ie we are including it |
| 510 | * in our list), or that is a specified BOTTOM commit. Then after computing |
| 511 | * a limited list, during processing we can generally ignore boundary merges |
| 512 | * coming from outside the graph, (ie from irrelevant parents), and treat |
| 513 | * those merges as if they were single-parent. TREESAME is defined to consider |
| 514 | * only relevant parents, if any. If we are TREESAME to our on-graph parents, |
| 515 | * we don't care if we were !TREESAME to non-graph parents. |
| 516 | * |
| 517 | * Treating bottom commits as relevant ensures that a limited graph's |
| 518 | * connection to the actual bottom commit is not viewed as a side branch, but |
| 519 | * treated as part of the graph. For example: |
| 520 | * |
| 521 | * ....Z...A---X---o---o---B |
| 522 | * . / |
| 523 | * W---Y |
| 524 | * |
| 525 | * When computing "A..B", the A-X connection is at least as important as |
| 526 | * Y-X, despite A being flagged UNINTERESTING. |
| 527 | * |
| 528 | * And when computing --ancestry-path "A..B", the A-X connection is more |
| 529 | * important than Y-X, despite both A and Y being flagged UNINTERESTING. |
| 530 | */ |
| 531 | static inline int relevant_commit(struct commit *commit) |
| 532 | { |
| 533 | return (commit->object.flags & (UNINTERESTING | BOTTOM)) != UNINTERESTING; |
| 534 | } |
| 535 | |
| 536 | /* |
| 537 | * Return a single relevant commit from a parent list. If we are a TREESAME |
| 538 | * commit, and this selects one of our parents, then we can safely simplify to |
| 539 | * that parent. |
| 540 | */ |
| 541 | static struct commit *one_relevant_parent(const struct rev_info *revs, |
| 542 | struct commit_list *orig) |
| 543 | { |
| 544 | struct commit_list *list = orig; |
| 545 | struct commit *relevant = NULL; |
| 546 | |
| 547 | if (!orig) |
| 548 | return NULL; |
| 549 | |
| 550 | /* |
| 551 | * For 1-parent commits, or if first-parent-only, then return that |
| 552 | * first parent (even if not "relevant" by the above definition). |
| 553 | * TREESAME will have been set purely on that parent. |
| 554 | */ |
| 555 | if (revs->first_parent_only || !orig->next) |
| 556 | return orig->item; |
| 557 | |
| 558 | /* |
| 559 | * For multi-parent commits, identify a sole relevant parent, if any. |
| 560 | * If we have only one relevant parent, then TREESAME will be set purely |
| 561 | * with regard to that parent, and we can simplify accordingly. |
| 562 | * |
| 563 | * If we have more than one relevant parent, or no relevant parents |
| 564 | * (and multiple irrelevant ones), then we can't select a parent here |
| 565 | * and return NULL. |
| 566 | */ |
| 567 | while (list) { |
| 568 | struct commit *commit = list->item; |
| 569 | list = list->next; |
| 570 | if (relevant_commit(commit)) { |
| 571 | if (relevant) |
| 572 | return NULL; |
| 573 | relevant = commit; |
| 574 | } |
| 575 | } |
| 576 | return relevant; |
| 577 | } |
| 578 | |
| 579 | /* |
Junio C Hamano | 0a4ba7f | 2007-03-14 13:12:18 -0700 | [diff] [blame] | 580 | * The goal is to get REV_TREE_NEW as the result only if the |
Linus Torvalds | ceff8e7 | 2009-06-02 18:34:01 -0700 | [diff] [blame] | 581 | * diff consists of all '+' (and no other changes), REV_TREE_OLD |
| 582 | * if the whole diff is removal of old data, and otherwise |
| 583 | * REV_TREE_DIFFERENT (of course if the trees are the same we |
| 584 | * want REV_TREE_SAME). |
Jeff King | a937b37 | 2017-10-13 11:27:45 -0400 | [diff] [blame] | 585 | * |
| 586 | * The only time we care about the distinction is when |
| 587 | * remove_empty_trees is in effect, in which case we care only about |
| 588 | * whether the whole change is REV_TREE_NEW, or if there's another type |
| 589 | * of change. Which means we can stop the diff early in either of these |
| 590 | * cases: |
| 591 | * |
| 592 | * 1. We're not using remove_empty_trees at all. |
| 593 | * |
| 594 | * 2. We saw anything except REV_TREE_NEW. |
Junio C Hamano | 0a4ba7f | 2007-03-14 13:12:18 -0700 | [diff] [blame] | 595 | */ |
Fredrik Kuivinen | 8efdc32 | 2006-03-10 10:21:39 +0100 | [diff] [blame] | 596 | static int tree_difference = REV_TREE_SAME; |
Linus Torvalds | a4a88b2 | 2006-02-28 11:24:00 -0800 | [diff] [blame] | 597 | |
| 598 | static void file_add_remove(struct diff_options *options, |
| 599 | int addremove, unsigned mode, |
Brandon Williams | c26022e | 2017-05-30 10:30:47 -0700 | [diff] [blame] | 600 | const struct object_id *oid, |
| 601 | int oid_valid, |
Jens Lehmann | e3d42c4 | 2010-01-18 21:26:18 +0100 | [diff] [blame] | 602 | const char *fullpath, unsigned dirty_submodule) |
Linus Torvalds | a4a88b2 | 2006-02-28 11:24:00 -0800 | [diff] [blame] | 603 | { |
Linus Torvalds | ceff8e7 | 2009-06-02 18:34:01 -0700 | [diff] [blame] | 604 | int diff = addremove == '+' ? REV_TREE_NEW : REV_TREE_OLD; |
Jeff King | a937b37 | 2017-10-13 11:27:45 -0400 | [diff] [blame] | 605 | struct rev_info *revs = options->change_fn_data; |
Linus Torvalds | a4a88b2 | 2006-02-28 11:24:00 -0800 | [diff] [blame] | 606 | |
Linus Torvalds | ceff8e7 | 2009-06-02 18:34:01 -0700 | [diff] [blame] | 607 | tree_difference |= diff; |
Jeff King | a937b37 | 2017-10-13 11:27:45 -0400 | [diff] [blame] | 608 | if (!revs->remove_empty_trees || tree_difference != REV_TREE_NEW) |
Brandon Williams | 0d1e0e7 | 2017-10-31 11:19:11 -0700 | [diff] [blame] | 609 | options->flags.has_changes = 1; |
Linus Torvalds | a4a88b2 | 2006-02-28 11:24:00 -0800 | [diff] [blame] | 610 | } |
| 611 | |
| 612 | static void file_change(struct diff_options *options, |
| 613 | unsigned old_mode, unsigned new_mode, |
Brandon Williams | 94a0097 | 2017-05-30 10:30:49 -0700 | [diff] [blame] | 614 | const struct object_id *old_oid, |
| 615 | const struct object_id *new_oid, |
| 616 | int old_oid_valid, int new_oid_valid, |
Jens Lehmann | e3d42c4 | 2010-01-18 21:26:18 +0100 | [diff] [blame] | 617 | const char *fullpath, |
| 618 | unsigned old_dirty_submodule, unsigned new_dirty_submodule) |
Linus Torvalds | a4a88b2 | 2006-02-28 11:24:00 -0800 | [diff] [blame] | 619 | { |
Fredrik Kuivinen | 8efdc32 | 2006-03-10 10:21:39 +0100 | [diff] [blame] | 620 | tree_difference = REV_TREE_DIFFERENT; |
Brandon Williams | 0d1e0e7 | 2017-10-31 11:19:11 -0700 | [diff] [blame] | 621 | options->flags.has_changes = 1; |
Linus Torvalds | a4a88b2 | 2006-02-28 11:24:00 -0800 | [diff] [blame] | 622 | } |
| 623 | |
Michael Haggerty | ff5f5f2 | 2013-05-25 11:08:07 +0200 | [diff] [blame] | 624 | static int rev_compare_tree(struct rev_info *revs, |
| 625 | struct commit *parent, struct commit *commit) |
Linus Torvalds | a4a88b2 | 2006-02-28 11:24:00 -0800 | [diff] [blame] | 626 | { |
Derrick Stolee | 2e27bd7 | 2018-04-06 19:09:38 +0000 | [diff] [blame] | 627 | struct tree *t1 = get_commit_tree(parent); |
| 628 | struct tree *t2 = get_commit_tree(commit); |
Linus Torvalds | 3a5e860 | 2008-11-03 10:45:41 -0800 | [diff] [blame] | 629 | |
Linus Torvalds | a4a88b2 | 2006-02-28 11:24:00 -0800 | [diff] [blame] | 630 | if (!t1) |
Fredrik Kuivinen | 8efdc32 | 2006-03-10 10:21:39 +0100 | [diff] [blame] | 631 | return REV_TREE_NEW; |
Linus Torvalds | ceff8e7 | 2009-06-02 18:34:01 -0700 | [diff] [blame] | 632 | if (!t2) |
| 633 | return REV_TREE_OLD; |
Linus Torvalds | 78892e3 | 2008-11-03 11:25:46 -0800 | [diff] [blame] | 634 | |
| 635 | if (revs->simplify_by_decoration) { |
| 636 | /* |
| 637 | * If we are simplifying by decoration, then the commit |
| 638 | * is worth showing if it has a tag pointing at it. |
| 639 | */ |
Jeff King | 2608c24 | 2014-08-26 06:23:54 -0400 | [diff] [blame] | 640 | if (get_name_decoration(&commit->object)) |
Linus Torvalds | 78892e3 | 2008-11-03 11:25:46 -0800 | [diff] [blame] | 641 | return REV_TREE_DIFFERENT; |
| 642 | /* |
| 643 | * A commit that is not pointed by a tag is uninteresting |
| 644 | * if we are not limited by path. This means that you will |
| 645 | * see the usual "commits that touch the paths" plus any |
| 646 | * tagged commit by specifying both --simplify-by-decoration |
| 647 | * and pathspec. |
| 648 | */ |
Nguyễn Thái Ngọc Duy | afe069d | 2010-12-17 19:43:06 +0700 | [diff] [blame] | 649 | if (!revs->prune_data.nr) |
Linus Torvalds | 78892e3 | 2008-11-03 11:25:46 -0800 | [diff] [blame] | 650 | return REV_TREE_SAME; |
| 651 | } |
Linus Torvalds | ceff8e7 | 2009-06-02 18:34:01 -0700 | [diff] [blame] | 652 | |
Fredrik Kuivinen | 8efdc32 | 2006-03-10 10:21:39 +0100 | [diff] [blame] | 653 | tree_difference = REV_TREE_SAME; |
Brandon Williams | 0d1e0e7 | 2017-10-31 11:19:11 -0700 | [diff] [blame] | 654 | revs->pruning.flags.has_changes = 0; |
Brandon Williams | 66f414f | 2017-05-30 10:31:03 -0700 | [diff] [blame] | 655 | if (diff_tree_oid(&t1->object.oid, &t2->object.oid, "", |
Linus Torvalds | cd2bdc5 | 2006-04-14 16:52:13 -0700 | [diff] [blame] | 656 | &revs->pruning) < 0) |
Fredrik Kuivinen | 8efdc32 | 2006-03-10 10:21:39 +0100 | [diff] [blame] | 657 | return REV_TREE_DIFFERENT; |
Linus Torvalds | a4a88b2 | 2006-02-28 11:24:00 -0800 | [diff] [blame] | 658 | return tree_difference; |
| 659 | } |
| 660 | |
Linus Torvalds | 3a5e860 | 2008-11-03 10:45:41 -0800 | [diff] [blame] | 661 | static int rev_same_tree_as_empty(struct rev_info *revs, struct commit *commit) |
Linus Torvalds | a4a88b2 | 2006-02-28 11:24:00 -0800 | [diff] [blame] | 662 | { |
| 663 | int retval; |
Derrick Stolee | 2e27bd7 | 2018-04-06 19:09:38 +0000 | [diff] [blame] | 664 | struct tree *t1 = get_commit_tree(commit); |
Linus Torvalds | a4a88b2 | 2006-02-28 11:24:00 -0800 | [diff] [blame] | 665 | |
| 666 | if (!t1) |
| 667 | return 0; |
| 668 | |
Junio C Hamano | 0a4ba7f | 2007-03-14 13:12:18 -0700 | [diff] [blame] | 669 | tree_difference = REV_TREE_SAME; |
Brandon Williams | 0d1e0e7 | 2017-10-31 11:19:11 -0700 | [diff] [blame] | 670 | revs->pruning.flags.has_changes = 0; |
Brandon Williams | 66f414f | 2017-05-30 10:31:03 -0700 | [diff] [blame] | 671 | retval = diff_tree_oid(NULL, &t1->object.oid, "", &revs->pruning); |
Linus Torvalds | a4a88b2 | 2006-02-28 11:24:00 -0800 | [diff] [blame] | 672 | |
Junio C Hamano | 0a4ba7f | 2007-03-14 13:12:18 -0700 | [diff] [blame] | 673 | return retval >= 0 && (tree_difference == REV_TREE_SAME); |
Linus Torvalds | a4a88b2 | 2006-02-28 11:24:00 -0800 | [diff] [blame] | 674 | } |
| 675 | |
Kevin Bracey | d0af663 | 2013-05-16 18:32:34 +0300 | [diff] [blame] | 676 | struct treesame_state { |
| 677 | unsigned int nparents; |
| 678 | unsigned char treesame[FLEX_ARRAY]; |
| 679 | }; |
| 680 | |
| 681 | static struct treesame_state *initialise_treesame(struct rev_info *revs, struct commit *commit) |
| 682 | { |
| 683 | unsigned n = commit_list_count(commit->parents); |
Jeff King | 50a6c8e | 2016-02-22 17:44:35 -0500 | [diff] [blame] | 684 | struct treesame_state *st = xcalloc(1, st_add(sizeof(*st), n)); |
Kevin Bracey | d0af663 | 2013-05-16 18:32:34 +0300 | [diff] [blame] | 685 | st->nparents = n; |
| 686 | add_decoration(&revs->treesame, &commit->object, st); |
| 687 | return st; |
| 688 | } |
| 689 | |
| 690 | /* |
| 691 | * Must be called immediately after removing the nth_parent from a commit's |
| 692 | * parent list, if we are maintaining the per-parent treesame[] decoration. |
| 693 | * This does not recalculate the master TREESAME flag - update_treesame() |
| 694 | * should be called to update it after a sequence of treesame[] modifications |
| 695 | * that may have affected it. |
| 696 | */ |
| 697 | static int compact_treesame(struct rev_info *revs, struct commit *commit, unsigned nth_parent) |
| 698 | { |
| 699 | struct treesame_state *st; |
| 700 | int old_same; |
| 701 | |
| 702 | if (!commit->parents) { |
| 703 | /* |
| 704 | * Have just removed the only parent from a non-merge. |
| 705 | * Different handling, as we lack decoration. |
| 706 | */ |
| 707 | if (nth_parent != 0) |
| 708 | die("compact_treesame %u", nth_parent); |
| 709 | old_same = !!(commit->object.flags & TREESAME); |
| 710 | if (rev_same_tree_as_empty(revs, commit)) |
| 711 | commit->object.flags |= TREESAME; |
| 712 | else |
| 713 | commit->object.flags &= ~TREESAME; |
| 714 | return old_same; |
| 715 | } |
| 716 | |
| 717 | st = lookup_decoration(&revs->treesame, &commit->object); |
| 718 | if (!st || nth_parent >= st->nparents) |
| 719 | die("compact_treesame %u", nth_parent); |
| 720 | |
| 721 | old_same = st->treesame[nth_parent]; |
| 722 | memmove(st->treesame + nth_parent, |
| 723 | st->treesame + nth_parent + 1, |
| 724 | st->nparents - nth_parent - 1); |
| 725 | |
| 726 | /* |
| 727 | * If we've just become a non-merge commit, update TREESAME |
| 728 | * immediately, and remove the no-longer-needed decoration. |
| 729 | * If still a merge, defer update until update_treesame(). |
| 730 | */ |
| 731 | if (--st->nparents == 1) { |
| 732 | if (commit->parents->next) |
| 733 | die("compact_treesame parents mismatch"); |
| 734 | if (st->treesame[0] && revs->dense) |
| 735 | commit->object.flags |= TREESAME; |
| 736 | else |
| 737 | commit->object.flags &= ~TREESAME; |
| 738 | free(add_decoration(&revs->treesame, &commit->object, NULL)); |
| 739 | } |
| 740 | |
| 741 | return old_same; |
| 742 | } |
| 743 | |
| 744 | static unsigned update_treesame(struct rev_info *revs, struct commit *commit) |
| 745 | { |
| 746 | if (commit->parents && commit->parents->next) { |
| 747 | unsigned n; |
| 748 | struct treesame_state *st; |
Kevin Bracey | 4d82660 | 2013-05-16 18:32:39 +0300 | [diff] [blame] | 749 | struct commit_list *p; |
| 750 | unsigned relevant_parents; |
| 751 | unsigned relevant_change, irrelevant_change; |
Kevin Bracey | d0af663 | 2013-05-16 18:32:34 +0300 | [diff] [blame] | 752 | |
| 753 | st = lookup_decoration(&revs->treesame, &commit->object); |
| 754 | if (!st) |
brian m. carlson | f2fd076 | 2015-11-10 02:22:28 +0000 | [diff] [blame] | 755 | die("update_treesame %s", oid_to_hex(&commit->object.oid)); |
Kevin Bracey | 4d82660 | 2013-05-16 18:32:39 +0300 | [diff] [blame] | 756 | relevant_parents = 0; |
| 757 | relevant_change = irrelevant_change = 0; |
| 758 | for (p = commit->parents, n = 0; p; n++, p = p->next) { |
| 759 | if (relevant_commit(p->item)) { |
| 760 | relevant_change |= !st->treesame[n]; |
| 761 | relevant_parents++; |
| 762 | } else |
| 763 | irrelevant_change |= !st->treesame[n]; |
Kevin Bracey | d0af663 | 2013-05-16 18:32:34 +0300 | [diff] [blame] | 764 | } |
Kevin Bracey | 4d82660 | 2013-05-16 18:32:39 +0300 | [diff] [blame] | 765 | if (relevant_parents ? relevant_change : irrelevant_change) |
| 766 | commit->object.flags &= ~TREESAME; |
| 767 | else |
| 768 | commit->object.flags |= TREESAME; |
Kevin Bracey | d0af663 | 2013-05-16 18:32:34 +0300 | [diff] [blame] | 769 | } |
| 770 | |
| 771 | return commit->object.flags & TREESAME; |
| 772 | } |
| 773 | |
Kevin Bracey | 4d82660 | 2013-05-16 18:32:39 +0300 | [diff] [blame] | 774 | static inline int limiting_can_increase_treesame(const struct rev_info *revs) |
| 775 | { |
| 776 | /* |
| 777 | * TREESAME is irrelevant unless prune && dense; |
| 778 | * if simplify_history is set, we can't have a mixture of TREESAME and |
| 779 | * !TREESAME INTERESTING parents (and we don't have treesame[] |
| 780 | * decoration anyway); |
| 781 | * if first_parent_only is set, then the TREESAME flag is locked |
| 782 | * against the first parent (and again we lack treesame[] decoration). |
| 783 | */ |
| 784 | return revs->prune && revs->dense && |
| 785 | !revs->simplify_history && |
| 786 | !revs->first_parent_only; |
| 787 | } |
| 788 | |
Linus Torvalds | a4a88b2 | 2006-02-28 11:24:00 -0800 | [diff] [blame] | 789 | static void try_to_simplify_commit(struct rev_info *revs, struct commit *commit) |
| 790 | { |
| 791 | struct commit_list **pp, *parent; |
Kevin Bracey | d0af663 | 2013-05-16 18:32:34 +0300 | [diff] [blame] | 792 | struct treesame_state *ts = NULL; |
Kevin Bracey | 4d82660 | 2013-05-16 18:32:39 +0300 | [diff] [blame] | 793 | int relevant_change = 0, irrelevant_change = 0; |
| 794 | int relevant_parents, nth_parent; |
Linus Torvalds | a4a88b2 | 2006-02-28 11:24:00 -0800 | [diff] [blame] | 795 | |
Linus Torvalds | 53b2c82 | 2007-11-05 13:22:34 -0800 | [diff] [blame] | 796 | /* |
| 797 | * If we don't do pruning, everything is interesting |
| 798 | */ |
Linus Torvalds | 7dc0fe3 | 2007-11-12 23:16:08 -0800 | [diff] [blame] | 799 | if (!revs->prune) |
Linus Torvalds | 53b2c82 | 2007-11-05 13:22:34 -0800 | [diff] [blame] | 800 | return; |
Linus Torvalds | 53b2c82 | 2007-11-05 13:22:34 -0800 | [diff] [blame] | 801 | |
Derrick Stolee | 2e27bd7 | 2018-04-06 19:09:38 +0000 | [diff] [blame] | 802 | if (!get_commit_tree(commit)) |
Linus Torvalds | a4a88b2 | 2006-02-28 11:24:00 -0800 | [diff] [blame] | 803 | return; |
| 804 | |
| 805 | if (!commit->parents) { |
Linus Torvalds | 3a5e860 | 2008-11-03 10:45:41 -0800 | [diff] [blame] | 806 | if (rev_same_tree_as_empty(revs, commit)) |
Linus Torvalds | 7dc0fe3 | 2007-11-12 23:16:08 -0800 | [diff] [blame] | 807 | commit->object.flags |= TREESAME; |
Linus Torvalds | a4a88b2 | 2006-02-28 11:24:00 -0800 | [diff] [blame] | 808 | return; |
| 809 | } |
| 810 | |
Linus Torvalds | 53b2c82 | 2007-11-05 13:22:34 -0800 | [diff] [blame] | 811 | /* |
| 812 | * Normal non-merge commit? If we don't want to make the |
| 813 | * history dense, we consider it always to be a change.. |
| 814 | */ |
Linus Torvalds | 7dc0fe3 | 2007-11-12 23:16:08 -0800 | [diff] [blame] | 815 | if (!revs->dense && !commit->parents->next) |
Linus Torvalds | 53b2c82 | 2007-11-05 13:22:34 -0800 | [diff] [blame] | 816 | return; |
Linus Torvalds | 53b2c82 | 2007-11-05 13:22:34 -0800 | [diff] [blame] | 817 | |
Kevin Bracey | 4d82660 | 2013-05-16 18:32:39 +0300 | [diff] [blame] | 818 | for (pp = &commit->parents, nth_parent = 0, relevant_parents = 0; |
Kevin Bracey | d0af663 | 2013-05-16 18:32:34 +0300 | [diff] [blame] | 819 | (parent = *pp) != NULL; |
| 820 | pp = &parent->next, nth_parent++) { |
Linus Torvalds | a4a88b2 | 2006-02-28 11:24:00 -0800 | [diff] [blame] | 821 | struct commit *p = parent->item; |
Kevin Bracey | 4d82660 | 2013-05-16 18:32:39 +0300 | [diff] [blame] | 822 | if (relevant_commit(p)) |
| 823 | relevant_parents++; |
Linus Torvalds | a4a88b2 | 2006-02-28 11:24:00 -0800 | [diff] [blame] | 824 | |
Kevin Bracey | d0af663 | 2013-05-16 18:32:34 +0300 | [diff] [blame] | 825 | if (nth_parent == 1) { |
| 826 | /* |
| 827 | * This our second loop iteration - so we now know |
| 828 | * we're dealing with a merge. |
| 829 | * |
| 830 | * Do not compare with later parents when we care only about |
| 831 | * the first parent chain, in order to avoid derailing the |
| 832 | * traversal to follow a side branch that brought everything |
| 833 | * in the path we are limited to by the pathspec. |
| 834 | */ |
| 835 | if (revs->first_parent_only) |
| 836 | break; |
| 837 | /* |
| 838 | * If this will remain a potentially-simplifiable |
| 839 | * merge, remember per-parent treesame if needed. |
| 840 | * Initialise the array with the comparison from our |
| 841 | * first iteration. |
| 842 | */ |
| 843 | if (revs->treesame.name && |
| 844 | !revs->simplify_history && |
| 845 | !(commit->object.flags & UNINTERESTING)) { |
| 846 | ts = initialise_treesame(revs, commit); |
Kevin Bracey | 4d82660 | 2013-05-16 18:32:39 +0300 | [diff] [blame] | 847 | if (!(irrelevant_change || relevant_change)) |
Kevin Bracey | d0af663 | 2013-05-16 18:32:34 +0300 | [diff] [blame] | 848 | ts->treesame[0] = 1; |
| 849 | } |
| 850 | } |
Alex Riesen | cc0e6c5 | 2007-05-04 23:54:57 +0200 | [diff] [blame] | 851 | if (parse_commit(p) < 0) |
| 852 | die("cannot simplify commit %s (because of %s)", |
brian m. carlson | f2fd076 | 2015-11-10 02:22:28 +0000 | [diff] [blame] | 853 | oid_to_hex(&commit->object.oid), |
| 854 | oid_to_hex(&p->object.oid)); |
Linus Torvalds | 3a5e860 | 2008-11-03 10:45:41 -0800 | [diff] [blame] | 855 | switch (rev_compare_tree(revs, p, commit)) { |
Fredrik Kuivinen | 8efdc32 | 2006-03-10 10:21:39 +0100 | [diff] [blame] | 856 | case REV_TREE_SAME: |
Kevin Bracey | 141efdb | 2013-05-16 18:32:41 +0300 | [diff] [blame] | 857 | if (!revs->simplify_history || !relevant_commit(p)) { |
Junio C Hamano | f3219fb | 2006-03-10 21:59:37 -0800 | [diff] [blame] | 858 | /* Even if a merge with an uninteresting |
| 859 | * side branch brought the entire change |
| 860 | * we are interested in, we do not want |
| 861 | * to lose the other branches of this |
| 862 | * merge, so we just keep going. |
| 863 | */ |
Kevin Bracey | d0af663 | 2013-05-16 18:32:34 +0300 | [diff] [blame] | 864 | if (ts) |
| 865 | ts->treesame[nth_parent] = 1; |
Junio C Hamano | f3219fb | 2006-03-10 21:59:37 -0800 | [diff] [blame] | 866 | continue; |
| 867 | } |
Linus Torvalds | a4a88b2 | 2006-02-28 11:24:00 -0800 | [diff] [blame] | 868 | parent->next = NULL; |
| 869 | commit->parents = parent; |
Linus Torvalds | 7dc0fe3 | 2007-11-12 23:16:08 -0800 | [diff] [blame] | 870 | commit->object.flags |= TREESAME; |
Linus Torvalds | a4a88b2 | 2006-02-28 11:24:00 -0800 | [diff] [blame] | 871 | return; |
| 872 | |
Fredrik Kuivinen | 8efdc32 | 2006-03-10 10:21:39 +0100 | [diff] [blame] | 873 | case REV_TREE_NEW: |
| 874 | if (revs->remove_empty_trees && |
Linus Torvalds | 3a5e860 | 2008-11-03 10:45:41 -0800 | [diff] [blame] | 875 | rev_same_tree_as_empty(revs, p)) { |
Junio C Hamano | c348f31 | 2006-03-12 13:39:31 -0800 | [diff] [blame] | 876 | /* We are adding all the specified |
| 877 | * paths from this parent, so the |
| 878 | * history beyond this parent is not |
| 879 | * interesting. Remove its parents |
| 880 | * (they are grandparents for us). |
| 881 | * IOW, we pretend this parent is a |
| 882 | * "root" commit. |
Junio C Hamano | a41e109 | 2006-03-12 13:39:31 -0800 | [diff] [blame] | 883 | */ |
Alex Riesen | cc0e6c5 | 2007-05-04 23:54:57 +0200 | [diff] [blame] | 884 | if (parse_commit(p) < 0) |
| 885 | die("cannot simplify commit %s (invalid %s)", |
brian m. carlson | f2fd076 | 2015-11-10 02:22:28 +0000 | [diff] [blame] | 886 | oid_to_hex(&commit->object.oid), |
| 887 | oid_to_hex(&p->object.oid)); |
Junio C Hamano | c348f31 | 2006-03-12 13:39:31 -0800 | [diff] [blame] | 888 | p->parents = NULL; |
Linus Torvalds | a4a88b2 | 2006-02-28 11:24:00 -0800 | [diff] [blame] | 889 | } |
| 890 | /* fallthrough */ |
Linus Torvalds | ceff8e7 | 2009-06-02 18:34:01 -0700 | [diff] [blame] | 891 | case REV_TREE_OLD: |
Fredrik Kuivinen | 8efdc32 | 2006-03-10 10:21:39 +0100 | [diff] [blame] | 892 | case REV_TREE_DIFFERENT: |
Kevin Bracey | 4d82660 | 2013-05-16 18:32:39 +0300 | [diff] [blame] | 893 | if (relevant_commit(p)) |
| 894 | relevant_change = 1; |
| 895 | else |
| 896 | irrelevant_change = 1; |
Linus Torvalds | a4a88b2 | 2006-02-28 11:24:00 -0800 | [diff] [blame] | 897 | continue; |
| 898 | } |
brian m. carlson | f2fd076 | 2015-11-10 02:22:28 +0000 | [diff] [blame] | 899 | die("bad tree compare for commit %s", oid_to_hex(&commit->object.oid)); |
Linus Torvalds | a4a88b2 | 2006-02-28 11:24:00 -0800 | [diff] [blame] | 900 | } |
Kevin Bracey | 4d82660 | 2013-05-16 18:32:39 +0300 | [diff] [blame] | 901 | |
| 902 | /* |
| 903 | * TREESAME is straightforward for single-parent commits. For merge |
| 904 | * commits, it is most useful to define it so that "irrelevant" |
| 905 | * parents cannot make us !TREESAME - if we have any relevant |
| 906 | * parents, then we only consider TREESAMEness with respect to them, |
| 907 | * allowing irrelevant merges from uninteresting branches to be |
| 908 | * simplified away. Only if we have only irrelevant parents do we |
| 909 | * base TREESAME on them. Note that this logic is replicated in |
| 910 | * update_treesame, which should be kept in sync. |
| 911 | */ |
| 912 | if (relevant_parents ? !relevant_change : !irrelevant_change) |
| 913 | commit->object.flags |= TREESAME; |
Linus Torvalds | a4a88b2 | 2006-02-28 11:24:00 -0800 | [diff] [blame] | 914 | } |
| 915 | |
Derrick Stolee | 5284fc5 | 2018-11-01 13:46:21 +0000 | [diff] [blame] | 916 | static int process_parents(struct rev_info *revs, struct commit *commit, |
Jeff King | 8320b1d | 2019-04-03 21:41:09 -0400 | [diff] [blame] | 917 | struct commit_list **list, struct prio_queue *queue) |
Linus Torvalds | a4a88b2 | 2006-02-28 11:24:00 -0800 | [diff] [blame] | 918 | { |
| 919 | struct commit_list *parent = commit->parents; |
Junio C Hamano | 577ed5c | 2006-10-22 17:32:47 -0700 | [diff] [blame] | 920 | unsigned left_flag; |
Linus Torvalds | a4a88b2 | 2006-02-28 11:24:00 -0800 | [diff] [blame] | 921 | |
Linus Torvalds | 3381c79 | 2006-04-08 17:05:58 -0700 | [diff] [blame] | 922 | if (commit->object.flags & ADDED) |
Alex Riesen | cc0e6c5 | 2007-05-04 23:54:57 +0200 | [diff] [blame] | 923 | return 0; |
Linus Torvalds | 3381c79 | 2006-04-08 17:05:58 -0700 | [diff] [blame] | 924 | commit->object.flags |= ADDED; |
| 925 | |
Vicent Marti | a330de3 | 2013-10-24 14:01:41 -0400 | [diff] [blame] | 926 | if (revs->include_check && |
| 927 | !revs->include_check(commit, revs->include_check_data)) |
| 928 | return 0; |
| 929 | |
Linus Torvalds | a4a88b2 | 2006-02-28 11:24:00 -0800 | [diff] [blame] | 930 | /* |
| 931 | * If the commit is uninteresting, don't try to |
| 932 | * prune parents - we want the maximal uninteresting |
| 933 | * set. |
| 934 | * |
| 935 | * Normally we haven't parsed the parent |
| 936 | * yet, so we won't have a parent of a parent |
| 937 | * here. However, it may turn out that we've |
| 938 | * reached this commit some other way (where it |
| 939 | * wasn't uninteresting), in which case we need |
| 940 | * to mark its parents recursively too.. |
| 941 | */ |
| 942 | if (commit->object.flags & UNINTERESTING) { |
| 943 | while (parent) { |
| 944 | struct commit *p = parent->item; |
| 945 | parent = parent->next; |
Junio C Hamano | aeeae1b | 2009-01-27 23:19:30 -0800 | [diff] [blame] | 946 | if (p) |
| 947 | p->object.flags |= UNINTERESTING; |
Jeff King | ce4e7b2 | 2015-06-01 05:56:40 -0400 | [diff] [blame] | 948 | if (parse_commit_gently(p, 1) < 0) |
Junio C Hamano | aeeae1b | 2009-01-27 23:19:30 -0800 | [diff] [blame] | 949 | continue; |
Linus Torvalds | a4a88b2 | 2006-02-28 11:24:00 -0800 | [diff] [blame] | 950 | if (p->parents) |
| 951 | mark_parents_uninteresting(p); |
| 952 | if (p->object.flags & SEEN) |
| 953 | continue; |
| 954 | p->object.flags |= SEEN; |
Derrick Stolee | 5284fc5 | 2018-11-01 13:46:21 +0000 | [diff] [blame] | 955 | if (list) |
Jeff King | 8320b1d | 2019-04-03 21:41:09 -0400 | [diff] [blame] | 956 | commit_list_insert_by_date(p, list); |
| 957 | if (queue) |
| 958 | prio_queue_put(queue, p); |
Linus Torvalds | a4a88b2 | 2006-02-28 11:24:00 -0800 | [diff] [blame] | 959 | } |
Alex Riesen | cc0e6c5 | 2007-05-04 23:54:57 +0200 | [diff] [blame] | 960 | return 0; |
Linus Torvalds | a4a88b2 | 2006-02-28 11:24:00 -0800 | [diff] [blame] | 961 | } |
| 962 | |
| 963 | /* |
| 964 | * Ok, the commit wasn't uninteresting. Try to |
| 965 | * simplify the commit history and find the parent |
| 966 | * that has no differences in the path set if one exists. |
| 967 | */ |
Linus Torvalds | 53b2c82 | 2007-11-05 13:22:34 -0800 | [diff] [blame] | 968 | try_to_simplify_commit(revs, commit); |
Linus Torvalds | a4a88b2 | 2006-02-28 11:24:00 -0800 | [diff] [blame] | 969 | |
Linus Torvalds | ba1d450 | 2006-04-15 12:09:56 -0700 | [diff] [blame] | 970 | if (revs->no_walk) |
Alex Riesen | cc0e6c5 | 2007-05-04 23:54:57 +0200 | [diff] [blame] | 971 | return 0; |
Linus Torvalds | ba1d450 | 2006-04-15 12:09:56 -0700 | [diff] [blame] | 972 | |
Junio C Hamano | 577ed5c | 2006-10-22 17:32:47 -0700 | [diff] [blame] | 973 | left_flag = (commit->object.flags & SYMMETRIC_LEFT); |
Junio C Hamano | 0053e90 | 2007-03-13 01:57:22 -0700 | [diff] [blame] | 974 | |
Stephen R. van den Berg | d9c292e | 2008-04-27 19:32:46 +0200 | [diff] [blame] | 975 | for (parent = commit->parents; parent; parent = parent->next) { |
Linus Torvalds | a4a88b2 | 2006-02-28 11:24:00 -0800 | [diff] [blame] | 976 | struct commit *p = parent->item; |
Jonathan Tan | df11e19 | 2017-12-08 15:27:15 +0000 | [diff] [blame] | 977 | int gently = revs->ignore_missing_links || |
| 978 | revs->exclude_promisor_objects; |
| 979 | if (parse_commit_gently(p, gently) < 0) { |
| 980 | if (revs->exclude_promisor_objects && |
| 981 | is_promisor_object(&p->object.oid)) { |
| 982 | if (revs->first_parent_only) |
| 983 | break; |
| 984 | continue; |
| 985 | } |
Alex Riesen | cc0e6c5 | 2007-05-04 23:54:57 +0200 | [diff] [blame] | 986 | return -1; |
Jonathan Tan | df11e19 | 2017-12-08 15:27:15 +0000 | [diff] [blame] | 987 | } |
Nguyễn Thái Ngọc Duy | 87be252 | 2018-05-19 07:28:24 +0200 | [diff] [blame] | 988 | if (revs->sources) { |
| 989 | char **slot = revision_sources_at(revs->sources, p); |
| 990 | |
| 991 | if (!*slot) |
| 992 | *slot = *revision_sources_at(revs->sources, commit); |
| 993 | } |
Junio C Hamano | 577ed5c | 2006-10-22 17:32:47 -0700 | [diff] [blame] | 994 | p->object.flags |= left_flag; |
Lars Hjemli | ad1012e | 2008-05-12 17:12:36 +0200 | [diff] [blame] | 995 | if (!(p->object.flags & SEEN)) { |
| 996 | p->object.flags |= SEEN; |
Derrick Stolee | 5284fc5 | 2018-11-01 13:46:21 +0000 | [diff] [blame] | 997 | if (list) |
Jeff King | 8320b1d | 2019-04-03 21:41:09 -0400 | [diff] [blame] | 998 | commit_list_insert_by_date(p, list); |
| 999 | if (queue) |
| 1000 | prio_queue_put(queue, p); |
Lars Hjemli | ad1012e | 2008-05-12 17:12:36 +0200 | [diff] [blame] | 1001 | } |
Junio C Hamano | 60d30b0 | 2008-07-31 22:17:13 -0700 | [diff] [blame] | 1002 | if (revs->first_parent_only) |
Stephen R. van den Berg | d9c292e | 2008-04-27 19:32:46 +0200 | [diff] [blame] | 1003 | break; |
Linus Torvalds | a4a88b2 | 2006-02-28 11:24:00 -0800 | [diff] [blame] | 1004 | } |
Alex Riesen | cc0e6c5 | 2007-05-04 23:54:57 +0200 | [diff] [blame] | 1005 | return 0; |
Linus Torvalds | a4a88b2 | 2006-02-28 11:24:00 -0800 | [diff] [blame] | 1006 | } |
| 1007 | |
Johannes Schindelin | 36d56de | 2007-07-10 14:50:49 +0100 | [diff] [blame] | 1008 | static void cherry_pick_list(struct commit_list *list, struct rev_info *revs) |
Junio C Hamano | d7a17ca | 2007-04-09 03:40:38 -0700 | [diff] [blame] | 1009 | { |
| 1010 | struct commit_list *p; |
| 1011 | int left_count = 0, right_count = 0; |
| 1012 | int left_first; |
| 1013 | struct patch_ids ids; |
Michael J Gruber | adbbb31 | 2011-03-07 13:31:40 +0100 | [diff] [blame] | 1014 | unsigned cherry_flag; |
Junio C Hamano | d7a17ca | 2007-04-09 03:40:38 -0700 | [diff] [blame] | 1015 | |
| 1016 | /* First count the commits on the left and on the right */ |
| 1017 | for (p = list; p; p = p->next) { |
| 1018 | struct commit *commit = p->item; |
| 1019 | unsigned flags = commit->object.flags; |
| 1020 | if (flags & BOUNDARY) |
| 1021 | ; |
| 1022 | else if (flags & SYMMETRIC_LEFT) |
| 1023 | left_count++; |
| 1024 | else |
| 1025 | right_count++; |
| 1026 | } |
| 1027 | |
Thomas Rast | 36c0797 | 2010-02-20 12:42:04 +0100 | [diff] [blame] | 1028 | if (!left_count || !right_count) |
| 1029 | return; |
| 1030 | |
Junio C Hamano | d7a17ca | 2007-04-09 03:40:38 -0700 | [diff] [blame] | 1031 | left_first = left_count < right_count; |
Nguyễn Thái Ngọc Duy | 2abf350 | 2018-09-21 17:57:38 +0200 | [diff] [blame] | 1032 | init_patch_ids(revs->repo, &ids); |
Nguyễn Thái Ngọc Duy | 66f1362 | 2010-12-15 22:02:38 +0700 | [diff] [blame] | 1033 | ids.diffopts.pathspec = revs->diffopt.pathspec; |
Junio C Hamano | d7a17ca | 2007-04-09 03:40:38 -0700 | [diff] [blame] | 1034 | |
| 1035 | /* Compute patch-ids for one side */ |
| 1036 | for (p = list; p; p = p->next) { |
| 1037 | struct commit *commit = p->item; |
| 1038 | unsigned flags = commit->object.flags; |
| 1039 | |
| 1040 | if (flags & BOUNDARY) |
| 1041 | continue; |
| 1042 | /* |
| 1043 | * If we have fewer left, left_first is set and we omit |
| 1044 | * commits on the right branch in this loop. If we have |
| 1045 | * fewer right, we skip the left ones. |
| 1046 | */ |
| 1047 | if (left_first != !!(flags & SYMMETRIC_LEFT)) |
| 1048 | continue; |
Kevin Willford | 683f17e | 2016-07-29 12:19:18 -0400 | [diff] [blame] | 1049 | add_commit_patch_id(commit, &ids); |
Junio C Hamano | d7a17ca | 2007-04-09 03:40:38 -0700 | [diff] [blame] | 1050 | } |
| 1051 | |
Michael J Gruber | adbbb31 | 2011-03-07 13:31:40 +0100 | [diff] [blame] | 1052 | /* either cherry_mark or cherry_pick are true */ |
| 1053 | cherry_flag = revs->cherry_mark ? PATCHSAME : SHOWN; |
| 1054 | |
Junio C Hamano | d7a17ca | 2007-04-09 03:40:38 -0700 | [diff] [blame] | 1055 | /* Check the other side */ |
| 1056 | for (p = list; p; p = p->next) { |
| 1057 | struct commit *commit = p->item; |
| 1058 | struct patch_id *id; |
| 1059 | unsigned flags = commit->object.flags; |
| 1060 | |
| 1061 | if (flags & BOUNDARY) |
| 1062 | continue; |
| 1063 | /* |
| 1064 | * If we have fewer left, left_first is set and we omit |
| 1065 | * commits on the left branch in this loop. |
| 1066 | */ |
| 1067 | if (left_first == !!(flags & SYMMETRIC_LEFT)) |
| 1068 | continue; |
| 1069 | |
| 1070 | /* |
| 1071 | * Have we seen the same patch id? |
| 1072 | */ |
| 1073 | id = has_commit_patch_id(commit, &ids); |
| 1074 | if (!id) |
| 1075 | continue; |
Kevin Willford | 683f17e | 2016-07-29 12:19:18 -0400 | [diff] [blame] | 1076 | |
Michael J Gruber | adbbb31 | 2011-03-07 13:31:40 +0100 | [diff] [blame] | 1077 | commit->object.flags |= cherry_flag; |
Kevin Willford | 683f17e | 2016-07-29 12:19:18 -0400 | [diff] [blame] | 1078 | id->commit->object.flags |= cherry_flag; |
Junio C Hamano | d7a17ca | 2007-04-09 03:40:38 -0700 | [diff] [blame] | 1079 | } |
| 1080 | |
| 1081 | free_patch_ids(&ids); |
| 1082 | } |
| 1083 | |
Linus Torvalds | 7d00419 | 2008-03-17 18:56:33 -0700 | [diff] [blame] | 1084 | /* How many extra uninteresting commits we want to see.. */ |
| 1085 | #define SLOP 5 |
| 1086 | |
Johannes Schindelin | dddbad7 | 2017-04-26 21:29:31 +0200 | [diff] [blame] | 1087 | static int still_interesting(struct commit_list *src, timestamp_t date, int slop, |
Jeff King | b6e8a3b | 2015-04-17 18:11:04 -0400 | [diff] [blame] | 1088 | struct commit **interesting_cache) |
Linus Torvalds | 3131b71 | 2008-02-09 14:02:07 -0800 | [diff] [blame] | 1089 | { |
Linus Torvalds | 7d00419 | 2008-03-17 18:56:33 -0700 | [diff] [blame] | 1090 | /* |
| 1091 | * No source list at all? We're definitely done.. |
| 1092 | */ |
| 1093 | if (!src) |
| 1094 | return 0; |
| 1095 | |
| 1096 | /* |
| 1097 | * Does the destination list contain entries with a date |
| 1098 | * before the source list? Definitely _not_ done. |
| 1099 | */ |
Kacper Kornet | c19d1b4 | 2013-03-22 19:38:19 +0100 | [diff] [blame] | 1100 | if (date <= src->item->date) |
Linus Torvalds | 7d00419 | 2008-03-17 18:56:33 -0700 | [diff] [blame] | 1101 | return SLOP; |
| 1102 | |
| 1103 | /* |
| 1104 | * Does the source list still have interesting commits in |
| 1105 | * it? Definitely not done.. |
| 1106 | */ |
Jeff King | b6e8a3b | 2015-04-17 18:11:04 -0400 | [diff] [blame] | 1107 | if (!everybody_uninteresting(src, interesting_cache)) |
Linus Torvalds | 7d00419 | 2008-03-17 18:56:33 -0700 | [diff] [blame] | 1108 | return SLOP; |
| 1109 | |
| 1110 | /* Ok, we're closing in.. */ |
| 1111 | return slop-1; |
Linus Torvalds | 3131b71 | 2008-02-09 14:02:07 -0800 | [diff] [blame] | 1112 | } |
| 1113 | |
Junio C Hamano | ebdc94f | 2010-04-20 13:48:39 -0700 | [diff] [blame] | 1114 | /* |
| 1115 | * "rev-list --ancestry-path A..B" computes commits that are ancestors |
| 1116 | * of B but not ancestors of A but further limits the result to those |
| 1117 | * that are descendants of A. This takes the list of bottom commits and |
| 1118 | * the result of "A..B" without --ancestry-path, and limits the latter |
| 1119 | * further to the ones that can reach one of the commits in "bottom". |
| 1120 | */ |
| 1121 | static void limit_to_ancestry(struct commit_list *bottom, struct commit_list *list) |
| 1122 | { |
| 1123 | struct commit_list *p; |
| 1124 | struct commit_list *rlist = NULL; |
| 1125 | int made_progress; |
| 1126 | |
| 1127 | /* |
| 1128 | * Reverse the list so that it will be likely that we would |
| 1129 | * process parents before children. |
| 1130 | */ |
| 1131 | for (p = list; p; p = p->next) |
| 1132 | commit_list_insert(p->item, &rlist); |
| 1133 | |
| 1134 | for (p = bottom; p; p = p->next) |
| 1135 | p->item->object.flags |= TMP_MARK; |
| 1136 | |
| 1137 | /* |
| 1138 | * Mark the ones that can reach bottom commits in "list", |
| 1139 | * in a bottom-up fashion. |
| 1140 | */ |
| 1141 | do { |
| 1142 | made_progress = 0; |
| 1143 | for (p = rlist; p; p = p->next) { |
| 1144 | struct commit *c = p->item; |
| 1145 | struct commit_list *parents; |
| 1146 | if (c->object.flags & (TMP_MARK | UNINTERESTING)) |
| 1147 | continue; |
| 1148 | for (parents = c->parents; |
| 1149 | parents; |
| 1150 | parents = parents->next) { |
| 1151 | if (!(parents->item->object.flags & TMP_MARK)) |
| 1152 | continue; |
| 1153 | c->object.flags |= TMP_MARK; |
| 1154 | made_progress = 1; |
| 1155 | break; |
| 1156 | } |
| 1157 | } |
| 1158 | } while (made_progress); |
| 1159 | |
| 1160 | /* |
| 1161 | * NEEDSWORK: decide if we want to remove parents that are |
| 1162 | * not marked with TMP_MARK from commit->parents for commits |
| 1163 | * in the resulting list. We may not want to do that, though. |
| 1164 | */ |
| 1165 | |
| 1166 | /* |
| 1167 | * The ones that are not marked with TMP_MARK are uninteresting |
| 1168 | */ |
| 1169 | for (p = list; p; p = p->next) { |
| 1170 | struct commit *c = p->item; |
| 1171 | if (c->object.flags & TMP_MARK) |
| 1172 | continue; |
| 1173 | c->object.flags |= UNINTERESTING; |
| 1174 | } |
| 1175 | |
| 1176 | /* We are done with the TMP_MARK */ |
| 1177 | for (p = list; p; p = p->next) |
| 1178 | p->item->object.flags &= ~TMP_MARK; |
| 1179 | for (p = bottom; p; p = p->next) |
| 1180 | p->item->object.flags &= ~TMP_MARK; |
| 1181 | free_commit_list(rlist); |
| 1182 | } |
| 1183 | |
| 1184 | /* |
| 1185 | * Before walking the history, keep the set of "negative" refs the |
| 1186 | * caller has asked to exclude. |
| 1187 | * |
| 1188 | * This is used to compute "rev-list --ancestry-path A..B", as we need |
| 1189 | * to filter the result of "A..B" further to the ones that can actually |
| 1190 | * reach A. |
| 1191 | */ |
Kevin Bracey | 7f34a46 | 2013-05-16 18:32:38 +0300 | [diff] [blame] | 1192 | static struct commit_list *collect_bottom_commits(struct commit_list *list) |
Junio C Hamano | ebdc94f | 2010-04-20 13:48:39 -0700 | [diff] [blame] | 1193 | { |
Kevin Bracey | 7f34a46 | 2013-05-16 18:32:38 +0300 | [diff] [blame] | 1194 | struct commit_list *elem, *bottom = NULL; |
| 1195 | for (elem = list; elem; elem = elem->next) |
| 1196 | if (elem->item->object.flags & BOTTOM) |
| 1197 | commit_list_insert(elem->item, &bottom); |
Junio C Hamano | ebdc94f | 2010-04-20 13:48:39 -0700 | [diff] [blame] | 1198 | return bottom; |
| 1199 | } |
| 1200 | |
Michael J Gruber | 60adf7d | 2011-02-21 17:09:11 +0100 | [diff] [blame] | 1201 | /* Assumes either left_only or right_only is set */ |
| 1202 | static void limit_left_right(struct commit_list *list, struct rev_info *revs) |
| 1203 | { |
| 1204 | struct commit_list *p; |
| 1205 | |
| 1206 | for (p = list; p; p = p->next) { |
| 1207 | struct commit *commit = p->item; |
| 1208 | |
| 1209 | if (revs->right_only) { |
| 1210 | if (commit->object.flags & SYMMETRIC_LEFT) |
| 1211 | commit->object.flags |= SHOWN; |
| 1212 | } else /* revs->left_only is set */ |
| 1213 | if (!(commit->object.flags & SYMMETRIC_LEFT)) |
| 1214 | commit->object.flags |= SHOWN; |
| 1215 | } |
| 1216 | } |
| 1217 | |
Alex Riesen | cc0e6c5 | 2007-05-04 23:54:57 +0200 | [diff] [blame] | 1218 | static int limit_list(struct rev_info *revs) |
Linus Torvalds | a4a88b2 | 2006-02-28 11:24:00 -0800 | [diff] [blame] | 1219 | { |
Linus Torvalds | 7d00419 | 2008-03-17 18:56:33 -0700 | [diff] [blame] | 1220 | int slop = SLOP; |
Johannes Schindelin | dddbad7 | 2017-04-26 21:29:31 +0200 | [diff] [blame] | 1221 | timestamp_t date = TIME_MAX; |
Linus Torvalds | a4a88b2 | 2006-02-28 11:24:00 -0800 | [diff] [blame] | 1222 | struct commit_list *list = revs->commits; |
| 1223 | struct commit_list *newlist = NULL; |
| 1224 | struct commit_list **p = &newlist; |
Junio C Hamano | ebdc94f | 2010-04-20 13:48:39 -0700 | [diff] [blame] | 1225 | struct commit_list *bottom = NULL; |
Jeff King | b6e8a3b | 2015-04-17 18:11:04 -0400 | [diff] [blame] | 1226 | struct commit *interesting_cache = NULL; |
Junio C Hamano | ebdc94f | 2010-04-20 13:48:39 -0700 | [diff] [blame] | 1227 | |
| 1228 | if (revs->ancestry_path) { |
Kevin Bracey | 7f34a46 | 2013-05-16 18:32:38 +0300 | [diff] [blame] | 1229 | bottom = collect_bottom_commits(list); |
Junio C Hamano | ebdc94f | 2010-04-20 13:48:39 -0700 | [diff] [blame] | 1230 | if (!bottom) |
Johan Herland | 97b03c3 | 2010-06-04 01:17:36 +0200 | [diff] [blame] | 1231 | die("--ancestry-path given but there are no bottom commits"); |
Junio C Hamano | ebdc94f | 2010-04-20 13:48:39 -0700 | [diff] [blame] | 1232 | } |
Linus Torvalds | a4a88b2 | 2006-02-28 11:24:00 -0800 | [diff] [blame] | 1233 | |
| 1234 | while (list) { |
René Scharfe | e510ab8 | 2015-10-24 18:21:31 +0200 | [diff] [blame] | 1235 | struct commit *commit = pop_commit(&list); |
Linus Torvalds | a4a88b2 | 2006-02-28 11:24:00 -0800 | [diff] [blame] | 1236 | struct object *obj = &commit->object; |
Linus Torvalds | cdcefbc | 2007-11-03 11:11:10 -0700 | [diff] [blame] | 1237 | show_early_output_fn_t show; |
Linus Torvalds | a4a88b2 | 2006-02-28 11:24:00 -0800 | [diff] [blame] | 1238 | |
Jeff King | b6e8a3b | 2015-04-17 18:11:04 -0400 | [diff] [blame] | 1239 | if (commit == interesting_cache) |
| 1240 | interesting_cache = NULL; |
| 1241 | |
Linus Torvalds | a4a88b2 | 2006-02-28 11:24:00 -0800 | [diff] [blame] | 1242 | if (revs->max_age != -1 && (commit->date < revs->max_age)) |
| 1243 | obj->flags |= UNINTERESTING; |
Derrick Stolee | 5284fc5 | 2018-11-01 13:46:21 +0000 | [diff] [blame] | 1244 | if (process_parents(revs, commit, &list, NULL) < 0) |
Alex Riesen | cc0e6c5 | 2007-05-04 23:54:57 +0200 | [diff] [blame] | 1245 | return -1; |
Linus Torvalds | a4a88b2 | 2006-02-28 11:24:00 -0800 | [diff] [blame] | 1246 | if (obj->flags & UNINTERESTING) { |
| 1247 | mark_parents_uninteresting(commit); |
Jeff King | b6e8a3b | 2015-04-17 18:11:04 -0400 | [diff] [blame] | 1248 | slop = still_interesting(list, date, slop, &interesting_cache); |
Linus Torvalds | 7d00419 | 2008-03-17 18:56:33 -0700 | [diff] [blame] | 1249 | if (slop) |
Linus Torvalds | 3131b71 | 2008-02-09 14:02:07 -0800 | [diff] [blame] | 1250 | continue; |
Linus Torvalds | 7d00419 | 2008-03-17 18:56:33 -0700 | [diff] [blame] | 1251 | break; |
Linus Torvalds | a4a88b2 | 2006-02-28 11:24:00 -0800 | [diff] [blame] | 1252 | } |
| 1253 | if (revs->min_age != -1 && (commit->date > revs->min_age)) |
| 1254 | continue; |
Linus Torvalds | 7d00419 | 2008-03-17 18:56:33 -0700 | [diff] [blame] | 1255 | date = commit->date; |
Linus Torvalds | a4a88b2 | 2006-02-28 11:24:00 -0800 | [diff] [blame] | 1256 | p = &commit_list_insert(commit, p)->next; |
Linus Torvalds | cdcefbc | 2007-11-03 11:11:10 -0700 | [diff] [blame] | 1257 | |
| 1258 | show = show_early_output; |
| 1259 | if (!show) |
| 1260 | continue; |
| 1261 | |
| 1262 | show(revs, newlist); |
| 1263 | show_early_output = NULL; |
Linus Torvalds | a4a88b2 | 2006-02-28 11:24:00 -0800 | [diff] [blame] | 1264 | } |
Michael J Gruber | adbbb31 | 2011-03-07 13:31:40 +0100 | [diff] [blame] | 1265 | if (revs->cherry_pick || revs->cherry_mark) |
Johannes Schindelin | 36d56de | 2007-07-10 14:50:49 +0100 | [diff] [blame] | 1266 | cherry_pick_list(newlist, revs); |
Junio C Hamano | d7a17ca | 2007-04-09 03:40:38 -0700 | [diff] [blame] | 1267 | |
Michael J Gruber | 60adf7d | 2011-02-21 17:09:11 +0100 | [diff] [blame] | 1268 | if (revs->left_only || revs->right_only) |
| 1269 | limit_left_right(newlist, revs); |
| 1270 | |
Junio C Hamano | ebdc94f | 2010-04-20 13:48:39 -0700 | [diff] [blame] | 1271 | if (bottom) { |
| 1272 | limit_to_ancestry(bottom, newlist); |
| 1273 | free_commit_list(bottom); |
| 1274 | } |
| 1275 | |
Kevin Bracey | 4d82660 | 2013-05-16 18:32:39 +0300 | [diff] [blame] | 1276 | /* |
| 1277 | * Check if any commits have become TREESAME by some of their parents |
| 1278 | * becoming UNINTERESTING. |
| 1279 | */ |
| 1280 | if (limiting_can_increase_treesame(revs)) |
| 1281 | for (list = newlist; list; list = list->next) { |
| 1282 | struct commit *c = list->item; |
| 1283 | if (c->object.flags & (UNINTERESTING | TREESAME)) |
| 1284 | continue; |
| 1285 | update_treesame(revs, c); |
| 1286 | } |
| 1287 | |
Linus Torvalds | a4a88b2 | 2006-02-28 11:24:00 -0800 | [diff] [blame] | 1288 | revs->commits = newlist; |
Alex Riesen | cc0e6c5 | 2007-05-04 23:54:57 +0200 | [diff] [blame] | 1289 | return 0; |
Linus Torvalds | a4a88b2 | 2006-02-28 11:24:00 -0800 | [diff] [blame] | 1290 | } |
| 1291 | |
Michael Haggerty | df835d3 | 2013-05-25 11:08:02 +0200 | [diff] [blame] | 1292 | /* |
| 1293 | * Add an entry to refs->cmdline with the specified information. |
| 1294 | * *name is copied. |
| 1295 | */ |
Junio C Hamano | 281eee4 | 2011-08-25 17:35:39 -0700 | [diff] [blame] | 1296 | static void add_rev_cmdline(struct rev_info *revs, |
| 1297 | struct object *item, |
| 1298 | const char *name, |
| 1299 | int whence, |
| 1300 | unsigned flags) |
| 1301 | { |
| 1302 | struct rev_cmdline_info *info = &revs->cmdline; |
Ramsay Jones | 071bcaa | 2017-09-21 17:49:38 +0100 | [diff] [blame] | 1303 | unsigned int nr = info->nr; |
Junio C Hamano | 281eee4 | 2011-08-25 17:35:39 -0700 | [diff] [blame] | 1304 | |
| 1305 | ALLOC_GROW(info->rev, nr + 1, info->alloc); |
| 1306 | info->rev[nr].item = item; |
Michael Haggerty | df835d3 | 2013-05-25 11:08:02 +0200 | [diff] [blame] | 1307 | info->rev[nr].name = xstrdup(name); |
Junio C Hamano | 281eee4 | 2011-08-25 17:35:39 -0700 | [diff] [blame] | 1308 | info->rev[nr].whence = whence; |
| 1309 | info->rev[nr].flags = flags; |
| 1310 | info->nr++; |
| 1311 | } |
| 1312 | |
Kevin Bracey | a765499 | 2013-05-13 18:00:47 +0300 | [diff] [blame] | 1313 | static void add_rev_cmdline_list(struct rev_info *revs, |
| 1314 | struct commit_list *commit_list, |
| 1315 | int whence, |
| 1316 | unsigned flags) |
| 1317 | { |
| 1318 | while (commit_list) { |
| 1319 | struct object *object = &commit_list->item->object; |
brian m. carlson | f2fd076 | 2015-11-10 02:22:28 +0000 | [diff] [blame] | 1320 | add_rev_cmdline(revs, object, oid_to_hex(&object->oid), |
Kevin Bracey | a765499 | 2013-05-13 18:00:47 +0300 | [diff] [blame] | 1321 | whence, flags); |
| 1322 | commit_list = commit_list->next; |
| 1323 | } |
| 1324 | } |
| 1325 | |
Junio C Hamano | 6304929 | 2006-12-18 17:25:28 -0800 | [diff] [blame] | 1326 | struct all_refs_cb { |
| 1327 | int all_flags; |
Shawn O. Pearce | 71b03b4 | 2006-12-21 19:49:06 -0500 | [diff] [blame] | 1328 | int warned_bad_reflog; |
Junio C Hamano | 6304929 | 2006-12-18 17:25:28 -0800 | [diff] [blame] | 1329 | struct rev_info *all_revs; |
| 1330 | const char *name_for_errormsg; |
Nguyễn Thái Ngọc Duy | ab3e1f7 | 2018-10-21 10:08:56 +0200 | [diff] [blame] | 1331 | struct worktree *wt; |
Junio C Hamano | 6304929 | 2006-12-18 17:25:28 -0800 | [diff] [blame] | 1332 | }; |
Linus Torvalds | ae56354 | 2006-02-25 16:19:46 -0800 | [diff] [blame] | 1333 | |
Junio C Hamano | ff32d34 | 2013-11-01 12:02:45 -0700 | [diff] [blame] | 1334 | int ref_excluded(struct string_list *ref_excludes, const char *path) |
Junio C Hamano | e7b432c | 2013-08-30 16:37:55 -0700 | [diff] [blame] | 1335 | { |
| 1336 | struct string_list_item *item; |
| 1337 | |
Junio C Hamano | ff32d34 | 2013-11-01 12:02:45 -0700 | [diff] [blame] | 1338 | if (!ref_excludes) |
Junio C Hamano | e7b432c | 2013-08-30 16:37:55 -0700 | [diff] [blame] | 1339 | return 0; |
Junio C Hamano | ff32d34 | 2013-11-01 12:02:45 -0700 | [diff] [blame] | 1340 | for_each_string_list_item(item, ref_excludes) { |
Ævar Arnfjörð Bjarmason | 55d3426 | 2017-06-22 21:38:08 +0000 | [diff] [blame] | 1341 | if (!wildmatch(item->string, path, 0)) |
Junio C Hamano | e7b432c | 2013-08-30 16:37:55 -0700 | [diff] [blame] | 1342 | return 1; |
| 1343 | } |
| 1344 | return 0; |
| 1345 | } |
| 1346 | |
Michael Haggerty | a217dcb | 2015-05-25 18:38:30 +0000 | [diff] [blame] | 1347 | static int handle_one_ref(const char *path, const struct object_id *oid, |
| 1348 | int flag, void *cb_data) |
Linus Torvalds | ae56354 | 2006-02-25 16:19:46 -0800 | [diff] [blame] | 1349 | { |
Junio C Hamano | 6304929 | 2006-12-18 17:25:28 -0800 | [diff] [blame] | 1350 | struct all_refs_cb *cb = cb_data; |
Junio C Hamano | e7b432c | 2013-08-30 16:37:55 -0700 | [diff] [blame] | 1351 | struct object *object; |
| 1352 | |
Junio C Hamano | ff32d34 | 2013-11-01 12:02:45 -0700 | [diff] [blame] | 1353 | if (ref_excluded(cb->all_revs->ref_excludes, path)) |
Junio C Hamano | e7b432c | 2013-08-30 16:37:55 -0700 | [diff] [blame] | 1354 | return 0; |
| 1355 | |
brian m. carlson | 654b9a9 | 2017-05-06 22:10:27 +0000 | [diff] [blame] | 1356 | object = get_reference(cb->all_revs, path, oid, cb->all_flags); |
Junio C Hamano | 281eee4 | 2011-08-25 17:35:39 -0700 | [diff] [blame] | 1357 | add_rev_cmdline(cb->all_revs, object, path, REV_CMD_REF, cb->all_flags); |
brian m. carlson | a58a1b0 | 2017-05-06 22:10:26 +0000 | [diff] [blame] | 1358 | add_pending_oid(cb->all_revs, path, oid, cb->all_flags); |
Linus Torvalds | ae56354 | 2006-02-25 16:19:46 -0800 | [diff] [blame] | 1359 | return 0; |
| 1360 | } |
| 1361 | |
Ilari Liusvaara | d08bae7 | 2010-01-20 11:48:25 +0200 | [diff] [blame] | 1362 | static void init_all_refs_cb(struct all_refs_cb *cb, struct rev_info *revs, |
| 1363 | unsigned flags) |
| 1364 | { |
| 1365 | cb->all_revs = revs; |
| 1366 | cb->all_flags = flags; |
Jeff King | 7ba8262 | 2017-08-02 18:25:27 -0400 | [diff] [blame] | 1367 | revs->rev_input_given = 1; |
Nguyễn Thái Ngọc Duy | ab3e1f7 | 2018-10-21 10:08:56 +0200 | [diff] [blame] | 1368 | cb->wt = NULL; |
Ilari Liusvaara | d08bae7 | 2010-01-20 11:48:25 +0200 | [diff] [blame] | 1369 | } |
| 1370 | |
Junio C Hamano | ff32d34 | 2013-11-01 12:02:45 -0700 | [diff] [blame] | 1371 | void clear_ref_exclusion(struct string_list **ref_excludes_p) |
Junio C Hamano | e7b432c | 2013-08-30 16:37:55 -0700 | [diff] [blame] | 1372 | { |
Junio C Hamano | ff32d34 | 2013-11-01 12:02:45 -0700 | [diff] [blame] | 1373 | if (*ref_excludes_p) { |
| 1374 | string_list_clear(*ref_excludes_p, 0); |
| 1375 | free(*ref_excludes_p); |
Junio C Hamano | e7b432c | 2013-08-30 16:37:55 -0700 | [diff] [blame] | 1376 | } |
Junio C Hamano | ff32d34 | 2013-11-01 12:02:45 -0700 | [diff] [blame] | 1377 | *ref_excludes_p = NULL; |
Junio C Hamano | e7b432c | 2013-08-30 16:37:55 -0700 | [diff] [blame] | 1378 | } |
| 1379 | |
Junio C Hamano | ff32d34 | 2013-11-01 12:02:45 -0700 | [diff] [blame] | 1380 | void add_ref_exclusion(struct string_list **ref_excludes_p, const char *exclude) |
Junio C Hamano | e7b432c | 2013-08-30 16:37:55 -0700 | [diff] [blame] | 1381 | { |
Junio C Hamano | ff32d34 | 2013-11-01 12:02:45 -0700 | [diff] [blame] | 1382 | if (!*ref_excludes_p) { |
| 1383 | *ref_excludes_p = xcalloc(1, sizeof(**ref_excludes_p)); |
| 1384 | (*ref_excludes_p)->strdup_strings = 1; |
Junio C Hamano | e7b432c | 2013-08-30 16:37:55 -0700 | [diff] [blame] | 1385 | } |
Junio C Hamano | ff32d34 | 2013-11-01 12:02:45 -0700 | [diff] [blame] | 1386 | string_list_append(*ref_excludes_p, exclude); |
Junio C Hamano | e7b432c | 2013-08-30 16:37:55 -0700 | [diff] [blame] | 1387 | } |
| 1388 | |
Nguyễn Thái Ngọc Duy | 073cf63 | 2017-08-23 19:36:56 +0700 | [diff] [blame] | 1389 | static void handle_refs(struct ref_store *refs, |
| 1390 | struct rev_info *revs, unsigned flags, |
| 1391 | int (*for_each)(struct ref_store *, each_ref_fn, void *)) |
Linus Torvalds | ae56354 | 2006-02-25 16:19:46 -0800 | [diff] [blame] | 1392 | { |
Junio C Hamano | 6304929 | 2006-12-18 17:25:28 -0800 | [diff] [blame] | 1393 | struct all_refs_cb cb; |
Nguyễn Thái Ngọc Duy | 073cf63 | 2017-08-23 19:36:56 +0700 | [diff] [blame] | 1394 | |
| 1395 | if (!refs) { |
| 1396 | /* this could happen with uninitialized submodules */ |
| 1397 | return; |
| 1398 | } |
| 1399 | |
Ilari Liusvaara | d08bae7 | 2010-01-20 11:48:25 +0200 | [diff] [blame] | 1400 | init_all_refs_cb(&cb, revs, flags); |
Nguyễn Thái Ngọc Duy | 073cf63 | 2017-08-23 19:36:56 +0700 | [diff] [blame] | 1401 | for_each(refs, handle_one_ref, &cb); |
Junio C Hamano | 6304929 | 2006-12-18 17:25:28 -0800 | [diff] [blame] | 1402 | } |
| 1403 | |
brian m. carlson | 9461d27 | 2017-02-21 23:47:32 +0000 | [diff] [blame] | 1404 | static void handle_one_reflog_commit(struct object_id *oid, void *cb_data) |
Junio C Hamano | 6304929 | 2006-12-18 17:25:28 -0800 | [diff] [blame] | 1405 | { |
| 1406 | struct all_refs_cb *cb = cb_data; |
brian m. carlson | 9461d27 | 2017-02-21 23:47:32 +0000 | [diff] [blame] | 1407 | if (!is_null_oid(oid)) { |
Nguyễn Thái Ngọc Duy | b3c7eef | 2018-09-21 17:57:39 +0200 | [diff] [blame] | 1408 | struct object *o = parse_object(cb->all_revs->repo, oid); |
Shawn O. Pearce | 71b03b4 | 2006-12-21 19:49:06 -0500 | [diff] [blame] | 1409 | if (o) { |
| 1410 | o->flags |= cb->all_flags; |
Junio C Hamano | 281eee4 | 2011-08-25 17:35:39 -0700 | [diff] [blame] | 1411 | /* ??? CMDLINEFLAGS ??? */ |
Shawn O. Pearce | 71b03b4 | 2006-12-21 19:49:06 -0500 | [diff] [blame] | 1412 | add_pending_object(cb->all_revs, o, ""); |
| 1413 | } |
| 1414 | else if (!cb->warned_bad_reflog) { |
Theodore Ts'o | 46efd2d | 2007-03-30 19:07:05 -0400 | [diff] [blame] | 1415 | warning("reflog of '%s' references pruned commits", |
Shawn O. Pearce | 71b03b4 | 2006-12-21 19:49:06 -0500 | [diff] [blame] | 1416 | cb->name_for_errormsg); |
| 1417 | cb->warned_bad_reflog = 1; |
| 1418 | } |
Junio C Hamano | 6304929 | 2006-12-18 17:25:28 -0800 | [diff] [blame] | 1419 | } |
Shawn O. Pearce | 71b03b4 | 2006-12-21 19:49:06 -0500 | [diff] [blame] | 1420 | } |
| 1421 | |
brian m. carlson | 9461d27 | 2017-02-21 23:47:32 +0000 | [diff] [blame] | 1422 | static int handle_one_reflog_ent(struct object_id *ooid, struct object_id *noid, |
Johannes Schindelin | dddbad7 | 2017-04-26 21:29:31 +0200 | [diff] [blame] | 1423 | const char *email, timestamp_t timestamp, int tz, |
Johannes Schindelin | 883d60f | 2007-01-08 01:59:54 +0100 | [diff] [blame] | 1424 | const char *message, void *cb_data) |
Shawn O. Pearce | 71b03b4 | 2006-12-21 19:49:06 -0500 | [diff] [blame] | 1425 | { |
brian m. carlson | 9461d27 | 2017-02-21 23:47:32 +0000 | [diff] [blame] | 1426 | handle_one_reflog_commit(ooid, cb_data); |
| 1427 | handle_one_reflog_commit(noid, cb_data); |
Junio C Hamano | 6304929 | 2006-12-18 17:25:28 -0800 | [diff] [blame] | 1428 | return 0; |
| 1429 | } |
| 1430 | |
Nguyễn Thái Ngọc Duy | ab3e1f7 | 2018-10-21 10:08:56 +0200 | [diff] [blame] | 1431 | static int handle_one_reflog(const char *refname_in_wt, |
Nguyễn Thái Ngọc Duy | 061e420 | 2018-10-21 10:08:55 +0200 | [diff] [blame] | 1432 | const struct object_id *oid, |
Michael Haggerty | a89caf4 | 2015-05-25 18:39:03 +0000 | [diff] [blame] | 1433 | int flag, void *cb_data) |
Junio C Hamano | 6304929 | 2006-12-18 17:25:28 -0800 | [diff] [blame] | 1434 | { |
| 1435 | struct all_refs_cb *cb = cb_data; |
Nguyễn Thái Ngọc Duy | ab3e1f7 | 2018-10-21 10:08:56 +0200 | [diff] [blame] | 1436 | struct strbuf refname = STRBUF_INIT; |
| 1437 | |
Shawn O. Pearce | 71b03b4 | 2006-12-21 19:49:06 -0500 | [diff] [blame] | 1438 | cb->warned_bad_reflog = 0; |
Nguyễn Thái Ngọc Duy | ab3e1f7 | 2018-10-21 10:08:56 +0200 | [diff] [blame] | 1439 | strbuf_worktree_ref(cb->wt, &refname, refname_in_wt); |
| 1440 | cb->name_for_errormsg = refname.buf; |
| 1441 | refs_for_each_reflog_ent(get_main_ref_store(the_repository), |
| 1442 | refname.buf, |
Nguyễn Thái Ngọc Duy | acd9544 | 2017-08-23 19:37:01 +0700 | [diff] [blame] | 1443 | handle_one_reflog_ent, cb_data); |
Nguyễn Thái Ngọc Duy | ab3e1f7 | 2018-10-21 10:08:56 +0200 | [diff] [blame] | 1444 | strbuf_release(&refname); |
Junio C Hamano | 6304929 | 2006-12-18 17:25:28 -0800 | [diff] [blame] | 1445 | return 0; |
| 1446 | } |
| 1447 | |
Nguyễn Thái Ngọc Duy | acd9544 | 2017-08-23 19:37:01 +0700 | [diff] [blame] | 1448 | static void add_other_reflogs_to_pending(struct all_refs_cb *cb) |
| 1449 | { |
| 1450 | struct worktree **worktrees, **p; |
| 1451 | |
| 1452 | worktrees = get_worktrees(0); |
| 1453 | for (p = worktrees; *p; p++) { |
| 1454 | struct worktree *wt = *p; |
| 1455 | |
| 1456 | if (wt->is_current) |
| 1457 | continue; |
| 1458 | |
Nguyễn Thái Ngọc Duy | ab3e1f7 | 2018-10-21 10:08:56 +0200 | [diff] [blame] | 1459 | cb->wt = wt; |
| 1460 | refs_for_each_reflog(get_worktree_ref_store(wt), |
Nguyễn Thái Ngọc Duy | acd9544 | 2017-08-23 19:37:01 +0700 | [diff] [blame] | 1461 | handle_one_reflog, |
| 1462 | cb); |
| 1463 | } |
| 1464 | free_worktrees(worktrees); |
| 1465 | } |
| 1466 | |
Jeff King | 718ccc9 | 2014-10-15 18:38:31 -0400 | [diff] [blame] | 1467 | void add_reflogs_to_pending(struct rev_info *revs, unsigned flags) |
Junio C Hamano | 6304929 | 2006-12-18 17:25:28 -0800 | [diff] [blame] | 1468 | { |
| 1469 | struct all_refs_cb cb; |
Michael Haggerty | 2b2a5be | 2015-05-25 18:38:28 +0000 | [diff] [blame] | 1470 | |
Junio C Hamano | 6304929 | 2006-12-18 17:25:28 -0800 | [diff] [blame] | 1471 | cb.all_revs = revs; |
| 1472 | cb.all_flags = flags; |
Nguyễn Thái Ngọc Duy | ab3e1f7 | 2018-10-21 10:08:56 +0200 | [diff] [blame] | 1473 | cb.wt = NULL; |
Michael Haggerty | a89caf4 | 2015-05-25 18:39:03 +0000 | [diff] [blame] | 1474 | for_each_reflog(handle_one_reflog, &cb); |
Nguyễn Thái Ngọc Duy | acd9544 | 2017-08-23 19:37:01 +0700 | [diff] [blame] | 1475 | |
| 1476 | if (!revs->single_worktree) |
| 1477 | add_other_reflogs_to_pending(&cb); |
Linus Torvalds | ae56354 | 2006-02-25 16:19:46 -0800 | [diff] [blame] | 1478 | } |
| 1479 | |
Jeff King | 4fe1021 | 2014-10-16 20:44:23 -0400 | [diff] [blame] | 1480 | static void add_cache_tree(struct cache_tree *it, struct rev_info *revs, |
Jeff King | b4cfcde | 2018-11-02 01:22:59 -0400 | [diff] [blame] | 1481 | struct strbuf *path, unsigned int flags) |
Jeff King | 4fe1021 | 2014-10-16 20:44:23 -0400 | [diff] [blame] | 1482 | { |
| 1483 | size_t baselen = path->len; |
| 1484 | int i; |
| 1485 | |
| 1486 | if (it->entry_count >= 0) { |
Nguyễn Thái Ngọc Duy | b3c7eef | 2018-09-21 17:57:39 +0200 | [diff] [blame] | 1487 | struct tree *tree = lookup_tree(revs->repo, &it->oid); |
Jeff King | b4cfcde | 2018-11-02 01:22:59 -0400 | [diff] [blame] | 1488 | tree->object.flags |= flags; |
Jeff King | 4fe1021 | 2014-10-16 20:44:23 -0400 | [diff] [blame] | 1489 | add_pending_object_with_path(revs, &tree->object, "", |
| 1490 | 040000, path->buf); |
| 1491 | } |
| 1492 | |
| 1493 | for (i = 0; i < it->subtree_nr; i++) { |
| 1494 | struct cache_tree_sub *sub = it->down[i]; |
| 1495 | strbuf_addf(path, "%s%s", baselen ? "/" : "", sub->name); |
Jeff King | b4cfcde | 2018-11-02 01:22:59 -0400 | [diff] [blame] | 1496 | add_cache_tree(sub->cache_tree, revs, path, flags); |
Jeff King | 4fe1021 | 2014-10-16 20:44:23 -0400 | [diff] [blame] | 1497 | strbuf_setlen(path, baselen); |
| 1498 | } |
| 1499 | |
| 1500 | } |
| 1501 | |
Nguyễn Thái Ngọc Duy | 6c3d818 | 2017-08-23 19:36:51 +0700 | [diff] [blame] | 1502 | static void do_add_index_objects_to_pending(struct rev_info *revs, |
Jeff King | b4cfcde | 2018-11-02 01:22:59 -0400 | [diff] [blame] | 1503 | struct index_state *istate, |
| 1504 | unsigned int flags) |
Jeff King | 4fe1021 | 2014-10-16 20:44:23 -0400 | [diff] [blame] | 1505 | { |
| 1506 | int i; |
| 1507 | |
Nguyễn Thái Ngọc Duy | 6c3d818 | 2017-08-23 19:36:51 +0700 | [diff] [blame] | 1508 | for (i = 0; i < istate->cache_nr; i++) { |
| 1509 | struct cache_entry *ce = istate->cache[i]; |
Jeff King | 4fe1021 | 2014-10-16 20:44:23 -0400 | [diff] [blame] | 1510 | struct blob *blob; |
| 1511 | |
| 1512 | if (S_ISGITLINK(ce->ce_mode)) |
| 1513 | continue; |
| 1514 | |
Nguyễn Thái Ngọc Duy | b3c7eef | 2018-09-21 17:57:39 +0200 | [diff] [blame] | 1515 | blob = lookup_blob(revs->repo, &ce->oid); |
Jeff King | 4fe1021 | 2014-10-16 20:44:23 -0400 | [diff] [blame] | 1516 | if (!blob) |
| 1517 | die("unable to add index blob to traversal"); |
Jeff King | b4cfcde | 2018-11-02 01:22:59 -0400 | [diff] [blame] | 1518 | blob->object.flags |= flags; |
Jeff King | 4fe1021 | 2014-10-16 20:44:23 -0400 | [diff] [blame] | 1519 | add_pending_object_with_path(revs, &blob->object, "", |
| 1520 | ce->ce_mode, ce->name); |
| 1521 | } |
| 1522 | |
Nguyễn Thái Ngọc Duy | 6c3d818 | 2017-08-23 19:36:51 +0700 | [diff] [blame] | 1523 | if (istate->cache_tree) { |
Jeff King | 4fe1021 | 2014-10-16 20:44:23 -0400 | [diff] [blame] | 1524 | struct strbuf path = STRBUF_INIT; |
Jeff King | b4cfcde | 2018-11-02 01:22:59 -0400 | [diff] [blame] | 1525 | add_cache_tree(istate->cache_tree, revs, &path, flags); |
Jeff King | 4fe1021 | 2014-10-16 20:44:23 -0400 | [diff] [blame] | 1526 | strbuf_release(&path); |
| 1527 | } |
| 1528 | } |
| 1529 | |
Nguyễn Thái Ngọc Duy | 6c3d818 | 2017-08-23 19:36:51 +0700 | [diff] [blame] | 1530 | void add_index_objects_to_pending(struct rev_info *revs, unsigned int flags) |
| 1531 | { |
Nguyễn Thái Ngọc Duy | be489d0 | 2017-08-23 19:36:52 +0700 | [diff] [blame] | 1532 | struct worktree **worktrees, **p; |
| 1533 | |
Nguyễn Thái Ngọc Duy | e1ff0a3 | 2019-01-12 09:13:26 +0700 | [diff] [blame] | 1534 | repo_read_index(revs->repo); |
Jeff King | b4cfcde | 2018-11-02 01:22:59 -0400 | [diff] [blame] | 1535 | do_add_index_objects_to_pending(revs, revs->repo->index, flags); |
Nguyễn Thái Ngọc Duy | be489d0 | 2017-08-23 19:36:52 +0700 | [diff] [blame] | 1536 | |
| 1537 | if (revs->single_worktree) |
| 1538 | return; |
| 1539 | |
| 1540 | worktrees = get_worktrees(0); |
| 1541 | for (p = worktrees; *p; p++) { |
| 1542 | struct worktree *wt = *p; |
| 1543 | struct index_state istate = { NULL }; |
| 1544 | |
| 1545 | if (wt->is_current) |
| 1546 | continue; /* current index already taken care of */ |
| 1547 | |
| 1548 | if (read_index_from(&istate, |
Thomas Gummerer | a125a22 | 2018-01-07 22:30:13 +0000 | [diff] [blame] | 1549 | worktree_git_path(wt, "index"), |
| 1550 | get_worktree_git_dir(wt)) > 0) |
Jeff King | b4cfcde | 2018-11-02 01:22:59 -0400 | [diff] [blame] | 1551 | do_add_index_objects_to_pending(revs, &istate, flags); |
Nguyễn Thái Ngọc Duy | be489d0 | 2017-08-23 19:36:52 +0700 | [diff] [blame] | 1552 | discard_index(&istate); |
| 1553 | } |
| 1554 | free_worktrees(worktrees); |
Nguyễn Thái Ngọc Duy | 6c3d818 | 2017-08-23 19:36:51 +0700 | [diff] [blame] | 1555 | } |
| 1556 | |
Jeff King | 39b44ba | 2019-07-01 09:18:15 -0400 | [diff] [blame] | 1557 | struct add_alternate_refs_data { |
| 1558 | struct rev_info *revs; |
| 1559 | unsigned int flags; |
| 1560 | }; |
| 1561 | |
| 1562 | static void add_one_alternate_ref(const struct object_id *oid, |
| 1563 | void *vdata) |
| 1564 | { |
| 1565 | const char *name = ".alternate"; |
| 1566 | struct add_alternate_refs_data *data = vdata; |
| 1567 | struct object *obj; |
| 1568 | |
| 1569 | obj = get_reference(data->revs, name, oid, data->flags); |
| 1570 | add_rev_cmdline(data->revs, obj, name, REV_CMD_REV, data->flags); |
| 1571 | add_pending_object(data->revs, obj, name); |
| 1572 | } |
| 1573 | |
| 1574 | static void add_alternate_refs_to_pending(struct rev_info *revs, |
| 1575 | unsigned int flags) |
| 1576 | { |
| 1577 | struct add_alternate_refs_data data; |
| 1578 | data.revs = revs; |
| 1579 | data.flags = flags; |
| 1580 | for_each_alternate_ref(add_one_alternate_ref, &data); |
| 1581 | } |
| 1582 | |
Vegard Nossum | 8779351 | 2016-09-27 10:32:49 +0200 | [diff] [blame] | 1583 | static int add_parents_only(struct rev_info *revs, const char *arg_, int flags, |
| 1584 | int exclude_parent) |
Junio C Hamano | ea4a19e | 2006-04-30 00:54:29 -0700 | [diff] [blame] | 1585 | { |
brian m. carlson | 654b9a9 | 2017-05-06 22:10:27 +0000 | [diff] [blame] | 1586 | struct object_id oid; |
Junio C Hamano | ea4a19e | 2006-04-30 00:54:29 -0700 | [diff] [blame] | 1587 | struct object *it; |
| 1588 | struct commit *commit; |
| 1589 | struct commit_list *parents; |
Vegard Nossum | 8779351 | 2016-09-27 10:32:49 +0200 | [diff] [blame] | 1590 | int parent_number; |
Junio C Hamano | 281eee4 | 2011-08-25 17:35:39 -0700 | [diff] [blame] | 1591 | const char *arg = arg_; |
Junio C Hamano | ea4a19e | 2006-04-30 00:54:29 -0700 | [diff] [blame] | 1592 | |
| 1593 | if (*arg == '^') { |
Kevin Bracey | 7f34a46 | 2013-05-16 18:32:38 +0300 | [diff] [blame] | 1594 | flags ^= UNINTERESTING | BOTTOM; |
Junio C Hamano | ea4a19e | 2006-04-30 00:54:29 -0700 | [diff] [blame] | 1595 | arg++; |
| 1596 | } |
brian m. carlson | e82caf3 | 2017-07-13 23:49:28 +0000 | [diff] [blame] | 1597 | if (get_oid_committish(arg, &oid)) |
Junio C Hamano | ea4a19e | 2006-04-30 00:54:29 -0700 | [diff] [blame] | 1598 | return 0; |
| 1599 | while (1) { |
brian m. carlson | 654b9a9 | 2017-05-06 22:10:27 +0000 | [diff] [blame] | 1600 | it = get_reference(revs, arg, &oid, 0); |
Junio C Hamano | cc243c3 | 2011-05-18 18:08:09 -0700 | [diff] [blame] | 1601 | if (!it && revs->ignore_missing) |
| 1602 | return 0; |
Linus Torvalds | 1974632 | 2006-07-11 20:45:31 -0700 | [diff] [blame] | 1603 | if (it->type != OBJ_TAG) |
Junio C Hamano | ea4a19e | 2006-04-30 00:54:29 -0700 | [diff] [blame] | 1604 | break; |
Martin Koegler | 9684afd | 2008-02-18 21:48:01 +0100 | [diff] [blame] | 1605 | if (!((struct tag*)it)->tagged) |
| 1606 | return 0; |
brian m. carlson | 654b9a9 | 2017-05-06 22:10:27 +0000 | [diff] [blame] | 1607 | oidcpy(&oid, &((struct tag*)it)->tagged->oid); |
Junio C Hamano | ea4a19e | 2006-04-30 00:54:29 -0700 | [diff] [blame] | 1608 | } |
Linus Torvalds | 1974632 | 2006-07-11 20:45:31 -0700 | [diff] [blame] | 1609 | if (it->type != OBJ_COMMIT) |
Junio C Hamano | ea4a19e | 2006-04-30 00:54:29 -0700 | [diff] [blame] | 1610 | return 0; |
| 1611 | commit = (struct commit *)it; |
Vegard Nossum | 8779351 | 2016-09-27 10:32:49 +0200 | [diff] [blame] | 1612 | if (exclude_parent && |
| 1613 | exclude_parent > commit_list_count(commit->parents)) |
| 1614 | return 0; |
| 1615 | for (parents = commit->parents, parent_number = 1; |
| 1616 | parents; |
| 1617 | parents = parents->next, parent_number++) { |
| 1618 | if (exclude_parent && parent_number != exclude_parent) |
| 1619 | continue; |
| 1620 | |
Junio C Hamano | ea4a19e | 2006-04-30 00:54:29 -0700 | [diff] [blame] | 1621 | it = &parents->item->object; |
| 1622 | it->flags |= flags; |
Junio C Hamano | 281eee4 | 2011-08-25 17:35:39 -0700 | [diff] [blame] | 1623 | add_rev_cmdline(revs, it, arg_, REV_CMD_PARENTS_ONLY, flags); |
Junio C Hamano | ea4a19e | 2006-04-30 00:54:29 -0700 | [diff] [blame] | 1624 | add_pending_object(revs, it, arg); |
| 1625 | } |
| 1626 | return 1; |
| 1627 | } |
| 1628 | |
Nguyễn Thái Ngọc Duy | 2abf350 | 2018-09-21 17:57:38 +0200 | [diff] [blame] | 1629 | void repo_init_revisions(struct repository *r, |
| 1630 | struct rev_info *revs, |
| 1631 | const char *prefix) |
Fredrik Kuivinen | 8efdc32 | 2006-03-10 10:21:39 +0100 | [diff] [blame] | 1632 | { |
| 1633 | memset(revs, 0, sizeof(*revs)); |
Junio C Hamano | 8e8f998 | 2006-04-14 22:19:38 -0700 | [diff] [blame] | 1634 | |
Nguyễn Thái Ngọc Duy | 2abf350 | 2018-09-21 17:57:38 +0200 | [diff] [blame] | 1635 | revs->repo = r; |
Junio C Hamano | 6b9c58f | 2006-04-15 23:46:36 -0700 | [diff] [blame] | 1636 | revs->abbrev = DEFAULT_ABBREV; |
Junio C Hamano | 8e8f998 | 2006-04-14 22:19:38 -0700 | [diff] [blame] | 1637 | revs->ignore_merges = 1; |
Linus Torvalds | 9202434 | 2006-06-11 10:57:35 -0700 | [diff] [blame] | 1638 | revs->simplify_history = 1; |
Nguyễn Thái Ngọc Duy | 67022e0 | 2018-11-18 17:47:57 +0100 | [diff] [blame] | 1639 | revs->pruning.repo = r; |
Brandon Williams | 0d1e0e7 | 2017-10-31 11:19:11 -0700 | [diff] [blame] | 1640 | revs->pruning.flags.recursive = 1; |
| 1641 | revs->pruning.flags.quick = 1; |
Linus Torvalds | cd2bdc5 | 2006-04-14 16:52:13 -0700 | [diff] [blame] | 1642 | revs->pruning.add_remove = file_add_remove; |
| 1643 | revs->pruning.change = file_change; |
Jeff King | a937b37 | 2017-10-13 11:27:45 -0400 | [diff] [blame] | 1644 | revs->pruning.change_fn_data = revs; |
Junio C Hamano | 08f704f | 2013-06-06 16:07:14 -0700 | [diff] [blame] | 1645 | revs->sort_order = REV_SORT_IN_GRAPH_ORDER; |
Fredrik Kuivinen | 8efdc32 | 2006-03-10 10:21:39 +0100 | [diff] [blame] | 1646 | revs->dense = 1; |
Linus Torvalds | db6296a | 2006-07-28 21:21:48 -0700 | [diff] [blame] | 1647 | revs->prefix = prefix; |
Fredrik Kuivinen | 8efdc32 | 2006-03-10 10:21:39 +0100 | [diff] [blame] | 1648 | revs->max_age = -1; |
| 1649 | revs->min_age = -1; |
Junio C Hamano | d5db6c9 | 2006-12-19 18:25:32 -0800 | [diff] [blame] | 1650 | revs->skip_count = -1; |
Fredrik Kuivinen | 8efdc32 | 2006-03-10 10:21:39 +0100 | [diff] [blame] | 1651 | revs->max_count = -1; |
Michael J Gruber | ad5aeed | 2011-03-21 11:14:06 +0100 | [diff] [blame] | 1652 | revs->max_parents = -1; |
Junio C Hamano | 0893eec | 2016-03-29 15:49:24 -0700 | [diff] [blame] | 1653 | revs->expand_tabs_in_log = -1; |
Fredrik Kuivinen | 8efdc32 | 2006-03-10 10:21:39 +0100 | [diff] [blame] | 1654 | |
Linus Torvalds | cd2bdc5 | 2006-04-14 16:52:13 -0700 | [diff] [blame] | 1655 | revs->commit_format = CMIT_FMT_DEFAULT; |
Junio C Hamano | fe37a9c | 2016-03-29 16:05:39 -0700 | [diff] [blame] | 1656 | revs->expand_tabs_in_log_default = 8; |
Linus Torvalds | cd2bdc5 | 2006-04-14 16:52:13 -0700 | [diff] [blame] | 1657 | |
Nguyễn Thái Ngọc Duy | 2abf350 | 2018-09-21 17:57:38 +0200 | [diff] [blame] | 1658 | init_grep_defaults(revs->repo); |
| 1659 | grep_init(&revs->grep_filter, revs->repo, prefix); |
Jeff King | 0843acf | 2008-08-25 02:15:05 -0400 | [diff] [blame] | 1660 | revs->grep_filter.status_only = 1; |
Jeff King | 0843acf | 2008-08-25 02:15:05 -0400 | [diff] [blame] | 1661 | |
Nguyễn Thái Ngọc Duy | 2abf350 | 2018-09-21 17:57:38 +0200 | [diff] [blame] | 1662 | repo_diff_setup(revs->repo, &revs->diffopt); |
Junio C Hamano | c0cb4a0 | 2008-02-13 00:34:39 -0800 | [diff] [blame] | 1663 | if (prefix && !revs->diffopt.prefix) { |
Junio C Hamano | cd676a5 | 2008-02-12 14:26:02 -0800 | [diff] [blame] | 1664 | revs->diffopt.prefix = prefix; |
| 1665 | revs->diffopt.prefix_length = strlen(prefix); |
| 1666 | } |
Jeff King | 3a03cf6 | 2011-03-29 16:57:27 -0400 | [diff] [blame] | 1667 | |
| 1668 | revs->notes_opt.use_default_notes = -1; |
Fredrik Kuivinen | 8efdc32 | 2006-03-10 10:21:39 +0100 | [diff] [blame] | 1669 | } |
| 1670 | |
Rene Scharfe | 0d2c9d6 | 2006-07-02 01:29:37 +0200 | [diff] [blame] | 1671 | static void add_pending_commit_list(struct rev_info *revs, |
Nguyễn Thái Ngọc Duy | ec36c42 | 2018-12-06 16:42:06 +0100 | [diff] [blame] | 1672 | struct commit_list *commit_list, |
| 1673 | unsigned int flags) |
Rene Scharfe | 0d2c9d6 | 2006-07-02 01:29:37 +0200 | [diff] [blame] | 1674 | { |
| 1675 | while (commit_list) { |
| 1676 | struct object *object = &commit_list->item->object; |
| 1677 | object->flags |= flags; |
brian m. carlson | f2fd076 | 2015-11-10 02:22:28 +0000 | [diff] [blame] | 1678 | add_pending_object(revs, object, oid_to_hex(&object->oid)); |
Rene Scharfe | 0d2c9d6 | 2006-07-02 01:29:37 +0200 | [diff] [blame] | 1679 | commit_list = commit_list->next; |
| 1680 | } |
| 1681 | } |
| 1682 | |
Junio C Hamano | ae3e5e1 | 2006-07-03 02:59:32 -0700 | [diff] [blame] | 1683 | static void prepare_show_merge(struct rev_info *revs) |
| 1684 | { |
| 1685 | struct commit_list *bases; |
| 1686 | struct commit *head, *other; |
brian m. carlson | 68ab61d | 2017-05-06 22:10:05 +0000 | [diff] [blame] | 1687 | struct object_id oid; |
Junio C Hamano | ae3e5e1 | 2006-07-03 02:59:32 -0700 | [diff] [blame] | 1688 | const char **prune = NULL; |
| 1689 | int i, prune_num = 1; /* counting terminating NULL */ |
Nguyễn Thái Ngọc Duy | 2abf350 | 2018-09-21 17:57:38 +0200 | [diff] [blame] | 1690 | struct index_state *istate = revs->repo->index; |
Junio C Hamano | ae3e5e1 | 2006-07-03 02:59:32 -0700 | [diff] [blame] | 1691 | |
brian m. carlson | 68ab61d | 2017-05-06 22:10:05 +0000 | [diff] [blame] | 1692 | if (get_oid("HEAD", &oid)) |
Junio C Hamano | ae3e5e1 | 2006-07-03 02:59:32 -0700 | [diff] [blame] | 1693 | die("--merge without HEAD?"); |
brian m. carlson | bc83266 | 2017-05-06 22:10:10 +0000 | [diff] [blame] | 1694 | head = lookup_commit_or_die(&oid, "HEAD"); |
brian m. carlson | 68ab61d | 2017-05-06 22:10:05 +0000 | [diff] [blame] | 1695 | if (get_oid("MERGE_HEAD", &oid)) |
Junio C Hamano | ae3e5e1 | 2006-07-03 02:59:32 -0700 | [diff] [blame] | 1696 | die("--merge without MERGE_HEAD?"); |
brian m. carlson | bc83266 | 2017-05-06 22:10:10 +0000 | [diff] [blame] | 1697 | other = lookup_commit_or_die(&oid, "MERGE_HEAD"); |
Junio C Hamano | ae3e5e1 | 2006-07-03 02:59:32 -0700 | [diff] [blame] | 1698 | add_pending_object(revs, &head->object, "HEAD"); |
| 1699 | add_pending_object(revs, &other->object, "MERGE_HEAD"); |
Junio C Hamano | 2ce406c | 2014-10-30 12:20:44 -0700 | [diff] [blame] | 1700 | bases = get_merge_bases(head, other); |
Kevin Bracey | 7f34a46 | 2013-05-16 18:32:38 +0300 | [diff] [blame] | 1701 | add_rev_cmdline_list(revs, bases, REV_CMD_MERGE_BASE, UNINTERESTING | BOTTOM); |
| 1702 | add_pending_commit_list(revs, bases, UNINTERESTING | BOTTOM); |
Junio C Hamano | e82447b | 2008-02-26 23:18:38 -0800 | [diff] [blame] | 1703 | free_commit_list(bases); |
| 1704 | head->object.flags |= SYMMETRIC_LEFT; |
Junio C Hamano | ae3e5e1 | 2006-07-03 02:59:32 -0700 | [diff] [blame] | 1705 | |
Nguyễn Thái Ngọc Duy | 2abf350 | 2018-09-21 17:57:38 +0200 | [diff] [blame] | 1706 | if (!istate->cache_nr) |
Nguyễn Thái Ngọc Duy | e1ff0a3 | 2019-01-12 09:13:26 +0700 | [diff] [blame] | 1707 | repo_read_index(revs->repo); |
Nguyễn Thái Ngọc Duy | 2abf350 | 2018-09-21 17:57:38 +0200 | [diff] [blame] | 1708 | for (i = 0; i < istate->cache_nr; i++) { |
| 1709 | const struct cache_entry *ce = istate->cache[i]; |
Junio C Hamano | ae3e5e1 | 2006-07-03 02:59:32 -0700 | [diff] [blame] | 1710 | if (!ce_stage(ce)) |
| 1711 | continue; |
Nguyễn Thái Ngọc Duy | 2abf350 | 2018-09-21 17:57:38 +0200 | [diff] [blame] | 1712 | if (ce_path_match(istate, ce, &revs->prune_data, NULL)) { |
Junio C Hamano | ae3e5e1 | 2006-07-03 02:59:32 -0700 | [diff] [blame] | 1713 | prune_num++; |
René Scharfe | 2756ca4 | 2014-09-16 20:56:57 +0200 | [diff] [blame] | 1714 | REALLOC_ARRAY(prune, prune_num); |
Junio C Hamano | ae3e5e1 | 2006-07-03 02:59:32 -0700 | [diff] [blame] | 1715 | prune[prune_num-2] = ce->name; |
| 1716 | prune[prune_num-1] = NULL; |
| 1717 | } |
Nguyễn Thái Ngọc Duy | 2abf350 | 2018-09-21 17:57:38 +0200 | [diff] [blame] | 1718 | while ((i+1 < istate->cache_nr) && |
| 1719 | ce_same_name(ce, istate->cache[i+1])) |
Junio C Hamano | ae3e5e1 | 2006-07-03 02:59:32 -0700 | [diff] [blame] | 1720 | i++; |
| 1721 | } |
Junio C Hamano | ed6e803 | 2016-06-02 14:09:22 -0700 | [diff] [blame] | 1722 | clear_pathspec(&revs->prune_data); |
Nguyễn Thái Ngọc Duy | 4a2d5ae | 2013-10-26 09:09:20 +0700 | [diff] [blame] | 1723 | parse_pathspec(&revs->prune_data, PATHSPEC_ALL_MAGIC & ~PATHSPEC_LITERAL, |
Junio C Hamano | c6f1b92 | 2013-11-18 14:31:29 -0800 | [diff] [blame] | 1724 | PATHSPEC_PREFER_FULL | PATHSPEC_LITERAL_PATH, "", prune); |
Junio C Hamano | e82447b | 2008-02-26 23:18:38 -0800 | [diff] [blame] | 1725 | revs->limited = 1; |
Junio C Hamano | ae3e5e1 | 2006-07-03 02:59:32 -0700 | [diff] [blame] | 1726 | } |
| 1727 | |
Jeff King | 62faad5 | 2017-05-19 08:52:00 -0400 | [diff] [blame] | 1728 | static int dotdot_missing(const char *arg, char *dotdot, |
| 1729 | struct rev_info *revs, int symmetric) |
| 1730 | { |
| 1731 | if (revs->ignore_missing) |
| 1732 | return 0; |
| 1733 | /* de-munge so we report the full argument */ |
| 1734 | *dotdot = '.'; |
| 1735 | die(symmetric |
| 1736 | ? "Invalid symmetric difference expression %s" |
| 1737 | : "Invalid revision range %s", arg); |
| 1738 | } |
| 1739 | |
| 1740 | static int handle_dotdot_1(const char *arg, char *dotdot, |
| 1741 | struct rev_info *revs, int flags, |
Jeff King | 18f1ad7 | 2017-05-19 08:55:26 -0400 | [diff] [blame] | 1742 | int cant_be_filename, |
| 1743 | struct object_context *a_oc, |
| 1744 | struct object_context *b_oc) |
Jeff King | 62faad5 | 2017-05-19 08:52:00 -0400 | [diff] [blame] | 1745 | { |
| 1746 | const char *a_name, *b_name; |
| 1747 | struct object_id a_oid, b_oid; |
| 1748 | struct object *a_obj, *b_obj; |
| 1749 | unsigned int a_flags, b_flags; |
| 1750 | int symmetric = 0; |
| 1751 | unsigned int flags_exclude = flags ^ (UNINTERESTING | BOTTOM); |
brian m. carlson | 321c89b | 2017-07-13 23:49:29 +0000 | [diff] [blame] | 1752 | unsigned int oc_flags = GET_OID_COMMITTISH | GET_OID_RECORD_PATH; |
Jeff King | 62faad5 | 2017-05-19 08:52:00 -0400 | [diff] [blame] | 1753 | |
| 1754 | a_name = arg; |
| 1755 | if (!*a_name) |
| 1756 | a_name = "HEAD"; |
| 1757 | |
| 1758 | b_name = dotdot + 2; |
| 1759 | if (*b_name == '.') { |
| 1760 | symmetric = 1; |
| 1761 | b_name++; |
| 1762 | } |
| 1763 | if (!*b_name) |
| 1764 | b_name = "HEAD"; |
| 1765 | |
Nguyễn Thái Ngọc Duy | 3a7a698 | 2019-01-12 09:13:28 +0700 | [diff] [blame] | 1766 | if (get_oid_with_context(revs->repo, a_name, oc_flags, &a_oid, a_oc) || |
| 1767 | get_oid_with_context(revs->repo, b_name, oc_flags, &b_oid, b_oc)) |
Jeff King | 62faad5 | 2017-05-19 08:52:00 -0400 | [diff] [blame] | 1768 | return -1; |
| 1769 | |
| 1770 | if (!cant_be_filename) { |
| 1771 | *dotdot = '.'; |
| 1772 | verify_non_filename(revs->prefix, arg); |
| 1773 | *dotdot = '\0'; |
| 1774 | } |
| 1775 | |
Nguyễn Thái Ngọc Duy | b3c7eef | 2018-09-21 17:57:39 +0200 | [diff] [blame] | 1776 | a_obj = parse_object(revs->repo, &a_oid); |
| 1777 | b_obj = parse_object(revs->repo, &b_oid); |
Jeff King | 62faad5 | 2017-05-19 08:52:00 -0400 | [diff] [blame] | 1778 | if (!a_obj || !b_obj) |
| 1779 | return dotdot_missing(arg, dotdot, revs, symmetric); |
| 1780 | |
| 1781 | if (!symmetric) { |
| 1782 | /* just A..B */ |
| 1783 | b_flags = flags; |
| 1784 | a_flags = flags_exclude; |
| 1785 | } else { |
| 1786 | /* A...B -- find merge bases between the two */ |
| 1787 | struct commit *a, *b; |
| 1788 | struct commit_list *exclude; |
| 1789 | |
Nguyễn Thái Ngọc Duy | b3c7eef | 2018-09-21 17:57:39 +0200 | [diff] [blame] | 1790 | a = lookup_commit_reference(revs->repo, &a_obj->oid); |
| 1791 | b = lookup_commit_reference(revs->repo, &b_obj->oid); |
Jeff King | 62faad5 | 2017-05-19 08:52:00 -0400 | [diff] [blame] | 1792 | if (!a || !b) |
| 1793 | return dotdot_missing(arg, dotdot, revs, symmetric); |
| 1794 | |
| 1795 | exclude = get_merge_bases(a, b); |
| 1796 | add_rev_cmdline_list(revs, exclude, REV_CMD_MERGE_BASE, |
| 1797 | flags_exclude); |
| 1798 | add_pending_commit_list(revs, exclude, flags_exclude); |
| 1799 | free_commit_list(exclude); |
| 1800 | |
| 1801 | b_flags = flags; |
| 1802 | a_flags = flags | SYMMETRIC_LEFT; |
| 1803 | } |
| 1804 | |
| 1805 | a_obj->flags |= a_flags; |
| 1806 | b_obj->flags |= b_flags; |
| 1807 | add_rev_cmdline(revs, a_obj, a_name, REV_CMD_LEFT, a_flags); |
| 1808 | add_rev_cmdline(revs, b_obj, b_name, REV_CMD_RIGHT, b_flags); |
Jeff King | 18f1ad7 | 2017-05-19 08:55:26 -0400 | [diff] [blame] | 1809 | add_pending_object_with_path(revs, a_obj, a_name, a_oc->mode, a_oc->path); |
| 1810 | add_pending_object_with_path(revs, b_obj, b_name, b_oc->mode, b_oc->path); |
Jeff King | 62faad5 | 2017-05-19 08:52:00 -0400 | [diff] [blame] | 1811 | return 0; |
| 1812 | } |
| 1813 | |
| 1814 | static int handle_dotdot(const char *arg, |
| 1815 | struct rev_info *revs, int flags, |
| 1816 | int cant_be_filename) |
| 1817 | { |
Jeff King | 18f1ad7 | 2017-05-19 08:55:26 -0400 | [diff] [blame] | 1818 | struct object_context a_oc, b_oc; |
Jeff King | 62faad5 | 2017-05-19 08:52:00 -0400 | [diff] [blame] | 1819 | char *dotdot = strstr(arg, ".."); |
| 1820 | int ret; |
| 1821 | |
| 1822 | if (!dotdot) |
| 1823 | return -1; |
| 1824 | |
Jeff King | 18f1ad7 | 2017-05-19 08:55:26 -0400 | [diff] [blame] | 1825 | memset(&a_oc, 0, sizeof(a_oc)); |
| 1826 | memset(&b_oc, 0, sizeof(b_oc)); |
| 1827 | |
Jeff King | 62faad5 | 2017-05-19 08:52:00 -0400 | [diff] [blame] | 1828 | *dotdot = '\0'; |
Jeff King | 18f1ad7 | 2017-05-19 08:55:26 -0400 | [diff] [blame] | 1829 | ret = handle_dotdot_1(arg, dotdot, revs, flags, cant_be_filename, |
| 1830 | &a_oc, &b_oc); |
Jeff King | 62faad5 | 2017-05-19 08:52:00 -0400 | [diff] [blame] | 1831 | *dotdot = '.'; |
| 1832 | |
Jeff King | 18f1ad7 | 2017-05-19 08:55:26 -0400 | [diff] [blame] | 1833 | free(a_oc.path); |
| 1834 | free(b_oc.path); |
| 1835 | |
Jeff King | 62faad5 | 2017-05-19 08:52:00 -0400 | [diff] [blame] | 1836 | return ret; |
| 1837 | } |
| 1838 | |
Junio C Hamano | 8e676e8 | 2012-07-02 12:33:52 -0700 | [diff] [blame] | 1839 | int handle_revision_arg(const char *arg_, struct rev_info *revs, int flags, unsigned revarg_opt) |
Junio C Hamano | 5d6f093 | 2006-09-05 21:28:36 -0700 | [diff] [blame] | 1840 | { |
Junio C Hamano | 249c8f4 | 2012-07-02 12:56:44 -0700 | [diff] [blame] | 1841 | struct object_context oc; |
Jeff King | f632ded | 2017-05-19 08:50:07 -0400 | [diff] [blame] | 1842 | char *mark; |
Junio C Hamano | 5d6f093 | 2006-09-05 21:28:36 -0700 | [diff] [blame] | 1843 | struct object *object; |
brian m. carlson | 654b9a9 | 2017-05-06 22:10:27 +0000 | [diff] [blame] | 1844 | struct object_id oid; |
Junio C Hamano | 5d6f093 | 2006-09-05 21:28:36 -0700 | [diff] [blame] | 1845 | int local_flags; |
Junio C Hamano | 281eee4 | 2011-08-25 17:35:39 -0700 | [diff] [blame] | 1846 | const char *arg = arg_; |
Junio C Hamano | 8e676e8 | 2012-07-02 12:33:52 -0700 | [diff] [blame] | 1847 | int cant_be_filename = revarg_opt & REVARG_CANNOT_BE_FILENAME; |
brian m. carlson | 321c89b | 2017-07-13 23:49:29 +0000 | [diff] [blame] | 1848 | unsigned get_sha1_flags = GET_OID_RECORD_PATH; |
Junio C Hamano | 5d6f093 | 2006-09-05 21:28:36 -0700 | [diff] [blame] | 1849 | |
Kevin Bracey | 7f34a46 | 2013-05-16 18:32:38 +0300 | [diff] [blame] | 1850 | flags = flags & UNINTERESTING ? flags | BOTTOM : flags & ~BOTTOM; |
| 1851 | |
Jeff King | d89797f | 2017-05-19 08:51:40 -0400 | [diff] [blame] | 1852 | if (!cant_be_filename && !strcmp(arg, "..")) { |
| 1853 | /* |
| 1854 | * Just ".."? That is not a range but the |
| 1855 | * pathspec for the parent directory. |
| 1856 | */ |
| 1857 | return -1; |
Junio C Hamano | 5d6f093 | 2006-09-05 21:28:36 -0700 | [diff] [blame] | 1858 | } |
Vegard Nossum | 8779351 | 2016-09-27 10:32:49 +0200 | [diff] [blame] | 1859 | |
Jeff King | 62faad5 | 2017-05-19 08:52:00 -0400 | [diff] [blame] | 1860 | if (!handle_dotdot(arg, revs, flags, revarg_opt)) |
| 1861 | return 0; |
Junio C Hamano | 5d6f093 | 2006-09-05 21:28:36 -0700 | [diff] [blame] | 1862 | |
Jeff King | f632ded | 2017-05-19 08:50:07 -0400 | [diff] [blame] | 1863 | mark = strstr(arg, "^@"); |
| 1864 | if (mark && !mark[2]) { |
| 1865 | *mark = 0; |
Vegard Nossum | 8779351 | 2016-09-27 10:32:49 +0200 | [diff] [blame] | 1866 | if (add_parents_only(revs, arg, flags, 0)) |
Junio C Hamano | 5d6f093 | 2006-09-05 21:28:36 -0700 | [diff] [blame] | 1867 | return 0; |
Jeff King | f632ded | 2017-05-19 08:50:07 -0400 | [diff] [blame] | 1868 | *mark = '^'; |
Junio C Hamano | 5d6f093 | 2006-09-05 21:28:36 -0700 | [diff] [blame] | 1869 | } |
Jeff King | f632ded | 2017-05-19 08:50:07 -0400 | [diff] [blame] | 1870 | mark = strstr(arg, "^!"); |
| 1871 | if (mark && !mark[2]) { |
| 1872 | *mark = 0; |
Vegard Nossum | 8779351 | 2016-09-27 10:32:49 +0200 | [diff] [blame] | 1873 | if (!add_parents_only(revs, arg, flags ^ (UNINTERESTING | BOTTOM), 0)) |
Jeff King | f632ded | 2017-05-19 08:50:07 -0400 | [diff] [blame] | 1874 | *mark = '^'; |
Vegard Nossum | 8779351 | 2016-09-27 10:32:49 +0200 | [diff] [blame] | 1875 | } |
Jeff King | f632ded | 2017-05-19 08:50:07 -0400 | [diff] [blame] | 1876 | mark = strstr(arg, "^-"); |
| 1877 | if (mark) { |
Vegard Nossum | 8779351 | 2016-09-27 10:32:49 +0200 | [diff] [blame] | 1878 | int exclude_parent = 1; |
| 1879 | |
Jeff King | f632ded | 2017-05-19 08:50:07 -0400 | [diff] [blame] | 1880 | if (mark[2]) { |
Vegard Nossum | 8779351 | 2016-09-27 10:32:49 +0200 | [diff] [blame] | 1881 | char *end; |
Jeff King | f632ded | 2017-05-19 08:50:07 -0400 | [diff] [blame] | 1882 | exclude_parent = strtoul(mark + 2, &end, 10); |
Vegard Nossum | 8779351 | 2016-09-27 10:32:49 +0200 | [diff] [blame] | 1883 | if (*end != '\0' || !exclude_parent) |
| 1884 | return -1; |
| 1885 | } |
| 1886 | |
Jeff King | f632ded | 2017-05-19 08:50:07 -0400 | [diff] [blame] | 1887 | *mark = 0; |
Vegard Nossum | 8779351 | 2016-09-27 10:32:49 +0200 | [diff] [blame] | 1888 | if (!add_parents_only(revs, arg, flags ^ (UNINTERESTING | BOTTOM), exclude_parent)) |
Jeff King | f632ded | 2017-05-19 08:50:07 -0400 | [diff] [blame] | 1889 | *mark = '^'; |
Junio C Hamano | 62476c8 | 2006-10-31 14:22:34 -0800 | [diff] [blame] | 1890 | } |
| 1891 | |
Junio C Hamano | 5d6f093 | 2006-09-05 21:28:36 -0700 | [diff] [blame] | 1892 | local_flags = 0; |
| 1893 | if (*arg == '^') { |
Kevin Bracey | 7f34a46 | 2013-05-16 18:32:38 +0300 | [diff] [blame] | 1894 | local_flags = UNINTERESTING | BOTTOM; |
Junio C Hamano | 5d6f093 | 2006-09-05 21:28:36 -0700 | [diff] [blame] | 1895 | arg++; |
| 1896 | } |
Junio C Hamano | d5f6b1d | 2012-07-02 12:43:05 -0700 | [diff] [blame] | 1897 | |
| 1898 | if (revarg_opt & REVARG_COMMITTISH) |
brian m. carlson | 321c89b | 2017-07-13 23:49:29 +0000 | [diff] [blame] | 1899 | get_sha1_flags |= GET_OID_COMMITTISH; |
Junio C Hamano | d5f6b1d | 2012-07-02 12:43:05 -0700 | [diff] [blame] | 1900 | |
Nguyễn Thái Ngọc Duy | 3a7a698 | 2019-01-12 09:13:28 +0700 | [diff] [blame] | 1901 | if (get_oid_with_context(revs->repo, arg, get_sha1_flags, &oid, &oc)) |
Junio C Hamano | cc243c3 | 2011-05-18 18:08:09 -0700 | [diff] [blame] | 1902 | return revs->ignore_missing ? 0 : -1; |
Junio C Hamano | 5d6f093 | 2006-09-05 21:28:36 -0700 | [diff] [blame] | 1903 | if (!cant_be_filename) |
| 1904 | verify_non_filename(revs->prefix, arg); |
brian m. carlson | 654b9a9 | 2017-05-06 22:10:27 +0000 | [diff] [blame] | 1905 | object = get_reference(revs, arg, &oid, flags ^ local_flags); |
Matthew DeVore | 4cf6786 | 2018-12-05 13:43:46 -0800 | [diff] [blame] | 1906 | if (!object) |
| 1907 | return revs->ignore_missing ? 0 : -1; |
Junio C Hamano | 281eee4 | 2011-08-25 17:35:39 -0700 | [diff] [blame] | 1908 | add_rev_cmdline(revs, object, arg_, REV_CMD_REV, flags ^ local_flags); |
Jeff King | 18f1ad7 | 2017-05-19 08:55:26 -0400 | [diff] [blame] | 1909 | add_pending_object_with_path(revs, object, arg, oc.mode, oc.path); |
| 1910 | free(oc.path); |
Junio C Hamano | 5d6f093 | 2006-09-05 21:28:36 -0700 | [diff] [blame] | 1911 | return 0; |
| 1912 | } |
| 1913 | |
Jeff King | 9163399 | 2019-03-20 04:13:36 -0400 | [diff] [blame] | 1914 | static void read_pathspec_from_stdin(struct strbuf *sb, |
Jeff King | 7fa3c2a | 2017-09-20 16:36:59 -0400 | [diff] [blame] | 1915 | struct argv_array *prune) |
Junio C Hamano | 4da5af3 | 2011-05-11 14:01:19 -0700 | [diff] [blame] | 1916 | { |
Jeff King | 7fa3c2a | 2017-09-20 16:36:59 -0400 | [diff] [blame] | 1917 | while (strbuf_getline(sb, stdin) != EOF) |
| 1918 | argv_array_push(prune, sb->buf); |
Junio C Hamano | 60da8b1 | 2009-11-20 02:50:21 -0800 | [diff] [blame] | 1919 | } |
| 1920 | |
Junio C Hamano | 4da5af3 | 2011-05-11 14:01:19 -0700 | [diff] [blame] | 1921 | static void read_revisions_from_stdin(struct rev_info *revs, |
Jeff King | 7fa3c2a | 2017-09-20 16:36:59 -0400 | [diff] [blame] | 1922 | struct argv_array *prune) |
Adam Brewster | 1fc561d | 2008-07-05 17:26:39 -0400 | [diff] [blame] | 1923 | { |
Junio C Hamano | 63d564b | 2009-11-20 02:00:40 -0800 | [diff] [blame] | 1924 | struct strbuf sb; |
Junio C Hamano | 60da8b1 | 2009-11-20 02:50:21 -0800 | [diff] [blame] | 1925 | int seen_dashdash = 0; |
Jeff King | 4c30d50 | 2014-03-12 16:06:17 -0400 | [diff] [blame] | 1926 | int save_warning; |
| 1927 | |
| 1928 | save_warning = warn_on_object_refname_ambiguity; |
| 1929 | warn_on_object_refname_ambiguity = 0; |
Adam Brewster | 1fc561d | 2008-07-05 17:26:39 -0400 | [diff] [blame] | 1930 | |
Junio C Hamano | 63d564b | 2009-11-20 02:00:40 -0800 | [diff] [blame] | 1931 | strbuf_init(&sb, 1000); |
Junio C Hamano | 6e8d46f | 2015-10-28 14:05:53 -0700 | [diff] [blame] | 1932 | while (strbuf_getline(&sb, stdin) != EOF) { |
Junio C Hamano | 63d564b | 2009-11-20 02:00:40 -0800 | [diff] [blame] | 1933 | int len = sb.len; |
Adam Brewster | 1fc561d | 2008-07-05 17:26:39 -0400 | [diff] [blame] | 1934 | if (!len) |
| 1935 | break; |
Junio C Hamano | 60da8b1 | 2009-11-20 02:50:21 -0800 | [diff] [blame] | 1936 | if (sb.buf[0] == '-') { |
| 1937 | if (len == 2 && sb.buf[1] == '-') { |
| 1938 | seen_dashdash = 1; |
| 1939 | break; |
| 1940 | } |
Adam Brewster | 1fc561d | 2008-07-05 17:26:39 -0400 | [diff] [blame] | 1941 | die("options not supported in --stdin mode"); |
Junio C Hamano | 60da8b1 | 2009-11-20 02:50:21 -0800 | [diff] [blame] | 1942 | } |
Michael Haggerty | 31faeb2 | 2013-05-25 11:08:14 +0200 | [diff] [blame] | 1943 | if (handle_revision_arg(sb.buf, revs, 0, |
Thomas Rast | 70d26c6 | 2013-04-16 11:57:45 +0200 | [diff] [blame] | 1944 | REVARG_CANNOT_BE_FILENAME)) |
Junio C Hamano | 63d564b | 2009-11-20 02:00:40 -0800 | [diff] [blame] | 1945 | die("bad revision '%s'", sb.buf); |
Adam Brewster | 1fc561d | 2008-07-05 17:26:39 -0400 | [diff] [blame] | 1946 | } |
Junio C Hamano | 60da8b1 | 2009-11-20 02:50:21 -0800 | [diff] [blame] | 1947 | if (seen_dashdash) |
Jeff King | 9163399 | 2019-03-20 04:13:36 -0400 | [diff] [blame] | 1948 | read_pathspec_from_stdin(&sb, prune); |
Jeff King | 4c30d50 | 2014-03-12 16:06:17 -0400 | [diff] [blame] | 1949 | |
Junio C Hamano | 63d564b | 2009-11-20 02:00:40 -0800 | [diff] [blame] | 1950 | strbuf_release(&sb); |
Jeff King | 4c30d50 | 2014-03-12 16:06:17 -0400 | [diff] [blame] | 1951 | warn_on_object_refname_ambiguity = save_warning; |
Adam Brewster | 1fc561d | 2008-07-05 17:26:39 -0400 | [diff] [blame] | 1952 | } |
| 1953 | |
Junio C Hamano | 2d10c55 | 2006-09-20 13:21:56 -0700 | [diff] [blame] | 1954 | static void add_grep(struct rev_info *revs, const char *ptn, enum grep_pat_token what) |
| 1955 | { |
Jeff King | 0843acf | 2008-08-25 02:15:05 -0400 | [diff] [blame] | 1956 | append_grep_pattern(&revs->grep_filter, ptn, "command line", 0, what); |
Junio C Hamano | 2d10c55 | 2006-09-20 13:21:56 -0700 | [diff] [blame] | 1957 | } |
| 1958 | |
Junio C Hamano | a4d7d2c | 2008-09-04 22:15:02 -0700 | [diff] [blame] | 1959 | static void add_header_grep(struct rev_info *revs, enum grep_header_field field, const char *pattern) |
Junio C Hamano | bd95fcd | 2006-09-17 17:23:20 -0700 | [diff] [blame] | 1960 | { |
Junio C Hamano | a4d7d2c | 2008-09-04 22:15:02 -0700 | [diff] [blame] | 1961 | append_header_grep_pattern(&revs->grep_filter, field, pattern); |
Junio C Hamano | bd95fcd | 2006-09-17 17:23:20 -0700 | [diff] [blame] | 1962 | } |
| 1963 | |
| 1964 | static void add_message_grep(struct rev_info *revs, const char *pattern) |
| 1965 | { |
Junio C Hamano | 2d10c55 | 2006-09-20 13:21:56 -0700 | [diff] [blame] | 1966 | add_grep(revs, pattern, GREP_PATTERN_BODY); |
Junio C Hamano | bd95fcd | 2006-09-17 17:23:20 -0700 | [diff] [blame] | 1967 | } |
| 1968 | |
Pierre Habouzit | 6b61ec0 | 2008-07-09 23:38:34 +0200 | [diff] [blame] | 1969 | static int handle_revision_opt(struct rev_info *revs, int argc, const char **argv, |
Matthew DeVore | bbcde41 | 2018-12-03 14:10:19 -0800 | [diff] [blame] | 1970 | int *unkc, const char **unkv, |
| 1971 | const struct setup_revision_opt* opt) |
Pierre Habouzit | 02e5422 | 2008-07-08 15:19:33 +0200 | [diff] [blame] | 1972 | { |
| 1973 | const char *arg = argv[0]; |
Matthieu Moy | 7d7b86f | 2010-08-05 10:22:55 +0200 | [diff] [blame] | 1974 | const char *optarg; |
| 1975 | int argcount; |
brian m. carlson | fd52124 | 2018-05-02 00:25:50 +0000 | [diff] [blame] | 1976 | const unsigned hexsz = the_hash_algo->hexsz; |
Pierre Habouzit | 02e5422 | 2008-07-08 15:19:33 +0200 | [diff] [blame] | 1977 | |
| 1978 | /* pseudo revision arguments */ |
| 1979 | if (!strcmp(arg, "--all") || !strcmp(arg, "--branches") || |
| 1980 | !strcmp(arg, "--tags") || !strcmp(arg, "--remotes") || |
| 1981 | !strcmp(arg, "--reflog") || !strcmp(arg, "--not") || |
Linus Torvalds | ad3f9a7 | 2009-10-27 11:28:07 -0700 | [diff] [blame] | 1982 | !strcmp(arg, "--no-walk") || !strcmp(arg, "--do-walk") || |
Christian Couder | 5955654 | 2013-11-30 21:55:40 +0100 | [diff] [blame] | 1983 | !strcmp(arg, "--bisect") || starts_with(arg, "--glob=") || |
Jeff King | 4fe1021 | 2014-10-16 20:44:23 -0400 | [diff] [blame] | 1984 | !strcmp(arg, "--indexed-objects") || |
Jeff King | 39b44ba | 2019-07-01 09:18:15 -0400 | [diff] [blame] | 1985 | !strcmp(arg, "--alternate-refs") || |
Junio C Hamano | 07768e0 | 2014-06-09 11:30:12 -0700 | [diff] [blame] | 1986 | starts_with(arg, "--exclude=") || |
Christian Couder | 5955654 | 2013-11-30 21:55:40 +0100 | [diff] [blame] | 1987 | starts_with(arg, "--branches=") || starts_with(arg, "--tags=") || |
| 1988 | starts_with(arg, "--remotes=") || starts_with(arg, "--no-walk=")) |
Pierre Habouzit | 02e5422 | 2008-07-08 15:19:33 +0200 | [diff] [blame] | 1989 | { |
| 1990 | unkv[(*unkc)++] = arg; |
Pierre Habouzit | 0fe8c13 | 2008-07-31 12:22:23 +0200 | [diff] [blame] | 1991 | return 1; |
Pierre Habouzit | 02e5422 | 2008-07-08 15:19:33 +0200 | [diff] [blame] | 1992 | } |
| 1993 | |
Matthieu Moy | 7d7b86f | 2010-08-05 10:22:55 +0200 | [diff] [blame] | 1994 | if ((argcount = parse_long_opt("max-count", argv, &optarg))) { |
| 1995 | revs->max_count = atoi(optarg); |
Jonathan Nieder | 5853cae | 2010-06-01 03:35:49 -0500 | [diff] [blame] | 1996 | revs->no_walk = 0; |
Matthieu Moy | 7d7b86f | 2010-08-05 10:22:55 +0200 | [diff] [blame] | 1997 | return argcount; |
| 1998 | } else if ((argcount = parse_long_opt("skip", argv, &optarg))) { |
| 1999 | revs->skip_count = atoi(optarg); |
| 2000 | return argcount; |
Pierre Habouzit | 02e5422 | 2008-07-08 15:19:33 +0200 | [diff] [blame] | 2001 | } else if ((*arg == '-') && isdigit(arg[1])) { |
Junio C Hamano | e3fa568 | 2014-06-06 15:33:25 -0700 | [diff] [blame] | 2002 | /* accept -<digit>, like traditional "head" */ |
| 2003 | if (strtol_i(arg + 1, 10, &revs->max_count) < 0 || |
| 2004 | revs->max_count < 0) |
| 2005 | die("'%s': not a non-negative integer", arg + 1); |
Jonathan Nieder | 5853cae | 2010-06-01 03:35:49 -0500 | [diff] [blame] | 2006 | revs->no_walk = 0; |
Pierre Habouzit | 02e5422 | 2008-07-08 15:19:33 +0200 | [diff] [blame] | 2007 | } else if (!strcmp(arg, "-n")) { |
| 2008 | if (argc <= 1) |
| 2009 | return error("-n requires an argument"); |
| 2010 | revs->max_count = atoi(argv[1]); |
Jonathan Nieder | 5853cae | 2010-06-01 03:35:49 -0500 | [diff] [blame] | 2011 | revs->no_walk = 0; |
Pierre Habouzit | 02e5422 | 2008-07-08 15:19:33 +0200 | [diff] [blame] | 2012 | return 2; |
SZEDER Gábor | 479b3d9 | 2017-06-09 20:17:32 +0200 | [diff] [blame] | 2013 | } else if (skip_prefix(arg, "-n", &optarg)) { |
| 2014 | revs->max_count = atoi(optarg); |
Jonathan Nieder | 5853cae | 2010-06-01 03:35:49 -0500 | [diff] [blame] | 2015 | revs->no_walk = 0; |
Matthieu Moy | 7d7b86f | 2010-08-05 10:22:55 +0200 | [diff] [blame] | 2016 | } else if ((argcount = parse_long_opt("max-age", argv, &optarg))) { |
| 2017 | revs->max_age = atoi(optarg); |
| 2018 | return argcount; |
| 2019 | } else if ((argcount = parse_long_opt("since", argv, &optarg))) { |
| 2020 | revs->max_age = approxidate(optarg); |
| 2021 | return argcount; |
| 2022 | } else if ((argcount = parse_long_opt("after", argv, &optarg))) { |
| 2023 | revs->max_age = approxidate(optarg); |
| 2024 | return argcount; |
| 2025 | } else if ((argcount = parse_long_opt("min-age", argv, &optarg))) { |
| 2026 | revs->min_age = atoi(optarg); |
| 2027 | return argcount; |
| 2028 | } else if ((argcount = parse_long_opt("before", argv, &optarg))) { |
| 2029 | revs->min_age = approxidate(optarg); |
| 2030 | return argcount; |
| 2031 | } else if ((argcount = parse_long_opt("until", argv, &optarg))) { |
| 2032 | revs->min_age = approxidate(optarg); |
| 2033 | return argcount; |
Pierre Habouzit | 02e5422 | 2008-07-08 15:19:33 +0200 | [diff] [blame] | 2034 | } else if (!strcmp(arg, "--first-parent")) { |
| 2035 | revs->first_parent_only = 1; |
Junio C Hamano | ebdc94f | 2010-04-20 13:48:39 -0700 | [diff] [blame] | 2036 | } else if (!strcmp(arg, "--ancestry-path")) { |
| 2037 | revs->ancestry_path = 1; |
Johan Herland | cb7529e | 2010-06-04 01:17:37 +0200 | [diff] [blame] | 2038 | revs->simplify_history = 0; |
Junio C Hamano | ebdc94f | 2010-04-20 13:48:39 -0700 | [diff] [blame] | 2039 | revs->limited = 1; |
Pierre Habouzit | 02e5422 | 2008-07-08 15:19:33 +0200 | [diff] [blame] | 2040 | } else if (!strcmp(arg, "-g") || !strcmp(arg, "--walk-reflogs")) { |
| 2041 | init_reflog_walk(&revs->reflog_info); |
| 2042 | } else if (!strcmp(arg, "--default")) { |
| 2043 | if (argc <= 1) |
| 2044 | return error("bad --default argument"); |
| 2045 | revs->def = argv[1]; |
| 2046 | return 2; |
| 2047 | } else if (!strcmp(arg, "--merge")) { |
| 2048 | revs->show_merge = 1; |
| 2049 | } else if (!strcmp(arg, "--topo-order")) { |
Junio C Hamano | 08f704f | 2013-06-06 16:07:14 -0700 | [diff] [blame] | 2050 | revs->sort_order = REV_SORT_IN_GRAPH_ORDER; |
Pierre Habouzit | 02e5422 | 2008-07-08 15:19:33 +0200 | [diff] [blame] | 2051 | revs->topo_order = 1; |
Junio C Hamano | 6546b59 | 2008-07-31 01:17:41 -0700 | [diff] [blame] | 2052 | } else if (!strcmp(arg, "--simplify-merges")) { |
| 2053 | revs->simplify_merges = 1; |
Junio C Hamano | a52f007 | 2012-06-08 14:47:08 -0700 | [diff] [blame] | 2054 | revs->topo_order = 1; |
Junio C Hamano | 6546b59 | 2008-07-31 01:17:41 -0700 | [diff] [blame] | 2055 | revs->rewrite_parents = 1; |
| 2056 | revs->simplify_history = 0; |
| 2057 | revs->limited = 1; |
Linus Torvalds | 78892e3 | 2008-11-03 11:25:46 -0800 | [diff] [blame] | 2058 | } else if (!strcmp(arg, "--simplify-by-decoration")) { |
| 2059 | revs->simplify_merges = 1; |
Junio C Hamano | a52f007 | 2012-06-08 14:47:08 -0700 | [diff] [blame] | 2060 | revs->topo_order = 1; |
Linus Torvalds | 78892e3 | 2008-11-03 11:25:46 -0800 | [diff] [blame] | 2061 | revs->rewrite_parents = 1; |
| 2062 | revs->simplify_history = 0; |
| 2063 | revs->simplify_by_decoration = 1; |
| 2064 | revs->limited = 1; |
| 2065 | revs->prune = 1; |
Rafael Ascensão | 65516f5 | 2017-11-21 21:33:41 +0000 | [diff] [blame] | 2066 | load_ref_decorations(NULL, DECORATE_SHORT_REFS); |
Pierre Habouzit | 02e5422 | 2008-07-08 15:19:33 +0200 | [diff] [blame] | 2067 | } else if (!strcmp(arg, "--date-order")) { |
Junio C Hamano | 08f704f | 2013-06-06 16:07:14 -0700 | [diff] [blame] | 2068 | revs->sort_order = REV_SORT_BY_COMMIT_DATE; |
Pierre Habouzit | 02e5422 | 2008-07-08 15:19:33 +0200 | [diff] [blame] | 2069 | revs->topo_order = 1; |
Junio C Hamano | 81c6b38 | 2013-06-07 10:35:54 -0700 | [diff] [blame] | 2070 | } else if (!strcmp(arg, "--author-date-order")) { |
| 2071 | revs->sort_order = REV_SORT_BY_AUTHOR_DATE; |
Pierre Habouzit | 02e5422 | 2008-07-08 15:19:33 +0200 | [diff] [blame] | 2072 | revs->topo_order = 1; |
SZEDER Gábor | dffc651 | 2017-06-09 20:17:31 +0200 | [diff] [blame] | 2073 | } else if (!strcmp(arg, "--early-output")) { |
| 2074 | revs->early_output = 100; |
| 2075 | revs->topo_order = 1; |
| 2076 | } else if (skip_prefix(arg, "--early-output=", &optarg)) { |
| 2077 | if (strtoul_ui(optarg, 10, &revs->early_output) < 0) |
| 2078 | die("'%s': not a non-negative integer", optarg); |
| 2079 | revs->topo_order = 1; |
Pierre Habouzit | 02e5422 | 2008-07-08 15:19:33 +0200 | [diff] [blame] | 2080 | } else if (!strcmp(arg, "--parents")) { |
| 2081 | revs->rewrite_parents = 1; |
| 2082 | revs->print_parents = 1; |
| 2083 | } else if (!strcmp(arg, "--dense")) { |
| 2084 | revs->dense = 1; |
| 2085 | } else if (!strcmp(arg, "--sparse")) { |
| 2086 | revs->dense = 0; |
Stefan Beller | ce5b6f9 | 2017-11-15 18:00:35 -0800 | [diff] [blame] | 2087 | } else if (!strcmp(arg, "--in-commit-order")) { |
| 2088 | revs->tree_blobs_in_commit_order = 1; |
Pierre Habouzit | 02e5422 | 2008-07-08 15:19:33 +0200 | [diff] [blame] | 2089 | } else if (!strcmp(arg, "--remove-empty")) { |
| 2090 | revs->remove_empty_trees = 1; |
Linus Torvalds | b8e8db2 | 2009-06-29 10:28:25 -0700 | [diff] [blame] | 2091 | } else if (!strcmp(arg, "--merges")) { |
Michael J Gruber | ad5aeed | 2011-03-21 11:14:06 +0100 | [diff] [blame] | 2092 | revs->min_parents = 2; |
Pierre Habouzit | 02e5422 | 2008-07-08 15:19:33 +0200 | [diff] [blame] | 2093 | } else if (!strcmp(arg, "--no-merges")) { |
Michael J Gruber | ad5aeed | 2011-03-21 11:14:06 +0100 | [diff] [blame] | 2094 | revs->max_parents = 1; |
SZEDER Gábor | 479b3d9 | 2017-06-09 20:17:32 +0200 | [diff] [blame] | 2095 | } else if (skip_prefix(arg, "--min-parents=", &optarg)) { |
| 2096 | revs->min_parents = atoi(optarg); |
SZEDER Gábor | 9ada7ae | 2017-06-09 20:17:30 +0200 | [diff] [blame] | 2097 | } else if (!strcmp(arg, "--no-min-parents")) { |
Michael J Gruber | ad5aeed | 2011-03-21 11:14:06 +0100 | [diff] [blame] | 2098 | revs->min_parents = 0; |
SZEDER Gábor | 479b3d9 | 2017-06-09 20:17:32 +0200 | [diff] [blame] | 2099 | } else if (skip_prefix(arg, "--max-parents=", &optarg)) { |
| 2100 | revs->max_parents = atoi(optarg); |
SZEDER Gábor | 9ada7ae | 2017-06-09 20:17:30 +0200 | [diff] [blame] | 2101 | } else if (!strcmp(arg, "--no-max-parents")) { |
Michael J Gruber | ad5aeed | 2011-03-21 11:14:06 +0100 | [diff] [blame] | 2102 | revs->max_parents = -1; |
Pierre Habouzit | 02e5422 | 2008-07-08 15:19:33 +0200 | [diff] [blame] | 2103 | } else if (!strcmp(arg, "--boundary")) { |
| 2104 | revs->boundary = 1; |
| 2105 | } else if (!strcmp(arg, "--left-right")) { |
| 2106 | revs->left_right = 1; |
Michael J Gruber | 60adf7d | 2011-02-21 17:09:11 +0100 | [diff] [blame] | 2107 | } else if (!strcmp(arg, "--left-only")) { |
Junio C Hamano | 24852d9 | 2011-02-21 16:58:37 -0800 | [diff] [blame] | 2108 | if (revs->right_only) |
Michael J Gruber | 94f605e | 2011-03-07 13:31:42 +0100 | [diff] [blame] | 2109 | die("--left-only is incompatible with --right-only" |
| 2110 | " or --cherry"); |
Michael J Gruber | 60adf7d | 2011-02-21 17:09:11 +0100 | [diff] [blame] | 2111 | revs->left_only = 1; |
| 2112 | } else if (!strcmp(arg, "--right-only")) { |
Junio C Hamano | 24852d9 | 2011-02-21 16:58:37 -0800 | [diff] [blame] | 2113 | if (revs->left_only) |
| 2114 | die("--right-only is incompatible with --left-only"); |
Michael J Gruber | 60adf7d | 2011-02-21 17:09:11 +0100 | [diff] [blame] | 2115 | revs->right_only = 1; |
Michael J Gruber | 94f605e | 2011-03-07 13:31:42 +0100 | [diff] [blame] | 2116 | } else if (!strcmp(arg, "--cherry")) { |
| 2117 | if (revs->left_only) |
| 2118 | die("--cherry is incompatible with --left-only"); |
| 2119 | revs->cherry_mark = 1; |
| 2120 | revs->right_only = 1; |
Michael J Gruber | ad5aeed | 2011-03-21 11:14:06 +0100 | [diff] [blame] | 2121 | revs->max_parents = 1; |
Michael J Gruber | 94f605e | 2011-03-07 13:31:42 +0100 | [diff] [blame] | 2122 | revs->limited = 1; |
Thomas Rast | f69c501 | 2010-06-10 13:47:23 +0200 | [diff] [blame] | 2123 | } else if (!strcmp(arg, "--count")) { |
| 2124 | revs->count = 1; |
Michael J Gruber | adbbb31 | 2011-03-07 13:31:40 +0100 | [diff] [blame] | 2125 | } else if (!strcmp(arg, "--cherry-mark")) { |
| 2126 | if (revs->cherry_pick) |
| 2127 | die("--cherry-mark is incompatible with --cherry-pick"); |
| 2128 | revs->cherry_mark = 1; |
| 2129 | revs->limited = 1; /* needs limit_list() */ |
Pierre Habouzit | 02e5422 | 2008-07-08 15:19:33 +0200 | [diff] [blame] | 2130 | } else if (!strcmp(arg, "--cherry-pick")) { |
Michael J Gruber | adbbb31 | 2011-03-07 13:31:40 +0100 | [diff] [blame] | 2131 | if (revs->cherry_mark) |
| 2132 | die("--cherry-pick is incompatible with --cherry-mark"); |
Pierre Habouzit | 02e5422 | 2008-07-08 15:19:33 +0200 | [diff] [blame] | 2133 | revs->cherry_pick = 1; |
| 2134 | revs->limited = 1; |
| 2135 | } else if (!strcmp(arg, "--objects")) { |
| 2136 | revs->tag_objects = 1; |
| 2137 | revs->tree_objects = 1; |
| 2138 | revs->blob_objects = 1; |
| 2139 | } else if (!strcmp(arg, "--objects-edge")) { |
| 2140 | revs->tag_objects = 1; |
| 2141 | revs->tree_objects = 1; |
| 2142 | revs->blob_objects = 1; |
| 2143 | revs->edge_hint = 1; |
brian m. carlson | 1684c1b | 2014-12-24 23:05:39 +0000 | [diff] [blame] | 2144 | } else if (!strcmp(arg, "--objects-edge-aggressive")) { |
| 2145 | revs->tag_objects = 1; |
| 2146 | revs->tree_objects = 1; |
| 2147 | revs->blob_objects = 1; |
| 2148 | revs->edge_hint = 1; |
| 2149 | revs->edge_hint_aggressive = 1; |
Junio C Hamano | 5a48d24 | 2011-09-01 15:43:34 -0700 | [diff] [blame] | 2150 | } else if (!strcmp(arg, "--verify-objects")) { |
| 2151 | revs->tag_objects = 1; |
| 2152 | revs->tree_objects = 1; |
| 2153 | revs->blob_objects = 1; |
| 2154 | revs->verify_objects = 1; |
Pierre Habouzit | 02e5422 | 2008-07-08 15:19:33 +0200 | [diff] [blame] | 2155 | } else if (!strcmp(arg, "--unpacked")) { |
| 2156 | revs->unpacked = 1; |
Christian Couder | 5955654 | 2013-11-30 21:55:40 +0100 | [diff] [blame] | 2157 | } else if (starts_with(arg, "--unpacked=")) { |
Junio C Hamano | 03a9683 | 2009-02-28 00:00:21 -0800 | [diff] [blame] | 2158 | die("--unpacked=<packfile> no longer supported."); |
Pierre Habouzit | 02e5422 | 2008-07-08 15:19:33 +0200 | [diff] [blame] | 2159 | } else if (!strcmp(arg, "-r")) { |
| 2160 | revs->diff = 1; |
Brandon Williams | 0d1e0e7 | 2017-10-31 11:19:11 -0700 | [diff] [blame] | 2161 | revs->diffopt.flags.recursive = 1; |
Pierre Habouzit | 02e5422 | 2008-07-08 15:19:33 +0200 | [diff] [blame] | 2162 | } else if (!strcmp(arg, "-t")) { |
| 2163 | revs->diff = 1; |
Brandon Williams | 0d1e0e7 | 2017-10-31 11:19:11 -0700 | [diff] [blame] | 2164 | revs->diffopt.flags.recursive = 1; |
| 2165 | revs->diffopt.flags.tree_in_recursive = 1; |
Pierre Habouzit | 02e5422 | 2008-07-08 15:19:33 +0200 | [diff] [blame] | 2166 | } else if (!strcmp(arg, "-m")) { |
| 2167 | revs->ignore_merges = 0; |
| 2168 | } else if (!strcmp(arg, "-c")) { |
| 2169 | revs->diff = 1; |
| 2170 | revs->dense_combined_merges = 0; |
| 2171 | revs->combine_merges = 1; |
Elijah Newren | d76ce4f | 2019-02-07 17:12:46 -0800 | [diff] [blame] | 2172 | } else if (!strcmp(arg, "--combined-all-paths")) { |
| 2173 | revs->diff = 1; |
| 2174 | revs->combined_all_paths = 1; |
Pierre Habouzit | 02e5422 | 2008-07-08 15:19:33 +0200 | [diff] [blame] | 2175 | } else if (!strcmp(arg, "--cc")) { |
| 2176 | revs->diff = 1; |
| 2177 | revs->dense_combined_merges = 1; |
| 2178 | revs->combine_merges = 1; |
| 2179 | } else if (!strcmp(arg, "-v")) { |
| 2180 | revs->verbose_header = 1; |
| 2181 | } else if (!strcmp(arg, "--pretty")) { |
| 2182 | revs->verbose_header = 1; |
Junio C Hamano | 66b2ed0 | 2010-01-20 13:59:36 -0800 | [diff] [blame] | 2183 | revs->pretty_given = 1; |
Jeff King | ae18165 | 2014-07-29 13:53:40 -0400 | [diff] [blame] | 2184 | get_commit_format(NULL, revs); |
SZEDER Gábor | 479b3d9 | 2017-06-09 20:17:32 +0200 | [diff] [blame] | 2185 | } else if (skip_prefix(arg, "--pretty=", &optarg) || |
| 2186 | skip_prefix(arg, "--format=", &optarg)) { |
Matthieu Moy | 7d7b86f | 2010-08-05 10:22:55 +0200 | [diff] [blame] | 2187 | /* |
| 2188 | * Detached form ("--pretty X" as opposed to "--pretty=X") |
| 2189 | * not allowed, since the argument is optional. |
| 2190 | */ |
Pierre Habouzit | 02e5422 | 2008-07-08 15:19:33 +0200 | [diff] [blame] | 2191 | revs->verbose_header = 1; |
Junio C Hamano | 66b2ed0 | 2010-01-20 13:59:36 -0800 | [diff] [blame] | 2192 | revs->pretty_given = 1; |
SZEDER Gábor | 479b3d9 | 2017-06-09 20:17:32 +0200 | [diff] [blame] | 2193 | get_commit_format(optarg, revs); |
Linus Torvalds | 7cc13c7 | 2016-03-16 09:15:53 -0700 | [diff] [blame] | 2194 | } else if (!strcmp(arg, "--expand-tabs")) { |
Junio C Hamano | fe37a9c | 2016-03-29 16:05:39 -0700 | [diff] [blame] | 2195 | revs->expand_tabs_in_log = 8; |
Junio C Hamano | 0893eec | 2016-03-29 15:49:24 -0700 | [diff] [blame] | 2196 | } else if (!strcmp(arg, "--no-expand-tabs")) { |
| 2197 | revs->expand_tabs_in_log = 0; |
Junio C Hamano | fe37a9c | 2016-03-29 16:05:39 -0700 | [diff] [blame] | 2198 | } else if (skip_prefix(arg, "--expand-tabs=", &arg)) { |
| 2199 | int val; |
| 2200 | if (strtol_i(arg, 10, &val) < 0 || val < 0) |
| 2201 | die("'%s': not a non-negative integer", arg); |
| 2202 | revs->expand_tabs_in_log = val; |
Jeff King | 7249e91 | 2011-03-29 16:57:47 -0400 | [diff] [blame] | 2203 | } else if (!strcmp(arg, "--show-notes") || !strcmp(arg, "--notes")) { |
Junio C Hamano | 66b2ed0 | 2010-01-20 13:59:36 -0800 | [diff] [blame] | 2204 | revs->show_notes = 1; |
| 2205 | revs->show_notes_given = 1; |
Jeff King | 3a03cf6 | 2011-03-29 16:57:27 -0400 | [diff] [blame] | 2206 | revs->notes_opt.use_default_notes = 1; |
Junio C Hamano | 0c37f1f | 2011-10-18 15:53:23 -0700 | [diff] [blame] | 2207 | } else if (!strcmp(arg, "--show-signature")) { |
| 2208 | revs->show_signature = 1; |
Mehul Jain | aa37999 | 2016-06-22 22:21:25 +0530 | [diff] [blame] | 2209 | } else if (!strcmp(arg, "--no-show-signature")) { |
| 2210 | revs->show_signature = 0; |
SZEDER Gábor | 479b3d9 | 2017-06-09 20:17:32 +0200 | [diff] [blame] | 2211 | } else if (!strcmp(arg, "--show-linear-break")) { |
| 2212 | revs->break_bar = " .........."; |
Nguyễn Thái Ngọc Duy | 1b32dec | 2014-03-25 20:23:27 +0700 | [diff] [blame] | 2213 | revs->track_linear = 1; |
| 2214 | revs->track_first_time = 1; |
SZEDER Gábor | 479b3d9 | 2017-06-09 20:17:32 +0200 | [diff] [blame] | 2215 | } else if (skip_prefix(arg, "--show-linear-break=", &optarg)) { |
| 2216 | revs->break_bar = xstrdup(optarg); |
| 2217 | revs->track_linear = 1; |
| 2218 | revs->track_first_time = 1; |
| 2219 | } else if (skip_prefix(arg, "--show-notes=", &optarg) || |
| 2220 | skip_prefix(arg, "--notes=", &optarg)) { |
Thomas Rast | 894a9d3 | 2010-03-12 18:04:26 +0100 | [diff] [blame] | 2221 | struct strbuf buf = STRBUF_INIT; |
| 2222 | revs->show_notes = 1; |
| 2223 | revs->show_notes_given = 1; |
SZEDER Gábor | 479b3d9 | 2017-06-09 20:17:32 +0200 | [diff] [blame] | 2224 | if (starts_with(arg, "--show-notes=") && |
| 2225 | revs->notes_opt.use_default_notes < 0) |
| 2226 | revs->notes_opt.use_default_notes = 1; |
| 2227 | strbuf_addstr(&buf, optarg); |
Jeff King | c063f0a | 2011-03-29 16:56:04 -0400 | [diff] [blame] | 2228 | expand_notes_ref(&buf); |
Jeff King | 304cc11 | 2011-03-29 16:56:53 -0400 | [diff] [blame] | 2229 | string_list_append(&revs->notes_opt.extra_notes_refs, |
Julian Phillips | 1d2f80f | 2010-06-26 00:41:38 +0100 | [diff] [blame] | 2230 | strbuf_detach(&buf, NULL)); |
Junio C Hamano | 66b2ed0 | 2010-01-20 13:59:36 -0800 | [diff] [blame] | 2231 | } else if (!strcmp(arg, "--no-notes")) { |
| 2232 | revs->show_notes = 0; |
| 2233 | revs->show_notes_given = 1; |
Jeff King | 92e0d42 | 2011-03-29 16:59:42 -0400 | [diff] [blame] | 2234 | revs->notes_opt.use_default_notes = -1; |
| 2235 | /* we have been strdup'ing ourselves, so trick |
| 2236 | * string_list into free()ing strings */ |
| 2237 | revs->notes_opt.extra_notes_refs.strdup_strings = 1; |
| 2238 | string_list_clear(&revs->notes_opt.extra_notes_refs, 0); |
| 2239 | revs->notes_opt.extra_notes_refs.strdup_strings = 0; |
Thomas Rast | 894a9d3 | 2010-03-12 18:04:26 +0100 | [diff] [blame] | 2240 | } else if (!strcmp(arg, "--standard-notes")) { |
| 2241 | revs->show_notes_given = 1; |
Jeff King | 3a03cf6 | 2011-03-29 16:57:27 -0400 | [diff] [blame] | 2242 | revs->notes_opt.use_default_notes = 1; |
Thomas Rast | 894a9d3 | 2010-03-12 18:04:26 +0100 | [diff] [blame] | 2243 | } else if (!strcmp(arg, "--no-standard-notes")) { |
Jeff King | 3a03cf6 | 2011-03-29 16:57:27 -0400 | [diff] [blame] | 2244 | revs->notes_opt.use_default_notes = 0; |
Nanako Shiraishi | de84acc | 2009-02-24 18:59:16 +0900 | [diff] [blame] | 2245 | } else if (!strcmp(arg, "--oneline")) { |
| 2246 | revs->verbose_header = 1; |
| 2247 | get_commit_format("oneline", revs); |
Junio C Hamano | 7dccadf | 2010-01-21 14:57:41 -0800 | [diff] [blame] | 2248 | revs->pretty_given = 1; |
Nanako Shiraishi | de84acc | 2009-02-24 18:59:16 +0900 | [diff] [blame] | 2249 | revs->abbrev_commit = 1; |
Pierre Habouzit | 02e5422 | 2008-07-08 15:19:33 +0200 | [diff] [blame] | 2250 | } else if (!strcmp(arg, "--graph")) { |
| 2251 | revs->topo_order = 1; |
| 2252 | revs->rewrite_parents = 1; |
| 2253 | revs->graph = graph_init(revs); |
| 2254 | } else if (!strcmp(arg, "--root")) { |
| 2255 | revs->show_root_diff = 1; |
| 2256 | } else if (!strcmp(arg, "--no-commit-id")) { |
| 2257 | revs->no_commit_id = 1; |
| 2258 | } else if (!strcmp(arg, "--always")) { |
| 2259 | revs->always_show_header = 1; |
| 2260 | } else if (!strcmp(arg, "--no-abbrev")) { |
| 2261 | revs->abbrev = 0; |
| 2262 | } else if (!strcmp(arg, "--abbrev")) { |
| 2263 | revs->abbrev = DEFAULT_ABBREV; |
SZEDER Gábor | 479b3d9 | 2017-06-09 20:17:32 +0200 | [diff] [blame] | 2264 | } else if (skip_prefix(arg, "--abbrev=", &optarg)) { |
| 2265 | revs->abbrev = strtoul(optarg, NULL, 10); |
Pierre Habouzit | 02e5422 | 2008-07-08 15:19:33 +0200 | [diff] [blame] | 2266 | if (revs->abbrev < MINIMUM_ABBREV) |
| 2267 | revs->abbrev = MINIMUM_ABBREV; |
brian m. carlson | fd52124 | 2018-05-02 00:25:50 +0000 | [diff] [blame] | 2268 | else if (revs->abbrev > hexsz) |
| 2269 | revs->abbrev = hexsz; |
Pierre Habouzit | 02e5422 | 2008-07-08 15:19:33 +0200 | [diff] [blame] | 2270 | } else if (!strcmp(arg, "--abbrev-commit")) { |
| 2271 | revs->abbrev_commit = 1; |
Jay Soffian | 0c47695 | 2011-05-18 13:56:04 -0400 | [diff] [blame] | 2272 | revs->abbrev_commit_given = 1; |
| 2273 | } else if (!strcmp(arg, "--no-abbrev-commit")) { |
| 2274 | revs->abbrev_commit = 0; |
Pierre Habouzit | 02e5422 | 2008-07-08 15:19:33 +0200 | [diff] [blame] | 2275 | } else if (!strcmp(arg, "--full-diff")) { |
| 2276 | revs->diff = 1; |
| 2277 | revs->full_diff = 1; |
| 2278 | } else if (!strcmp(arg, "--full-history")) { |
| 2279 | revs->simplify_history = 0; |
| 2280 | } else if (!strcmp(arg, "--relative-date")) { |
Jeff King | a5481a6 | 2015-06-25 12:55:02 -0400 | [diff] [blame] | 2281 | revs->date_mode.type = DATE_RELATIVE; |
Jeff King | f4ea32f | 2009-09-24 04:28:15 -0400 | [diff] [blame] | 2282 | revs->date_mode_explicit = 1; |
Matthieu Moy | 7d7b86f | 2010-08-05 10:22:55 +0200 | [diff] [blame] | 2283 | } else if ((argcount = parse_long_opt("date", argv, &optarg))) { |
Jeff King | a5481a6 | 2015-06-25 12:55:02 -0400 | [diff] [blame] | 2284 | parse_date_format(optarg, &revs->date_mode); |
Jeff King | f4ea32f | 2009-09-24 04:28:15 -0400 | [diff] [blame] | 2285 | revs->date_mode_explicit = 1; |
Matthieu Moy | 7d7b86f | 2010-08-05 10:22:55 +0200 | [diff] [blame] | 2286 | return argcount; |
Pierre Habouzit | 02e5422 | 2008-07-08 15:19:33 +0200 | [diff] [blame] | 2287 | } else if (!strcmp(arg, "--log-size")) { |
| 2288 | revs->show_log_size = 1; |
| 2289 | } |
| 2290 | /* |
| 2291 | * Grepping the commit log |
| 2292 | */ |
Matthieu Moy | 7d7b86f | 2010-08-05 10:22:55 +0200 | [diff] [blame] | 2293 | else if ((argcount = parse_long_opt("author", argv, &optarg))) { |
| 2294 | add_header_grep(revs, GREP_HEADER_AUTHOR, optarg); |
| 2295 | return argcount; |
| 2296 | } else if ((argcount = parse_long_opt("committer", argv, &optarg))) { |
| 2297 | add_header_grep(revs, GREP_HEADER_COMMITTER, optarg); |
| 2298 | return argcount; |
Nguyễn Thái Ngọc Duy | 72fd13f | 2012-09-29 11:41:28 +0700 | [diff] [blame] | 2299 | } else if ((argcount = parse_long_opt("grep-reflog", argv, &optarg))) { |
| 2300 | add_header_grep(revs, GREP_HEADER_REFLOG, optarg); |
| 2301 | return argcount; |
Matthieu Moy | 7d7b86f | 2010-08-05 10:22:55 +0200 | [diff] [blame] | 2302 | } else if ((argcount = parse_long_opt("grep", argv, &optarg))) { |
| 2303 | add_message_grep(revs, optarg); |
| 2304 | return argcount; |
Junio C Hamano | 17bf35a | 2012-09-13 14:21:44 -0700 | [diff] [blame] | 2305 | } else if (!strcmp(arg, "--grep-debug")) { |
| 2306 | revs->grep_filter.debug = 1; |
Junio C Hamano | 727b6fc | 2012-10-03 15:01:34 -0700 | [diff] [blame] | 2307 | } else if (!strcmp(arg, "--basic-regexp")) { |
Junio C Hamano | 8465541 | 2016-07-22 11:43:14 -0700 | [diff] [blame] | 2308 | revs->grep_filter.pattern_type_option = GREP_PATTERN_TYPE_BRE; |
Pierre Habouzit | 02e5422 | 2008-07-08 15:19:33 +0200 | [diff] [blame] | 2309 | } else if (!strcmp(arg, "--extended-regexp") || !strcmp(arg, "-E")) { |
Junio C Hamano | 8465541 | 2016-07-22 11:43:14 -0700 | [diff] [blame] | 2310 | revs->grep_filter.pattern_type_option = GREP_PATTERN_TYPE_ERE; |
Pierre Habouzit | 02e5422 | 2008-07-08 15:19:33 +0200 | [diff] [blame] | 2311 | } else if (!strcmp(arg, "--regexp-ignore-case") || !strcmp(arg, "-i")) { |
Ævar Arnfjörð Bjarmason | 9e3cbc5 | 2017-05-20 21:42:08 +0000 | [diff] [blame] | 2312 | revs->grep_filter.ignore_case = 1; |
Stefan Beller | c1ddc46 | 2018-01-04 14:50:40 -0800 | [diff] [blame] | 2313 | revs->diffopt.pickaxe_opts |= DIFF_PICKAXE_IGNORE_CASE; |
Pierre Habouzit | 02e5422 | 2008-07-08 15:19:33 +0200 | [diff] [blame] | 2314 | } else if (!strcmp(arg, "--fixed-strings") || !strcmp(arg, "-F")) { |
Junio C Hamano | 8465541 | 2016-07-22 11:43:14 -0700 | [diff] [blame] | 2315 | revs->grep_filter.pattern_type_option = GREP_PATTERN_TYPE_FIXED; |
Ævar Arnfjörð Bjarmason | 7531a2d | 2017-05-25 20:05:24 +0000 | [diff] [blame] | 2316 | } else if (!strcmp(arg, "--perl-regexp") || !strcmp(arg, "-P")) { |
Junio C Hamano | 8465541 | 2016-07-22 11:43:14 -0700 | [diff] [blame] | 2317 | revs->grep_filter.pattern_type_option = GREP_PATTERN_TYPE_PCRE; |
Pierre Habouzit | 02e5422 | 2008-07-08 15:19:33 +0200 | [diff] [blame] | 2318 | } else if (!strcmp(arg, "--all-match")) { |
Jeff King | 0843acf | 2008-08-25 02:15:05 -0400 | [diff] [blame] | 2319 | revs->grep_filter.all_match = 1; |
Christoph Junghans | 22dfa8a | 2015-01-12 18:33:32 -0700 | [diff] [blame] | 2320 | } else if (!strcmp(arg, "--invert-grep")) { |
| 2321 | revs->invert_grep = 1; |
Matthieu Moy | 7d7b86f | 2010-08-05 10:22:55 +0200 | [diff] [blame] | 2322 | } else if ((argcount = parse_long_opt("encoding", argv, &optarg))) { |
| 2323 | if (strcmp(optarg, "none")) |
| 2324 | git_log_output_encoding = xstrdup(optarg); |
Pierre Habouzit | 02e5422 | 2008-07-08 15:19:33 +0200 | [diff] [blame] | 2325 | else |
| 2326 | git_log_output_encoding = ""; |
Matthieu Moy | 7d7b86f | 2010-08-05 10:22:55 +0200 | [diff] [blame] | 2327 | return argcount; |
Pierre Habouzit | 02e5422 | 2008-07-08 15:19:33 +0200 | [diff] [blame] | 2328 | } else if (!strcmp(arg, "--reverse")) { |
| 2329 | revs->reverse ^= 1; |
| 2330 | } else if (!strcmp(arg, "--children")) { |
| 2331 | revs->children.name = "children"; |
| 2332 | revs->limited = 1; |
Junio C Hamano | cc243c3 | 2011-05-18 18:08:09 -0700 | [diff] [blame] | 2333 | } else if (!strcmp(arg, "--ignore-missing")) { |
| 2334 | revs->ignore_missing = 1; |
Matthew DeVore | bbcde41 | 2018-12-03 14:10:19 -0800 | [diff] [blame] | 2335 | } else if (opt && opt->allow_exclude_promisor_objects && |
Matthew DeVore | 669b1d2 | 2018-10-22 18:13:42 -0700 | [diff] [blame] | 2336 | !strcmp(arg, "--exclude-promisor-objects")) { |
Jonathan Tan | df11e19 | 2017-12-08 15:27:15 +0000 | [diff] [blame] | 2337 | if (fetch_if_missing) |
Johannes Schindelin | 033abf9 | 2018-05-02 11:38:39 +0200 | [diff] [blame] | 2338 | BUG("exclude_promisor_objects can only be used when fetch_if_missing is 0"); |
Jonathan Tan | df11e19 | 2017-12-08 15:27:15 +0000 | [diff] [blame] | 2339 | revs->exclude_promisor_objects = 1; |
Pierre Habouzit | 02e5422 | 2008-07-08 15:19:33 +0200 | [diff] [blame] | 2340 | } else { |
Duy Nguyen | a97262c | 2016-01-21 18:48:44 +0700 | [diff] [blame] | 2341 | int opts = diff_opt_parse(&revs->diffopt, argv, argc, revs->prefix); |
Pierre Habouzit | 02e5422 | 2008-07-08 15:19:33 +0200 | [diff] [blame] | 2342 | if (!opts) |
| 2343 | unkv[(*unkc)++] = arg; |
| 2344 | return opts; |
| 2345 | } |
Nguyễn Thái Ngọc Duy | 1b32dec | 2014-03-25 20:23:27 +0700 | [diff] [blame] | 2346 | if (revs->graph && revs->track_linear) |
| 2347 | die("--show-linear-break and --graph are incompatible"); |
Pierre Habouzit | 02e5422 | 2008-07-08 15:19:33 +0200 | [diff] [blame] | 2348 | |
| 2349 | return 1; |
| 2350 | } |
| 2351 | |
Pierre Habouzit | 6b61ec0 | 2008-07-09 23:38:34 +0200 | [diff] [blame] | 2352 | void parse_revision_opt(struct rev_info *revs, struct parse_opt_ctx_t *ctx, |
| 2353 | const struct option *options, |
| 2354 | const char * const usagestr[]) |
| 2355 | { |
| 2356 | int n = handle_revision_opt(revs, ctx->argc, ctx->argv, |
Matthew DeVore | bbcde41 | 2018-12-03 14:10:19 -0800 | [diff] [blame] | 2357 | &ctx->cpidx, ctx->out, NULL); |
Pierre Habouzit | 6b61ec0 | 2008-07-09 23:38:34 +0200 | [diff] [blame] | 2358 | if (n <= 0) { |
| 2359 | error("unknown option `%s'", ctx->argv[0]); |
| 2360 | usage_with_options(usagestr, options); |
| 2361 | } |
| 2362 | ctx->argv += n; |
| 2363 | ctx->argc -= n; |
| 2364 | } |
| 2365 | |
Nguyễn Thái Ngọc Duy | 073cf63 | 2017-08-23 19:36:56 +0700 | [diff] [blame] | 2366 | static int for_each_bisect_ref(struct ref_store *refs, each_ref_fn fn, |
| 2367 | void *cb_data, const char *term) |
| 2368 | { |
Antoine Delaite | cb46d63 | 2015-06-29 17:40:30 +0200 | [diff] [blame] | 2369 | struct strbuf bisect_refs = STRBUF_INIT; |
| 2370 | int status; |
| 2371 | strbuf_addf(&bisect_refs, "refs/bisect/%s", term); |
Nguyễn Thái Ngọc Duy | 073cf63 | 2017-08-23 19:36:56 +0700 | [diff] [blame] | 2372 | status = refs_for_each_fullref_in(refs, bisect_refs.buf, fn, cb_data, 0); |
Antoine Delaite | cb46d63 | 2015-06-29 17:40:30 +0200 | [diff] [blame] | 2373 | strbuf_release(&bisect_refs); |
| 2374 | return status; |
| 2375 | } |
| 2376 | |
Nguyễn Thái Ngọc Duy | 073cf63 | 2017-08-23 19:36:56 +0700 | [diff] [blame] | 2377 | static int for_each_bad_bisect_ref(struct ref_store *refs, each_ref_fn fn, void *cb_data) |
Linus Torvalds | ad3f9a7 | 2009-10-27 11:28:07 -0700 | [diff] [blame] | 2378 | { |
Nguyễn Thái Ngọc Duy | 073cf63 | 2017-08-23 19:36:56 +0700 | [diff] [blame] | 2379 | return for_each_bisect_ref(refs, fn, cb_data, term_bad); |
Linus Torvalds | ad3f9a7 | 2009-10-27 11:28:07 -0700 | [diff] [blame] | 2380 | } |
| 2381 | |
Nguyễn Thái Ngọc Duy | 073cf63 | 2017-08-23 19:36:56 +0700 | [diff] [blame] | 2382 | static int for_each_good_bisect_ref(struct ref_store *refs, each_ref_fn fn, void *cb_data) |
Linus Torvalds | ad3f9a7 | 2009-10-27 11:28:07 -0700 | [diff] [blame] | 2383 | { |
Nguyễn Thái Ngọc Duy | 073cf63 | 2017-08-23 19:36:56 +0700 | [diff] [blame] | 2384 | return for_each_bisect_ref(refs, fn, cb_data, term_good); |
Linus Torvalds | ad3f9a7 | 2009-10-27 11:28:07 -0700 | [diff] [blame] | 2385 | } |
| 2386 | |
Jonathan Nieder | f6aca0d | 2011-04-21 05:45:07 -0500 | [diff] [blame] | 2387 | static int handle_revision_pseudo_opt(const char *submodule, |
| 2388 | struct rev_info *revs, |
| 2389 | int argc, const char **argv, int *flags) |
| 2390 | { |
| 2391 | const char *arg = argv[0]; |
| 2392 | const char *optarg; |
Nguyễn Thái Ngọc Duy | 073cf63 | 2017-08-23 19:36:56 +0700 | [diff] [blame] | 2393 | struct ref_store *refs; |
Jonathan Nieder | f6aca0d | 2011-04-21 05:45:07 -0500 | [diff] [blame] | 2394 | int argcount; |
| 2395 | |
Nguyễn Thái Ngọc Duy | 073cf63 | 2017-08-23 19:36:56 +0700 | [diff] [blame] | 2396 | if (submodule) { |
Nguyễn Thái Ngọc Duy | d0c39a4 | 2017-08-23 19:36:59 +0700 | [diff] [blame] | 2397 | /* |
| 2398 | * We need some something like get_submodule_worktrees() |
| 2399 | * before we can go through all worktrees of a submodule, |
| 2400 | * .e.g with adding all HEADs from --all, which is not |
| 2401 | * supported right now, so stick to single worktree. |
| 2402 | */ |
| 2403 | if (!revs->single_worktree) |
Johannes Schindelin | 033abf9 | 2018-05-02 11:38:39 +0200 | [diff] [blame] | 2404 | BUG("--single-worktree cannot be used together with submodule"); |
Nguyễn Thái Ngọc Duy | 073cf63 | 2017-08-23 19:36:56 +0700 | [diff] [blame] | 2405 | refs = get_submodule_ref_store(submodule); |
| 2406 | } else |
Nguyễn Thái Ngọc Duy | b3c7eef | 2018-09-21 17:57:39 +0200 | [diff] [blame] | 2407 | refs = get_main_ref_store(revs->repo); |
Nguyễn Thái Ngọc Duy | 073cf63 | 2017-08-23 19:36:56 +0700 | [diff] [blame] | 2408 | |
Jonathan Nieder | 0fc63ec | 2011-04-21 05:48:24 -0500 | [diff] [blame] | 2409 | /* |
| 2410 | * NOTE! |
| 2411 | * |
| 2412 | * Commands like "git shortlog" will not accept the options below |
| 2413 | * unless parse_revision_opt queues them (as opposed to erroring |
| 2414 | * out). |
| 2415 | * |
| 2416 | * When implementing your new pseudo-option, remember to |
| 2417 | * register it in the list at the top of handle_revision_opt. |
| 2418 | */ |
Jonathan Nieder | f6aca0d | 2011-04-21 05:45:07 -0500 | [diff] [blame] | 2419 | if (!strcmp(arg, "--all")) { |
Nguyễn Thái Ngọc Duy | 073cf63 | 2017-08-23 19:36:56 +0700 | [diff] [blame] | 2420 | handle_refs(refs, revs, *flags, refs_for_each_ref); |
| 2421 | handle_refs(refs, revs, *flags, refs_head_ref); |
Nguyễn Thái Ngọc Duy | d0c39a4 | 2017-08-23 19:36:59 +0700 | [diff] [blame] | 2422 | if (!revs->single_worktree) { |
| 2423 | struct all_refs_cb cb; |
| 2424 | |
| 2425 | init_all_refs_cb(&cb, revs, *flags); |
| 2426 | other_head_refs(handle_one_ref, &cb); |
| 2427 | } |
Junio C Hamano | ff32d34 | 2013-11-01 12:02:45 -0700 | [diff] [blame] | 2428 | clear_ref_exclusion(&revs->ref_excludes); |
Jonathan Nieder | f6aca0d | 2011-04-21 05:45:07 -0500 | [diff] [blame] | 2429 | } else if (!strcmp(arg, "--branches")) { |
Nguyễn Thái Ngọc Duy | 073cf63 | 2017-08-23 19:36:56 +0700 | [diff] [blame] | 2430 | handle_refs(refs, revs, *flags, refs_for_each_branch_ref); |
Junio C Hamano | ff32d34 | 2013-11-01 12:02:45 -0700 | [diff] [blame] | 2431 | clear_ref_exclusion(&revs->ref_excludes); |
Jonathan Nieder | f6aca0d | 2011-04-21 05:45:07 -0500 | [diff] [blame] | 2432 | } else if (!strcmp(arg, "--bisect")) { |
Antoine Delaite | cb46d63 | 2015-06-29 17:40:30 +0200 | [diff] [blame] | 2433 | read_bisect_terms(&term_bad, &term_good); |
Nguyễn Thái Ngọc Duy | 073cf63 | 2017-08-23 19:36:56 +0700 | [diff] [blame] | 2434 | handle_refs(refs, revs, *flags, for_each_bad_bisect_ref); |
| 2435 | handle_refs(refs, revs, *flags ^ (UNINTERESTING | BOTTOM), |
| 2436 | for_each_good_bisect_ref); |
Jonathan Nieder | f6aca0d | 2011-04-21 05:45:07 -0500 | [diff] [blame] | 2437 | revs->bisect = 1; |
| 2438 | } else if (!strcmp(arg, "--tags")) { |
Nguyễn Thái Ngọc Duy | 073cf63 | 2017-08-23 19:36:56 +0700 | [diff] [blame] | 2439 | handle_refs(refs, revs, *flags, refs_for_each_tag_ref); |
Junio C Hamano | ff32d34 | 2013-11-01 12:02:45 -0700 | [diff] [blame] | 2440 | clear_ref_exclusion(&revs->ref_excludes); |
Jonathan Nieder | f6aca0d | 2011-04-21 05:45:07 -0500 | [diff] [blame] | 2441 | } else if (!strcmp(arg, "--remotes")) { |
Nguyễn Thái Ngọc Duy | 073cf63 | 2017-08-23 19:36:56 +0700 | [diff] [blame] | 2442 | handle_refs(refs, revs, *flags, refs_for_each_remote_ref); |
Junio C Hamano | ff32d34 | 2013-11-01 12:02:45 -0700 | [diff] [blame] | 2443 | clear_ref_exclusion(&revs->ref_excludes); |
Jonathan Nieder | f6aca0d | 2011-04-21 05:45:07 -0500 | [diff] [blame] | 2444 | } else if ((argcount = parse_long_opt("glob", argv, &optarg))) { |
| 2445 | struct all_refs_cb cb; |
| 2446 | init_all_refs_cb(&cb, revs, *flags); |
Michael Haggerty | a217dcb | 2015-05-25 18:38:30 +0000 | [diff] [blame] | 2447 | for_each_glob_ref(handle_one_ref, optarg, &cb); |
Junio C Hamano | ff32d34 | 2013-11-01 12:02:45 -0700 | [diff] [blame] | 2448 | clear_ref_exclusion(&revs->ref_excludes); |
Junio C Hamano | e7b432c | 2013-08-30 16:37:55 -0700 | [diff] [blame] | 2449 | return argcount; |
| 2450 | } else if ((argcount = parse_long_opt("exclude", argv, &optarg))) { |
Junio C Hamano | ff32d34 | 2013-11-01 12:02:45 -0700 | [diff] [blame] | 2451 | add_ref_exclusion(&revs->ref_excludes, optarg); |
Jonathan Nieder | f6aca0d | 2011-04-21 05:45:07 -0500 | [diff] [blame] | 2452 | return argcount; |
SZEDER Gábor | 8b1d913 | 2017-06-09 20:17:33 +0200 | [diff] [blame] | 2453 | } else if (skip_prefix(arg, "--branches=", &optarg)) { |
Jonathan Nieder | f6aca0d | 2011-04-21 05:45:07 -0500 | [diff] [blame] | 2454 | struct all_refs_cb cb; |
| 2455 | init_all_refs_cb(&cb, revs, *flags); |
SZEDER Gábor | 8b1d913 | 2017-06-09 20:17:33 +0200 | [diff] [blame] | 2456 | for_each_glob_ref_in(handle_one_ref, optarg, "refs/heads/", &cb); |
Junio C Hamano | ff32d34 | 2013-11-01 12:02:45 -0700 | [diff] [blame] | 2457 | clear_ref_exclusion(&revs->ref_excludes); |
SZEDER Gábor | 8b1d913 | 2017-06-09 20:17:33 +0200 | [diff] [blame] | 2458 | } else if (skip_prefix(arg, "--tags=", &optarg)) { |
Jonathan Nieder | f6aca0d | 2011-04-21 05:45:07 -0500 | [diff] [blame] | 2459 | struct all_refs_cb cb; |
| 2460 | init_all_refs_cb(&cb, revs, *flags); |
SZEDER Gábor | 8b1d913 | 2017-06-09 20:17:33 +0200 | [diff] [blame] | 2461 | for_each_glob_ref_in(handle_one_ref, optarg, "refs/tags/", &cb); |
Junio C Hamano | ff32d34 | 2013-11-01 12:02:45 -0700 | [diff] [blame] | 2462 | clear_ref_exclusion(&revs->ref_excludes); |
SZEDER Gábor | 8b1d913 | 2017-06-09 20:17:33 +0200 | [diff] [blame] | 2463 | } else if (skip_prefix(arg, "--remotes=", &optarg)) { |
Jonathan Nieder | f6aca0d | 2011-04-21 05:45:07 -0500 | [diff] [blame] | 2464 | struct all_refs_cb cb; |
| 2465 | init_all_refs_cb(&cb, revs, *flags); |
SZEDER Gábor | 8b1d913 | 2017-06-09 20:17:33 +0200 | [diff] [blame] | 2466 | for_each_glob_ref_in(handle_one_ref, optarg, "refs/remotes/", &cb); |
Junio C Hamano | ff32d34 | 2013-11-01 12:02:45 -0700 | [diff] [blame] | 2467 | clear_ref_exclusion(&revs->ref_excludes); |
Jonathan Nieder | f6aca0d | 2011-04-21 05:45:07 -0500 | [diff] [blame] | 2468 | } else if (!strcmp(arg, "--reflog")) { |
Jeff King | 718ccc9 | 2014-10-15 18:38:31 -0400 | [diff] [blame] | 2469 | add_reflogs_to_pending(revs, *flags); |
Jeff King | 4fe1021 | 2014-10-16 20:44:23 -0400 | [diff] [blame] | 2470 | } else if (!strcmp(arg, "--indexed-objects")) { |
| 2471 | add_index_objects_to_pending(revs, *flags); |
Jeff King | 39b44ba | 2019-07-01 09:18:15 -0400 | [diff] [blame] | 2472 | } else if (!strcmp(arg, "--alternate-refs")) { |
| 2473 | add_alternate_refs_to_pending(revs, *flags); |
Jonathan Nieder | f6aca0d | 2011-04-21 05:45:07 -0500 | [diff] [blame] | 2474 | } else if (!strcmp(arg, "--not")) { |
Kevin Bracey | 7f34a46 | 2013-05-16 18:32:38 +0300 | [diff] [blame] | 2475 | *flags ^= UNINTERESTING | BOTTOM; |
Jonathan Nieder | f6aca0d | 2011-04-21 05:45:07 -0500 | [diff] [blame] | 2476 | } else if (!strcmp(arg, "--no-walk")) { |
Martin von Zweigbergk | ca92e59 | 2012-08-28 23:15:54 -0700 | [diff] [blame] | 2477 | revs->no_walk = REVISION_WALK_NO_WALK_SORTED; |
SZEDER Gábor | 8b1d913 | 2017-06-09 20:17:33 +0200 | [diff] [blame] | 2478 | } else if (skip_prefix(arg, "--no-walk=", &optarg)) { |
Martin von Zweigbergk | ca92e59 | 2012-08-28 23:15:54 -0700 | [diff] [blame] | 2479 | /* |
| 2480 | * Detached form ("--no-walk X" as opposed to "--no-walk=X") |
| 2481 | * not allowed, since the argument is optional. |
| 2482 | */ |
SZEDER Gábor | 8b1d913 | 2017-06-09 20:17:33 +0200 | [diff] [blame] | 2483 | if (!strcmp(optarg, "sorted")) |
Martin von Zweigbergk | ca92e59 | 2012-08-28 23:15:54 -0700 | [diff] [blame] | 2484 | revs->no_walk = REVISION_WALK_NO_WALK_SORTED; |
SZEDER Gábor | 8b1d913 | 2017-06-09 20:17:33 +0200 | [diff] [blame] | 2485 | else if (!strcmp(optarg, "unsorted")) |
Martin von Zweigbergk | ca92e59 | 2012-08-28 23:15:54 -0700 | [diff] [blame] | 2486 | revs->no_walk = REVISION_WALK_NO_WALK_UNSORTED; |
| 2487 | else |
| 2488 | return error("invalid argument to --no-walk"); |
Jonathan Nieder | f6aca0d | 2011-04-21 05:45:07 -0500 | [diff] [blame] | 2489 | } else if (!strcmp(arg, "--do-walk")) { |
| 2490 | revs->no_walk = 0; |
Nguyễn Thái Ngọc Duy | 32619f9 | 2017-08-23 19:37:02 +0700 | [diff] [blame] | 2491 | } else if (!strcmp(arg, "--single-worktree")) { |
| 2492 | revs->single_worktree = 1; |
Jonathan Nieder | f6aca0d | 2011-04-21 05:45:07 -0500 | [diff] [blame] | 2493 | } else { |
| 2494 | return 0; |
| 2495 | } |
| 2496 | |
| 2497 | return 1; |
| 2498 | } |
| 2499 | |
Jeff King | ce11360 | 2015-08-29 01:04:18 -0400 | [diff] [blame] | 2500 | static void NORETURN diagnose_missing_default(const char *def) |
| 2501 | { |
Jeff King | ce11360 | 2015-08-29 01:04:18 -0400 | [diff] [blame] | 2502 | int flags; |
| 2503 | const char *refname; |
| 2504 | |
René Scharfe | 744c040 | 2017-09-23 11:45:04 +0200 | [diff] [blame] | 2505 | refname = resolve_ref_unsafe(def, 0, NULL, &flags); |
Jeff King | ce11360 | 2015-08-29 01:04:18 -0400 | [diff] [blame] | 2506 | if (!refname || !(flags & REF_ISSYMREF) || (flags & REF_ISBROKEN)) |
| 2507 | die(_("your current branch appears to be broken")); |
| 2508 | |
| 2509 | skip_prefix(refname, "refs/heads/", &refname); |
| 2510 | die(_("your current branch '%s' does not have any commits yet"), |
| 2511 | refname); |
| 2512 | } |
| 2513 | |
Linus Torvalds | ae56354 | 2006-02-25 16:19:46 -0800 | [diff] [blame] | 2514 | /* |
| 2515 | * Parse revision information, filling in the "rev_info" structure, |
| 2516 | * and removing the used arguments from the argument list. |
| 2517 | * |
Linus Torvalds | 765ac8e | 2006-02-28 15:07:20 -0800 | [diff] [blame] | 2518 | * Returns the number of arguments left that weren't recognized |
| 2519 | * (which are also moved to the head of the argument list) |
Linus Torvalds | ae56354 | 2006-02-25 16:19:46 -0800 | [diff] [blame] | 2520 | */ |
Junio C Hamano | 32962c9 | 2010-03-08 22:58:09 -0800 | [diff] [blame] | 2521 | int setup_revisions(int argc, const char **argv, struct rev_info *revs, struct setup_revision_opt *opt) |
Linus Torvalds | ae56354 | 2006-02-25 16:19:46 -0800 | [diff] [blame] | 2522 | { |
Jeff King | a12cbe2 | 2018-08-22 17:37:23 -0400 | [diff] [blame] | 2523 | int i, flags, left, seen_dashdash, got_rev_arg = 0, revarg_opt; |
Jeff King | 7fa3c2a | 2017-09-20 16:36:59 -0400 | [diff] [blame] | 2524 | struct argv_array prune_data = ARGV_ARRAY_INIT; |
Heiko Voigt | 9ef6aeb | 2010-07-07 15:39:12 +0200 | [diff] [blame] | 2525 | const char *submodule = NULL; |
| 2526 | |
| 2527 | if (opt) |
| 2528 | submodule = opt->submodule; |
Linus Torvalds | ae56354 | 2006-02-25 16:19:46 -0800 | [diff] [blame] | 2529 | |
Linus Torvalds | ae56354 | 2006-02-25 16:19:46 -0800 | [diff] [blame] | 2530 | /* First, search for "--" */ |
Clemens Buchacher | 6d5b93f | 2012-04-14 21:04:48 +0200 | [diff] [blame] | 2531 | if (opt && opt->assume_dashdash) { |
Linus Torvalds | ae56354 | 2006-02-25 16:19:46 -0800 | [diff] [blame] | 2532 | seen_dashdash = 1; |
Clemens Buchacher | 6d5b93f | 2012-04-14 21:04:48 +0200 | [diff] [blame] | 2533 | } else { |
| 2534 | seen_dashdash = 0; |
| 2535 | for (i = 1; i < argc; i++) { |
| 2536 | const char *arg = argv[i]; |
| 2537 | if (strcmp(arg, "--")) |
| 2538 | continue; |
| 2539 | argv[i] = NULL; |
| 2540 | argc = i; |
| 2541 | if (argv[i + 1]) |
Jeff King | 7fa3c2a | 2017-09-20 16:36:59 -0400 | [diff] [blame] | 2542 | argv_array_pushv(&prune_data, argv + i + 1); |
Clemens Buchacher | 6d5b93f | 2012-04-14 21:04:48 +0200 | [diff] [blame] | 2543 | seen_dashdash = 1; |
| 2544 | break; |
| 2545 | } |
Linus Torvalds | ae56354 | 2006-02-25 16:19:46 -0800 | [diff] [blame] | 2546 | } |
| 2547 | |
Pierre Habouzit | 02e5422 | 2008-07-08 15:19:33 +0200 | [diff] [blame] | 2548 | /* Second, deal with arguments and options */ |
| 2549 | flags = 0; |
Junio C Hamano | d5f6b1d | 2012-07-02 12:43:05 -0700 | [diff] [blame] | 2550 | revarg_opt = opt ? opt->revarg_opt : 0; |
| 2551 | if (seen_dashdash) |
| 2552 | revarg_opt |= REVARG_CANNOT_BE_FILENAME; |
Pierre Habouzit | 02e5422 | 2008-07-08 15:19:33 +0200 | [diff] [blame] | 2553 | for (left = i = 1; i < argc; i++) { |
Linus Torvalds | ae56354 | 2006-02-25 16:19:46 -0800 | [diff] [blame] | 2554 | const char *arg = argv[i]; |
Linus Torvalds | ae56354 | 2006-02-25 16:19:46 -0800 | [diff] [blame] | 2555 | if (*arg == '-') { |
Linus Torvalds | cd2bdc5 | 2006-04-14 16:52:13 -0700 | [diff] [blame] | 2556 | int opts; |
Pierre Habouzit | 02e5422 | 2008-07-08 15:19:33 +0200 | [diff] [blame] | 2557 | |
Jonathan Nieder | f6aca0d | 2011-04-21 05:45:07 -0500 | [diff] [blame] | 2558 | opts = handle_revision_pseudo_opt(submodule, |
| 2559 | revs, argc - i, argv + i, |
| 2560 | &flags); |
| 2561 | if (opts > 0) { |
| 2562 | i += opts - 1; |
Uwe Kleine-König | a5aa930 | 2008-02-28 08:24:25 +0100 | [diff] [blame] | 2563 | continue; |
| 2564 | } |
Jonathan Nieder | f6aca0d | 2011-04-21 05:45:07 -0500 | [diff] [blame] | 2565 | |
Junio C Hamano | 8b3dce5 | 2009-11-03 06:59:18 -0800 | [diff] [blame] | 2566 | if (!strcmp(arg, "--stdin")) { |
| 2567 | if (revs->disable_stdin) { |
| 2568 | argv[left++] = arg; |
| 2569 | continue; |
| 2570 | } |
Jeff King | a12cbe2 | 2018-08-22 17:37:23 -0400 | [diff] [blame] | 2571 | if (revs->read_from_stdin++) |
Junio C Hamano | 8b3dce5 | 2009-11-03 06:59:18 -0800 | [diff] [blame] | 2572 | die("--stdin given twice?"); |
Junio C Hamano | 60da8b1 | 2009-11-20 02:50:21 -0800 | [diff] [blame] | 2573 | read_revisions_from_stdin(revs, &prune_data); |
Junio C Hamano | 8b3dce5 | 2009-11-03 06:59:18 -0800 | [diff] [blame] | 2574 | continue; |
| 2575 | } |
Junio C Hamano | 2d10c55 | 2006-09-20 13:21:56 -0700 | [diff] [blame] | 2576 | |
Matthew DeVore | bbcde41 | 2018-12-03 14:10:19 -0800 | [diff] [blame] | 2577 | opts = handle_revision_opt(revs, argc - i, argv + i, |
| 2578 | &left, argv, opt); |
Linus Torvalds | cd2bdc5 | 2006-04-14 16:52:13 -0700 | [diff] [blame] | 2579 | if (opts > 0) { |
Linus Torvalds | cd2bdc5 | 2006-04-14 16:52:13 -0700 | [diff] [blame] | 2580 | i += opts - 1; |
| 2581 | continue; |
| 2582 | } |
Pierre Habouzit | 02e5422 | 2008-07-08 15:19:33 +0200 | [diff] [blame] | 2583 | if (opts < 0) |
| 2584 | exit(128); |
Linus Torvalds | ae56354 | 2006-02-25 16:19:46 -0800 | [diff] [blame] | 2585 | continue; |
| 2586 | } |
Rene Scharfe | 0d2c9d6 | 2006-07-02 01:29:37 +0200 | [diff] [blame] | 2587 | |
Junio C Hamano | 8e676e8 | 2012-07-02 12:33:52 -0700 | [diff] [blame] | 2588 | |
| 2589 | if (handle_revision_arg(arg, revs, flags, revarg_opt)) { |
Linus Torvalds | ae56354 | 2006-02-25 16:19:46 -0800 | [diff] [blame] | 2590 | int j; |
Junio C Hamano | 5d6f093 | 2006-09-05 21:28:36 -0700 | [diff] [blame] | 2591 | if (seen_dashdash || *arg == '^') |
Linus Torvalds | ae56354 | 2006-02-25 16:19:46 -0800 | [diff] [blame] | 2592 | die("bad revision '%s'", arg); |
| 2593 | |
Junio C Hamano | ea92f41 | 2006-04-26 15:09:27 -0700 | [diff] [blame] | 2594 | /* If we didn't have a "--": |
| 2595 | * (1) all filenames must exist; |
| 2596 | * (2) all rev-args must not be interpretable |
| 2597 | * as a valid filename. |
| 2598 | * but the latter we have checked in the main loop. |
| 2599 | */ |
Linus Torvalds | e23d0b4 | 2006-04-26 10:15:54 -0700 | [diff] [blame] | 2600 | for (j = i; j < argc; j++) |
Matthieu Moy | 023e37c | 2012-06-18 20:18:21 +0200 | [diff] [blame] | 2601 | verify_filename(revs->prefix, argv[j], j == i); |
Linus Torvalds | e23d0b4 | 2006-04-26 10:15:54 -0700 | [diff] [blame] | 2602 | |
Jeff King | 7fa3c2a | 2017-09-20 16:36:59 -0400 | [diff] [blame] | 2603 | argv_array_pushv(&prune_data, argv + i); |
Linus Torvalds | ae56354 | 2006-02-25 16:19:46 -0800 | [diff] [blame] | 2604 | break; |
| 2605 | } |
Dave Olszewski | 8fcaca3 | 2010-03-13 14:47:05 -0800 | [diff] [blame] | 2606 | else |
| 2607 | got_rev_arg = 1; |
Linus Torvalds | ae56354 | 2006-02-25 16:19:46 -0800 | [diff] [blame] | 2608 | } |
Junio C Hamano | 5d6f093 | 2006-09-05 21:28:36 -0700 | [diff] [blame] | 2609 | |
Jeff King | 7fa3c2a | 2017-09-20 16:36:59 -0400 | [diff] [blame] | 2610 | if (prune_data.argc) { |
Junio C Hamano | 93e7d67 | 2011-05-11 15:23:25 -0700 | [diff] [blame] | 2611 | /* |
| 2612 | * If we need to introduce the magic "a lone ':' means no |
| 2613 | * pathspec whatsoever", here is the place to do so. |
| 2614 | * |
| 2615 | * if (prune_data.nr == 1 && !strcmp(prune_data[0], ":")) { |
| 2616 | * prune_data.nr = 0; |
| 2617 | * prune_data.alloc = 0; |
| 2618 | * free(prune_data.path); |
| 2619 | * prune_data.path = NULL; |
| 2620 | * } else { |
| 2621 | * terminate prune_data.alloc with NULL and |
| 2622 | * call init_pathspec() to set revs->prune_data here. |
| 2623 | * } |
| 2624 | */ |
Nguyễn Thái Ngọc Duy | 0fdc2ae | 2013-07-14 15:35:31 +0700 | [diff] [blame] | 2625 | parse_pathspec(&revs->prune_data, 0, 0, |
Jeff King | 7fa3c2a | 2017-09-20 16:36:59 -0400 | [diff] [blame] | 2626 | revs->prefix, prune_data.argv); |
Junio C Hamano | 4da5af3 | 2011-05-11 14:01:19 -0700 | [diff] [blame] | 2627 | } |
Jeff King | 7fa3c2a | 2017-09-20 16:36:59 -0400 | [diff] [blame] | 2628 | argv_array_clear(&prune_data); |
Junio C Hamano | 5486ef0 | 2009-11-20 02:33:28 -0800 | [diff] [blame] | 2629 | |
Pierre Habouzit | 02e5422 | 2008-07-08 15:19:33 +0200 | [diff] [blame] | 2630 | if (revs->def == NULL) |
Junio C Hamano | 32962c9 | 2010-03-08 22:58:09 -0800 | [diff] [blame] | 2631 | revs->def = opt ? opt->def : NULL; |
Junio C Hamano | b449005 | 2010-03-08 23:27:25 -0800 | [diff] [blame] | 2632 | if (opt && opt->tweak) |
| 2633 | opt->tweak(revs, opt); |
Pierre Habouzit | 02e5422 | 2008-07-08 15:19:33 +0200 | [diff] [blame] | 2634 | if (revs->show_merge) |
Junio C Hamano | ae3e5e1 | 2006-07-03 02:59:32 -0700 | [diff] [blame] | 2635 | prepare_show_merge(revs); |
Jeff King | 5d34d1a | 2017-08-02 18:30:19 -0400 | [diff] [blame] | 2636 | if (revs->def && !revs->pending.nr && !revs->rev_input_given && !got_rev_arg) { |
brian m. carlson | 654b9a9 | 2017-05-06 22:10:27 +0000 | [diff] [blame] | 2637 | struct object_id oid; |
Linus Torvalds | cd2bdc5 | 2006-04-14 16:52:13 -0700 | [diff] [blame] | 2638 | struct object *object; |
Junio C Hamano | 249c8f4 | 2012-07-02 12:56:44 -0700 | [diff] [blame] | 2639 | struct object_context oc; |
Nguyễn Thái Ngọc Duy | 3a7a698 | 2019-01-12 09:13:28 +0700 | [diff] [blame] | 2640 | if (get_oid_with_context(revs->repo, revs->def, 0, &oid, &oc)) |
Jeff King | ce11360 | 2015-08-29 01:04:18 -0400 | [diff] [blame] | 2641 | diagnose_missing_default(revs->def); |
brian m. carlson | 654b9a9 | 2017-05-06 22:10:27 +0000 | [diff] [blame] | 2642 | object = get_reference(revs, revs->def, &oid, 0); |
Junio C Hamano | 249c8f4 | 2012-07-02 12:56:44 -0700 | [diff] [blame] | 2643 | add_pending_object_with_mode(revs, object, revs->def, oc.mode); |
Linus Torvalds | ae56354 | 2006-02-25 16:19:46 -0800 | [diff] [blame] | 2644 | } |
Fredrik Kuivinen | 8efdc32 | 2006-03-10 10:21:39 +0100 | [diff] [blame] | 2645 | |
Linus Torvalds | b7bb760 | 2007-09-29 09:50:39 -0700 | [diff] [blame] | 2646 | /* Did the user ask for any diff output? Run the diff! */ |
| 2647 | if (revs->diffopt.output_format & ~DIFF_FORMAT_NO_OUTPUT) |
| 2648 | revs->diff = 1; |
| 2649 | |
Arjen Laarhoven | 0faf2da | 2007-12-25 12:06:47 +0100 | [diff] [blame] | 2650 | /* Pickaxe, diff-filter and rename following need diffs */ |
Stefan Beller | cf63051 | 2018-01-04 14:50:41 -0800 | [diff] [blame] | 2651 | if ((revs->diffopt.pickaxe_opts & DIFF_PICKAXE_KINDS_MASK) || |
Arjen Laarhoven | 0faf2da | 2007-12-25 12:06:47 +0100 | [diff] [blame] | 2652 | revs->diffopt.filter || |
Brandon Williams | 0d1e0e7 | 2017-10-31 11:19:11 -0700 | [diff] [blame] | 2653 | revs->diffopt.flags.follow_renames) |
Linus Torvalds | b7bb760 | 2007-09-29 09:50:39 -0700 | [diff] [blame] | 2654 | revs->diff = 1; |
| 2655 | |
Stefan Beller | 15af58c | 2018-01-04 14:50:42 -0800 | [diff] [blame] | 2656 | if (revs->diffopt.objfind) |
| 2657 | revs->simplify_history = 0; |
| 2658 | |
Derrick Stolee | f0d9cc4 | 2018-11-01 13:46:20 +0000 | [diff] [blame] | 2659 | if (revs->topo_order && !generation_numbers_enabled(the_repository)) |
Junio C Hamano | 5306968 | 2006-04-01 18:38:25 -0800 | [diff] [blame] | 2660 | revs->limited = 1; |
| 2661 | |
Nguyễn Thái Ngọc Duy | afe069d | 2010-12-17 19:43:06 +0700 | [diff] [blame] | 2662 | if (revs->prune_data.nr) { |
Nguyễn Thái Ngọc Duy | bd1928d | 2013-07-14 15:35:58 +0700 | [diff] [blame] | 2663 | copy_pathspec(&revs->pruning.pathspec, &revs->prune_data); |
Linus Torvalds | 750f7b6 | 2007-06-19 14:22:46 -0700 | [diff] [blame] | 2664 | /* Can't prune commits with rename following: the paths change.. */ |
Brandon Williams | 0d1e0e7 | 2017-10-31 11:19:11 -0700 | [diff] [blame] | 2665 | if (!revs->diffopt.flags.follow_renames) |
Linus Torvalds | 53b2c82 | 2007-11-05 13:22:34 -0800 | [diff] [blame] | 2666 | revs->prune = 1; |
Linus Torvalds | cd2bdc5 | 2006-04-14 16:52:13 -0700 | [diff] [blame] | 2667 | if (!revs->full_diff) |
Nguyễn Thái Ngọc Duy | bd1928d | 2013-07-14 15:35:58 +0700 | [diff] [blame] | 2668 | copy_pathspec(&revs->diffopt.pathspec, |
| 2669 | &revs->prune_data); |
Fredrik Kuivinen | 8efdc32 | 2006-03-10 10:21:39 +0100 | [diff] [blame] | 2670 | } |
Junio C Hamano | b449005 | 2010-03-08 23:27:25 -0800 | [diff] [blame] | 2671 | if (revs->combine_merges) |
Linus Torvalds | cd2bdc5 | 2006-04-14 16:52:13 -0700 | [diff] [blame] | 2672 | revs->ignore_merges = 0; |
Elijah Newren | d76ce4f | 2019-02-07 17:12:46 -0800 | [diff] [blame] | 2673 | if (revs->combined_all_paths && !revs->combine_merges) |
| 2674 | die("--combined-all-paths makes no sense without -c or --cc"); |
| 2675 | |
Linus Torvalds | cd2bdc5 | 2006-04-14 16:52:13 -0700 | [diff] [blame] | 2676 | revs->diffopt.abbrev = revs->abbrev; |
Thomas Rast | 12da1d1 | 2013-03-28 17:47:32 +0100 | [diff] [blame] | 2677 | |
| 2678 | if (revs->line_level_traverse) { |
| 2679 | revs->limited = 1; |
| 2680 | revs->topo_order = 1; |
| 2681 | } |
| 2682 | |
Thomas Rast | 2845265 | 2012-08-03 14:16:24 +0200 | [diff] [blame] | 2683 | diff_setup_done(&revs->diffopt); |
Fredrik Kuivinen | 8efdc32 | 2006-03-10 10:21:39 +0100 | [diff] [blame] | 2684 | |
Junio C Hamano | 918d4e1 | 2012-10-09 16:40:03 -0700 | [diff] [blame] | 2685 | grep_commit_pattern_type(GREP_PATTERN_TYPE_UNSPECIFIED, |
| 2686 | &revs->grep_filter); |
Jeff King | 0843acf | 2008-08-25 02:15:05 -0400 | [diff] [blame] | 2687 | compile_grep_patterns(&revs->grep_filter); |
Junio C Hamano | bd95fcd | 2006-09-17 17:23:20 -0700 | [diff] [blame] | 2688 | |
Shawn O. Pearce | d56651c | 2007-08-19 22:33:43 -0400 | [diff] [blame] | 2689 | if (revs->reverse && revs->reflog_info) |
| 2690 | die("cannot combine --reverse with --walk-reflogs"); |
Jeff King | 82fd0f4 | 2017-07-07 05:07:16 -0400 | [diff] [blame] | 2691 | if (revs->reflog_info && revs->limited) |
| 2692 | die("cannot combine --walk-reflogs with history-limiting options"); |
Junio C Hamano | 8bb6588 | 2008-07-08 15:25:44 -0700 | [diff] [blame] | 2693 | if (revs->rewrite_parents && revs->children.name) |
Junio C Hamano | f35f560 | 2008-04-03 02:12:06 -0700 | [diff] [blame] | 2694 | die("cannot combine --parents and --children"); |
Shawn O. Pearce | d56651c | 2007-08-19 22:33:43 -0400 | [diff] [blame] | 2695 | |
Adam Simpkins | 7fefda5 | 2008-05-04 03:36:54 -0700 | [diff] [blame] | 2696 | /* |
| 2697 | * Limitations on the graph functionality |
| 2698 | */ |
| 2699 | if (revs->reverse && revs->graph) |
| 2700 | die("cannot combine --reverse with --graph"); |
| 2701 | |
| 2702 | if (revs->reflog_info && revs->graph) |
| 2703 | die("cannot combine --walk-reflogs with --graph"); |
Dongcan Jiang | 695985f | 2015-03-11 10:13:02 +0800 | [diff] [blame] | 2704 | if (revs->no_walk && revs->graph) |
| 2705 | die("cannot combine --no-walk with --graph"); |
Junio C Hamano | baa6378 | 2012-09-29 11:59:52 -0700 | [diff] [blame] | 2706 | if (!revs->reflog_info && revs->grep_filter.use_reflog_filter) |
| 2707 | die("cannot use --grep-reflog without --walk-reflogs"); |
Adam Simpkins | 7fefda5 | 2008-05-04 03:36:54 -0700 | [diff] [blame] | 2708 | |
Kevin Daudt | f88851c | 2015-03-19 23:14:08 +0100 | [diff] [blame] | 2709 | if (revs->first_parent_only && revs->bisect) |
| 2710 | die(_("--first-parent is incompatible with --bisect")); |
| 2711 | |
Jeff King | 05314ef | 2019-03-10 23:54:33 -0400 | [diff] [blame] | 2712 | if (revs->line_level_traverse && |
| 2713 | (revs->diffopt.output_format & ~(DIFF_FORMAT_PATCH | DIFF_FORMAT_NO_OUTPUT))) |
| 2714 | die(_("-L does not yet support diff formats besides -p and -s")); |
| 2715 | |
Junio C Hamano | 0893eec | 2016-03-29 15:49:24 -0700 | [diff] [blame] | 2716 | if (revs->expand_tabs_in_log < 0) |
| 2717 | revs->expand_tabs_in_log = revs->expand_tabs_in_log_default; |
| 2718 | |
Linus Torvalds | ae56354 | 2006-02-25 16:19:46 -0800 | [diff] [blame] | 2719 | return left; |
| 2720 | } |
Linus Torvalds | a4a88b2 | 2006-02-28 11:24:00 -0800 | [diff] [blame] | 2721 | |
Junio C Hamano | f35f560 | 2008-04-03 02:12:06 -0700 | [diff] [blame] | 2722 | static void add_child(struct rev_info *revs, struct commit *parent, struct commit *child) |
| 2723 | { |
| 2724 | struct commit_list *l = xcalloc(1, sizeof(*l)); |
| 2725 | |
| 2726 | l->item = child; |
| 2727 | l->next = add_decoration(&revs->children, &parent->object, l); |
| 2728 | } |
| 2729 | |
Kevin Bracey | d0af663 | 2013-05-16 18:32:34 +0300 | [diff] [blame] | 2730 | static int remove_duplicate_parents(struct rev_info *revs, struct commit *commit) |
Junio C Hamano | 6546b59 | 2008-07-31 01:17:41 -0700 | [diff] [blame] | 2731 | { |
Kevin Bracey | d0af663 | 2013-05-16 18:32:34 +0300 | [diff] [blame] | 2732 | struct treesame_state *ts = lookup_decoration(&revs->treesame, &commit->object); |
Junio C Hamano | 6546b59 | 2008-07-31 01:17:41 -0700 | [diff] [blame] | 2733 | struct commit_list **pp, *p; |
| 2734 | int surviving_parents; |
| 2735 | |
| 2736 | /* Examine existing parents while marking ones we have seen... */ |
| 2737 | pp = &commit->parents; |
Kevin Bracey | d0af663 | 2013-05-16 18:32:34 +0300 | [diff] [blame] | 2738 | surviving_parents = 0; |
Junio C Hamano | 6546b59 | 2008-07-31 01:17:41 -0700 | [diff] [blame] | 2739 | while ((p = *pp) != NULL) { |
| 2740 | struct commit *parent = p->item; |
| 2741 | if (parent->object.flags & TMP_MARK) { |
| 2742 | *pp = p->next; |
Kevin Bracey | d0af663 | 2013-05-16 18:32:34 +0300 | [diff] [blame] | 2743 | if (ts) |
| 2744 | compact_treesame(revs, commit, surviving_parents); |
Junio C Hamano | 6546b59 | 2008-07-31 01:17:41 -0700 | [diff] [blame] | 2745 | continue; |
| 2746 | } |
| 2747 | parent->object.flags |= TMP_MARK; |
Kevin Bracey | d0af663 | 2013-05-16 18:32:34 +0300 | [diff] [blame] | 2748 | surviving_parents++; |
Junio C Hamano | 6546b59 | 2008-07-31 01:17:41 -0700 | [diff] [blame] | 2749 | pp = &p->next; |
| 2750 | } |
Kevin Bracey | d0af663 | 2013-05-16 18:32:34 +0300 | [diff] [blame] | 2751 | /* clear the temporary mark */ |
Junio C Hamano | 6546b59 | 2008-07-31 01:17:41 -0700 | [diff] [blame] | 2752 | for (p = commit->parents; p; p = p->next) { |
| 2753 | p->item->object.flags &= ~TMP_MARK; |
Junio C Hamano | 6546b59 | 2008-07-31 01:17:41 -0700 | [diff] [blame] | 2754 | } |
Kevin Bracey | d0af663 | 2013-05-16 18:32:34 +0300 | [diff] [blame] | 2755 | /* no update_treesame() - removing duplicates can't affect TREESAME */ |
Junio C Hamano | 6546b59 | 2008-07-31 01:17:41 -0700 | [diff] [blame] | 2756 | return surviving_parents; |
| 2757 | } |
| 2758 | |
Junio C Hamano | faf0156 | 2008-08-14 10:59:44 -0700 | [diff] [blame] | 2759 | struct merge_simplify_state { |
| 2760 | struct commit *simplified; |
| 2761 | }; |
| 2762 | |
| 2763 | static struct merge_simplify_state *locate_simplify_state(struct rev_info *revs, struct commit *commit) |
| 2764 | { |
| 2765 | struct merge_simplify_state *st; |
| 2766 | |
| 2767 | st = lookup_decoration(&revs->merge_simplification, &commit->object); |
| 2768 | if (!st) { |
| 2769 | st = xcalloc(1, sizeof(*st)); |
| 2770 | add_decoration(&revs->merge_simplification, &commit->object, st); |
| 2771 | } |
| 2772 | return st; |
| 2773 | } |
| 2774 | |
Jeff King | 9163399 | 2019-03-20 04:13:36 -0400 | [diff] [blame] | 2775 | static int mark_redundant_parents(struct commit *commit) |
Kevin Bracey | d0af663 | 2013-05-16 18:32:34 +0300 | [diff] [blame] | 2776 | { |
| 2777 | struct commit_list *h = reduce_heads(commit->parents); |
| 2778 | int i = 0, marked = 0; |
| 2779 | struct commit_list *po, *pn; |
| 2780 | |
| 2781 | /* Want these for sanity-checking only */ |
| 2782 | int orig_cnt = commit_list_count(commit->parents); |
| 2783 | int cnt = commit_list_count(h); |
| 2784 | |
| 2785 | /* |
| 2786 | * Not ready to remove items yet, just mark them for now, based |
| 2787 | * on the output of reduce_heads(). reduce_heads outputs the reduced |
| 2788 | * set in its original order, so this isn't too hard. |
| 2789 | */ |
| 2790 | po = commit->parents; |
| 2791 | pn = h; |
| 2792 | while (po) { |
| 2793 | if (pn && po->item == pn->item) { |
| 2794 | pn = pn->next; |
| 2795 | i++; |
| 2796 | } else { |
| 2797 | po->item->object.flags |= TMP_MARK; |
| 2798 | marked++; |
| 2799 | } |
| 2800 | po=po->next; |
| 2801 | } |
| 2802 | |
| 2803 | if (i != cnt || cnt+marked != orig_cnt) |
| 2804 | die("mark_redundant_parents %d %d %d %d", orig_cnt, cnt, i, marked); |
| 2805 | |
| 2806 | free_commit_list(h); |
| 2807 | |
| 2808 | return marked; |
| 2809 | } |
| 2810 | |
Jeff King | 9163399 | 2019-03-20 04:13:36 -0400 | [diff] [blame] | 2811 | static int mark_treesame_root_parents(struct commit *commit) |
Kevin Bracey | 143f1ea | 2013-05-16 18:32:37 +0300 | [diff] [blame] | 2812 | { |
| 2813 | struct commit_list *p; |
| 2814 | int marked = 0; |
| 2815 | |
| 2816 | for (p = commit->parents; p; p = p->next) { |
| 2817 | struct commit *parent = p->item; |
| 2818 | if (!parent->parents && (parent->object.flags & TREESAME)) { |
| 2819 | parent->object.flags |= TMP_MARK; |
| 2820 | marked++; |
| 2821 | } |
| 2822 | } |
| 2823 | |
| 2824 | return marked; |
| 2825 | } |
| 2826 | |
Kevin Bracey | 9c129ea | 2013-05-16 18:32:36 +0300 | [diff] [blame] | 2827 | /* |
| 2828 | * Awkward naming - this means one parent we are TREESAME to. |
| 2829 | * cf mark_treesame_root_parents: root parents that are TREESAME (to an |
| 2830 | * empty tree). Better name suggestions? |
| 2831 | */ |
| 2832 | static int leave_one_treesame_to_parent(struct rev_info *revs, struct commit *commit) |
| 2833 | { |
| 2834 | struct treesame_state *ts = lookup_decoration(&revs->treesame, &commit->object); |
| 2835 | struct commit *unmarked = NULL, *marked = NULL; |
| 2836 | struct commit_list *p; |
| 2837 | unsigned n; |
| 2838 | |
| 2839 | for (p = commit->parents, n = 0; p; p = p->next, n++) { |
| 2840 | if (ts->treesame[n]) { |
| 2841 | if (p->item->object.flags & TMP_MARK) { |
| 2842 | if (!marked) |
| 2843 | marked = p->item; |
| 2844 | } else { |
| 2845 | if (!unmarked) { |
| 2846 | unmarked = p->item; |
| 2847 | break; |
| 2848 | } |
| 2849 | } |
| 2850 | } |
| 2851 | } |
| 2852 | |
| 2853 | /* |
| 2854 | * If we are TREESAME to a marked-for-deletion parent, but not to any |
| 2855 | * unmarked parents, unmark the first TREESAME parent. This is the |
| 2856 | * parent that the default simplify_history==1 scan would have followed, |
| 2857 | * and it doesn't make sense to omit that path when asking for a |
| 2858 | * simplified full history. Retaining it improves the chances of |
| 2859 | * understanding odd missed merges that took an old version of a file. |
| 2860 | * |
| 2861 | * Example: |
| 2862 | * |
| 2863 | * I--------*X A modified the file, but mainline merge X used |
| 2864 | * \ / "-s ours", so took the version from I. X is |
| 2865 | * `-*A--' TREESAME to I and !TREESAME to A. |
| 2866 | * |
| 2867 | * Default log from X would produce "I". Without this check, |
| 2868 | * --full-history --simplify-merges would produce "I-A-X", showing |
| 2869 | * the merge commit X and that it changed A, but not making clear that |
| 2870 | * it had just taken the I version. With this check, the topology above |
| 2871 | * is retained. |
| 2872 | * |
| 2873 | * Note that it is possible that the simplification chooses a different |
| 2874 | * TREESAME parent from the default, in which case this test doesn't |
| 2875 | * activate, and we _do_ drop the default parent. Example: |
| 2876 | * |
| 2877 | * I------X A modified the file, but it was reverted in B, |
| 2878 | * \ / meaning mainline merge X is TREESAME to both |
| 2879 | * *A-*B parents. |
| 2880 | * |
| 2881 | * Default log would produce "I" by following the first parent; |
| 2882 | * --full-history --simplify-merges will produce "I-A-B". But this is a |
| 2883 | * reasonable result - it presents a logical full history leading from |
| 2884 | * I to X, and X is not an important merge. |
| 2885 | */ |
| 2886 | if (!unmarked && marked) { |
| 2887 | marked->object.flags &= ~TMP_MARK; |
| 2888 | return 1; |
| 2889 | } |
| 2890 | |
| 2891 | return 0; |
| 2892 | } |
| 2893 | |
Kevin Bracey | d0af663 | 2013-05-16 18:32:34 +0300 | [diff] [blame] | 2894 | static int remove_marked_parents(struct rev_info *revs, struct commit *commit) |
| 2895 | { |
| 2896 | struct commit_list **pp, *p; |
| 2897 | int nth_parent, removed = 0; |
| 2898 | |
| 2899 | pp = &commit->parents; |
| 2900 | nth_parent = 0; |
| 2901 | while ((p = *pp) != NULL) { |
| 2902 | struct commit *parent = p->item; |
| 2903 | if (parent->object.flags & TMP_MARK) { |
| 2904 | parent->object.flags &= ~TMP_MARK; |
| 2905 | *pp = p->next; |
| 2906 | free(p); |
| 2907 | removed++; |
| 2908 | compact_treesame(revs, commit, nth_parent); |
| 2909 | continue; |
| 2910 | } |
| 2911 | pp = &p->next; |
| 2912 | nth_parent++; |
| 2913 | } |
| 2914 | |
| 2915 | /* Removing parents can only increase TREESAMEness */ |
| 2916 | if (removed && !(commit->object.flags & TREESAME)) |
| 2917 | update_treesame(revs, commit); |
| 2918 | |
| 2919 | return nth_parent; |
| 2920 | } |
| 2921 | |
Junio C Hamano | faf0156 | 2008-08-14 10:59:44 -0700 | [diff] [blame] | 2922 | static struct commit_list **simplify_one(struct rev_info *revs, struct commit *commit, struct commit_list **tail) |
Junio C Hamano | 6546b59 | 2008-07-31 01:17:41 -0700 | [diff] [blame] | 2923 | { |
| 2924 | struct commit_list *p; |
Kevin Bracey | 4d82660 | 2013-05-16 18:32:39 +0300 | [diff] [blame] | 2925 | struct commit *parent; |
Junio C Hamano | faf0156 | 2008-08-14 10:59:44 -0700 | [diff] [blame] | 2926 | struct merge_simplify_state *st, *pst; |
Junio C Hamano | 6546b59 | 2008-07-31 01:17:41 -0700 | [diff] [blame] | 2927 | int cnt; |
| 2928 | |
Junio C Hamano | faf0156 | 2008-08-14 10:59:44 -0700 | [diff] [blame] | 2929 | st = locate_simplify_state(revs, commit); |
| 2930 | |
Junio C Hamano | 6546b59 | 2008-07-31 01:17:41 -0700 | [diff] [blame] | 2931 | /* |
Junio C Hamano | 6546b59 | 2008-07-31 01:17:41 -0700 | [diff] [blame] | 2932 | * Have we handled this one? |
| 2933 | */ |
Junio C Hamano | faf0156 | 2008-08-14 10:59:44 -0700 | [diff] [blame] | 2934 | if (st->simplified) |
Junio C Hamano | 6546b59 | 2008-07-31 01:17:41 -0700 | [diff] [blame] | 2935 | return tail; |
| 2936 | |
| 2937 | /* |
| 2938 | * An UNINTERESTING commit simplifies to itself, so does a |
| 2939 | * root commit. We do not rewrite parents of such commit |
| 2940 | * anyway. |
| 2941 | */ |
| 2942 | if ((commit->object.flags & UNINTERESTING) || !commit->parents) { |
Junio C Hamano | faf0156 | 2008-08-14 10:59:44 -0700 | [diff] [blame] | 2943 | st->simplified = commit; |
Junio C Hamano | 6546b59 | 2008-07-31 01:17:41 -0700 | [diff] [blame] | 2944 | return tail; |
| 2945 | } |
| 2946 | |
| 2947 | /* |
Junio C Hamano | 6e513ba | 2012-06-08 14:56:03 -0700 | [diff] [blame] | 2948 | * Do we know what commit all of our parents that matter |
| 2949 | * should be rewritten to? Otherwise we are not ready to |
| 2950 | * rewrite this one yet. |
Junio C Hamano | 6546b59 | 2008-07-31 01:17:41 -0700 | [diff] [blame] | 2951 | */ |
| 2952 | for (cnt = 0, p = commit->parents; p; p = p->next) { |
Junio C Hamano | faf0156 | 2008-08-14 10:59:44 -0700 | [diff] [blame] | 2953 | pst = locate_simplify_state(revs, p->item); |
| 2954 | if (!pst->simplified) { |
Junio C Hamano | 6546b59 | 2008-07-31 01:17:41 -0700 | [diff] [blame] | 2955 | tail = &commit_list_insert(p->item, tail)->next; |
| 2956 | cnt++; |
| 2957 | } |
Junio C Hamano | 6e513ba | 2012-06-08 14:56:03 -0700 | [diff] [blame] | 2958 | if (revs->first_parent_only) |
| 2959 | break; |
Junio C Hamano | 6546b59 | 2008-07-31 01:17:41 -0700 | [diff] [blame] | 2960 | } |
Junio C Hamano | 53030f8 | 2008-08-18 00:37:34 -0700 | [diff] [blame] | 2961 | if (cnt) { |
| 2962 | tail = &commit_list_insert(commit, tail)->next; |
Junio C Hamano | 6546b59 | 2008-07-31 01:17:41 -0700 | [diff] [blame] | 2963 | return tail; |
Junio C Hamano | 53030f8 | 2008-08-18 00:37:34 -0700 | [diff] [blame] | 2964 | } |
Junio C Hamano | 6546b59 | 2008-07-31 01:17:41 -0700 | [diff] [blame] | 2965 | |
| 2966 | /* |
Kevin Bracey | d0af663 | 2013-05-16 18:32:34 +0300 | [diff] [blame] | 2967 | * Rewrite our list of parents. Note that this cannot |
| 2968 | * affect our TREESAME flags in any way - a commit is |
| 2969 | * always TREESAME to its simplification. |
Junio C Hamano | 6546b59 | 2008-07-31 01:17:41 -0700 | [diff] [blame] | 2970 | */ |
Junio C Hamano | faf0156 | 2008-08-14 10:59:44 -0700 | [diff] [blame] | 2971 | for (p = commit->parents; p; p = p->next) { |
| 2972 | pst = locate_simplify_state(revs, p->item); |
| 2973 | p->item = pst->simplified; |
Junio C Hamano | 6e513ba | 2012-06-08 14:56:03 -0700 | [diff] [blame] | 2974 | if (revs->first_parent_only) |
| 2975 | break; |
Junio C Hamano | faf0156 | 2008-08-14 10:59:44 -0700 | [diff] [blame] | 2976 | } |
Junio C Hamano | 4b7f53d | 2013-01-17 14:23:03 -0800 | [diff] [blame] | 2977 | |
Junio C Hamano | 0290bf1 | 2013-04-08 13:10:27 -0700 | [diff] [blame] | 2978 | if (revs->first_parent_only) |
Junio C Hamano | 6e513ba | 2012-06-08 14:56:03 -0700 | [diff] [blame] | 2979 | cnt = 1; |
Junio C Hamano | 0290bf1 | 2013-04-08 13:10:27 -0700 | [diff] [blame] | 2980 | else |
Kevin Bracey | d0af663 | 2013-05-16 18:32:34 +0300 | [diff] [blame] | 2981 | cnt = remove_duplicate_parents(revs, commit); |
Junio C Hamano | 6546b59 | 2008-07-31 01:17:41 -0700 | [diff] [blame] | 2982 | |
| 2983 | /* |
| 2984 | * It is possible that we are a merge and one side branch |
| 2985 | * does not have any commit that touches the given paths; |
Kevin Bracey | d0af663 | 2013-05-16 18:32:34 +0300 | [diff] [blame] | 2986 | * in such a case, the immediate parent from that branch |
| 2987 | * will be rewritten to be the merge base. |
Junio C Hamano | 6546b59 | 2008-07-31 01:17:41 -0700 | [diff] [blame] | 2988 | * |
| 2989 | * o----X X: the commit we are looking at; |
| 2990 | * / / o: a commit that touches the paths; |
| 2991 | * ---o----' |
| 2992 | * |
Kevin Bracey | 143f1ea | 2013-05-16 18:32:37 +0300 | [diff] [blame] | 2993 | * Further, a merge of an independent branch that doesn't |
| 2994 | * touch the path will reduce to a treesame root parent: |
| 2995 | * |
| 2996 | * ----o----X X: the commit we are looking at; |
| 2997 | * / o: a commit that touches the paths; |
| 2998 | * r r: a root commit not touching the paths |
| 2999 | * |
| 3000 | * Detect and simplify both cases. |
Junio C Hamano | 6546b59 | 2008-07-31 01:17:41 -0700 | [diff] [blame] | 3001 | */ |
| 3002 | if (1 < cnt) { |
Jeff King | 9163399 | 2019-03-20 04:13:36 -0400 | [diff] [blame] | 3003 | int marked = mark_redundant_parents(commit); |
| 3004 | marked += mark_treesame_root_parents(commit); |
Kevin Bracey | d0af663 | 2013-05-16 18:32:34 +0300 | [diff] [blame] | 3005 | if (marked) |
Kevin Bracey | 9c129ea | 2013-05-16 18:32:36 +0300 | [diff] [blame] | 3006 | marked -= leave_one_treesame_to_parent(revs, commit); |
| 3007 | if (marked) |
Kevin Bracey | d0af663 | 2013-05-16 18:32:34 +0300 | [diff] [blame] | 3008 | cnt = remove_marked_parents(revs, commit); |
Junio C Hamano | 6546b59 | 2008-07-31 01:17:41 -0700 | [diff] [blame] | 3009 | } |
| 3010 | |
| 3011 | /* |
| 3012 | * A commit simplifies to itself if it is a root, if it is |
| 3013 | * UNINTERESTING, if it touches the given paths, or if it is a |
Kevin Bracey | 4d82660 | 2013-05-16 18:32:39 +0300 | [diff] [blame] | 3014 | * merge and its parents don't simplify to one relevant commit |
Junio C Hamano | 6546b59 | 2008-07-31 01:17:41 -0700 | [diff] [blame] | 3015 | * (the first two cases are already handled at the beginning of |
| 3016 | * this function). |
| 3017 | * |
Kevin Bracey | 4d82660 | 2013-05-16 18:32:39 +0300 | [diff] [blame] | 3018 | * Otherwise, it simplifies to what its sole relevant parent |
| 3019 | * simplifies to. |
Junio C Hamano | 6546b59 | 2008-07-31 01:17:41 -0700 | [diff] [blame] | 3020 | */ |
| 3021 | if (!cnt || |
| 3022 | (commit->object.flags & UNINTERESTING) || |
| 3023 | !(commit->object.flags & TREESAME) || |
Kevin Bracey | 4d82660 | 2013-05-16 18:32:39 +0300 | [diff] [blame] | 3024 | (parent = one_relevant_parent(revs, commit->parents)) == NULL) |
Junio C Hamano | faf0156 | 2008-08-14 10:59:44 -0700 | [diff] [blame] | 3025 | st->simplified = commit; |
| 3026 | else { |
Kevin Bracey | 4d82660 | 2013-05-16 18:32:39 +0300 | [diff] [blame] | 3027 | pst = locate_simplify_state(revs, parent); |
Junio C Hamano | faf0156 | 2008-08-14 10:59:44 -0700 | [diff] [blame] | 3028 | st->simplified = pst->simplified; |
| 3029 | } |
Junio C Hamano | 6546b59 | 2008-07-31 01:17:41 -0700 | [diff] [blame] | 3030 | return tail; |
| 3031 | } |
| 3032 | |
| 3033 | static void simplify_merges(struct rev_info *revs) |
| 3034 | { |
Junio C Hamano | ab9d75a | 2012-06-08 14:50:22 -0700 | [diff] [blame] | 3035 | struct commit_list *list, *next; |
Junio C Hamano | 6546b59 | 2008-07-31 01:17:41 -0700 | [diff] [blame] | 3036 | struct commit_list *yet_to_do, **tail; |
Junio C Hamano | ab9d75a | 2012-06-08 14:50:22 -0700 | [diff] [blame] | 3037 | struct commit *commit; |
Junio C Hamano | 6546b59 | 2008-07-31 01:17:41 -0700 | [diff] [blame] | 3038 | |
Junio C Hamano | 5eac739 | 2008-08-14 13:52:36 -0700 | [diff] [blame] | 3039 | if (!revs->prune) |
| 3040 | return; |
Junio C Hamano | 6534703 | 2008-08-03 17:47:16 -0700 | [diff] [blame] | 3041 | |
Junio C Hamano | 6546b59 | 2008-07-31 01:17:41 -0700 | [diff] [blame] | 3042 | /* feed the list reversed */ |
| 3043 | yet_to_do = NULL; |
Junio C Hamano | ab9d75a | 2012-06-08 14:50:22 -0700 | [diff] [blame] | 3044 | for (list = revs->commits; list; list = next) { |
| 3045 | commit = list->item; |
| 3046 | next = list->next; |
| 3047 | /* |
| 3048 | * Do not free(list) here yet; the original list |
| 3049 | * is used later in this function. |
| 3050 | */ |
| 3051 | commit_list_insert(commit, &yet_to_do); |
| 3052 | } |
Junio C Hamano | 6546b59 | 2008-07-31 01:17:41 -0700 | [diff] [blame] | 3053 | while (yet_to_do) { |
| 3054 | list = yet_to_do; |
| 3055 | yet_to_do = NULL; |
| 3056 | tail = &yet_to_do; |
| 3057 | while (list) { |
René Scharfe | e510ab8 | 2015-10-24 18:21:31 +0200 | [diff] [blame] | 3058 | commit = pop_commit(&list); |
Junio C Hamano | faf0156 | 2008-08-14 10:59:44 -0700 | [diff] [blame] | 3059 | tail = simplify_one(revs, commit, tail); |
Junio C Hamano | 6546b59 | 2008-07-31 01:17:41 -0700 | [diff] [blame] | 3060 | } |
| 3061 | } |
| 3062 | |
| 3063 | /* clean up the result, removing the simplified ones */ |
| 3064 | list = revs->commits; |
| 3065 | revs->commits = NULL; |
| 3066 | tail = &revs->commits; |
| 3067 | while (list) { |
Junio C Hamano | faf0156 | 2008-08-14 10:59:44 -0700 | [diff] [blame] | 3068 | struct merge_simplify_state *st; |
Junio C Hamano | ab9d75a | 2012-06-08 14:50:22 -0700 | [diff] [blame] | 3069 | |
René Scharfe | e510ab8 | 2015-10-24 18:21:31 +0200 | [diff] [blame] | 3070 | commit = pop_commit(&list); |
Junio C Hamano | faf0156 | 2008-08-14 10:59:44 -0700 | [diff] [blame] | 3071 | st = locate_simplify_state(revs, commit); |
| 3072 | if (st->simplified == commit) |
Junio C Hamano | 6546b59 | 2008-07-31 01:17:41 -0700 | [diff] [blame] | 3073 | tail = &commit_list_insert(commit, tail)->next; |
| 3074 | } |
Junio C Hamano | 6546b59 | 2008-07-31 01:17:41 -0700 | [diff] [blame] | 3075 | } |
| 3076 | |
Junio C Hamano | f35f560 | 2008-04-03 02:12:06 -0700 | [diff] [blame] | 3077 | static void set_children(struct rev_info *revs) |
| 3078 | { |
| 3079 | struct commit_list *l; |
| 3080 | for (l = revs->commits; l; l = l->next) { |
| 3081 | struct commit *commit = l->item; |
| 3082 | struct commit_list *p; |
| 3083 | |
| 3084 | for (p = commit->parents; p; p = p->next) |
| 3085 | add_child(revs, p->item, commit); |
| 3086 | } |
| 3087 | } |
| 3088 | |
Heiko Voigt | bcc0a3e | 2012-03-29 09:21:21 +0200 | [diff] [blame] | 3089 | void reset_revision_walk(void) |
| 3090 | { |
| 3091 | clear_object_flags(SEEN | ADDED | SHOWN); |
| 3092 | } |
| 3093 | |
Jonathan Tan | df11e19 | 2017-12-08 15:27:15 +0000 | [diff] [blame] | 3094 | static int mark_uninteresting(const struct object_id *oid, |
| 3095 | struct packed_git *pack, |
| 3096 | uint32_t pos, |
Nguyễn Thái Ngọc Duy | b3c7eef | 2018-09-21 17:57:39 +0200 | [diff] [blame] | 3097 | void *cb) |
Jonathan Tan | df11e19 | 2017-12-08 15:27:15 +0000 | [diff] [blame] | 3098 | { |
Nguyễn Thái Ngọc Duy | b3c7eef | 2018-09-21 17:57:39 +0200 | [diff] [blame] | 3099 | struct rev_info *revs = cb; |
| 3100 | struct object *o = parse_object(revs->repo, oid); |
Jonathan Tan | df11e19 | 2017-12-08 15:27:15 +0000 | [diff] [blame] | 3101 | o->flags |= UNINTERESTING | SEEN; |
| 3102 | return 0; |
| 3103 | } |
| 3104 | |
Derrick Stolee | b454241 | 2018-11-01 13:46:22 +0000 | [diff] [blame] | 3105 | define_commit_slab(indegree_slab, int); |
| 3106 | define_commit_slab(author_date_slab, timestamp_t); |
| 3107 | |
| 3108 | struct topo_walk_info { |
| 3109 | uint32_t min_generation; |
| 3110 | struct prio_queue explore_queue; |
| 3111 | struct prio_queue indegree_queue; |
| 3112 | struct prio_queue topo_queue; |
| 3113 | struct indegree_slab indegree; |
| 3114 | struct author_date_slab author_date; |
| 3115 | }; |
| 3116 | |
| 3117 | static inline void test_flag_and_insert(struct prio_queue *q, struct commit *c, int flag) |
| 3118 | { |
| 3119 | if (c->object.flags & flag) |
| 3120 | return; |
| 3121 | |
| 3122 | c->object.flags |= flag; |
| 3123 | prio_queue_put(q, c); |
| 3124 | } |
| 3125 | |
| 3126 | static void explore_walk_step(struct rev_info *revs) |
| 3127 | { |
| 3128 | struct topo_walk_info *info = revs->topo_walk_info; |
| 3129 | struct commit_list *p; |
| 3130 | struct commit *c = prio_queue_get(&info->explore_queue); |
| 3131 | |
| 3132 | if (!c) |
| 3133 | return; |
| 3134 | |
| 3135 | if (parse_commit_gently(c, 1) < 0) |
| 3136 | return; |
| 3137 | |
| 3138 | if (revs->sort_order == REV_SORT_BY_AUTHOR_DATE) |
| 3139 | record_author_date(&info->author_date, c); |
| 3140 | |
| 3141 | if (revs->max_age != -1 && (c->date < revs->max_age)) |
| 3142 | c->object.flags |= UNINTERESTING; |
| 3143 | |
| 3144 | if (process_parents(revs, c, NULL, NULL) < 0) |
| 3145 | return; |
| 3146 | |
| 3147 | if (c->object.flags & UNINTERESTING) |
| 3148 | mark_parents_uninteresting(c); |
| 3149 | |
| 3150 | for (p = c->parents; p; p = p->next) |
| 3151 | test_flag_and_insert(&info->explore_queue, p->item, TOPO_WALK_EXPLORED); |
| 3152 | } |
| 3153 | |
| 3154 | static void explore_to_depth(struct rev_info *revs, |
| 3155 | uint32_t gen_cutoff) |
| 3156 | { |
| 3157 | struct topo_walk_info *info = revs->topo_walk_info; |
| 3158 | struct commit *c; |
| 3159 | while ((c = prio_queue_peek(&info->explore_queue)) && |
| 3160 | c->generation >= gen_cutoff) |
| 3161 | explore_walk_step(revs); |
| 3162 | } |
| 3163 | |
| 3164 | static void indegree_walk_step(struct rev_info *revs) |
| 3165 | { |
| 3166 | struct commit_list *p; |
| 3167 | struct topo_walk_info *info = revs->topo_walk_info; |
| 3168 | struct commit *c = prio_queue_get(&info->indegree_queue); |
| 3169 | |
| 3170 | if (!c) |
| 3171 | return; |
| 3172 | |
| 3173 | if (parse_commit_gently(c, 1) < 0) |
| 3174 | return; |
| 3175 | |
| 3176 | explore_to_depth(revs, c->generation); |
| 3177 | |
| 3178 | for (p = c->parents; p; p = p->next) { |
| 3179 | struct commit *parent = p->item; |
| 3180 | int *pi = indegree_slab_at(&info->indegree, parent); |
| 3181 | |
| 3182 | if (*pi) |
| 3183 | (*pi)++; |
| 3184 | else |
| 3185 | *pi = 2; |
| 3186 | |
| 3187 | test_flag_and_insert(&info->indegree_queue, parent, TOPO_WALK_INDEGREE); |
| 3188 | |
| 3189 | if (revs->first_parent_only) |
| 3190 | return; |
| 3191 | } |
| 3192 | } |
| 3193 | |
| 3194 | static void compute_indegrees_to_depth(struct rev_info *revs, |
| 3195 | uint32_t gen_cutoff) |
| 3196 | { |
| 3197 | struct topo_walk_info *info = revs->topo_walk_info; |
| 3198 | struct commit *c; |
| 3199 | while ((c = prio_queue_peek(&info->indegree_queue)) && |
| 3200 | c->generation >= gen_cutoff) |
| 3201 | indegree_walk_step(revs); |
| 3202 | } |
Derrick Stolee | f0d9cc4 | 2018-11-01 13:46:20 +0000 | [diff] [blame] | 3203 | |
| 3204 | static void init_topo_walk(struct rev_info *revs) |
| 3205 | { |
| 3206 | struct topo_walk_info *info; |
Derrick Stolee | b454241 | 2018-11-01 13:46:22 +0000 | [diff] [blame] | 3207 | struct commit_list *list; |
Derrick Stolee | f0d9cc4 | 2018-11-01 13:46:20 +0000 | [diff] [blame] | 3208 | revs->topo_walk_info = xmalloc(sizeof(struct topo_walk_info)); |
| 3209 | info = revs->topo_walk_info; |
| 3210 | memset(info, 0, sizeof(struct topo_walk_info)); |
| 3211 | |
Derrick Stolee | b454241 | 2018-11-01 13:46:22 +0000 | [diff] [blame] | 3212 | init_indegree_slab(&info->indegree); |
| 3213 | memset(&info->explore_queue, 0, sizeof(info->explore_queue)); |
| 3214 | memset(&info->indegree_queue, 0, sizeof(info->indegree_queue)); |
| 3215 | memset(&info->topo_queue, 0, sizeof(info->topo_queue)); |
| 3216 | |
| 3217 | switch (revs->sort_order) { |
| 3218 | default: /* REV_SORT_IN_GRAPH_ORDER */ |
| 3219 | info->topo_queue.compare = NULL; |
| 3220 | break; |
| 3221 | case REV_SORT_BY_COMMIT_DATE: |
| 3222 | info->topo_queue.compare = compare_commits_by_commit_date; |
| 3223 | break; |
| 3224 | case REV_SORT_BY_AUTHOR_DATE: |
| 3225 | init_author_date_slab(&info->author_date); |
| 3226 | info->topo_queue.compare = compare_commits_by_author_date; |
| 3227 | info->topo_queue.cb_data = &info->author_date; |
| 3228 | break; |
| 3229 | } |
| 3230 | |
| 3231 | info->explore_queue.compare = compare_commits_by_gen_then_commit_date; |
| 3232 | info->indegree_queue.compare = compare_commits_by_gen_then_commit_date; |
| 3233 | |
| 3234 | info->min_generation = GENERATION_NUMBER_INFINITY; |
| 3235 | for (list = revs->commits; list; list = list->next) { |
| 3236 | struct commit *c = list->item; |
| 3237 | |
| 3238 | if (parse_commit_gently(c, 1)) |
| 3239 | continue; |
| 3240 | |
| 3241 | test_flag_and_insert(&info->explore_queue, c, TOPO_WALK_EXPLORED); |
| 3242 | test_flag_and_insert(&info->indegree_queue, c, TOPO_WALK_INDEGREE); |
| 3243 | |
| 3244 | if (c->generation < info->min_generation) |
| 3245 | info->min_generation = c->generation; |
| 3246 | |
| 3247 | *(indegree_slab_at(&info->indegree, c)) = 1; |
| 3248 | |
| 3249 | if (revs->sort_order == REV_SORT_BY_AUTHOR_DATE) |
| 3250 | record_author_date(&info->author_date, c); |
| 3251 | } |
| 3252 | compute_indegrees_to_depth(revs, info->min_generation); |
| 3253 | |
| 3254 | for (list = revs->commits; list; list = list->next) { |
| 3255 | struct commit *c = list->item; |
| 3256 | |
| 3257 | if (*(indegree_slab_at(&info->indegree, c)) == 1) |
| 3258 | prio_queue_put(&info->topo_queue, c); |
| 3259 | } |
| 3260 | |
| 3261 | /* |
| 3262 | * This is unfortunate; the initial tips need to be shown |
| 3263 | * in the order given from the revision traversal machinery. |
| 3264 | */ |
| 3265 | if (revs->sort_order == REV_SORT_IN_GRAPH_ORDER) |
| 3266 | prio_queue_reverse(&info->topo_queue); |
Derrick Stolee | f0d9cc4 | 2018-11-01 13:46:20 +0000 | [diff] [blame] | 3267 | } |
| 3268 | |
| 3269 | static struct commit *next_topo_commit(struct rev_info *revs) |
| 3270 | { |
Derrick Stolee | b454241 | 2018-11-01 13:46:22 +0000 | [diff] [blame] | 3271 | struct commit *c; |
| 3272 | struct topo_walk_info *info = revs->topo_walk_info; |
| 3273 | |
| 3274 | /* pop next off of topo_queue */ |
| 3275 | c = prio_queue_get(&info->topo_queue); |
| 3276 | |
| 3277 | if (c) |
| 3278 | *(indegree_slab_at(&info->indegree, c)) = 0; |
| 3279 | |
| 3280 | return c; |
Derrick Stolee | f0d9cc4 | 2018-11-01 13:46:20 +0000 | [diff] [blame] | 3281 | } |
| 3282 | |
| 3283 | static void expand_topo_walk(struct rev_info *revs, struct commit *commit) |
| 3284 | { |
Derrick Stolee | b454241 | 2018-11-01 13:46:22 +0000 | [diff] [blame] | 3285 | struct commit_list *p; |
| 3286 | struct topo_walk_info *info = revs->topo_walk_info; |
| 3287 | if (process_parents(revs, commit, NULL, NULL) < 0) { |
Derrick Stolee | f0d9cc4 | 2018-11-01 13:46:20 +0000 | [diff] [blame] | 3288 | if (!revs->ignore_missing_links) |
| 3289 | die("Failed to traverse parents of commit %s", |
| 3290 | oid_to_hex(&commit->object.oid)); |
| 3291 | } |
Derrick Stolee | b454241 | 2018-11-01 13:46:22 +0000 | [diff] [blame] | 3292 | |
| 3293 | for (p = commit->parents; p; p = p->next) { |
| 3294 | struct commit *parent = p->item; |
| 3295 | int *pi; |
| 3296 | |
Derrick Stolee | 1d8e31a | 2019-05-21 09:59:53 -0400 | [diff] [blame] | 3297 | if (parent->object.flags & UNINTERESTING) |
| 3298 | continue; |
| 3299 | |
Derrick Stolee | b454241 | 2018-11-01 13:46:22 +0000 | [diff] [blame] | 3300 | if (parse_commit_gently(parent, 1) < 0) |
| 3301 | continue; |
| 3302 | |
| 3303 | if (parent->generation < info->min_generation) { |
| 3304 | info->min_generation = parent->generation; |
| 3305 | compute_indegrees_to_depth(revs, info->min_generation); |
| 3306 | } |
| 3307 | |
| 3308 | pi = indegree_slab_at(&info->indegree, parent); |
| 3309 | |
| 3310 | (*pi)--; |
| 3311 | if (*pi == 1) |
| 3312 | prio_queue_put(&info->topo_queue, parent); |
| 3313 | |
| 3314 | if (revs->first_parent_only) |
| 3315 | return; |
| 3316 | } |
Derrick Stolee | f0d9cc4 | 2018-11-01 13:46:20 +0000 | [diff] [blame] | 3317 | } |
| 3318 | |
Alex Riesen | cc0e6c5 | 2007-05-04 23:54:57 +0200 | [diff] [blame] | 3319 | int prepare_revision_walk(struct rev_info *revs) |
Linus Torvalds | a4a88b2 | 2006-02-28 11:24:00 -0800 | [diff] [blame] | 3320 | { |
Jeff King | 1da1e07 | 2014-10-15 18:35:12 -0400 | [diff] [blame] | 3321 | int i; |
| 3322 | struct object_array old_pending; |
René Scharfe | 2e7da8e | 2012-04-25 22:35:41 +0200 | [diff] [blame] | 3323 | struct commit_list **next = &revs->commits; |
Linus Torvalds | cd2bdc5 | 2006-04-14 16:52:13 -0700 | [diff] [blame] | 3324 | |
Jeff King | 1da1e07 | 2014-10-15 18:35:12 -0400 | [diff] [blame] | 3325 | memcpy(&old_pending, &revs->pending, sizeof(old_pending)); |
Linus Torvalds | 1f1e895 | 2006-06-19 17:42:35 -0700 | [diff] [blame] | 3326 | revs->pending.nr = 0; |
| 3327 | revs->pending.alloc = 0; |
| 3328 | revs->pending.objects = NULL; |
Jeff King | 1da1e07 | 2014-10-15 18:35:12 -0400 | [diff] [blame] | 3329 | for (i = 0; i < old_pending.nr; i++) { |
| 3330 | struct object_array_entry *e = old_pending.objects + i; |
Jeff King | 2073949 | 2014-10-15 18:43:19 -0400 | [diff] [blame] | 3331 | struct commit *commit = handle_commit(revs, e); |
Linus Torvalds | cd2bdc5 | 2006-04-14 16:52:13 -0700 | [diff] [blame] | 3332 | if (commit) { |
| 3333 | if (!(commit->object.flags & SEEN)) { |
| 3334 | commit->object.flags |= SEEN; |
René Scharfe | 2e7da8e | 2012-04-25 22:35:41 +0200 | [diff] [blame] | 3335 | next = commit_list_append(commit, next); |
Linus Torvalds | cd2bdc5 | 2006-04-14 16:52:13 -0700 | [diff] [blame] | 3336 | } |
| 3337 | } |
Linus Torvalds | cd2bdc5 | 2006-04-14 16:52:13 -0700 | [diff] [blame] | 3338 | } |
René Scharfe | f1230fb | 2017-12-25 18:47:51 +0100 | [diff] [blame] | 3339 | object_array_clear(&old_pending); |
Linus Torvalds | cd2bdc5 | 2006-04-14 16:52:13 -0700 | [diff] [blame] | 3340 | |
Kevin Bracey | d0af663 | 2013-05-16 18:32:34 +0300 | [diff] [blame] | 3341 | /* Signal whether we need per-parent treesame decoration */ |
Kevin Bracey | 4d82660 | 2013-05-16 18:32:39 +0300 | [diff] [blame] | 3342 | if (revs->simplify_merges || |
| 3343 | (revs->limited && limiting_can_increase_treesame(revs))) |
Kevin Bracey | d0af663 | 2013-05-16 18:32:34 +0300 | [diff] [blame] | 3344 | revs->treesame.name = "treesame"; |
| 3345 | |
Jonathan Tan | df11e19 | 2017-12-08 15:27:15 +0000 | [diff] [blame] | 3346 | if (revs->exclude_promisor_objects) { |
Nguyễn Thái Ngọc Duy | b3c7eef | 2018-09-21 17:57:39 +0200 | [diff] [blame] | 3347 | for_each_packed_object(mark_uninteresting, revs, |
Jonathan Tan | df11e19 | 2017-12-08 15:27:15 +0000 | [diff] [blame] | 3348 | FOR_EACH_OBJECT_PROMISOR_ONLY); |
| 3349 | } |
| 3350 | |
Martin von Zweigbergk | ca92e59 | 2012-08-28 23:15:54 -0700 | [diff] [blame] | 3351 | if (revs->no_walk != REVISION_WALK_NO_WALK_UNSORTED) |
| 3352 | commit_list_sort_by_date(&revs->commits); |
Linus Torvalds | ba1d450 | 2006-04-15 12:09:56 -0700 | [diff] [blame] | 3353 | if (revs->no_walk) |
Alex Riesen | cc0e6c5 | 2007-05-04 23:54:57 +0200 | [diff] [blame] | 3354 | return 0; |
Derrick Stolee | f0d9cc4 | 2018-11-01 13:46:20 +0000 | [diff] [blame] | 3355 | if (revs->limited) { |
Alex Riesen | cc0e6c5 | 2007-05-04 23:54:57 +0200 | [diff] [blame] | 3356 | if (limit_list(revs) < 0) |
| 3357 | return -1; |
Derrick Stolee | f0d9cc4 | 2018-11-01 13:46:20 +0000 | [diff] [blame] | 3358 | if (revs->topo_order) |
| 3359 | sort_in_topological_order(&revs->commits, revs->sort_order); |
| 3360 | } else if (revs->topo_order) |
| 3361 | init_topo_walk(revs); |
Thomas Rast | 12da1d1 | 2013-03-28 17:47:32 +0100 | [diff] [blame] | 3362 | if (revs->line_level_traverse) |
| 3363 | line_log_filter(revs); |
Junio C Hamano | 6546b59 | 2008-07-31 01:17:41 -0700 | [diff] [blame] | 3364 | if (revs->simplify_merges) |
| 3365 | simplify_merges(revs); |
Junio C Hamano | f35f560 | 2008-04-03 02:12:06 -0700 | [diff] [blame] | 3366 | if (revs->children.name) |
| 3367 | set_children(revs); |
Alex Riesen | cc0e6c5 | 2007-05-04 23:54:57 +0200 | [diff] [blame] | 3368 | return 0; |
Linus Torvalds | a4a88b2 | 2006-02-28 11:24:00 -0800 | [diff] [blame] | 3369 | } |
| 3370 | |
Jeff King | 8320b1d | 2019-04-03 21:41:09 -0400 | [diff] [blame] | 3371 | static enum rewrite_result rewrite_one_1(struct rev_info *revs, |
| 3372 | struct commit **pp, |
| 3373 | struct prio_queue *queue) |
Linus Torvalds | a4a88b2 | 2006-02-28 11:24:00 -0800 | [diff] [blame] | 3374 | { |
Linus Torvalds | 765ac8e | 2006-02-28 15:07:20 -0800 | [diff] [blame] | 3375 | for (;;) { |
| 3376 | struct commit *p = *pp; |
Linus Torvalds | 3381c79 | 2006-04-08 17:05:58 -0700 | [diff] [blame] | 3377 | if (!revs->limited) |
Jeff King | 8320b1d | 2019-04-03 21:41:09 -0400 | [diff] [blame] | 3378 | if (process_parents(revs, p, NULL, queue) < 0) |
Alex Riesen | cc0e6c5 | 2007-05-04 23:54:57 +0200 | [diff] [blame] | 3379 | return rewrite_one_error; |
Linus Torvalds | 7dc0fe3 | 2007-11-12 23:16:08 -0800 | [diff] [blame] | 3380 | if (p->object.flags & UNINTERESTING) |
| 3381 | return rewrite_one_ok; |
| 3382 | if (!(p->object.flags & TREESAME)) |
Alex Riesen | cc0e6c5 | 2007-05-04 23:54:57 +0200 | [diff] [blame] | 3383 | return rewrite_one_ok; |
Linus Torvalds | 765ac8e | 2006-02-28 15:07:20 -0800 | [diff] [blame] | 3384 | if (!p->parents) |
Alex Riesen | cc0e6c5 | 2007-05-04 23:54:57 +0200 | [diff] [blame] | 3385 | return rewrite_one_noparents; |
Kevin Bracey | 4d82660 | 2013-05-16 18:32:39 +0300 | [diff] [blame] | 3386 | if ((p = one_relevant_parent(revs, p->parents)) == NULL) |
| 3387 | return rewrite_one_ok; |
| 3388 | *pp = p; |
Linus Torvalds | 765ac8e | 2006-02-28 15:07:20 -0800 | [diff] [blame] | 3389 | } |
Linus Torvalds | a4a88b2 | 2006-02-28 11:24:00 -0800 | [diff] [blame] | 3390 | } |
| 3391 | |
Jeff King | 8320b1d | 2019-04-03 21:41:09 -0400 | [diff] [blame] | 3392 | static void merge_queue_into_list(struct prio_queue *q, struct commit_list **list) |
| 3393 | { |
| 3394 | while (q->nr) { |
| 3395 | struct commit *item = prio_queue_peek(q); |
| 3396 | struct commit_list *p = *list; |
| 3397 | |
| 3398 | if (p && p->item->date >= item->date) |
| 3399 | list = &p->next; |
| 3400 | else { |
| 3401 | p = commit_list_insert(item, list); |
| 3402 | list = &p->next; /* skip newly added item */ |
| 3403 | prio_queue_get(q); /* pop item */ |
| 3404 | } |
| 3405 | } |
| 3406 | } |
| 3407 | |
| 3408 | static enum rewrite_result rewrite_one(struct rev_info *revs, struct commit **pp) |
| 3409 | { |
| 3410 | struct prio_queue queue = { compare_commits_by_commit_date }; |
| 3411 | enum rewrite_result ret = rewrite_one_1(revs, pp, &queue); |
| 3412 | merge_queue_into_list(&queue, &revs->commits); |
| 3413 | clear_prio_queue(&queue); |
| 3414 | return ret; |
| 3415 | } |
| 3416 | |
Bo Yang | c7edcae | 2013-03-28 17:47:31 +0100 | [diff] [blame] | 3417 | int rewrite_parents(struct rev_info *revs, struct commit *commit, |
| 3418 | rewrite_parent_fn_t rewrite_parent) |
Linus Torvalds | 765ac8e | 2006-02-28 15:07:20 -0800 | [diff] [blame] | 3419 | { |
| 3420 | struct commit_list **pp = &commit->parents; |
| 3421 | while (*pp) { |
| 3422 | struct commit_list *parent = *pp; |
Bo Yang | c7edcae | 2013-03-28 17:47:31 +0100 | [diff] [blame] | 3423 | switch (rewrite_parent(revs, &parent->item)) { |
Alex Riesen | cc0e6c5 | 2007-05-04 23:54:57 +0200 | [diff] [blame] | 3424 | case rewrite_one_ok: |
| 3425 | break; |
| 3426 | case rewrite_one_noparents: |
Linus Torvalds | 765ac8e | 2006-02-28 15:07:20 -0800 | [diff] [blame] | 3427 | *pp = parent->next; |
| 3428 | continue; |
Alex Riesen | cc0e6c5 | 2007-05-04 23:54:57 +0200 | [diff] [blame] | 3429 | case rewrite_one_error: |
| 3430 | return -1; |
Linus Torvalds | 765ac8e | 2006-02-28 15:07:20 -0800 | [diff] [blame] | 3431 | } |
| 3432 | pp = &parent->next; |
| 3433 | } |
Kevin Bracey | d0af663 | 2013-05-16 18:32:34 +0300 | [diff] [blame] | 3434 | remove_duplicate_parents(revs, commit); |
Alex Riesen | cc0e6c5 | 2007-05-04 23:54:57 +0200 | [diff] [blame] | 3435 | return 0; |
Linus Torvalds | 765ac8e | 2006-02-28 15:07:20 -0800 | [diff] [blame] | 3436 | } |
Linus Torvalds | a4a88b2 | 2006-02-28 11:24:00 -0800 | [diff] [blame] | 3437 | |
Antoine Pelisse | d72fbe8 | 2013-01-05 22:26:45 +0100 | [diff] [blame] | 3438 | static int commit_rewrite_person(struct strbuf *buf, const char *what, struct string_list *mailmap) |
| 3439 | { |
| 3440 | char *person, *endp; |
| 3441 | size_t len, namelen, maillen; |
| 3442 | const char *name; |
| 3443 | const char *mail; |
| 3444 | struct ident_split ident; |
| 3445 | |
| 3446 | person = strstr(buf->buf, what); |
| 3447 | if (!person) |
| 3448 | return 0; |
| 3449 | |
| 3450 | person += strlen(what); |
| 3451 | endp = strchr(person, '\n'); |
| 3452 | if (!endp) |
| 3453 | return 0; |
| 3454 | |
| 3455 | len = endp - person; |
| 3456 | |
| 3457 | if (split_ident_line(&ident, person, len)) |
| 3458 | return 0; |
| 3459 | |
| 3460 | mail = ident.mail_begin; |
| 3461 | maillen = ident.mail_end - ident.mail_begin; |
| 3462 | name = ident.name_begin; |
| 3463 | namelen = ident.name_end - ident.name_begin; |
| 3464 | |
| 3465 | if (map_user(mailmap, &mail, &maillen, &name, &namelen)) { |
| 3466 | struct strbuf namemail = STRBUF_INIT; |
| 3467 | |
| 3468 | strbuf_addf(&namemail, "%.*s <%.*s>", |
| 3469 | (int)namelen, name, (int)maillen, mail); |
| 3470 | |
| 3471 | strbuf_splice(buf, ident.name_begin - buf->buf, |
| 3472 | ident.mail_end - ident.name_begin + 1, |
| 3473 | namemail.buf, namemail.len); |
| 3474 | |
| 3475 | strbuf_release(&namemail); |
| 3476 | |
| 3477 | return 1; |
| 3478 | } |
| 3479 | |
| 3480 | return 0; |
| 3481 | } |
| 3482 | |
Junio C Hamano | 8ecae9b | 2006-09-17 15:43:40 -0700 | [diff] [blame] | 3483 | static int commit_match(struct commit *commit, struct rev_info *opt) |
| 3484 | { |
Nguyễn Thái Ngọc Duy | 72fd13f | 2012-09-29 11:41:28 +0700 | [diff] [blame] | 3485 | int retval; |
Jeff King | 04deccd | 2013-02-11 15:59:58 -0500 | [diff] [blame] | 3486 | const char *encoding; |
Jeff King | b000c59 | 2014-06-10 17:39:30 -0400 | [diff] [blame] | 3487 | const char *message; |
Nguyễn Thái Ngọc Duy | 72fd13f | 2012-09-29 11:41:28 +0700 | [diff] [blame] | 3488 | struct strbuf buf = STRBUF_INIT; |
Jeff King | 04deccd | 2013-02-11 15:59:58 -0500 | [diff] [blame] | 3489 | |
Junio C Hamano | 80235ba | 2010-01-17 20:09:06 -0800 | [diff] [blame] | 3490 | if (!opt->grep_filter.pattern_list && !opt->grep_filter.header_list) |
Junio C Hamano | 8ecae9b | 2006-09-17 15:43:40 -0700 | [diff] [blame] | 3491 | return 1; |
Junio C Hamano | baa6378 | 2012-09-29 11:59:52 -0700 | [diff] [blame] | 3492 | |
| 3493 | /* Prepend "fake" headers as needed */ |
| 3494 | if (opt->grep_filter.use_reflog_filter) { |
Nguyễn Thái Ngọc Duy | 72fd13f | 2012-09-29 11:41:28 +0700 | [diff] [blame] | 3495 | strbuf_addstr(&buf, "reflog "); |
| 3496 | get_reflog_message(&buf, opt->reflog_info); |
| 3497 | strbuf_addch(&buf, '\n'); |
Nguyễn Thái Ngọc Duy | 72fd13f | 2012-09-29 11:41:28 +0700 | [diff] [blame] | 3498 | } |
Junio C Hamano | baa6378 | 2012-09-29 11:59:52 -0700 | [diff] [blame] | 3499 | |
Jeff King | 04deccd | 2013-02-11 15:59:58 -0500 | [diff] [blame] | 3500 | /* |
| 3501 | * We grep in the user's output encoding, under the assumption that it |
| 3502 | * is the encoding they are most likely to write their grep pattern |
| 3503 | * for. In addition, it means we will match the "notes" encoding below, |
| 3504 | * so we will not end up with a buffer that has two different encodings |
| 3505 | * in it. |
| 3506 | */ |
| 3507 | encoding = get_log_output_encoding(); |
Nguyễn Thái Ngọc Duy | 5a10d23 | 2013-04-19 09:08:40 +1000 | [diff] [blame] | 3508 | message = logmsg_reencode(commit, NULL, encoding); |
Jeff King | 04deccd | 2013-02-11 15:59:58 -0500 | [diff] [blame] | 3509 | |
Junio C Hamano | baa6378 | 2012-09-29 11:59:52 -0700 | [diff] [blame] | 3510 | /* Copy the commit to temporary if we are using "fake" headers */ |
| 3511 | if (buf.len) |
Jeff King | 04deccd | 2013-02-11 15:59:58 -0500 | [diff] [blame] | 3512 | strbuf_addstr(&buf, message); |
Junio C Hamano | baa6378 | 2012-09-29 11:59:52 -0700 | [diff] [blame] | 3513 | |
Junio C Hamano | df874fa | 2013-01-08 00:02:49 -0800 | [diff] [blame] | 3514 | if (opt->grep_filter.header_list && opt->mailmap) { |
Antoine Pelisse | d72fbe8 | 2013-01-05 22:26:45 +0100 | [diff] [blame] | 3515 | if (!buf.len) |
Jeff King | 04deccd | 2013-02-11 15:59:58 -0500 | [diff] [blame] | 3516 | strbuf_addstr(&buf, message); |
Antoine Pelisse | d72fbe8 | 2013-01-05 22:26:45 +0100 | [diff] [blame] | 3517 | |
| 3518 | commit_rewrite_person(&buf, "\nauthor ", opt->mailmap); |
| 3519 | commit_rewrite_person(&buf, "\ncommitter ", opt->mailmap); |
| 3520 | } |
| 3521 | |
Nguyễn Thái Ngọc Duy | 38cfe91 | 2012-09-29 11:41:29 +0700 | [diff] [blame] | 3522 | /* Append "fake" message parts as needed */ |
| 3523 | if (opt->show_notes) { |
| 3524 | if (!buf.len) |
Jeff King | 04deccd | 2013-02-11 15:59:58 -0500 | [diff] [blame] | 3525 | strbuf_addstr(&buf, message); |
brian m. carlson | fb61e4d | 2017-05-30 10:30:41 -0700 | [diff] [blame] | 3526 | format_display_notes(&commit->object.oid, &buf, encoding, 1); |
Nguyễn Thái Ngọc Duy | 38cfe91 | 2012-09-29 11:41:29 +0700 | [diff] [blame] | 3527 | } |
| 3528 | |
Jeff King | b000c59 | 2014-06-10 17:39:30 -0400 | [diff] [blame] | 3529 | /* |
| 3530 | * Find either in the original commit message, or in the temporary. |
| 3531 | * Note that we cast away the constness of "message" here. It is |
| 3532 | * const because it may come from the cached commit buffer. That's OK, |
| 3533 | * because we know that it is modifiable heap memory, and that while |
| 3534 | * grep_buffer may modify it for speed, it will restore any |
| 3535 | * changes before returning. |
| 3536 | */ |
Nguyễn Thái Ngọc Duy | 72fd13f | 2012-09-29 11:41:28 +0700 | [diff] [blame] | 3537 | if (buf.len) |
| 3538 | retval = grep_buffer(&opt->grep_filter, buf.buf, buf.len); |
| 3539 | else |
| 3540 | retval = grep_buffer(&opt->grep_filter, |
Jeff King | b000c59 | 2014-06-10 17:39:30 -0400 | [diff] [blame] | 3541 | (char *)message, strlen(message)); |
Nguyễn Thái Ngọc Duy | 72fd13f | 2012-09-29 11:41:28 +0700 | [diff] [blame] | 3542 | strbuf_release(&buf); |
Jeff King | b66103c | 2014-06-10 17:41:39 -0400 | [diff] [blame] | 3543 | unuse_commit_buffer(commit, message); |
Christoph Junghans | 22dfa8a | 2015-01-12 18:33:32 -0700 | [diff] [blame] | 3544 | return opt->invert_grep ? !retval : retval; |
Junio C Hamano | 8ecae9b | 2006-09-17 15:43:40 -0700 | [diff] [blame] | 3545 | } |
| 3546 | |
Thomas Rast | 53d00b3 | 2013-07-31 22:13:20 +0200 | [diff] [blame] | 3547 | static inline int want_ancestry(const struct rev_info *revs) |
Junio C Hamano | f35f560 | 2008-04-03 02:12:06 -0700 | [diff] [blame] | 3548 | { |
Junio C Hamano | 8bb6588 | 2008-07-08 15:25:44 -0700 | [diff] [blame] | 3549 | return (revs->rewrite_parents || revs->children.name); |
Junio C Hamano | f35f560 | 2008-04-03 02:12:06 -0700 | [diff] [blame] | 3550 | } |
| 3551 | |
Jeff King | de23944 | 2017-07-07 05:16:21 -0400 | [diff] [blame] | 3552 | /* |
| 3553 | * Return a timestamp to be used for --since/--until comparisons for this |
| 3554 | * commit, based on the revision options. |
| 3555 | */ |
| 3556 | static timestamp_t comparison_date(const struct rev_info *revs, |
| 3557 | struct commit *commit) |
| 3558 | { |
| 3559 | return revs->reflog_info ? |
| 3560 | get_reflog_timestamp(revs->reflog_info) : |
| 3561 | commit->date; |
| 3562 | } |
| 3563 | |
Adam Simpkins | beb5af4 | 2009-08-18 19:34:33 -0700 | [diff] [blame] | 3564 | enum commit_action get_commit_action(struct rev_info *revs, struct commit *commit) |
Linus Torvalds | 252a7c0 | 2007-11-04 12:12:05 -0800 | [diff] [blame] | 3565 | { |
| 3566 | if (commit->object.flags & SHOWN) |
| 3567 | return commit_ignore; |
brian m. carlson | 14c3c80 | 2018-05-02 00:25:33 +0000 | [diff] [blame] | 3568 | if (revs->unpacked && has_object_pack(&commit->object.oid)) |
Linus Torvalds | 252a7c0 | 2007-11-04 12:12:05 -0800 | [diff] [blame] | 3569 | return commit_ignore; |
| 3570 | if (commit->object.flags & UNINTERESTING) |
| 3571 | return commit_ignore; |
Jeff King | de23944 | 2017-07-07 05:16:21 -0400 | [diff] [blame] | 3572 | if (revs->min_age != -1 && |
| 3573 | comparison_date(revs, commit) > revs->min_age) |
| 3574 | return commit_ignore; |
Michael J Gruber | ad5aeed | 2011-03-21 11:14:06 +0100 | [diff] [blame] | 3575 | if (revs->min_parents || (revs->max_parents >= 0)) { |
Kevin Bracey | bf3418b | 2013-05-16 18:32:40 +0300 | [diff] [blame] | 3576 | int n = commit_list_count(commit->parents); |
Michael J Gruber | ad5aeed | 2011-03-21 11:14:06 +0100 | [diff] [blame] | 3577 | if ((n < revs->min_parents) || |
| 3578 | ((revs->max_parents >= 0) && (n > revs->max_parents))) |
| 3579 | return commit_ignore; |
| 3580 | } |
Linus Torvalds | 252a7c0 | 2007-11-04 12:12:05 -0800 | [diff] [blame] | 3581 | if (!commit_match(commit, revs)) |
| 3582 | return commit_ignore; |
Linus Torvalds | 53b2c82 | 2007-11-05 13:22:34 -0800 | [diff] [blame] | 3583 | if (revs->prune && revs->dense) { |
Linus Torvalds | 252a7c0 | 2007-11-04 12:12:05 -0800 | [diff] [blame] | 3584 | /* Commit without changes? */ |
Linus Torvalds | 7dc0fe3 | 2007-11-12 23:16:08 -0800 | [diff] [blame] | 3585 | if (commit->object.flags & TREESAME) { |
Kevin Bracey | bf3418b | 2013-05-16 18:32:40 +0300 | [diff] [blame] | 3586 | int n; |
| 3587 | struct commit_list *p; |
Linus Torvalds | 252a7c0 | 2007-11-04 12:12:05 -0800 | [diff] [blame] | 3588 | /* drop merges unless we want parenthood */ |
Junio C Hamano | f35f560 | 2008-04-03 02:12:06 -0700 | [diff] [blame] | 3589 | if (!want_ancestry(revs)) |
Linus Torvalds | 252a7c0 | 2007-11-04 12:12:05 -0800 | [diff] [blame] | 3590 | return commit_ignore; |
Kevin Bracey | bf3418b | 2013-05-16 18:32:40 +0300 | [diff] [blame] | 3591 | /* |
| 3592 | * If we want ancestry, then need to keep any merges |
| 3593 | * between relevant commits to tie together topology. |
| 3594 | * For consistency with TREESAME and simplification |
| 3595 | * use "relevant" here rather than just INTERESTING, |
| 3596 | * to treat bottom commit(s) as part of the topology. |
| 3597 | */ |
| 3598 | for (n = 0, p = commit->parents; p; p = p->next) |
| 3599 | if (relevant_commit(p->item)) |
| 3600 | if (++n >= 2) |
| 3601 | return commit_show; |
| 3602 | return commit_ignore; |
Linus Torvalds | 252a7c0 | 2007-11-04 12:12:05 -0800 | [diff] [blame] | 3603 | } |
Linus Torvalds | 252a7c0 | 2007-11-04 12:12:05 -0800 | [diff] [blame] | 3604 | } |
| 3605 | return commit_show; |
| 3606 | } |
| 3607 | |
Junio C Hamano | 0131c49 | 2015-01-14 14:49:24 -0800 | [diff] [blame] | 3608 | define_commit_slab(saved_parents, struct commit_list *); |
| 3609 | |
| 3610 | #define EMPTY_PARENT_LIST ((struct commit_list *)-1) |
| 3611 | |
| 3612 | /* |
| 3613 | * You may only call save_parents() once per commit (this is checked |
| 3614 | * for non-root commits). |
| 3615 | */ |
| 3616 | static void save_parents(struct rev_info *revs, struct commit *commit) |
| 3617 | { |
| 3618 | struct commit_list **pp; |
| 3619 | |
| 3620 | if (!revs->saved_parents_slab) { |
| 3621 | revs->saved_parents_slab = xmalloc(sizeof(struct saved_parents)); |
| 3622 | init_saved_parents(revs->saved_parents_slab); |
| 3623 | } |
| 3624 | |
| 3625 | pp = saved_parents_at(revs->saved_parents_slab, commit); |
| 3626 | |
| 3627 | /* |
| 3628 | * When walking with reflogs, we may visit the same commit |
| 3629 | * several times: once for each appearance in the reflog. |
| 3630 | * |
| 3631 | * In this case, save_parents() will be called multiple times. |
| 3632 | * We want to keep only the first set of parents. We need to |
| 3633 | * store a sentinel value for an empty (i.e., NULL) parent |
| 3634 | * list to distinguish it from a not-yet-saved list, however. |
| 3635 | */ |
| 3636 | if (*pp) |
| 3637 | return; |
| 3638 | if (commit->parents) |
| 3639 | *pp = copy_commit_list(commit->parents); |
| 3640 | else |
| 3641 | *pp = EMPTY_PARENT_LIST; |
| 3642 | } |
| 3643 | |
| 3644 | static void free_saved_parents(struct rev_info *revs) |
| 3645 | { |
| 3646 | if (revs->saved_parents_slab) |
| 3647 | clear_saved_parents(revs->saved_parents_slab); |
| 3648 | } |
| 3649 | |
| 3650 | struct commit_list *get_saved_parents(struct rev_info *revs, const struct commit *commit) |
| 3651 | { |
| 3652 | struct commit_list *parents; |
| 3653 | |
| 3654 | if (!revs->saved_parents_slab) |
| 3655 | return commit->parents; |
| 3656 | |
| 3657 | parents = *saved_parents_at(revs->saved_parents_slab, commit); |
| 3658 | if (parents == EMPTY_PARENT_LIST) |
| 3659 | return NULL; |
| 3660 | return parents; |
| 3661 | } |
| 3662 | |
Adam Simpkins | beb5af4 | 2009-08-18 19:34:33 -0700 | [diff] [blame] | 3663 | enum commit_action simplify_commit(struct rev_info *revs, struct commit *commit) |
| 3664 | { |
| 3665 | enum commit_action action = get_commit_action(revs, commit); |
| 3666 | |
| 3667 | if (action == commit_show && |
Adam Simpkins | beb5af4 | 2009-08-18 19:34:33 -0700 | [diff] [blame] | 3668 | revs->prune && revs->dense && want_ancestry(revs)) { |
Thomas Rast | 53d00b3 | 2013-07-31 22:13:20 +0200 | [diff] [blame] | 3669 | /* |
| 3670 | * --full-diff on simplified parents is no good: it |
| 3671 | * will show spurious changes from the commits that |
| 3672 | * were elided. So we save the parents on the side |
| 3673 | * when --full-diff is in effect. |
| 3674 | */ |
| 3675 | if (revs->full_diff) |
| 3676 | save_parents(revs, commit); |
Bo Yang | c7edcae | 2013-03-28 17:47:31 +0100 | [diff] [blame] | 3677 | if (rewrite_parents(revs, commit, rewrite_one) < 0) |
Adam Simpkins | beb5af4 | 2009-08-18 19:34:33 -0700 | [diff] [blame] | 3678 | return commit_error; |
| 3679 | } |
| 3680 | return action; |
| 3681 | } |
| 3682 | |
Nguyễn Thái Ngọc Duy | 1b32dec | 2014-03-25 20:23:27 +0700 | [diff] [blame] | 3683 | static void track_linear(struct rev_info *revs, struct commit *commit) |
| 3684 | { |
| 3685 | if (revs->track_first_time) { |
| 3686 | revs->linear = 1; |
| 3687 | revs->track_first_time = 0; |
| 3688 | } else { |
| 3689 | struct commit_list *p; |
| 3690 | for (p = revs->previous_parents; p; p = p->next) |
| 3691 | if (p->item == NULL || /* first commit */ |
Jeff King | 4a7e27e | 2018-08-28 17:22:40 -0400 | [diff] [blame] | 3692 | oideq(&p->item->object.oid, &commit->object.oid)) |
Nguyễn Thái Ngọc Duy | 1b32dec | 2014-03-25 20:23:27 +0700 | [diff] [blame] | 3693 | break; |
| 3694 | revs->linear = p != NULL; |
| 3695 | } |
| 3696 | if (revs->reverse) { |
| 3697 | if (revs->linear) |
| 3698 | commit->object.flags |= TRACK_LINEAR; |
| 3699 | } |
| 3700 | free_commit_list(revs->previous_parents); |
| 3701 | revs->previous_parents = copy_commit_list(commit->parents); |
| 3702 | } |
| 3703 | |
Junio C Hamano | d5db6c9 | 2006-12-19 18:25:32 -0800 | [diff] [blame] | 3704 | static struct commit *get_revision_1(struct rev_info *revs) |
Linus Torvalds | 765ac8e | 2006-02-28 15:07:20 -0800 | [diff] [blame] | 3705 | { |
Jeff King | 7c2f08a | 2017-07-07 05:07:58 -0400 | [diff] [blame] | 3706 | while (1) { |
Jeff King | d08565b | 2017-07-07 05:14:07 -0400 | [diff] [blame] | 3707 | struct commit *commit; |
Linus Torvalds | 765ac8e | 2006-02-28 15:07:20 -0800 | [diff] [blame] | 3708 | |
Jeff King | d08565b | 2017-07-07 05:14:07 -0400 | [diff] [blame] | 3709 | if (revs->reflog_info) |
| 3710 | commit = next_reflog_entry(revs->reflog_info); |
Derrick Stolee | f0d9cc4 | 2018-11-01 13:46:20 +0000 | [diff] [blame] | 3711 | else if (revs->topo_walk_info) |
| 3712 | commit = next_topo_commit(revs); |
Jeff King | d08565b | 2017-07-07 05:14:07 -0400 | [diff] [blame] | 3713 | else |
| 3714 | commit = pop_commit(&revs->commits); |
Linus Torvalds | 2a0925b | 2006-03-30 17:05:25 -0800 | [diff] [blame] | 3715 | |
Jeff King | 7c2f08a | 2017-07-07 05:07:58 -0400 | [diff] [blame] | 3716 | if (!commit) |
| 3717 | return NULL; |
| 3718 | |
Jeff King | d08565b | 2017-07-07 05:14:07 -0400 | [diff] [blame] | 3719 | if (revs->reflog_info) |
Jeff King | ffa1eea | 2010-11-21 23:42:53 -0500 | [diff] [blame] | 3720 | commit->object.flags &= ~(ADDED | SEEN | SHOWN); |
Johannes Schindelin | 8860fd4 | 2007-01-11 11:47:48 +0100 | [diff] [blame] | 3721 | |
Linus Torvalds | 2a0925b | 2006-03-30 17:05:25 -0800 | [diff] [blame] | 3722 | /* |
| 3723 | * If we haven't done the list limiting, we need to look at |
Linus Torvalds | be7db6e | 2006-04-01 16:35:06 -0800 | [diff] [blame] | 3724 | * the parents here. We also need to do the date-based limiting |
| 3725 | * that we'd otherwise have done in limit_list(). |
Linus Torvalds | 2a0925b | 2006-03-30 17:05:25 -0800 | [diff] [blame] | 3726 | */ |
Linus Torvalds | be7db6e | 2006-04-01 16:35:06 -0800 | [diff] [blame] | 3727 | if (!revs->limited) { |
Jan Harkes | 744f498 | 2006-10-30 20:37:49 -0500 | [diff] [blame] | 3728 | if (revs->max_age != -1 && |
Jeff King | de23944 | 2017-07-07 05:16:21 -0400 | [diff] [blame] | 3729 | comparison_date(revs, commit) < revs->max_age) |
Junio C Hamano | 86ab490 | 2007-03-05 13:10:06 -0800 | [diff] [blame] | 3730 | continue; |
Jeff King | d08565b | 2017-07-07 05:14:07 -0400 | [diff] [blame] | 3731 | |
| 3732 | if (revs->reflog_info) |
| 3733 | try_to_simplify_commit(revs, commit); |
Derrick Stolee | f0d9cc4 | 2018-11-01 13:46:20 +0000 | [diff] [blame] | 3734 | else if (revs->topo_walk_info) |
| 3735 | expand_topo_walk(revs, commit); |
Derrick Stolee | 5284fc5 | 2018-11-01 13:46:21 +0000 | [diff] [blame] | 3736 | else if (process_parents(revs, commit, &revs->commits, NULL) < 0) { |
Vicent Marti | 2db1a43 | 2014-03-28 06:00:43 -0400 | [diff] [blame] | 3737 | if (!revs->ignore_missing_links) |
| 3738 | die("Failed to traverse parents of commit %s", |
brian m. carlson | f2fd076 | 2015-11-10 02:22:28 +0000 | [diff] [blame] | 3739 | oid_to_hex(&commit->object.oid)); |
Vicent Marti | 2db1a43 | 2014-03-28 06:00:43 -0400 | [diff] [blame] | 3740 | } |
Linus Torvalds | be7db6e | 2006-04-01 16:35:06 -0800 | [diff] [blame] | 3741 | } |
Junio C Hamano | 1b65a5a | 2006-04-16 18:12:49 -0700 | [diff] [blame] | 3742 | |
Linus Torvalds | 252a7c0 | 2007-11-04 12:12:05 -0800 | [diff] [blame] | 3743 | switch (simplify_commit(revs, commit)) { |
| 3744 | case commit_ignore: |
Linus Torvalds | 2a0925b | 2006-03-30 17:05:25 -0800 | [diff] [blame] | 3745 | continue; |
Linus Torvalds | 252a7c0 | 2007-11-04 12:12:05 -0800 | [diff] [blame] | 3746 | case commit_error: |
Junio C Hamano | ed62089 | 2009-02-11 01:27:43 -0800 | [diff] [blame] | 3747 | die("Failed to simplify parents of commit %s", |
brian m. carlson | f2fd076 | 2015-11-10 02:22:28 +0000 | [diff] [blame] | 3748 | oid_to_hex(&commit->object.oid)); |
Linus Torvalds | 252a7c0 | 2007-11-04 12:12:05 -0800 | [diff] [blame] | 3749 | default: |
Nguyễn Thái Ngọc Duy | 1b32dec | 2014-03-25 20:23:27 +0700 | [diff] [blame] | 3750 | if (revs->track_linear) |
| 3751 | track_linear(revs, commit); |
Linus Torvalds | 252a7c0 | 2007-11-04 12:12:05 -0800 | [diff] [blame] | 3752 | return commit; |
Junio C Hamano | 384e99a | 2006-03-27 23:58:34 -0800 | [diff] [blame] | 3753 | } |
Jeff King | 7c2f08a | 2017-07-07 05:07:58 -0400 | [diff] [blame] | 3754 | } |
Linus Torvalds | 765ac8e | 2006-02-28 15:07:20 -0800 | [diff] [blame] | 3755 | } |
Junio C Hamano | d5db6c9 | 2006-12-19 18:25:32 -0800 | [diff] [blame] | 3756 | |
Michael Haggerty | be6754c | 2013-05-25 11:08:09 +0200 | [diff] [blame] | 3757 | /* |
| 3758 | * Return true for entries that have not yet been shown. (This is an |
| 3759 | * object_array_each_func_t.) |
| 3760 | */ |
| 3761 | static int entry_unshown(struct object_array_entry *entry, void *cb_data_unused) |
| 3762 | { |
| 3763 | return !(entry->item->flags & SHOWN); |
| 3764 | } |
| 3765 | |
| 3766 | /* |
| 3767 | * If array is on the verge of a realloc, garbage-collect any entries |
| 3768 | * that have already been shown to try to free up some space. |
| 3769 | */ |
Junio C Hamano | 86ab490 | 2007-03-05 13:10:06 -0800 | [diff] [blame] | 3770 | static void gc_boundary(struct object_array *array) |
| 3771 | { |
Michael Haggerty | be6754c | 2013-05-25 11:08:09 +0200 | [diff] [blame] | 3772 | if (array->nr == array->alloc) |
| 3773 | object_array_filter(array, entry_unshown, NULL); |
Junio C Hamano | 86ab490 | 2007-03-05 13:10:06 -0800 | [diff] [blame] | 3774 | } |
| 3775 | |
Adam Simpkins | 4603ec0 | 2008-05-24 16:02:05 -0700 | [diff] [blame] | 3776 | static void create_boundary_commit_list(struct rev_info *revs) |
| 3777 | { |
| 3778 | unsigned i; |
| 3779 | struct commit *c; |
| 3780 | struct object_array *array = &revs->boundary_commits; |
| 3781 | struct object_array_entry *objects = array->objects; |
| 3782 | |
| 3783 | /* |
| 3784 | * If revs->commits is non-NULL at this point, an error occurred in |
| 3785 | * get_revision_1(). Ignore the error and continue printing the |
| 3786 | * boundary commits anyway. (This is what the code has always |
| 3787 | * done.) |
| 3788 | */ |
| 3789 | if (revs->commits) { |
| 3790 | free_commit_list(revs->commits); |
| 3791 | revs->commits = NULL; |
| 3792 | } |
| 3793 | |
| 3794 | /* |
| 3795 | * Put all of the actual boundary commits from revs->boundary_commits |
| 3796 | * into revs->commits |
| 3797 | */ |
| 3798 | for (i = 0; i < array->nr; i++) { |
| 3799 | c = (struct commit *)(objects[i].item); |
| 3800 | if (!c) |
| 3801 | continue; |
| 3802 | if (!(c->object.flags & CHILD_SHOWN)) |
| 3803 | continue; |
| 3804 | if (c->object.flags & (SHOWN | BOUNDARY)) |
| 3805 | continue; |
| 3806 | c->object.flags |= BOUNDARY; |
| 3807 | commit_list_insert(c, &revs->commits); |
| 3808 | } |
| 3809 | |
| 3810 | /* |
| 3811 | * If revs->topo_order is set, sort the boundary commits |
| 3812 | * in topological order |
| 3813 | */ |
Junio C Hamano | 08f704f | 2013-06-06 16:07:14 -0700 | [diff] [blame] | 3814 | sort_in_topological_order(&revs->commits, revs->sort_order); |
Adam Simpkins | 4603ec0 | 2008-05-24 16:02:05 -0700 | [diff] [blame] | 3815 | } |
| 3816 | |
Adam Simpkins | 7fefda5 | 2008-05-04 03:36:54 -0700 | [diff] [blame] | 3817 | static struct commit *get_revision_internal(struct rev_info *revs) |
Junio C Hamano | d5db6c9 | 2006-12-19 18:25:32 -0800 | [diff] [blame] | 3818 | { |
| 3819 | struct commit *c = NULL; |
Junio C Hamano | 86ab490 | 2007-03-05 13:10:06 -0800 | [diff] [blame] | 3820 | struct commit_list *l; |
Junio C Hamano | d5db6c9 | 2006-12-19 18:25:32 -0800 | [diff] [blame] | 3821 | |
Junio C Hamano | 86ab490 | 2007-03-05 13:10:06 -0800 | [diff] [blame] | 3822 | if (revs->boundary == 2) { |
Adam Simpkins | 4603ec0 | 2008-05-24 16:02:05 -0700 | [diff] [blame] | 3823 | /* |
| 3824 | * All of the normal commits have already been returned, |
| 3825 | * and we are now returning boundary commits. |
| 3826 | * create_boundary_commit_list() has populated |
| 3827 | * revs->commits with the remaining commits to return. |
| 3828 | */ |
| 3829 | c = pop_commit(&revs->commits); |
| 3830 | if (c) |
| 3831 | c->object.flags |= SHOWN; |
Johannes Schindelin | 9c5e66e | 2007-01-20 23:04:02 +0100 | [diff] [blame] | 3832 | return c; |
| 3833 | } |
| 3834 | |
Junio C Hamano | 86ab490 | 2007-03-05 13:10:06 -0800 | [diff] [blame] | 3835 | /* |
Jeff King | b72a190 | 2012-07-13 03:50:23 -0400 | [diff] [blame] | 3836 | * If our max_count counter has reached zero, then we are done. We |
| 3837 | * don't simply return NULL because we still might need to show |
| 3838 | * boundary commits. But we want to avoid calling get_revision_1, which |
| 3839 | * might do a considerable amount of work finding the next commit only |
| 3840 | * for us to throw it away. |
| 3841 | * |
| 3842 | * If it is non-zero, then either we don't have a max_count at all |
| 3843 | * (-1), or it is still counting, in which case we decrement. |
Junio C Hamano | 86ab490 | 2007-03-05 13:10:06 -0800 | [diff] [blame] | 3844 | */ |
Jeff King | b72a190 | 2012-07-13 03:50:23 -0400 | [diff] [blame] | 3845 | if (revs->max_count) { |
| 3846 | c = get_revision_1(revs); |
| 3847 | if (c) { |
Felipe Contreras | 9e57ac5 | 2013-10-31 03:25:43 -0600 | [diff] [blame] | 3848 | while (revs->skip_count > 0) { |
Jeff King | b72a190 | 2012-07-13 03:50:23 -0400 | [diff] [blame] | 3849 | revs->skip_count--; |
| 3850 | c = get_revision_1(revs); |
| 3851 | if (!c) |
| 3852 | break; |
| 3853 | } |
Junio C Hamano | 8839ac9 | 2007-03-06 03:20:55 -0800 | [diff] [blame] | 3854 | } |
Junio C Hamano | 86ab490 | 2007-03-05 13:10:06 -0800 | [diff] [blame] | 3855 | |
Jeff King | b72a190 | 2012-07-13 03:50:23 -0400 | [diff] [blame] | 3856 | if (revs->max_count > 0) |
| 3857 | revs->max_count--; |
Junio C Hamano | d5db6c9 | 2006-12-19 18:25:32 -0800 | [diff] [blame] | 3858 | } |
Junio C Hamano | 86ab490 | 2007-03-05 13:10:06 -0800 | [diff] [blame] | 3859 | |
Junio C Hamano | c33d859 | 2007-03-05 18:23:57 -0800 | [diff] [blame] | 3860 | if (c) |
| 3861 | c->object.flags |= SHOWN; |
| 3862 | |
Felipe Contreras | 9e57ac5 | 2013-10-31 03:25:43 -0600 | [diff] [blame] | 3863 | if (!revs->boundary) |
Junio C Hamano | d5db6c9 | 2006-12-19 18:25:32 -0800 | [diff] [blame] | 3864 | return c; |
Junio C Hamano | 86ab490 | 2007-03-05 13:10:06 -0800 | [diff] [blame] | 3865 | |
| 3866 | if (!c) { |
| 3867 | /* |
| 3868 | * get_revision_1() runs out the commits, and |
| 3869 | * we are done computing the boundaries. |
| 3870 | * switch to boundary commits output mode. |
| 3871 | */ |
| 3872 | revs->boundary = 2; |
Adam Simpkins | 4603ec0 | 2008-05-24 16:02:05 -0700 | [diff] [blame] | 3873 | |
| 3874 | /* |
| 3875 | * Update revs->commits to contain the list of |
| 3876 | * boundary commits. |
| 3877 | */ |
| 3878 | create_boundary_commit_list(revs); |
| 3879 | |
Adam Simpkins | 3c68d67 | 2008-05-24 16:02:04 -0700 | [diff] [blame] | 3880 | return get_revision_internal(revs); |
Junio C Hamano | 86ab490 | 2007-03-05 13:10:06 -0800 | [diff] [blame] | 3881 | } |
| 3882 | |
| 3883 | /* |
| 3884 | * boundary commits are the commits that are parents of the |
| 3885 | * ones we got from get_revision_1() but they themselves are |
| 3886 | * not returned from get_revision_1(). Before returning |
| 3887 | * 'c', we need to mark its parents that they could be boundaries. |
| 3888 | */ |
| 3889 | |
| 3890 | for (l = c->parents; l; l = l->next) { |
| 3891 | struct object *p; |
| 3892 | p = &(l->item->object); |
Junio C Hamano | c33d859 | 2007-03-05 18:23:57 -0800 | [diff] [blame] | 3893 | if (p->flags & (CHILD_SHOWN | SHOWN)) |
Junio C Hamano | 86ab490 | 2007-03-05 13:10:06 -0800 | [diff] [blame] | 3894 | continue; |
| 3895 | p->flags |= CHILD_SHOWN; |
| 3896 | gc_boundary(&revs->boundary_commits); |
| 3897 | add_object_array(p, NULL, &revs->boundary_commits); |
| 3898 | } |
| 3899 | |
| 3900 | return c; |
Junio C Hamano | d5db6c9 | 2006-12-19 18:25:32 -0800 | [diff] [blame] | 3901 | } |
Adam Simpkins | 7fefda5 | 2008-05-04 03:36:54 -0700 | [diff] [blame] | 3902 | |
| 3903 | struct commit *get_revision(struct rev_info *revs) |
| 3904 | { |
Thomas Rast | 498bcd3 | 2008-08-29 21:18:38 +0200 | [diff] [blame] | 3905 | struct commit *c; |
| 3906 | struct commit_list *reversed; |
| 3907 | |
| 3908 | if (revs->reverse) { |
| 3909 | reversed = NULL; |
Felipe Contreras | 9e57ac5 | 2013-10-31 03:25:43 -0600 | [diff] [blame] | 3910 | while ((c = get_revision_internal(revs))) |
Thomas Rast | 498bcd3 | 2008-08-29 21:18:38 +0200 | [diff] [blame] | 3911 | commit_list_insert(c, &reversed); |
Thomas Rast | 498bcd3 | 2008-08-29 21:18:38 +0200 | [diff] [blame] | 3912 | revs->commits = reversed; |
| 3913 | revs->reverse = 0; |
| 3914 | revs->reverse_output_stage = 1; |
| 3915 | } |
| 3916 | |
Nguyễn Thái Ngọc Duy | 1b32dec | 2014-03-25 20:23:27 +0700 | [diff] [blame] | 3917 | if (revs->reverse_output_stage) { |
| 3918 | c = pop_commit(&revs->commits); |
| 3919 | if (revs->track_linear) |
| 3920 | revs->linear = !!(c && c->object.flags & TRACK_LINEAR); |
| 3921 | return c; |
| 3922 | } |
Thomas Rast | 498bcd3 | 2008-08-29 21:18:38 +0200 | [diff] [blame] | 3923 | |
| 3924 | c = get_revision_internal(revs); |
Adam Simpkins | 7fefda5 | 2008-05-04 03:36:54 -0700 | [diff] [blame] | 3925 | if (c && revs->graph) |
| 3926 | graph_update(revs->graph, c); |
Nguyễn Thái Ngọc Duy | 1b32dec | 2014-03-25 20:23:27 +0700 | [diff] [blame] | 3927 | if (!c) { |
Thomas Rast | 53d00b3 | 2013-07-31 22:13:20 +0200 | [diff] [blame] | 3928 | free_saved_parents(revs); |
Nguyễn Thái Ngọc Duy | 1b32dec | 2014-03-25 20:23:27 +0700 | [diff] [blame] | 3929 | if (revs->previous_parents) { |
| 3930 | free_commit_list(revs->previous_parents); |
| 3931 | revs->previous_parents = NULL; |
| 3932 | } |
| 3933 | } |
Adam Simpkins | 7fefda5 | 2008-05-04 03:36:54 -0700 | [diff] [blame] | 3934 | return c; |
| 3935 | } |
Michael J Gruber | 1df2d65 | 2011-03-07 13:31:39 +0100 | [diff] [blame] | 3936 | |
| 3937 | char *get_revision_mark(const struct rev_info *revs, const struct commit *commit) |
| 3938 | { |
| 3939 | if (commit->object.flags & BOUNDARY) |
| 3940 | return "-"; |
| 3941 | else if (commit->object.flags & UNINTERESTING) |
| 3942 | return "^"; |
Michael J Gruber | adbbb31 | 2011-03-07 13:31:40 +0100 | [diff] [blame] | 3943 | else if (commit->object.flags & PATCHSAME) |
| 3944 | return "="; |
Michael J Gruber | 1df2d65 | 2011-03-07 13:31:39 +0100 | [diff] [blame] | 3945 | else if (!revs || revs->left_right) { |
| 3946 | if (commit->object.flags & SYMMETRIC_LEFT) |
| 3947 | return "<"; |
| 3948 | else |
| 3949 | return ">"; |
| 3950 | } else if (revs->graph) |
| 3951 | return "*"; |
Michael J Gruber | adbbb31 | 2011-03-07 13:31:40 +0100 | [diff] [blame] | 3952 | else if (revs->cherry_mark) |
| 3953 | return "+"; |
Michael J Gruber | 1df2d65 | 2011-03-07 13:31:39 +0100 | [diff] [blame] | 3954 | return ""; |
| 3955 | } |
Michael J Gruber | b1b4755 | 2011-03-10 15:45:03 +0100 | [diff] [blame] | 3956 | |
| 3957 | void put_revision_mark(const struct rev_info *revs, const struct commit *commit) |
| 3958 | { |
| 3959 | char *mark = get_revision_mark(revs, commit); |
| 3960 | if (!strlen(mark)) |
| 3961 | return; |
| 3962 | fputs(mark, stdout); |
| 3963 | putchar(' '); |
| 3964 | } |