diff options
Diffstat (limited to 'revision.c')
-rw-r--r-- | revision.c | 81 |
1 files changed, 63 insertions, 18 deletions
diff --git a/revision.c b/revision.c index f82b833fbc..05d2d7763a 100644 --- a/revision.c +++ b/revision.c @@ -139,8 +139,7 @@ void mark_tree_uninteresting(struct tree *tree) * We don't care about the tree any more * after it has been marked uninteresting. */ - free(tree->buffer); - tree->buffer = NULL; + free_tree_buffer(tree); } void mark_parents_uninteresting(struct commit *commit) @@ -201,7 +200,7 @@ static void add_pending_object_with_mode(struct rev_info *revs, revs->no_walk = 0; if (revs->reflog_info && obj->type == OBJ_COMMIT) { struct strbuf buf = STRBUF_INIT; - int len = interpret_branch_name(name, &buf); + int len = interpret_branch_name(name, 0, &buf); int st; if (0 < len && name[len] && buf.len) @@ -1181,11 +1180,28 @@ struct all_refs_cb { const char *name_for_errormsg; }; +int ref_excluded(struct string_list *ref_excludes, const char *path) +{ + struct string_list_item *item; + + if (!ref_excludes) + return 0; + for_each_string_list_item(item, ref_excludes) { + if (!fnmatch(item->string, path, 0)) + return 1; + } + return 0; +} + static int handle_one_ref(const char *path, const unsigned char *sha1, int flag, void *cb_data) { struct all_refs_cb *cb = cb_data; - struct object *object = get_reference(cb->all_revs, path, sha1, - cb->all_flags); + struct object *object; + + if (ref_excluded(cb->all_revs->ref_excludes, path)) + return 0; + + object = get_reference(cb->all_revs, path, sha1, cb->all_flags); add_rev_cmdline(cb->all_revs, object, path, REV_CMD_REF, cb->all_flags); add_pending_sha1(cb->all_revs, path, sha1, cb->all_flags); return 0; @@ -1198,6 +1214,24 @@ static void init_all_refs_cb(struct all_refs_cb *cb, struct rev_info *revs, cb->all_flags = flags; } +void clear_ref_exclusion(struct string_list **ref_excludes_p) +{ + if (*ref_excludes_p) { + string_list_clear(*ref_excludes_p, 0); + free(*ref_excludes_p); + } + *ref_excludes_p = NULL; +} + +void add_ref_exclusion(struct string_list **ref_excludes_p, const char *exclude) +{ + if (!*ref_excludes_p) { + *ref_excludes_p = xcalloc(1, sizeof(**ref_excludes_p)); + (*ref_excludes_p)->strdup_strings = 1; + } + string_list_append(*ref_excludes_p, exclude); +} + static void handle_refs(const char *submodule, struct rev_info *revs, unsigned flags, int (*for_each)(const char *, each_ref_fn, void *)) { @@ -1373,7 +1407,8 @@ static void prepare_show_merge(struct rev_info *revs) i++; } free_pathspec(&revs->prune_data); - init_pathspec(&revs->prune_data, prune); + parse_pathspec(&revs->prune_data, PATHSPEC_ALL_MAGIC & ~PATHSPEC_LITERAL, + PATHSPEC_PREFER_FULL | PATHSPEC_LITERAL_PATH, "", prune); revs->limited = 1; } @@ -1519,7 +1554,7 @@ struct cmdline_pathspec { static void append_prune_data(struct cmdline_pathspec *prune, const char **av) { while (*av) { - ALLOC_GROW(prune->path, prune->nr+1, prune->alloc); + ALLOC_GROW(prune->path, prune->nr + 1, prune->alloc); prune->path[prune->nr++] = *(av++); } } @@ -1531,7 +1566,7 @@ static void read_pathspec_from_stdin(struct rev_info *revs, struct strbuf *sb, int len = sb->len; if (len && sb->buf[len - 1] == '\n') sb->buf[--len] = '\0'; - ALLOC_GROW(prune->path, prune->nr+1, prune->alloc); + ALLOC_GROW(prune->path, prune->nr + 1, prune->alloc); prune->path[prune->nr++] = xstrdup(sb->buf); } } @@ -1969,33 +2004,44 @@ static int handle_revision_pseudo_opt(const char *submodule, if (!strcmp(arg, "--all")) { handle_refs(submodule, revs, *flags, for_each_ref_submodule); handle_refs(submodule, revs, *flags, head_ref_submodule); + clear_ref_exclusion(&revs->ref_excludes); } else if (!strcmp(arg, "--branches")) { handle_refs(submodule, revs, *flags, for_each_branch_ref_submodule); + clear_ref_exclusion(&revs->ref_excludes); } else if (!strcmp(arg, "--bisect")) { handle_refs(submodule, revs, *flags, for_each_bad_bisect_ref); handle_refs(submodule, revs, *flags ^ (UNINTERESTING | BOTTOM), for_each_good_bisect_ref); revs->bisect = 1; } else if (!strcmp(arg, "--tags")) { handle_refs(submodule, revs, *flags, for_each_tag_ref_submodule); + clear_ref_exclusion(&revs->ref_excludes); } else if (!strcmp(arg, "--remotes")) { handle_refs(submodule, revs, *flags, for_each_remote_ref_submodule); + clear_ref_exclusion(&revs->ref_excludes); } else if ((argcount = parse_long_opt("glob", argv, &optarg))) { struct all_refs_cb cb; init_all_refs_cb(&cb, revs, *flags); for_each_glob_ref(handle_one_ref, optarg, &cb); + clear_ref_exclusion(&revs->ref_excludes); + return argcount; + } else if ((argcount = parse_long_opt("exclude", argv, &optarg))) { + add_ref_exclusion(&revs->ref_excludes, optarg); return argcount; } else if (!prefixcmp(arg, "--branches=")) { struct all_refs_cb cb; init_all_refs_cb(&cb, revs, *flags); for_each_glob_ref_in(handle_one_ref, arg + 11, "refs/heads/", &cb); + clear_ref_exclusion(&revs->ref_excludes); } else if (!prefixcmp(arg, "--tags=")) { struct all_refs_cb cb; init_all_refs_cb(&cb, revs, *flags); for_each_glob_ref_in(handle_one_ref, arg + 7, "refs/tags/", &cb); + clear_ref_exclusion(&revs->ref_excludes); } else if (!prefixcmp(arg, "--remotes=")) { struct all_refs_cb cb; init_all_refs_cb(&cb, revs, *flags); for_each_glob_ref_in(handle_one_ref, arg + 10, "refs/remotes/", &cb); + clear_ref_exclusion(&revs->ref_excludes); } else if (!strcmp(arg, "--reflog")) { handle_reflog(revs, *flags); } else if (!strcmp(arg, "--not")) { @@ -2134,10 +2180,10 @@ int setup_revisions(int argc, const char **argv, struct rev_info *revs, struct s * call init_pathspec() to set revs->prune_data here. * } */ - ALLOC_GROW(prune_data.path, prune_data.nr+1, prune_data.alloc); + ALLOC_GROW(prune_data.path, prune_data.nr + 1, prune_data.alloc); prune_data.path[prune_data.nr++] = NULL; - init_pathspec(&revs->prune_data, - get_pathspec(revs->prefix, prune_data.path)); + parse_pathspec(&revs->prune_data, 0, 0, + revs->prefix, prune_data.path); } if (revs->def == NULL) @@ -2170,12 +2216,13 @@ int setup_revisions(int argc, const char **argv, struct rev_info *revs, struct s revs->limited = 1; if (revs->prune_data.nr) { - diff_tree_setup_paths(revs->prune_data.raw, &revs->pruning); + copy_pathspec(&revs->pruning.pathspec, &revs->prune_data); /* Can't prune commits with rename following: the paths change.. */ if (!DIFF_OPT_TST(&revs->diffopt, FOLLOW_RENAMES)) revs->prune = 1; if (!revs->full_diff) - diff_tree_setup_paths(revs->prune_data.raw, &revs->diffopt); + copy_pathspec(&revs->diffopt.pathspec, + &revs->prune_data); } if (revs->combine_merges) revs->ignore_merges = 0; @@ -2986,7 +3033,7 @@ static struct commit *get_revision_internal(struct rev_info *revs) if (revs->max_count) { c = get_revision_1(revs); if (c) { - while (0 < revs->skip_count) { + while (revs->skip_count > 0) { revs->skip_count--; c = get_revision_1(revs); if (!c) @@ -3001,9 +3048,8 @@ static struct commit *get_revision_internal(struct rev_info *revs) if (c) c->object.flags |= SHOWN; - if (!revs->boundary) { + if (!revs->boundary) return c; - } if (!c) { /* @@ -3049,9 +3095,8 @@ struct commit *get_revision(struct rev_info *revs) if (revs->reverse) { reversed = NULL; - while ((c = get_revision_internal(revs))) { + while ((c = get_revision_internal(revs))) commit_list_insert(c, &reversed); - } revs->commits = reversed; revs->reverse = 0; revs->reverse_output_stage = 1; |