Thread (1 message) 1 message, 1 author, 2018-09-14

Re: [PATCH v8 7/7] list-objects-filter: implement filter tree:0

From: Junio C Hamano <hidden>
Date: 2018-09-14 17:39:49

Matthew DeVore [off-list ref] writes:
quoted hunk
diff --git a/list-objects-filter-options.c b/list-objects-filter-options.c
index c0e2bd6a0..14f251de4 100644
--- a/list-objects-filter-options.c
+++ b/list-objects-filter-options.c
@@ -50,6 +50,20 @@ static int gently_parse_list_objects_filter(
 			return 0;
 		}
 
+	} else if (skip_prefix(arg, "tree:", &v0)) {
+		unsigned long depth;
+		if (!git_parse_ulong(v0, &depth) || depth != 0) {
+			if (errbuf) {
+				strbuf_init(errbuf, 0);
+				strbuf_addstr(
+					errbuf,
+					_("only 'tree:0' is supported"));
This is not a new issue with this patch, but I think strbuf_init()
at the location of filling done like this is a bad idea.  If the
caller gave you an errbuf that is pre-filled with something, we'd
leak memory and lose information.  It only makes sense to _init() if
the caller gave us an uninitialized garbage (or a strbuf that has
just been initialized and is empty).  

The existing callers seem to do STRBUF_INIT before passing it to
this function, so we probably should not do strbuf_init() here (and
other two places in this function) and simply add to it.
quoted hunk
diff --git a/t/t5616-partial-clone.sh b/t/t5616-partial-clone.sh
index bbbe7537d..8eeb85fbc 100755
--- a/t/t5616-partial-clone.sh
+++ b/t/t5616-partial-clone.sh
@@ -154,6 +154,44 @@ test_expect_success 'partial clone with transfer.fsckobjects=1 uses index-pack -
 	grep "git index-pack.*--fsck-objects" trace
 '
 
+test_expect_success 'use fsck before and after manually fetching a missing subtree' '
+	# push new commit so server has a subtree
+	mkdir src/dir &&
+	echo "in dir" >src/dir/file.txt &&
+	git -C src add dir/file.txt &&
+	git -C src commit -m "file in dir" &&
+	git -C src push -u srv master &&
+	SUBTREE=$(git -C src rev-parse HEAD:dir) &&
+
+	rm -rf dst &&
+	git clone --no-checkout --filter=tree:0 "file://$(pwd)/srv.bare" dst &&
+	git -C dst fsck &&
+
+	# Make sure we only have commits, and all trees and blobs are missing.
+	git -C dst rev-list master --missing=allow-any --objects >fetched_objects &&
+	awk -f print_1.awk fetched_objects \
+		| xargs -n1 git -C dst cat-file -t >fetched_types &&
Break line after pipe "|", not before, and lose the backslash.  You
do not need to over-indent the command on the downstream of the
pipe, i.e.

	awk ... |
	xargs -n1 git -C ... &&

Same comment applies elsewhere in this patch, not limited to this file.
+	sort fetched_types -u >unique_types.observed &&
Make it a habit not to add dashed options after real arguments, i.e.

	sort -u fetched_types
+	echo commit >unique_types.expected &&
+	test_cmp unique_types.observed unique_types.expected &&
Always compare "expect" with "actual", not in the reverse order, i.e.

	test_cmp expect actual

not

	test_cmp actual expect

This is important because test_cmp reports failures by showing you
an output of "diff expect actual" and from "sh t5616-part*.sh -v"
you can see what additional/excess things were produced by the test
over what is expected, prefixed with "+", and what your code failed
to produce are shown prefixed with "-".

Thanks.
Keyboard shortcuts
hback out one level
jnext message in thread
kprevious message in thread
ldrill in
Escclose help / fold thread tree
?toggle this help