summaryrefslogtreecommitdiff
path: root/list-objects.c
diff options
context:
space:
mode:
Diffstat (limited to 'list-objects.c')
-rw-r--r--list-objects.c124
1 files changed, 87 insertions, 37 deletions
diff --git a/list-objects.c b/list-objects.c
index 8953548c07..b3931fa434 100644
--- a/list-objects.c
+++ b/list-objects.c
@@ -11,10 +11,12 @@
static void process_blob(struct rev_info *revs,
struct blob *blob,
show_object_fn show,
- struct name_path *path,
- const char *name)
+ struct strbuf *path,
+ const char *name,
+ void *cb_data)
{
struct object *obj = &blob->object;
+ size_t pathlen;
if (!revs->blob_objects)
return;
@@ -23,7 +25,11 @@ static void process_blob(struct rev_info *revs,
if (obj->flags & (UNINTERESTING | SEEN))
return;
obj->flags |= SEEN;
- show(obj, path, name);
+
+ pathlen = path->len;
+ strbuf_addstr(path, name);
+ show(obj, path->buf, cb_data);
+ strbuf_setlen(path, pathlen);
}
/*
@@ -51,8 +57,9 @@ static void process_blob(struct rev_info *revs,
static void process_gitlink(struct rev_info *revs,
const unsigned char *sha1,
show_object_fn show,
- struct name_path *path,
- const char *name)
+ struct strbuf *path,
+ const char *name,
+ void *cb_data)
{
/* Nothing to do */
}
@@ -60,13 +67,16 @@ static void process_gitlink(struct rev_info *revs,
static void process_tree(struct rev_info *revs,
struct tree *tree,
show_object_fn show,
- struct name_path *path,
- const char *name)
+ struct strbuf *base,
+ const char *name,
+ void *cb_data)
{
struct object *obj = &tree->object;
struct tree_desc desc;
struct name_entry entry;
- struct name_path me;
+ enum interesting match = revs->diffopt.pathspec.nr == 0 ?
+ all_entries_interesting: entry_not_interesting;
+ int baselen = base->len;
if (!revs->tree_objects)
return;
@@ -74,31 +84,47 @@ static void process_tree(struct rev_info *revs,
die("bad tree object");
if (obj->flags & (UNINTERESTING | SEEN))
return;
- if (parse_tree(tree) < 0)
- die("bad tree object %s", sha1_to_hex(obj->sha1));
+ if (parse_tree_gently(tree, revs->ignore_missing_links) < 0) {
+ if (revs->ignore_missing_links)
+ return;
+ die("bad tree object %s", oid_to_hex(&obj->oid));
+ }
+
obj->flags |= SEEN;
- show(obj, path, name);
- me.up = path;
- me.elem = name;
- me.elem_len = strlen(name);
+ strbuf_addstr(base, name);
+ show(obj, base->buf, cb_data);
+ if (base->len)
+ strbuf_addch(base, '/');
init_tree_desc(&desc, tree->buffer, tree->size);
while (tree_entry(&desc, &entry)) {
+ if (match != all_entries_interesting) {
+ match = tree_entry_interesting(&entry, base, 0,
+ &revs->diffopt.pathspec);
+ if (match == all_entries_not_interesting)
+ break;
+ if (match == entry_not_interesting)
+ continue;
+ }
+
if (S_ISDIR(entry.mode))
process_tree(revs,
- lookup_tree(entry.sha1),
- show, &me, entry.path);
+ lookup_tree(entry.oid),
+ show, base, entry.path,
+ cb_data);
else if (S_ISGITLINK(entry.mode))
- process_gitlink(revs, entry.sha1,
- show, &me, entry.path);
+ process_gitlink(revs, entry.oid->hash,
+ show, base, entry.path,
+ cb_data);
else
process_blob(revs,
- lookup_blob(entry.sha1),
- show, &me, entry.path);
+ lookup_blob(entry.oid),
+ show, base, entry.path,
+ cb_data);
}
- free(tree->buffer);
- tree->buffer = NULL;
+ strbuf_setlen(base, baselen);
+ free_tree_buffer(tree);
}
static void mark_edge_parents_uninteresting(struct commit *commit,
@@ -119,19 +145,37 @@ static void mark_edge_parents_uninteresting(struct commit *commit,
}
}
-void mark_edges_uninteresting(struct commit_list *list,
- struct rev_info *revs,
- show_edge_fn show_edge)
+void mark_edges_uninteresting(struct rev_info *revs, show_edge_fn show_edge)
{
- for ( ; list; list = list->next) {
+ struct commit_list *list;
+ int i;
+
+ for (list = revs->commits; list; list = list->next) {
struct commit *commit = list->item;
if (commit->object.flags & UNINTERESTING) {
mark_tree_uninteresting(commit->tree);
+ if (revs->edge_hint_aggressive && !(commit->object.flags & SHOWN)) {
+ commit->object.flags |= SHOWN;
+ show_edge(commit);
+ }
continue;
}
mark_edge_parents_uninteresting(commit, revs, show_edge);
}
+ if (revs->edge_hint_aggressive) {
+ for (i = 0; i < revs->cmdline.nr; i++) {
+ struct object *obj = revs->cmdline.rev[i].item;
+ struct commit *commit = (struct commit *)obj;
+ if (obj->type != OBJ_COMMIT || !(obj->flags & UNINTERESTING))
+ continue;
+ mark_tree_uninteresting(commit->tree);
+ if (!(obj->flags & SHOWN)) {
+ obj->flags |= SHOWN;
+ show_edge(commit);
+ }
+ }
+ }
}
static void add_pending_tree(struct rev_info *revs, struct tree *tree)
@@ -146,39 +190,45 @@ void traverse_commit_list(struct rev_info *revs,
{
int i;
struct commit *commit;
+ struct strbuf base;
+ strbuf_init(&base, PATH_MAX);
while ((commit = get_revision(revs)) != NULL) {
- add_pending_tree(revs, commit->tree);
+ /*
+ * an uninteresting boundary commit may not have its tree
+ * parsed yet, but we are not going to show them anyway
+ */
+ if (commit->tree)
+ add_pending_tree(revs, commit->tree);
show_commit(commit, data);
}
for (i = 0; i < revs->pending.nr; i++) {
struct object_array_entry *pending = revs->pending.objects + i;
struct object *obj = pending->item;
const char *name = pending->name;
+ const char *path = pending->path;
if (obj->flags & (UNINTERESTING | SEEN))
continue;
if (obj->type == OBJ_TAG) {
obj->flags |= SEEN;
- show_object(obj, NULL, name);
+ show_object(obj, name, data);
continue;
}
+ if (!path)
+ path = "";
if (obj->type == OBJ_TREE) {
process_tree(revs, (struct tree *)obj, show_object,
- NULL, name);
+ &base, path, data);
continue;
}
if (obj->type == OBJ_BLOB) {
process_blob(revs, (struct blob *)obj, show_object,
- NULL, name);
+ &base, path, data);
continue;
}
die("unknown pending object %s (%s)",
- sha1_to_hex(obj->sha1), name);
- }
- if (revs->pending.nr) {
- free(revs->pending.objects);
- revs->pending.nr = 0;
- revs->pending.alloc = 0;
- revs->pending.objects = NULL;
+ oid_to_hex(&obj->oid), name);
}
+ object_array_clear(&revs->pending);
+ strbuf_release(&base);
}