Commit Diff


commit - 7563c72e2e41ada53a4ff42883e4a80831fc3f3018028386f44a2664ec502065
commit + 2bb69d40249420751c9f31ec0006145738af69aba1abcb2af26966af74e3da29
blob - af9d941d599beff2661fbe07ddcf04419ddca5cbb81958f551bb36e349231ac5
blob + f234568271cfa6f35764ec3480436777093f9cb41e77a94d9f9944cee53d22e5
--- lib/got_lib_pack_create.h	
+++ lib/got_lib_pack_create.h	
@@ -55,6 +55,9 @@ enum got_pack_findtwixt_color {
 
 const struct got_error *got_pack_paint_commit(struct got_object_qid *qid,
     intptr_t color);
+const struct got_error *got_pack_repaint_parent_commits(
+    struct got_object_id *commit_id, int color, struct got_object_idset *set,
+    struct got_object_idset *skip, struct got_repository *repo);
 const struct got_error *got_pack_queue_commit_id(
     struct got_object_id_queue *ids, struct got_object_id *id, intptr_t color,
     struct got_repository *repo);
blob - 4e3cfc6b8f88b856e566a5a2f00c4e3231b29d7d8f86b1b489653afa5a7dfc90
blob + bb111f40027808632d73b913559eb3eac81d7c4770e4ea815556ab5bbbfb6bbc
--- lib/pack_create.c	
+++ lib/pack_create.c	
@@ -1049,6 +1049,77 @@ got_pack_paint_commit(struct got_object_qid *qid, intp
 }
 
 const struct got_error *
+got_pack_repaint_parent_commits(struct got_object_id *commit_id, int color,
+    struct got_object_idset *set, struct got_object_idset *skip,
+    struct got_repository *repo)
+{
+	const struct got_error *err;
+	struct got_object_id_queue ids;
+	struct got_object_qid *qid;
+	struct got_commit_object *commit;
+	const struct got_object_id_queue *parents;
+
+	STAILQ_INIT(&ids);
+
+	err = got_object_open_as_commit(&commit, repo, commit_id);
+	if (err)
+		return err;
+
+	while (commit) {
+		parents = got_object_commit_get_parent_ids(commit);
+		if (parents) {
+			struct got_object_qid *pid;
+			STAILQ_FOREACH(pid, parents, entry) {
+				/*
+				 * No need to traverse parents which are
+				 * already in the desired set or are
+				 * marked for skipping already.
+				 */
+				if (got_object_idset_contains(set, &pid->id))
+					continue;
+				if (skip != set &&
+				    got_object_idset_contains(skip, &pid->id))
+					continue;
+
+				err = got_pack_queue_commit_id(&ids, &pid->id,
+				    color, repo);
+				if (err)
+					break;
+			}
+		}
+		got_object_commit_close(commit);
+		commit = NULL;
+
+		qid = STAILQ_FIRST(&ids);
+		if (qid) {
+			STAILQ_REMOVE_HEAD(&ids, entry);
+			if (!got_object_idset_contains(set, &qid->id)) {
+				err = got_object_idset_add(set, &qid->id,
+				    NULL);
+				if (err)
+					break;
+			}
+
+			err = got_object_open_as_commit(&commit, repo,
+			    &qid->id);
+			if (err)
+				break;
+
+			got_object_qid_free(qid);
+			qid = NULL;
+		}
+	}
+
+	if (commit)
+		got_object_commit_close(commit);
+	if (qid)
+		got_object_qid_free(qid);
+	got_object_id_queue_free(&ids);
+
+	return err;
+}
+
+const struct got_error *
 got_pack_queue_commit_id(struct got_object_id_queue *ids,
     struct got_object_id *id, intptr_t color, struct got_repository *repo)
 {
blob - f1030ff9a47cd74ca33627e4e80821c3ad5b67aef58c053581ef96235454d7df
blob + 78da71aec4c0379472d2873f6b84a8601beaf665bd61de8dacd677aa297b51cc
--- lib/pack_create_io.c	
+++ lib/pack_create_io.c	
@@ -278,6 +278,14 @@ got_pack_paint_commits(int *ncolored, struct got_objec
 				err = got_pack_paint_commit(qid, COLOR_SKIP);
 				if (err)
 					goto done;
+				err = got_object_idset_add(skip, &qid->id,
+				    NULL);
+				if (err)
+					goto done;
+				err = got_pack_repaint_parent_commits(&qid->id,
+				    COLOR_SKIP, skip, skip, repo);
+				if (err)
+					goto done;
 			} else
 				(*ncolored)++;
 			err = got_object_idset_add(keep, &qid->id, NULL);
@@ -289,6 +297,14 @@ got_pack_paint_commits(int *ncolored, struct got_objec
 				err = got_pack_paint_commit(qid, COLOR_SKIP);
 				if (err)
 					goto done;
+				err = got_object_idset_add(skip, &qid->id,
+				    NULL);
+				if (err)
+					goto done;
+				err = got_pack_repaint_parent_commits(&qid->id,
+				    COLOR_SKIP, skip, skip, repo);
+				if (err)
+					goto done;
 			} else
 				(*ncolored)++;
 			err = got_object_idset_add(drop, &qid->id, NULL);
blob - 01b674dc63b1714a739ff40927c2dad3518eddf37221bebce8252520aee56c32
blob + 7c852564c96d9825a8cd9d29706b879998ebc0406ff1c77247ac531e605c6a0a
--- lib/pack_create_privsep.c	
+++ lib/pack_create_privsep.c	
@@ -413,6 +413,14 @@ got_pack_paint_commits(int *ncolored, struct got_objec
 				err = got_pack_paint_commit(qid, COLOR_SKIP);
 				if (err)
 					goto done;
+				err = got_object_idset_add(skip, &qid->id,
+				    NULL);
+				if (err)
+					goto done;
+				err = got_pack_repaint_parent_commits(&qid->id,
+				    COLOR_SKIP, skip, skip, repo);
+				if (err)
+					goto done;
 			} else
 				(*ncolored)++;
 			err = got_object_idset_add(keep, &qid->id, NULL);
@@ -424,6 +432,14 @@ got_pack_paint_commits(int *ncolored, struct got_objec
 				err = got_pack_paint_commit(qid, COLOR_SKIP);
 				if (err)
 					goto done;
+				err = got_object_idset_add(skip, &qid->id,
+				    NULL);
+				if (err)
+					goto done;
+				err = got_pack_repaint_parent_commits(&qid->id,
+				    COLOR_SKIP, skip, skip, repo);
+				if (err)
+					goto done;
 			} else
 				(*ncolored)++;
 			err = got_object_idset_add(drop, &qid->id, NULL);
blob - 6a58704f28a0ec05303b1ffc7fab1a221696174154b45ae11597cda79567bb72
blob + 7f4f55828aa14ec8d0f87761d013674514bc85bfda160651c4bab81600b4b514
--- regress/cmdline/pack.sh	
+++ regress/cmdline/pack.sh	
@@ -711,6 +711,67 @@ test_pack_tagged_tag() {
 	test_done "$testroot" "$ret"
 }
 
+test_pack_exclude_via_ancestor_commit() {
+	local testroot=`test_init pack_exclude`
+	local commit0=`git_show_head $testroot/repo`
+
+	# no pack files should exist yet
+	ls $testroot/repo/.git/objects/pack/ > $testroot/stdout
+	ret=$?
+	if [ $ret -ne 0 ]; then
+		test_done "$testroot" "$ret"
+		return 1
+	fi
+	echo -n > $testroot/stdout.expected
+	cmp -s $testroot/stdout.expected $testroot/stdout
+	ret=$?
+	if [ $ret -ne 0 ]; then
+		diff -u $testroot/stdout.expected $testroot/stdout
+		test_done "$testroot" "$ret"
+		return 1
+	fi
+
+	got checkout $testroot/repo $testroot/wt > /dev/null
+	ret=$?
+	if [ $ret -ne 0 ]; then
+		test_done "$testroot" "$ret"
+		return 1
+	fi
+
+	for i in 1 2 3; do 
+		echo a new line >> $testroot/wt/alpha
+		(cd $testroot/wt && got commit -m "edit alpha" >/dev/null)
+	done
+	local parent_commit=`git_show_head $testroot/repo`
+
+	echo a new line >> $testroot/wt/alpha
+	(cd $testroot/wt && got commit -m "edit alpha" >/dev/null)
+
+	got ref -r $testroot/repo -c $parent_commit refs/heads/pleasepackthis
+
+	# Packing the 'pleasepackthis' branch while exluding commits
+	# reachable via 'master' should result in an empty pack file.
+	gotadmin pack -a -r $testroot/repo -x master pleasepackthis \
+		> $testroot/stdout 2> $testroot/stderr
+	ret=$?
+	if [ $ret -eq 0 ]; then
+		echo "gotadmin pack succeeded unexpectedly" >&2
+		test_done "$testroot" "1"
+		return 1
+	fi
+
+	echo "gotadmin: not enough objects to pack" > $testroot/stderr.expected
+	cmp -s $testroot/stderr.expected $testroot/stderr
+	ret=$?
+	if [ $ret -ne 0 ]; then
+		diff -u $testroot/stderr.expected $testroot/stderr
+		test_done "$testroot" "$ret"
+		return 1
+	fi
+
+	test_done "$testroot" "$ret"
+}
+
 test_parseargs "$@"
 run_test test_pack_all_loose_objects
 run_test test_pack_exclude
@@ -721,3 +782,4 @@ run_test test_pack_loose_only
 run_test test_pack_all_objects
 run_test test_pack_bad_ref
 run_test test_pack_tagged_tag
+run_test test_pack_exclude_via_ancestor_commit