add histedit -f flag for folding shortcut "please push it" stsp
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176
diff --git a/got/got.1 b/got/got.1
index c44524c..f8e70b8 100644
--- a/got/got.1
+++ b/got/got.1
@@ -1489,7 +1489,7 @@ If this option is used, no other command-line arguments are allowed.
.It Cm rb
Short alias for
.Cm rebase .
-.It Cm histedit Oo Fl a Oc Oo Fl c Oc Oo Fl F Ar histedit-script Oc Oo Fl m Oc
+.It Cm histedit Oo Fl a Oc Oo Fl c Oc Oo Fl f Oc Oo Fl F Ar histedit-script Oc Oo Fl m Oc
Edit commit history between the work tree's current base commit and
the tip commit of the work tree's current branch.
.Pp
@@ -1517,8 +1517,15 @@ Editing of commit history is controlled via a
.Ar histedit script
which can be written in an editor based on a template, passed on the
command line, or generated with the
+.Fl f
+or
.Fl m
-option if only log messages need to be edited.
+options.
+The
+.Fl f
+option folds all commits into one commit, while the
+.Fl m
+option is used only if log messages need to be edited.
.Pp
The format of the histedit script is line-based.
Each line in the script begins with a command name, followed by
@@ -1618,6 +1625,11 @@ If this option is used, no other command-line arguments are allowed.
.It Fl c
Continue an interrupted histedit operation.
If this option is used, no other command-line arguments are allowed.
+.It Fl f
+Fold all commits into a single commit.
+This option is a quick equivalent to a histedit script which folds all
+commits, combining them all into one commit.
+If this option is used, no other command-line arguments are allowed.
.It Fl F Ar histedit-script
Use the specified
.Ar histedit-script
diff --git a/got/got.c b/got/got.c
index 3b8ba65..7bdd9e1 100644
--- a/got/got.c
+++ b/got/got.c
@@ -7747,7 +7747,7 @@ done:
__dead static void
usage_histedit(void)
{
- fprintf(stderr, "usage: %s histedit [-a] [-c] [-F histedit-script] [-m]\n",
+ fprintf(stderr, "usage: %s histedit [-a] [-c] [-f] [-F histedit-script] [-m]\n",
getprogname());
exit(1);
}
@@ -7814,17 +7814,20 @@ done:
static const struct got_error *
histedit_write_commit_list(struct got_object_id_queue *commits,
- FILE *f, int edit_logmsg_only, struct got_repository *repo)
+ FILE *f, int edit_logmsg_only, int fold_only, struct got_repository *repo)
{
const struct got_error *err = NULL;
struct got_object_qid *qid;
+ const char *histedit_cmd = NULL;
if (SIMPLEQ_EMPTY(commits))
return got_error(GOT_ERR_EMPTY_HISTEDIT);
SIMPLEQ_FOREACH(qid, commits, entry) {
- err = histedit_write_commit(qid->id, got_histedit_cmds[0].name,
- f, repo);
+ histedit_cmd = got_histedit_cmds[0].name;
+ if (fold_only && SIMPLEQ_NEXT(qid, entry) != NULL)
+ histedit_cmd = "fold";
+ err = histedit_write_commit(qid->id, histedit_cmd, f, repo);
if (err)
break;
if (edit_logmsg_only) {
@@ -8232,7 +8235,7 @@ histedit_edit_list_retry(struct got_histedit_list *, const struct got_error *,
static const struct got_error *
histedit_edit_script(struct got_histedit_list *histedit_cmds,
struct got_object_id_queue *commits, const char *branch_name,
- int edit_logmsg_only, struct got_repository *repo)
+ int edit_logmsg_only, int fold_only, struct got_repository *repo)
{
const struct got_error *err;
FILE *f = NULL;
@@ -8246,11 +8249,12 @@ histedit_edit_script(struct got_histedit_list *histedit_cmds,
if (err)
goto done;
- err = histedit_write_commit_list(commits, f, edit_logmsg_only, repo);
+ err = histedit_write_commit_list(commits, f, edit_logmsg_only,
+ fold_only, repo);
if (err)
goto done;
- if (edit_logmsg_only) {
+ if (edit_logmsg_only || fold_only) {
rewind(f);
err = histedit_parse_list(histedit_cmds, f, repo);
} else {
@@ -8381,7 +8385,7 @@ histedit_edit_list_retry(struct got_histedit_list *histedit_cmds,
} else if (resp == 'r') {
histedit_free_list(histedit_cmds);
err = histedit_edit_script(histedit_cmds,
- commits, branch_name, 0, repo);
+ commits, branch_name, 0, 0, repo);
if (err) {
if (err->code != GOT_ERR_HISTEDIT_SYNTAX &&
err->code != GOT_ERR_HISTEDIT_CMD)
@@ -8573,7 +8577,7 @@ cmd_histedit(int argc, char *argv[])
int ch, rebase_in_progress = 0;
struct got_update_progress_arg upa;
int edit_in_progress = 0, abort_edit = 0, continue_edit = 0;
- int edit_logmsg_only = 0;
+ int edit_logmsg_only = 0, fold_only = 0;
const char *edit_script_path = NULL;
unsigned char rebase_status = GOT_STATUS_NO_CHANGE;
struct got_object_id_queue commits;
@@ -8588,7 +8592,7 @@ cmd_histedit(int argc, char *argv[])
TAILQ_INIT(&merged_paths);
memset(&upa, 0, sizeof(upa));
- while ((ch = getopt(argc, argv, "acF:m")) != -1) {
+ while ((ch = getopt(argc, argv, "acfF:m")) != -1) {
switch (ch) {
case 'a':
abort_edit = 1;
@@ -8596,6 +8600,9 @@ cmd_histedit(int argc, char *argv[])
case 'c':
continue_edit = 1;
break;
+ case 'f':
+ fold_only = 1;
+ break;
case 'F':
edit_script_path = optarg;
break;
@@ -8624,6 +8631,12 @@ cmd_histedit(int argc, char *argv[])
errx(1, "histedit's -a and -m options are mutually exclusive");
if (continue_edit && edit_logmsg_only)
errx(1, "histedit's -c and -m options are mutually exclusive");
+ if (abort_edit && fold_only)
+ errx(1, "histedit's -a and -f options are mutually exclusive");
+ if (continue_edit && fold_only)
+ errx(1, "histedit's -c and -f options are mutually exclusive");
+ if (fold_only && edit_logmsg_only)
+ errx(1, "histedit's -f and -m options are mutually exclusive");
if (argc != 0)
usage_histedit();
@@ -8672,6 +8685,13 @@ cmd_histedit(int argc, char *argv[])
"before the -m option can be used");
goto done;
}
+ if (edit_in_progress && fold_only) {
+ error = got_error_msg(GOT_ERR_HISTEDIT_BUSY,
+ "histedit operation is in progress in this "
+ "work tree and must be continued or aborted "
+ "before the -f option can be used");
+ goto done;
+ }
if (edit_in_progress && abort_edit) {
error = got_worktree_histedit_continue(&resume_commit_id,
@@ -8807,7 +8827,7 @@ cmd_histedit(int argc, char *argv[])
if (strncmp(branch_name, "refs/heads/", 11) == 0)
branch_name += 11;
error = histedit_edit_script(&histedit_cmds, &commits,
- branch_name, edit_logmsg_only, repo);
+ branch_name, edit_logmsg_only, fold_only, repo);
if (error) {
got_worktree_histedit_abort(worktree, fileindex,
repo, branch, base_commit_id,