commit a7c9878d5b0e7770339e76efc0821897fe7a6be8 from: Stefan Sperling date: Thu Aug 08 06:40:38 2019 UTC make stage -p show the number of changes in a file commit - 6d23ec10d58455c5dd25839caf9e0b84461c4acb commit + a7c9878d5b0e7770339e76efc0821897fe7a6be8 blob - 3f39bc910f78147e8018edefbed523871fd89043 blob + 022dc3679c92b06dec343178983f00ab324b3b4e --- got/got.c +++ got/got.c @@ -5193,7 +5193,8 @@ print_stage(void *arg, unsigned char status, unsigned } static const struct got_error * -show_change(unsigned char status, const char *path, FILE *patch_file) +show_change(unsigned char status, const char *path, FILE *patch_file, int n, + int nchanges) { char *line = NULL; size_t linesize = 0; @@ -5215,7 +5216,8 @@ show_change(unsigned char status, const char *path, FI if (ferror(patch_file)) return got_error_from_errno("getline"); printf(GOT_COMMIT_SEP_STR); - printf("M %s\nstage this change? [y/n/q] ", path); + printf("M %s (change %d of %d)\nstage this change? [y/n/q] ", + path, n, nchanges); break; default: return got_error_path(path, GOT_ERR_FILE_STATUS); @@ -5226,7 +5228,7 @@ show_change(unsigned char status, const char *path, FI static const struct got_error * choose_patch(int *choice, void *arg, unsigned char status, const char *path, - FILE *patch_file) + FILE *patch_file, int n, int nchanges) { const struct got_error *err = NULL; char *line = NULL; @@ -5248,7 +5250,7 @@ choose_patch(int *choice, void *arg, unsigned char sta nl = strchr(line, '\n'); if (nl) *nl = '\0'; - err = show_change(status, path, patch_file); + err = show_change(status, path, patch_file, n, nchanges); if (err) return err; if (strcmp(line, "y") == 0) { @@ -5268,7 +5270,7 @@ choose_patch(int *choice, void *arg, unsigned char sta } while (resp != 'y' && resp != 'n' && resp != 'q') { - err = show_change(status, path, patch_file); + err = show_change(status, path, patch_file, n, nchanges); if (err) return err; resp = getchar(); blob - c4b942501561a17043e8895b1f6f2779fd3ebb10 blob + b07be0075e7e1ea62cda811facea1131cf1463c0 --- include/got_worktree.h +++ include/got_worktree.h @@ -375,7 +375,7 @@ const struct got_error *got_worktree_get_histedit_scri /* A callback function which is used to select or reject a patch. */ typedef const struct got_error *(*got_worktree_patch_cb)(int *, void *, - unsigned char, const char *, FILE *); + unsigned char, const char *, FILE *, int, int); /* Values for result output parameter of got_wortree_patch_cb. */ #define GOT_PATCH_CHOICE_NONE 0 blob - 496525cdbab66eb5140f3e444ebb242457424957 blob + e3af9a1729612641589c1819b36dbbbb23207911 --- lib/got_lib_diff.h +++ lib/got_lib_diff.h @@ -93,7 +93,7 @@ struct got_diff_change { }; struct got_diff_changes { - size_t nchanges; + int nchanges; SIMPLEQ_HEAD(, got_diff_change) entries; }; blob - 7de42bb2933ea1ece79a2ae3b05f4d3eec9aa4cc blob + 73c9e659a5d078b48f853bb0fb2ebf16cedef6f0 --- lib/worktree.c +++ lib/worktree.c @@ -5177,10 +5177,11 @@ skip_one_line(FILE *f) } static const struct got_error * -apply_or_reject_change(int *choice, struct got_diff_change *change, - struct got_diff_state *ds, struct got_diff_args *args, int diff_flags, - const char *relpath, FILE *f1, FILE *f2, int *line_cur1, int *line_cur2, - FILE *outfile, got_worktree_patch_cb patch_cb, void *patch_arg) +apply_or_reject_change(int *choice, struct got_diff_change *change, int n, + int nchanges, struct got_diff_state *ds, struct got_diff_args *args, + int diff_flags, const char *relpath, FILE *f1, FILE *f2, int *line_cur1, + int *line_cur2, FILE *outfile, got_worktree_patch_cb patch_cb, + void *patch_arg) { const struct got_error *err = NULL; int start_old = change->cv.a; @@ -5216,7 +5217,7 @@ apply_or_reject_change(int *choice, struct got_diff_ch } err = (*patch_cb)(choice, patch_arg, GOT_STATUS_MODIFY, relpath, - hunkfile); + hunkfile, n, nchanges); if (err) goto done; @@ -5308,6 +5309,7 @@ create_staged_content(char **path_outfile, struct got_ struct got_diff_args *args = NULL; struct got_diff_change *change; int diff_flags = 0, line_cur1 = 1, line_cur2 = 1, have_content = 0; + int n = 0; *path_outfile = NULL; @@ -5357,8 +5359,9 @@ create_staged_content(char **path_outfile, struct got_ return got_ferror(f2, GOT_ERR_IO); SIMPLEQ_FOREACH(change, &changes->entries, entry) { int choice; - err = apply_or_reject_change(&choice, change, ds, args, - diff_flags, relpath, f1, f2, &line_cur1, &line_cur2, + err = apply_or_reject_change(&choice, change, ++n, + changes->nchanges, ds, args, diff_flags, relpath, + f1, f2, &line_cur1, &line_cur2, outfile, patch_cb, patch_arg); if (err) goto done; @@ -5433,7 +5436,7 @@ stage_path(void *arg, unsigned char status, if (status == GOT_STATUS_ADD) { int choice = GOT_PATCH_CHOICE_NONE; err = (*a->patch_cb)(&choice, a->patch_arg, - status, ie->path, NULL); + status, ie->path, NULL, 1, 1); if (err) break; if (choice != GOT_PATCH_CHOICE_YES) @@ -5469,7 +5472,7 @@ stage_path(void *arg, unsigned char status, if (a->patch_cb) { int choice = GOT_PATCH_CHOICE_NONE; err = (*a->patch_cb)(&choice, a->patch_arg, status, - ie->path, NULL); + ie->path, NULL, 1, 1); if (err) break; if (choice != GOT_PATCH_CHOICE_YES) blob - 83c66f0ba6329c5e2da2747a82ae24dbdf3000cd blob + 3d1f624eae4a18cd9f42dbc35954c703cf11bc54 --- regress/cmdline/stage.sh +++ regress/cmdline/stage.sh @@ -1180,7 +1180,7 @@ function test_stage_patch { 4 5 ----------------------------------------------- -M numbers +M numbers (change 1 of 3) stage this change? [y/n/q] n ----------------------------------------------- @@ -4,7 +4,7 @@ @@ -1193,7 +1193,7 @@ stage this change? [y/n/q] n 9 10 ----------------------------------------------- -M numbers +M numbers (change 2 of 3) stage this change? [y/n/q] n ----------------------------------------------- @@ -13,4 +13,4 @@ @@ -1203,7 +1203,7 @@ stage this change? [y/n/q] n -16 +c ----------------------------------------------- -M numbers +M numbers (change 3 of 3) stage this change? [y/n/q] n EOF cmp -s $testroot/stdout.expected $testroot/stdout @@ -1239,7 +1239,7 @@ EOF 4 5 ----------------------------------------------- -M numbers +M numbers (change 1 of 3) stage this change? [y/n/q] n ----------------------------------------------- @@ -4,7 +4,7 @@ @@ -1252,7 +1252,7 @@ stage this change? [y/n/q] n 9 10 ----------------------------------------------- -M numbers +M numbers (change 2 of 3) stage this change? [y/n/q] y ----------------------------------------------- @@ -13,4 +13,4 @@ @@ -1262,7 +1262,7 @@ stage this change? [y/n/q] y -16 +c ----------------------------------------------- -M numbers +M numbers (change 3 of 3) stage this change? [y/n/q] n EOF cmp -s $testroot/stdout.expected $testroot/stdout @@ -1345,7 +1345,7 @@ EOF 4 5 ----------------------------------------------- -M numbers +M numbers (change 1 of 3) stage this change? [y/n/q] n ----------------------------------------------- @@ -4,7 +4,7 @@ @@ -1358,7 +1358,7 @@ stage this change? [y/n/q] n 9 10 ----------------------------------------------- -M numbers +M numbers (change 2 of 3) stage this change? [y/n/q] n ----------------------------------------------- @@ -13,4 +13,4 @@ @@ -1368,7 +1368,7 @@ stage this change? [y/n/q] n -16 +c ----------------------------------------------- -M numbers +M numbers (change 3 of 3) stage this change? [y/n/q] y EOF cmp -s $testroot/stdout.expected $testroot/stdout @@ -1572,7 +1572,7 @@ function test_stage_patch_quit { 4 5 ----------------------------------------------- -M numbers +M numbers (change 1 of 3) stage this change? [y/n/q] y ----------------------------------------------- @@ -4,7 +4,7 @@ @@ -1585,7 +1585,7 @@ stage this change? [y/n/q] y 9 10 ----------------------------------------------- -M numbers +M numbers (change 2 of 3) stage this change? [y/n/q] q EOF cmp -s $testroot/stdout.expected $testroot/stdout