Commit Diff


commit - 8e6eb32a6fc7af2d3bb89aebad7f5f9ae122b017
commit + 1faec3fb1acea5d3cb89b1e0ae2eeddb84cda4b9
blob - 38fd7b70ea3e69af82d8890621885791d38b1202
blob + 7d9b4c1647248ed45242f165d0852514e9a15ea8
--- got/got.c
+++ got/got.c
@@ -8163,6 +8163,12 @@ patch_from_stdin(int *patchfd)
 
 	return err;
 }
+
+struct got_patch_progress_arg {
+	int did_something;
+	int conflicts;
+	int rejects;
+};
 
 static const struct got_error *
 patch_progress(void *arg, const char *old, const char *new,
@@ -8171,13 +8177,24 @@ patch_progress(void *arg, const char *old, const char 
     int ws_mangled, const struct got_error *hunk_err)
 {
 	const char *path = new == NULL ? old : new;
+	struct got_patch_progress_arg *a = arg;
 
 	while (*path == '/')
 		path++;
 
-	if (status != 0)
+	if (status != GOT_STATUS_NO_CHANGE &&
+	    status != 0 /* per-hunk progress */) {
 		printf("%c  %s\n", status, path);
+		a->did_something = 1;
+	}
 
+	if (hunk_err == NULL) {
+		if (status == GOT_STATUS_CANNOT_UPDATE)
+			a->rejects++;
+		else if (status == GOT_STATUS_CONFLICT)
+			a->conflicts++;
+	}
+
 	if (error != NULL)
 		fprintf(stderr, "%s: %s\n", getprogname(), error->msg);
 
@@ -8193,6 +8210,21 @@ patch_progress(void *arg, const char *old, const char 
 	}
 
 	return NULL;
+}
+
+static void
+print_patch_progress_stats(struct got_patch_progress_arg *ppa)
+{
+	if (!ppa->did_something)
+		return;
+
+	if (ppa->conflicts > 0)
+		printf("Files with merge conflicts: %d\n", ppa->conflicts);
+
+	if (ppa->rejects > 0) {
+		printf("Files where patch failed to apply: %d\n",
+		    ppa->rejects);
+	}
 }
 
 static const struct got_error *
@@ -8210,6 +8242,7 @@ cmd_patch(int argc, char *argv[])
 	int ch, nop = 0, strip = -1, reverse = 0;
 	int patchfd;
 	int *pack_fds = NULL;
+	struct got_patch_progress_arg ppa;
 
 	TAILQ_INIT(&refs);
 
@@ -8300,9 +8333,10 @@ cmd_patch(int argc, char *argv[])
 			goto done;
 	}
 
+	memset(&ppa, 0, sizeof(ppa));
 	error = got_patch(patchfd, worktree, repo, nop, strip, reverse,
-	    commit_id, &patch_progress, NULL, check_cancelled, NULL);
-
+	    commit_id, patch_progress, &ppa, check_cancelled, NULL);
+	print_patch_progress_stats(&ppa);
 done:
 	got_ref_list_free(&refs);
 	free(commit_id);
blob - f8f96458bc264b17a74e776857380fbf625c03d2
blob + 17db471e5c3aa81e0eb9233b406861cdccd08fcd
--- regress/cmdline/patch.sh
+++ regress/cmdline/patch.sh
@@ -202,6 +202,7 @@ EOF
 @@ -1,1 +1,2 @@ hunk failed to apply
 #  numbers
 @@ -1,9 +0,0 @@ hunk failed to apply
+Files where patch failed to apply: 2
 EOF
 
 	cmp -s $testroot/stdout.expected $testroot/stdout
@@ -561,6 +562,7 @@ EOF
 #  iota
 #  kappa
 #  lambda
+Files where patch failed to apply: 5
 EOF
 
 	cat <<EOF > $testroot/stderr.expected
@@ -1528,6 +1530,7 @@ test_patch_merge_conflict() {
 
 	echo 'C  alpha' > $testroot/stdout.expected
 	echo 'C  numbers' >> $testroot/stdout.expected
+	echo 'Files with merge conflicts: 2' >> $testroot/stdout.expected
 	cmp -s $testroot/stdout $testroot/stdout.expected
 	ret=$?
 	if [ $ret -ne 0 ]; then