summaryrefslogtreecommitdiff
path: root/revision.c
diff options
context:
space:
mode:
Diffstat (limited to 'revision.c')
-rw-r--r--revision.c369
1 files changed, 267 insertions, 102 deletions
diff --git a/revision.c b/revision.c
index f82b833..75dda92 100644
--- a/revision.c
+++ b/revision.c
@@ -16,6 +16,8 @@
#include "line-log.h"
#include "mailmap.h"
#include "commit-slab.h"
+#include "dir.h"
+#include "cache-tree.h"
volatile show_early_output_fn_t show_early_output;
@@ -85,16 +87,6 @@ void show_object_with_name(FILE *out, struct object *obj,
fputc('\n', out);
}
-void add_object(struct object *obj,
- struct object_array *p,
- struct name_path *path,
- const char *name)
-{
- char *pn = path_name(path, name);
- add_object_array(obj, pn, p);
- free(pn);
-}
-
static void mark_blob_uninteresting(struct blob *blob)
{
if (!blob)
@@ -104,17 +96,12 @@ static void mark_blob_uninteresting(struct blob *blob)
blob->object.flags |= UNINTERESTING;
}
-void mark_tree_uninteresting(struct tree *tree)
+static void mark_tree_contents_uninteresting(struct tree *tree)
{
struct tree_desc desc;
struct name_entry entry;
struct object *obj = &tree->object;
- if (!tree)
- return;
- if (obj->flags & UNINTERESTING)
- return;
- obj->flags |= UNINTERESTING;
if (!has_sha1_file(obj->sha1))
return;
if (parse_tree(tree) < 0)
@@ -139,8 +126,19 @@ 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_tree_uninteresting(struct tree *tree)
+{
+ struct object *obj = &tree->object;
+
+ if (!tree)
+ return;
+ if (obj->flags & UNINTERESTING)
+ return;
+ obj->flags |= UNINTERESTING;
+ mark_tree_contents_uninteresting(tree);
}
void mark_parents_uninteresting(struct commit *commit)
@@ -191,9 +189,10 @@ void mark_parents_uninteresting(struct commit *commit)
}
}
-static void add_pending_object_with_mode(struct rev_info *revs,
+static void add_pending_object_with_path(struct rev_info *revs,
struct object *obj,
- const char *name, unsigned mode)
+ const char *name, unsigned mode,
+ const char *path)
{
if (!obj)
return;
@@ -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)
@@ -213,7 +212,14 @@ static void add_pending_object_with_mode(struct rev_info *revs,
if (st)
return;
}
- add_object_array_with_mode(obj, name, &revs->pending, mode);
+ add_object_array_with_path(obj, name, &revs->pending, mode, path);
+}
+
+static void add_pending_object_with_mode(struct rev_info *revs,
+ struct object *obj,
+ const char *name, unsigned mode)
+{
+ add_pending_object_with_path(revs, obj, name, mode, NULL);
}
void add_pending_object(struct rev_info *revs,
@@ -258,8 +264,12 @@ void add_pending_sha1(struct rev_info *revs, const char *name,
}
static struct commit *handle_commit(struct rev_info *revs,
- struct object *object, const char *name)
+ struct object_array_entry *entry)
{
+ struct object *object = entry->item;
+ const char *name = entry->name;
+ const char *path = entry->path;
+ unsigned int mode = entry->mode;
unsigned long flags = object->flags;
/*
@@ -277,6 +287,15 @@ static struct commit *handle_commit(struct rev_info *revs,
return NULL;
die("bad object %s", sha1_to_hex(tag->tagged->sha1));
}
+ object->flags |= flags;
+ /*
+ * We'll handle the tagged object by looping or dropping
+ * through to the non-tag handlers below. Do not
+ * propagate data from the tag's pending entry.
+ */
+ name = "";
+ path = NULL;
+ mode = 0;
}
/*
@@ -288,12 +307,11 @@ static struct commit *handle_commit(struct rev_info *revs,
if (parse_commit(commit) < 0)
die("unable to parse commit %s", name);
if (flags & UNINTERESTING) {
- commit->object.flags |= UNINTERESTING;
mark_parents_uninteresting(commit);
revs->limited = 1;
}
if (revs->show_source && !commit->util)
- commit->util = (void *) name;
+ commit->util = xstrdup(name);
return commit;
}
@@ -306,10 +324,10 @@ static struct commit *handle_commit(struct rev_info *revs,
if (!revs->tree_objects)
return NULL;
if (flags & UNINTERESTING) {
- mark_tree_uninteresting(tree);
+ mark_tree_contents_uninteresting(tree);
return NULL;
}
- add_pending_object(revs, object, "");
+ add_pending_object_with_path(revs, object, name, mode, path);
return NULL;
}
@@ -317,14 +335,11 @@ static struct commit *handle_commit(struct rev_info *revs,
* Blob object? You know the drill by now..
*/
if (object->type == OBJ_BLOB) {
- struct blob *blob = (struct blob *)object;
if (!revs->blob_objects)
return NULL;
- if (flags & UNINTERESTING) {
- mark_blob_uninteresting(blob);
+ if (flags & UNINTERESTING)
return NULL;
- }
- add_pending_object(revs, object, "");
+ add_pending_object_with_path(revs, object, name, mode, path);
return NULL;
}
die("%s is unknown object", name);
@@ -469,7 +484,7 @@ static int rev_compare_tree(struct rev_info *revs,
* If we are simplifying by decoration, then the commit
* is worth showing if it has a tag pointing at it.
*/
- if (lookup_decoration(&name_decoration, &commit->object))
+ if (get_name_decoration(&commit->object))
return REV_TREE_DIFFERENT;
/*
* A commit that is not pointed by a tag is uninteresting
@@ -493,24 +508,14 @@ static int rev_compare_tree(struct rev_info *revs,
static int rev_same_tree_as_empty(struct rev_info *revs, struct commit *commit)
{
int retval;
- void *tree;
- unsigned long size;
- struct tree_desc empty, real;
struct tree *t1 = commit->tree;
if (!t1)
return 0;
- tree = read_object_with_reference(t1->object.sha1, tree_type, &size, NULL);
- if (!tree)
- return 0;
- init_tree_desc(&real, tree, size);
- init_tree_desc(&empty, "", 0);
-
tree_difference = REV_TREE_SAME;
DIFF_OPT_CLR(&revs->pruning, HAS_CHANGES);
- retval = diff_tree(&empty, &real, "", &revs->pruning);
- free(tree);
+ retval = diff_tree_sha1(NULL, t1->object.sha1, "", &revs->pruning);
return retval >= 0 && (tree_difference == REV_TREE_SAME);
}
@@ -780,6 +785,10 @@ static int add_parents_to_list(struct rev_info *revs, struct commit *commit,
return 0;
commit->object.flags |= ADDED;
+ if (revs->include_check &&
+ !revs->include_check(commit, revs->include_check_data))
+ return 0;
+
/*
* If the commit is uninteresting, don't try to
* prune parents - we want the maximal uninteresting
@@ -1181,11 +1190,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 (!wildmatch(item->string, path, 0, NULL))
+ 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 +1224,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 *))
{
@@ -1242,7 +1286,7 @@ static int handle_one_reflog(const char *path, const unsigned char *sha1, int fl
return 0;
}
-static void handle_reflog(struct rev_info *revs, unsigned flags)
+void add_reflogs_to_pending(struct rev_info *revs, unsigned flags)
{
struct all_refs_cb cb;
cb.all_revs = revs;
@@ -1250,6 +1294,53 @@ static void handle_reflog(struct rev_info *revs, unsigned flags)
for_each_reflog(handle_one_reflog, &cb);
}
+static void add_cache_tree(struct cache_tree *it, struct rev_info *revs,
+ struct strbuf *path)
+{
+ size_t baselen = path->len;
+ int i;
+
+ if (it->entry_count >= 0) {
+ struct tree *tree = lookup_tree(it->sha1);
+ add_pending_object_with_path(revs, &tree->object, "",
+ 040000, path->buf);
+ }
+
+ for (i = 0; i < it->subtree_nr; i++) {
+ struct cache_tree_sub *sub = it->down[i];
+ strbuf_addf(path, "%s%s", baselen ? "/" : "", sub->name);
+ add_cache_tree(sub->cache_tree, revs, path);
+ strbuf_setlen(path, baselen);
+ }
+
+}
+
+void add_index_objects_to_pending(struct rev_info *revs, unsigned flags)
+{
+ int i;
+
+ read_cache();
+ for (i = 0; i < active_nr; i++) {
+ struct cache_entry *ce = active_cache[i];
+ struct blob *blob;
+
+ if (S_ISGITLINK(ce->ce_mode))
+ continue;
+
+ blob = lookup_blob(ce->sha1);
+ if (!blob)
+ die("unable to add index blob to traversal");
+ add_pending_object_with_path(revs, &blob->object, "",
+ ce->ce_mode, ce->name);
+ }
+
+ if (active_cache_tree) {
+ struct strbuf path = STRBUF_INIT;
+ add_cache_tree(active_cache_tree, revs, &path);
+ strbuf_release(&path);
+ }
+}
+
static int add_parents_only(struct rev_info *revs, const char *arg_, int flags)
{
unsigned char sha1[20];
@@ -1362,9 +1453,9 @@ static void prepare_show_merge(struct rev_info *revs)
const struct cache_entry *ce = active_cache[i];
if (!ce_stage(ce))
continue;
- if (ce_path_match(ce, &revs->prune_data)) {
+ if (ce_path_match(ce, &revs->prune_data, NULL)) {
prune_num++;
- prune = xrealloc(prune, sizeof(*prune) * prune_num);
+ REALLOC_ARRAY(prune, prune_num);
prune[prune_num-2] = ce->name;
prune[prune_num-1] = NULL;
}
@@ -1373,7 +1464,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 +1611,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 +1623,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);
}
}
@@ -1541,6 +1633,10 @@ static void read_revisions_from_stdin(struct rev_info *revs,
{
struct strbuf sb;
int seen_dashdash = 0;
+ int save_warning;
+
+ save_warning = warn_on_object_refname_ambiguity;
+ warn_on_object_refname_ambiguity = 0;
strbuf_init(&sb, 1000);
while (strbuf_getwholeline(&sb, stdin, '\n') != EOF) {
@@ -1562,7 +1658,9 @@ static void read_revisions_from_stdin(struct rev_info *revs,
}
if (seen_dashdash)
read_pathspec_from_stdin(revs, &sb, prune);
+
strbuf_release(&sb);
+ warn_on_object_refname_ambiguity = save_warning;
}
static void add_grep(struct rev_info *revs, const char *ptn, enum grep_pat_token what)
@@ -1592,9 +1690,11 @@ static int handle_revision_opt(struct rev_info *revs, int argc, const char **arg
!strcmp(arg, "--tags") || !strcmp(arg, "--remotes") ||
!strcmp(arg, "--reflog") || !strcmp(arg, "--not") ||
!strcmp(arg, "--no-walk") || !strcmp(arg, "--do-walk") ||
- !strcmp(arg, "--bisect") || !prefixcmp(arg, "--glob=") ||
- !prefixcmp(arg, "--branches=") || !prefixcmp(arg, "--tags=") ||
- !prefixcmp(arg, "--remotes=") || !prefixcmp(arg, "--no-walk="))
+ !strcmp(arg, "--bisect") || starts_with(arg, "--glob=") ||
+ !strcmp(arg, "--indexed-objects") ||
+ starts_with(arg, "--exclude=") ||
+ starts_with(arg, "--branches=") || starts_with(arg, "--tags=") ||
+ starts_with(arg, "--remotes=") || starts_with(arg, "--no-walk="))
{
unkv[(*unkc)++] = arg;
return 1;
@@ -1608,8 +1708,10 @@ static int handle_revision_opt(struct rev_info *revs, int argc, const char **arg
revs->skip_count = atoi(optarg);
return argcount;
} else if ((*arg == '-') && isdigit(arg[1])) {
- /* accept -<digit>, like traditional "head" */
- revs->max_count = atoi(arg + 1);
+ /* accept -<digit>, like traditional "head" */
+ if (strtol_i(arg + 1, 10, &revs->max_count) < 0 ||
+ revs->max_count < 0)
+ die("'%s': not a non-negative integer", arg + 1);
revs->no_walk = 0;
} else if (!strcmp(arg, "-n")) {
if (argc <= 1)
@@ -1617,7 +1719,7 @@ static int handle_revision_opt(struct rev_info *revs, int argc, const char **arg
revs->max_count = atoi(argv[1]);
revs->no_walk = 0;
return 2;
- } else if (!prefixcmp(arg, "-n")) {
+ } else if (starts_with(arg, "-n")) {
revs->max_count = atoi(arg + 2);
revs->no_walk = 0;
} else if ((argcount = parse_long_opt("max-age", argv, &optarg))) {
@@ -1677,7 +1779,7 @@ static int handle_revision_opt(struct rev_info *revs, int argc, const char **arg
} else if (!strcmp(arg, "--author-date-order")) {
revs->sort_order = REV_SORT_BY_AUTHOR_DATE;
revs->topo_order = 1;
- } else if (!prefixcmp(arg, "--early-output")) {
+ } else if (starts_with(arg, "--early-output")) {
int count = 100;
switch (arg[14]) {
case '=':
@@ -1702,13 +1804,13 @@ static int handle_revision_opt(struct rev_info *revs, int argc, const char **arg
revs->min_parents = 2;
} else if (!strcmp(arg, "--no-merges")) {
revs->max_parents = 1;
- } else if (!prefixcmp(arg, "--min-parents=")) {
+ } else if (starts_with(arg, "--min-parents=")) {
revs->min_parents = atoi(arg+14);
- } else if (!prefixcmp(arg, "--no-min-parents")) {
+ } else if (starts_with(arg, "--no-min-parents")) {
revs->min_parents = 0;
- } else if (!prefixcmp(arg, "--max-parents=")) {
+ } else if (starts_with(arg, "--max-parents=")) {
revs->max_parents = atoi(arg+14);
- } else if (!prefixcmp(arg, "--no-max-parents")) {
+ } else if (starts_with(arg, "--no-max-parents")) {
revs->max_parents = -1;
} else if (!strcmp(arg, "--boundary")) {
revs->boundary = 1;
@@ -1758,7 +1860,7 @@ static int handle_revision_opt(struct rev_info *revs, int argc, const char **arg
revs->verify_objects = 1;
} else if (!strcmp(arg, "--unpacked")) {
revs->unpacked = 1;
- } else if (!prefixcmp(arg, "--unpacked=")) {
+ } else if (starts_with(arg, "--unpacked=")) {
die("--unpacked=<packfile> no longer supported.");
} else if (!strcmp(arg, "-r")) {
revs->diff = 1;
@@ -1782,8 +1884,8 @@ static int handle_revision_opt(struct rev_info *revs, int argc, const char **arg
} else if (!strcmp(arg, "--pretty")) {
revs->verbose_header = 1;
revs->pretty_given = 1;
- get_commit_format(arg+8, revs);
- } else if (!prefixcmp(arg, "--pretty=") || !prefixcmp(arg, "--format=")) {
+ get_commit_format(NULL, revs);
+ } else if (starts_with(arg, "--pretty=") || starts_with(arg, "--format=")) {
/*
* Detached form ("--pretty X" as opposed to "--pretty=X")
* not allowed, since the argument is optional.
@@ -1797,12 +1899,20 @@ static int handle_revision_opt(struct rev_info *revs, int argc, const char **arg
revs->notes_opt.use_default_notes = 1;
} else if (!strcmp(arg, "--show-signature")) {
revs->show_signature = 1;
- } else if (!prefixcmp(arg, "--show-notes=") ||
- !prefixcmp(arg, "--notes=")) {
+ } else if (!strcmp(arg, "--show-linear-break") ||
+ starts_with(arg, "--show-linear-break=")) {
+ if (starts_with(arg, "--show-linear-break="))
+ revs->break_bar = xstrdup(arg + 20);
+ else
+ revs->break_bar = " ..........";
+ revs->track_linear = 1;
+ revs->track_first_time = 1;
+ } else if (starts_with(arg, "--show-notes=") ||
+ starts_with(arg, "--notes=")) {
struct strbuf buf = STRBUF_INIT;
revs->show_notes = 1;
revs->show_notes_given = 1;
- if (!prefixcmp(arg, "--show-notes")) {
+ if (starts_with(arg, "--show-notes")) {
if (revs->notes_opt.use_default_notes < 0)
revs->notes_opt.use_default_notes = 1;
strbuf_addstr(&buf, arg+13);
@@ -1845,7 +1955,7 @@ static int handle_revision_opt(struct rev_info *revs, int argc, const char **arg
revs->abbrev = 0;
} else if (!strcmp(arg, "--abbrev")) {
revs->abbrev = DEFAULT_ABBREV;
- } else if (!prefixcmp(arg, "--abbrev=")) {
+ } else if (starts_with(arg, "--abbrev=")) {
revs->abbrev = strtoul(arg + 9, NULL, 10);
if (revs->abbrev < MINIMUM_ABBREV)
revs->abbrev = MINIMUM_ABBREV;
@@ -1920,6 +2030,8 @@ static int handle_revision_opt(struct rev_info *revs, int argc, const char **arg
unkv[(*unkc)++] = arg;
return opts;
}
+ if (revs->graph && revs->track_linear)
+ die("--show-linear-break and --graph are incompatible");
return 1;
}
@@ -1969,40 +2081,53 @@ 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=")) {
+ } else if (starts_with(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);
- } else if (!prefixcmp(arg, "--tags=")) {
+ clear_ref_exclusion(&revs->ref_excludes);
+ } else if (starts_with(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);
- } else if (!prefixcmp(arg, "--remotes=")) {
+ clear_ref_exclusion(&revs->ref_excludes);
+ } else if (starts_with(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);
+ add_reflogs_to_pending(revs, *flags);
+ } else if (!strcmp(arg, "--indexed-objects")) {
+ add_index_objects_to_pending(revs, *flags);
} else if (!strcmp(arg, "--not")) {
*flags ^= UNINTERESTING | BOTTOM;
} else if (!strcmp(arg, "--no-walk")) {
revs->no_walk = REVISION_WALK_NO_WALK_SORTED;
- } else if (!prefixcmp(arg, "--no-walk=")) {
+ } else if (starts_with(arg, "--no-walk=")) {
/*
* Detached form ("--no-walk X" as opposed to "--no-walk=X")
* not allowed, since the argument is optional.
@@ -2134,10 +2259,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 +2295,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;
@@ -2591,26 +2717,26 @@ void reset_revision_walk(void)
int prepare_revision_walk(struct rev_info *revs)
{
- int nr = revs->pending.nr;
- struct object_array_entry *e, *list;
+ int i;
+ struct object_array old_pending;
struct commit_list **next = &revs->commits;
- e = list = revs->pending.objects;
+ memcpy(&old_pending, &revs->pending, sizeof(old_pending));
revs->pending.nr = 0;
revs->pending.alloc = 0;
revs->pending.objects = NULL;
- while (--nr >= 0) {
- struct commit *commit = handle_commit(revs, e->item, e->name);
+ for (i = 0; i < old_pending.nr; i++) {
+ struct object_array_entry *e = old_pending.objects + i;
+ struct commit *commit = handle_commit(revs, e);
if (commit) {
if (!(commit->object.flags & SEEN)) {
commit->object.flags |= SEEN;
next = commit_list_append(commit, next);
}
}
- e++;
}
if (!revs->leak_pending)
- free(list);
+ object_array_clear(&old_pending);
/* Signal whether we need per-parent treesame decoration */
if (revs->simplify_merges ||
@@ -2726,7 +2852,7 @@ static int commit_match(struct commit *commit, struct rev_info *opt)
{
int retval;
const char *encoding;
- char *message;
+ const char *message;
struct strbuf buf = STRBUF_INIT;
if (!opt->grep_filter.pattern_list && !opt->grep_filter.header_list)
@@ -2768,14 +2894,21 @@ static int commit_match(struct commit *commit, struct rev_info *opt)
format_display_notes(commit->object.sha1, &buf, encoding, 1);
}
- /* Find either in the original commit message, or in the temporary */
+ /*
+ * Find either in the original commit message, or in the temporary.
+ * Note that we cast away the constness of "message" here. It is
+ * const because it may come from the cached commit buffer. That's OK,
+ * because we know that it is modifiable heap memory, and that while
+ * grep_buffer may modify it for speed, it will restore any
+ * changes before returning.
+ */
if (buf.len)
retval = grep_buffer(&opt->grep_filter, buf.buf, buf.len);
else
retval = grep_buffer(&opt->grep_filter,
- message, strlen(message));
+ (char *)message, strlen(message));
strbuf_release(&buf);
- logmsg_free(message, commit);
+ unuse_commit_buffer(commit, message);
return retval;
}
@@ -2850,6 +2983,27 @@ enum commit_action simplify_commit(struct rev_info *revs, struct commit *commit)
return action;
}
+static void track_linear(struct rev_info *revs, struct commit *commit)
+{
+ if (revs->track_first_time) {
+ revs->linear = 1;
+ revs->track_first_time = 0;
+ } else {
+ struct commit_list *p;
+ for (p = revs->previous_parents; p; p = p->next)
+ if (p->item == NULL || /* first commit */
+ !hashcmp(p->item->object.sha1, commit->object.sha1))
+ break;
+ revs->linear = p != NULL;
+ }
+ if (revs->reverse) {
+ if (revs->linear)
+ commit->object.flags |= TRACK_LINEAR;
+ }
+ free_commit_list(revs->previous_parents);
+ revs->previous_parents = copy_commit_list(commit->parents);
+}
+
static struct commit *get_revision_1(struct rev_info *revs)
{
if (!revs->commits)
@@ -2877,9 +3031,11 @@ static struct commit *get_revision_1(struct rev_info *revs)
if (revs->max_age != -1 &&
(commit->date < revs->max_age))
continue;
- if (add_parents_to_list(revs, commit, &revs->commits, NULL) < 0)
- die("Failed to traverse parents of commit %s",
- sha1_to_hex(commit->object.sha1));
+ if (add_parents_to_list(revs, commit, &revs->commits, NULL) < 0) {
+ if (!revs->ignore_missing_links)
+ die("Failed to traverse parents of commit %s",
+ sha1_to_hex(commit->object.sha1));
+ }
}
switch (simplify_commit(revs, commit)) {
@@ -2889,6 +3045,8 @@ static struct commit *get_revision_1(struct rev_info *revs)
die("Failed to simplify parents of commit %s",
sha1_to_hex(commit->object.sha1));
default:
+ if (revs->track_linear)
+ track_linear(revs, commit);
return commit;
}
} while (revs->commits);
@@ -2986,7 +3144,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 +3159,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,22 +3206,30 @@ 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;
}
- if (revs->reverse_output_stage)
- return pop_commit(&revs->commits);
+ if (revs->reverse_output_stage) {
+ c = pop_commit(&revs->commits);
+ if (revs->track_linear)
+ revs->linear = !!(c && c->object.flags & TRACK_LINEAR);
+ return c;
+ }
c = get_revision_internal(revs);
if (c && revs->graph)
graph_update(revs->graph, c);
- if (!c)
+ if (!c) {
free_saved_parents(revs);
+ if (revs->previous_parents) {
+ free_commit_list(revs->previous_parents);
+ revs->previous_parents = NULL;
+ }
+ }
return c;
}