Skip to content
This repository was archived by the owner on Nov 9, 2017. It is now read-only.

Commit 2ac5e44

Browse files
committed
revision: mark contents of an uninteresting tree uninteresting
"git rev-list --objects ^A^{tree} B^{tree}" ought to mean "I want a list of objects inside B's tree, but please exclude the objects that appear inside A's tree". we see the top-level tree marked as uninteresting (i.e. ^A^{tree} in the above example) and call mark_tree_uninteresting() on it; this unfortunately prevents us from recursing into the tree and marking the objects in the tree as uninteresting. The reason why "git log ^A A" yields an empty set of commits, i.e. we do not have a similar issue for commits, is because we call mark_parents_uninteresting() after seeing an uninteresting commit. The uninteresting-ness of the commit itself does not prevent its parents from being marked as uninteresting. Introduce mark_tree_contents_uninteresting() and structure the code in handle_commit() in such a way that it makes it the responsibility of the callchain leading to this function to mark commits, trees and blobs as uninteresting, and also make it the responsibility of the helpers called from this function to mark objects that are reachable from them. Note that this is a very old bug that probably dates back to the day when "rev-list --objects" was introduced. The line to clear tree->object.parsed at the end of mark_tree_contents_uninteresting() can be removed when this fix is merged to the codebase after 6e454b9 (clear parsed flag when we free tree buffers, 2013-06-05). Signed-off-by: Junio C Hamano <[email protected]>
1 parent 895c5ba commit 2ac5e44

File tree

2 files changed

+23
-8
lines changed

2 files changed

+23
-8
lines changed

revision.c

Lines changed: 17 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -98,17 +98,12 @@ static void mark_blob_uninteresting(struct blob *blob)
9898
blob->object.flags |= UNINTERESTING;
9999
}
100100

101-
void mark_tree_uninteresting(struct tree *tree)
101+
static void mark_tree_contents_uninteresting(struct tree *tree)
102102
{
103103
struct tree_desc desc;
104104
struct name_entry entry;
105105
struct object *obj = &tree->object;
106106

107-
if (!tree)
108-
return;
109-
if (obj->flags & UNINTERESTING)
110-
return;
111-
obj->flags |= UNINTERESTING;
112107
if (!has_sha1_file(obj->sha1))
113108
return;
114109
if (parse_tree(tree) < 0)
@@ -135,6 +130,19 @@ void mark_tree_uninteresting(struct tree *tree)
135130
*/
136131
free(tree->buffer);
137132
tree->buffer = NULL;
133+
tree->object.parsed = 0;
134+
}
135+
136+
void mark_tree_uninteresting(struct tree *tree)
137+
{
138+
struct object *obj = &tree->object;
139+
140+
if (!tree)
141+
return;
142+
if (obj->flags & UNINTERESTING)
143+
return;
144+
obj->flags |= UNINTERESTING;
145+
mark_tree_contents_uninteresting(tree);
138146
}
139147

140148
void mark_parents_uninteresting(struct commit *commit)
@@ -294,7 +302,8 @@ static struct commit *handle_commit(struct rev_info *revs, struct object *object
294302
if (!revs->tree_objects)
295303
return NULL;
296304
if (flags & UNINTERESTING) {
297-
mark_tree_uninteresting(tree);
305+
tree->object.flags |= UNINTERESTING;
306+
mark_tree_contents_uninteresting(tree);
298307
return NULL;
299308
}
300309
add_pending_object(revs, object, "");
@@ -309,7 +318,7 @@ static struct commit *handle_commit(struct rev_info *revs, struct object *object
309318
if (!revs->blob_objects)
310319
return NULL;
311320
if (flags & UNINTERESTING) {
312-
mark_blob_uninteresting(blob);
321+
blob->object.flags |= UNINTERESTING;
313322
return NULL;
314323
}
315324
add_pending_object(revs, object, "");

t/t6000-rev-list-misc.sh

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,4 +56,10 @@ test_expect_success 'rev-list A..B and rev-list ^A B are the same' '
5656
test_cmp expect actual
5757
'
5858

59+
test_expect_success 'propagate uninteresting flag down correctly' '
60+
git rev-list --objects ^HEAD^{tree} HEAD^{tree} >actual &&
61+
>expect &&
62+
test_cmp expect actual
63+
'
64+
5965
test_done

0 commit comments

Comments
 (0)