t/helper: add a test helper to compute hash speed
[gitweb.git] / list-objects.c
index 0966cdc9fa8dd448aa9955a2fb5324ae8ebbf97d..c99c47ac181612db5122a313557090e1957fea4f 100644 (file)
@@ -9,6 +9,8 @@
 #include "list-objects.h"
 #include "list-objects-filter.h"
 #include "list-objects-filter-options.h"
+#include "packfile.h"
+#include "object-store.h"
 
 static void process_blob(struct rev_info *revs,
                         struct blob *blob,
@@ -30,9 +32,23 @@ static void process_blob(struct rev_info *revs,
        if (obj->flags & (UNINTERESTING | SEEN))
                return;
 
+       /*
+        * Pre-filter known-missing objects when explicitly requested.
+        * Otherwise, a missing object error message may be reported
+        * later (depending on other filtering criteria).
+        *
+        * Note that this "--exclude-promisor-objects" pre-filtering
+        * may cause the actual filter to report an incomplete list
+        * of missing objects.
+        */
+       if (revs->exclude_promisor_objects &&
+           !has_object_file(&obj->oid) &&
+           is_promisor_object(&obj->oid))
+               return;
+
        pathlen = path->len;
        strbuf_addstr(path, name);
-       if (filter_fn)
+       if (!(obj->flags & USER_GIVEN) && filter_fn)
                r = filter_fn(LOFS_BLOB, obj,
                              path->buf, &path->buf[pathlen],
                              filter_data);
@@ -91,6 +107,8 @@ static void process_tree(struct rev_info *revs,
                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;
 
        if (!revs->tree_objects)
                return;
@@ -98,14 +116,24 @@ static void process_tree(struct rev_info *revs,
                die("bad tree object");
        if (obj->flags & (UNINTERESTING | SEEN))
                return;
-       if (parse_tree_gently(tree, revs->ignore_missing_links) < 0) {
+       if (parse_tree_gently(tree, gently) < 0) {
                if (revs->ignore_missing_links)
                        return;
+
+               /*
+                * Pre-filter known-missing tree objects when explicitly
+                * requested.  This may cause the actual filter to report
+                * an incomplete list of missing objects.
+                */
+               if (revs->exclude_promisor_objects &&
+                   is_promisor_object(&obj->oid))
+                       return;
+
                die("bad tree object %s", oid_to_hex(&obj->oid));
        }
 
        strbuf_addstr(base, name);
-       if (filter_fn)
+       if (!(obj->flags & USER_GIVEN) && filter_fn)
                r = filter_fn(LOFS_BEGIN_TREE, obj,
                              base->buf, &base->buf[baselen],
                              filter_data);
@@ -130,7 +158,7 @@ static void process_tree(struct rev_info *revs,
 
                if (S_ISDIR(entry.mode))
                        process_tree(revs,
-                                    lookup_tree(entry.oid),
+                                    lookup_tree(the_repository, entry.oid),
                                     show, base, entry.path,
                                     cb_data, filter_fn, filter_data);
                else if (S_ISGITLINK(entry.mode))
@@ -139,12 +167,12 @@ static void process_tree(struct rev_info *revs,
                                        cb_data);
                else
                        process_blob(revs,
-                                    lookup_blob(entry.oid),
+                                    lookup_blob(the_repository, entry.oid),
                                     show, base, entry.path,
                                     cb_data, filter_fn, filter_data);
        }
 
-       if (filter_fn) {
+       if (!(obj->flags & USER_GIVEN) && filter_fn) {
                r = filter_fn(LOFS_END_TREE, obj,
                              base->buf, &base->buf[baselen],
                              filter_data);
@@ -168,7 +196,7 @@ static void mark_edge_parents_uninteresting(struct commit *commit,
                struct commit *parent = parents->item;
                if (!(parent->object.flags & UNINTERESTING))
                        continue;
-               mark_tree_uninteresting(parent->tree);
+               mark_tree_uninteresting(get_commit_tree(parent));
                if (revs->edge_hint && !(parent->object.flags & SHOWN)) {
                        parent->object.flags |= SHOWN;
                        show_edge(parent);
@@ -185,7 +213,7 @@ 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(commit->tree);
+                       mark_tree_uninteresting(get_commit_tree(commit));
                        if (revs->edge_hint_aggressive && !(commit->object.flags & SHOWN)) {
                                commit->object.flags |= SHOWN;
                                show_edge(commit);
@@ -200,7 +228,7 @@ 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(commit->tree);
+                       mark_tree_uninteresting(get_commit_tree(commit));
                        if (!(obj->flags & SHOWN)) {
                                obj->flags |= SHOWN;
                                show_edge(commit);
@@ -273,8 +301,8 @@ static void do_traverse(struct rev_info *revs,
                 * 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);
+               if (get_commit_tree(commit))
+                       add_pending_tree(revs, get_commit_tree(commit));
                show_commit(commit, show_data);
 
                if (revs->tree_blobs_in_commit_order)