Commit 502b9684f951602db159ea8e357e404480666eec

Stefan Sperling 2020-07-31T15:36:42

make 'got log' -R and -P options work in combination With -R, the -P option did not show any paths. Regression test added here demonstrates the problem.

diff --git a/got/got.c b/got/got.c
index b786141..7d306e8 100644
--- a/got/got.c
+++ b/got/got.c
@@ -3259,7 +3259,7 @@ print_commits(struct got_object_id *root_id, struct got_object_id *end_id,
 		if (err)
 			break;
 
-		if (show_changed_paths) {
+		if (show_changed_paths && !reverse_display_order) {
 			err = get_changed_paths(&changed_paths, commit, repo);
 			if (err)
 				break;
@@ -3314,12 +3314,23 @@ print_commits(struct got_object_id *root_id, struct got_object_id *end_id,
 			err = got_object_open_as_commit(&commit, repo, qid->id);
 			if (err)
 				break;
+			if (show_changed_paths) {
+				err = get_changed_paths(&changed_paths,
+				    commit, repo);
+				if (err)
+					break;
+			}
 			err = print_commit(commit, qid->id, repo, path,
 			    show_changed_paths ? &changed_paths : NULL,
 			    show_patch, diff_context, refs);
 			got_object_commit_close(commit);
 			if (err)
 				break;
+			TAILQ_FOREACH(pe, &changed_paths, entry) {
+				free((char *)pe->path);
+				free(pe->data);
+			}
+			got_pathlist_free(&changed_paths);
 		}
 	}
 done:
diff --git a/regress/cmdline/log.sh b/regress/cmdline/log.sh
index c563ee1..6f9463f 100755
--- a/regress/cmdline/log.sh
+++ b/regress/cmdline/log.sh
@@ -577,6 +577,29 @@ function test_log_reverse_display {
 	ret="$?"
 	if [ "$ret" != "0" ]; then
 		diff -u $testroot/stdout.expected $testroot/stdout
+		test_done "$testroot" "$ret"
+		return 1
+	fi
+
+	# -R works in combination with -P
+	echo "" > $testroot/stdout.expected
+	(cd $testroot/wt && got log -R -P | grep -E '^(commit| [MDmA])' \
+		> $testroot/stdout)
+	echo "commit $commit_id0" > $testroot/stdout.expected
+	echo " A  alpha" >> $testroot/stdout.expected
+	echo " A  beta" >> $testroot/stdout.expected
+	echo " A  epsilon/zeta" >> $testroot/stdout.expected
+	echo " A  gamma/delta" >> $testroot/stdout.expected
+	echo "commit $commit_id1" >> $testroot/stdout.expected
+	echo " M  alpha" >> $testroot/stdout.expected
+	echo "commit $commit_id2" >> $testroot/stdout.expected
+	echo " D  beta" >> $testroot/stdout.expected
+	echo "commit $commit_id3 (master)" >> $testroot/stdout.expected
+	echo " A  new" >> $testroot/stdout.expected
+	cmp -s $testroot/stdout.expected $testroot/stdout
+	ret="$?"
+	if [ "$ret" != "0" ]; then
+		diff -u $testroot/stdout.expected $testroot/stdout
 	fi
 	test_done "$testroot" "$ret"
 }