commit - e423877dd3fa76444ef448d4272a9f6d3ff32b54
commit + bfcdc9e9816dc81c90ce2db28ad9b602ec06b95a
blob - 5b1264a0869935160185d8dbf60cfca23110939d
blob + 8d34fc2c0463ba9b0482b97a427cd03c82b875d8
--- got/got.c
+++ got/got.c
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,
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);
}
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 *
int ch, nop = 0, strip = -1, reverse = 0;
int patchfd;
int *pack_fds = NULL;
+ struct got_patch_progress_arg ppa;
TAILQ_INIT(&refs);
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
@@ -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
# iota
# kappa
# lambda
+Files where patch failed to apply: 5
EOF
cat <<EOF > $testroot/stderr.expected
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