diff-parseopt: convert --[src|dst]-prefix
[gitweb.git] / list-objects.c
index 584518a3fade48bce872fc5a4c09b97b286f43d2..4e2789768d21ccb47a8fe2d5de62b6be58ea9bb7 100644 (file)
@@ -11,6 +11,7 @@
 #include "list-objects-filter-options.h"
 #include "packfile.h"
 #include "object-store.h"
+#include "trace.h"
 
 struct traversal_context {
        struct rev_info *revs;
@@ -53,8 +54,9 @@ static void process_blob(struct traversal_context *ctx,
 
        pathlen = path->len;
        strbuf_addstr(path, name);
-       if (!(obj->flags & USER_GIVEN) && ctx->filter_fn)
-               r = ctx->filter_fn(LOFS_BLOB, obj,
+       if ((obj->flags & NOT_USER_GIVEN) && ctx->filter_fn)
+               r = ctx->filter_fn(ctx->revs->repo,
+                                  LOFS_BLOB, obj,
                                   path->buf, &path->buf[pathlen],
                                   ctx->filter_data);
        if (r & LOFR_MARK_SEEN)
@@ -94,6 +96,49 @@ static void process_gitlink(struct traversal_context *ctx,
        /* Nothing to do */
 }
 
+static void process_tree(struct traversal_context *ctx,
+                        struct tree *tree,
+                        struct strbuf *base,
+                        const char *name);
+
+static void process_tree_contents(struct traversal_context *ctx,
+                                 struct tree *tree,
+                                 struct strbuf *base)
+{
+       struct tree_desc desc;
+       struct name_entry entry;
+       enum interesting match = ctx->revs->diffopt.pathspec.nr == 0 ?
+               all_entries_interesting : entry_not_interesting;
+
+       init_tree_desc(&desc, tree->buffer, tree->size);
+
+       while (tree_entry(&desc, &entry)) {
+               if (match != all_entries_interesting) {
+                       match = tree_entry_interesting(ctx->revs->repo->index,
+                                                      &entry, base, 0,
+                                                      &ctx->revs->diffopt.pathspec);
+                       if (match == all_entries_not_interesting)
+                               break;
+                       if (match == entry_not_interesting)
+                               continue;
+               }
+
+               if (S_ISDIR(entry.mode)) {
+                       struct tree *t = lookup_tree(ctx->revs->repo, entry.oid);
+                       t->object.flags |= NOT_USER_GIVEN;
+                       process_tree(ctx, t, base, entry.path);
+               }
+               else if (S_ISGITLINK(entry.mode))
+                       process_gitlink(ctx, entry.oid->hash,
+                                       base, entry.path);
+               else {
+                       struct blob *b = lookup_blob(ctx->revs->repo, entry.oid);
+                       b->object.flags |= NOT_USER_GIVEN;
+                       process_blob(ctx, b, base, entry.path);
+               }
+       }
+}
+
 static void process_tree(struct traversal_context *ctx,
                         struct tree *tree,
                         struct strbuf *base,
@@ -101,14 +146,9 @@ static void process_tree(struct traversal_context *ctx,
 {
        struct object *obj = &tree->object;
        struct rev_info *revs = ctx->revs;
-       struct tree_desc desc;
-       struct name_entry entry;
-       enum interesting match = revs->diffopt.pathspec.nr == 0 ?
-               all_entries_interesting: entry_not_interesting;
        int baselen = base->len;
        enum list_objects_filter_result r = LOFR_MARK_SEEN | LOFR_DO_SHOW;
-       int gently = revs->ignore_missing_links ||
-                    revs->exclude_promisor_objects;
+       int failed_parse;
 
        if (!revs->tree_objects)
                return;
@@ -116,7 +156,9 @@ static void process_tree(struct traversal_context *ctx,
                die("bad tree object");
        if (obj->flags & (UNINTERESTING | SEEN))
                return;
-       if (parse_tree_gently(tree, gently) < 0) {
+
+       failed_parse = parse_tree_gently(tree, 1);
+       if (failed_parse) {
                if (revs->ignore_missing_links)
                        return;
 
@@ -129,12 +171,14 @@ static void process_tree(struct traversal_context *ctx,
                    is_promisor_object(&obj->oid))
                        return;
 
-               die("bad tree object %s", oid_to_hex(&obj->oid));
+               if (!revs->do_not_die_on_missing_tree)
+                       die("bad tree object %s", oid_to_hex(&obj->oid));
        }
 
        strbuf_addstr(base, name);
-       if (!(obj->flags & USER_GIVEN) && ctx->filter_fn)
-               r = ctx->filter_fn(LOFS_BEGIN_TREE, obj,
+       if ((obj->flags & NOT_USER_GIVEN) && ctx->filter_fn)
+               r = ctx->filter_fn(ctx->revs->repo,
+                                  LOFS_BEGIN_TREE, obj,
                                   base->buf, &base->buf[baselen],
                                   ctx->filter_data);
        if (r & LOFR_MARK_SEEN)
@@ -144,32 +188,14 @@ static void process_tree(struct traversal_context *ctx,
        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(ctx,
-                                    lookup_tree(the_repository, entry.oid),
-                                    base, entry.path);
-               else if (S_ISGITLINK(entry.mode))
-                       process_gitlink(ctx, entry.oid->hash, base, entry.path);
-               else
-                       process_blob(ctx,
-                                    lookup_blob(the_repository, entry.oid),
-                                    base, entry.path);
-       }
+       if (r & LOFR_SKIP_TREE)
+               trace_printf("Skipping contents of tree %s...\n", base->buf);
+       else if (!failed_parse)
+               process_tree_contents(ctx, tree, base);
 
-       if (!(obj->flags & USER_GIVEN) && ctx->filter_fn) {
-               r = ctx->filter_fn(LOFS_END_TREE, obj,
+       if ((obj->flags & NOT_USER_GIVEN) && ctx->filter_fn) {
+               r = ctx->filter_fn(ctx->revs->repo,
+                                  LOFS_END_TREE, obj,
                                   base->buf, &base->buf[baselen],
                                   ctx->filter_data);
                if (r & LOFR_MARK_SEEN)
@@ -192,7 +218,7 @@ static void mark_edge_parents_uninteresting(struct commit *commit,
                struct commit *parent = parents->item;
                if (!(parent->object.flags & UNINTERESTING))
                        continue;
-               mark_tree_uninteresting(get_commit_tree(parent));
+               mark_tree_uninteresting(revs->repo, get_commit_tree(parent));
                if (revs->edge_hint && !(parent->object.flags & SHOWN)) {
                        parent->object.flags |= SHOWN;
                        show_edge(parent);
@@ -209,7 +235,8 @@ void mark_edges_uninteresting(struct rev_info *revs, show_edge_fn show_edge)
                struct commit *commit = list->item;
 
                if (commit->object.flags & UNINTERESTING) {
-                       mark_tree_uninteresting(get_commit_tree(commit));
+                       mark_tree_uninteresting(revs->repo,
+                                               get_commit_tree(commit));
                        if (revs->edge_hint_aggressive && !(commit->object.flags & SHOWN)) {
                                commit->object.flags |= SHOWN;
                                show_edge(commit);
@@ -224,7 +251,8 @@ void mark_edges_uninteresting(struct rev_info *revs, show_edge_fn show_edge)
                        struct commit *commit = (struct commit *)obj;
                        if (obj->type != OBJ_COMMIT || !(obj->flags & UNINTERESTING))
                                continue;
-                       mark_tree_uninteresting(get_commit_tree(commit));
+                       mark_tree_uninteresting(revs->repo,
+                                               get_commit_tree(commit));
                        if (!(obj->flags & SHOWN)) {
                                obj->flags |= SHOWN;
                                show_edge(commit);
@@ -284,8 +312,11 @@ static void do_traverse(struct traversal_context *ctx)
                 * an uninteresting boundary commit may not have its tree
                 * parsed yet, but we are not going to show them anyway
                 */
-               if (get_commit_tree(commit))
-                       add_pending_tree(ctx->revs, get_commit_tree(commit));
+               if (get_commit_tree(commit)) {
+                       struct tree *tree = get_commit_tree(commit);
+                       tree->object.flags |= NOT_USER_GIVEN;
+                       add_pending_tree(ctx->revs, tree);
+               }
                ctx->show_commit(commit, ctx->show_data);
 
                if (ctx->revs->tree_blobs_in_commit_order)