Commit c2105d002a73e60c6f3194dd96a1a0b09eb34e08

Stefan Sperling 2021-09-14T19:02:10

fix another instance of 'got send' sending branches the server already has

diff --git a/lib/send.c b/lib/send.c
index 389638c..439105b 100644
--- a/lib/send.c
+++ b/lib/send.c
@@ -330,7 +330,6 @@ got_send_pack(const char *remote_name, struct got_pathlist_head *branch_names,
 	struct got_reflist_entry *re;
 	struct got_object_id **our_ids = NULL;
 	struct got_object_id **their_ids = NULL;
-	struct got_object_id *my_id = NULL;
 	int i, nours = 0, ntheirs = 0;
 	size_t nalloc_ours = 0, nalloc_theirs = 0;
 	int refs_to_send = 0, refs_to_delete = 0;
@@ -518,15 +517,13 @@ got_send_pack(const char *remote_name, struct got_pathlist_head *branch_names,
 		 */
 		my_ref = find_ref(&refs, refname);
 		if (my_ref) {
+			struct got_object_id *my_id;
 			err = got_ref_resolve(&my_id, repo, my_ref);
 			if (err)
 				goto done;
-			if (got_object_id_cmp(my_id, their_id) == 0) {
-				free(my_id);
-				my_id = NULL;
-				continue;
-			}
-			refs_to_send++;
+			if (got_object_id_cmp(my_id, their_id) != 0)
+				refs_to_send++;
+			free(my_id);
 
 		}
 
@@ -722,6 +719,5 @@ done:
 	for (i = 0; i < ntheirs; i++)
 		free(their_ids[i]);
 	free(their_ids);
-	free(my_id);
 	return err;
 }
diff --git a/regress/cmdline/send.sh b/regress/cmdline/send.sh
index f090679..eb88e75 100755
--- a/regress/cmdline/send.sh
+++ b/regress/cmdline/send.sh
@@ -719,8 +719,47 @@ EOF
 	ret="$?"
 	if [ "$ret" != "0" ]; then
 		diff -u $testroot/stdout.expected $testroot/stdout
+		test_done "$testroot" "$ret"
+		return 1
 	fi
-	test_done "$testroot" "$ret"
+
+	got checkout $testroot/repo $testroot/wt > /dev/null
+	echo 'new line in file alpha' >> $testroot/wt/alpha
+	(cd $testroot/wt && got commit -m 'changing file alpha' > /dev/null)
+
+	# Send the new commit in isolation.
+	got send -q -r $testroot/repo > $testroot/stdout \
+		2> $testroot/stderr
+	ret="$?"
+	if [ "$ret" != "0" ]; then
+		echo "got send command failed unexpectedly" >&2
+		test_done "$testroot" "$ret"
+		return 1
+	fi
+
+	# Now tag it and send the tag.
+	# Verify that just the new tag object gets sent.
+	got tag -r $testroot/repo -m '3.0' 3.0 >/dev/null
+	tag_id4=`got ref -r $testroot/repo -l | grep "^refs/tags/1.0" \
+		| tr -d ' ' | cut -d: -f2`
+
+	got send -r $testroot/repo -t 3.0 > $testroot/stdout.raw \
+		2> $testroot/stderr
+	ret="$?"
+	if [ "$ret" != "0" ]; then
+		echo "got send command failed unexpectedly" >&2
+		test_done "$testroot" "$ret"
+		return 1
+	fi
+	tr -d '\r' < $testroot/stdout.raw > $testroot/stdout
+	if ! grep -q "packing 2 references; 1 object; deltify: 100%" \
+		$testroot/stdout; then
+		echo "got send did apparently pack too many objects:" >&2
+		cat $testroot/stdout.raw >&2
+		test_done "$testroot" "1"
+		return 1
+	fi
+	test_done "$testroot" "0"
 }
 
 test_send_tag_of_deleted_branch() {