builtin/merge: support --squash --commit
PATCH v3 1/1 builtin/merge: support --squash --commit
Using --squash made git stop regardless of conflicts so that the user could finish the operation with a later call to git-commit.
Now --squash --commit allows for the operation to finish with the new revision if there are no conflicts. If the user does not use --commit, then --no-commit is used as default so that it doesn't break previous git behavior.
Function squash_message() now saves the value in merge_msg so that the message with the squashed revisions is readily available when calling finish_automerge() to create new revision object.
Function finish() used to skip execution paths if using --squash because there would be no new revision object created. Also, it now makes sure to skip reflog update if using --squash _without_ --commit.
Function finish_automerge() allows to create a new revision object for an squashed merge (sets parent to current revision only, merge_msg will be set to squashed revisions by calling squash_message()), sets the reflog message to specify that it was a merge-squash operation and removes the $GIT_DIR/SQUASH_MSG file if needed.
--- builtin/merge.c | 93 +++++++++++++++++++++++++++++------------------- t/t7600-merge.sh | 86 ++++++++++++++++++++++++++++++++++++++++---- 2 files changed, 136 insertions(+), 43 deletions(-)
builtin/merge.c +56 -37
@@ -390,11 +390,13 @@ static void finish_up_to_date(const char *msg)static void squash_message (struct commit *commit,struct commit_list *remoteheads) {struct rev_info rev; -struct strbuf out =STRBUF_INIT ;struct commit_list *j;struct pretty_print_context ctx = {0 }; -printf (_ ("Squash commit -- not updating HEAD\n" )); +strbuf_release (&merge_msg); + +if (!option_commit) +printf (_ ("Squash commit -- not updating HEAD\n" ));repo_init_revisions (the_repository, &rev,NULL ); rev.ignore_merges =1 ;
@@ -414,15 +416,14 @@ static void squash_message(struct commit *commit, struct commit_list *remotehead ctx.date_mode = rev.date_mode; ctx.fmt = rev.commit_format; -strbuf_addstr (&out,"Squashed commit of the following:\n" ); +strbuf_addstr (&merge_msg,"Squashed commit of the following:\n" );while ((commit =get_revision (&rev)) !=NULL ) { -strbuf_addch (&out,'\n' ); -strbuf_addf (&out,"commit %s\n" , +strbuf_addch (&merge_msg,'\n' ); +strbuf_addf (&merge_msg,"commit %s\n" ,oid_to_hex (&commit->object.oid)); -pretty_print_commit (&ctx, commit, &out); +pretty_print_commit (&ctx, commit, &merge_msg); } -write_file_buf (git_path_squash_msg (the_repository), out.buf, out.len); -strbuf_release (&out); +write_file_buf (git_path_squash_msg (the_repository), merge_msg.buf, merge_msg.len); } static void finish(struct commit *head_commit,
@@ -440,22 +441,22 @@ static void finish(struct commit *head_commit,strbuf_addf (&reflog_message,"%s: %s" ,getenv ("GIT_REFLOG_ACTION" ), msg); } -if (squash) { +if (squash)squash_message (head_commit, remoteheads); - }else { -if (verbosity >=0 && !merge_msg.len) -printf (_ ("No merge message -- not updating HEAD\n" )); -else { -const char *argv_gc_auto[] = {"gc" ,"--auto" ,NULL }; -update_ref (reflog_message.buf,"HEAD" , new_head, head, -0 ,UPDATE_REFS_DIE_ON_ERR ); -/* -* We ignore errors in 'gc --auto', since the -* user should see them. -*/ -close_object_store (the_repository->objects); -run_command_v_opt (argv_gc_auto,RUN_GIT_CMD ); - } +if (verbosity >=0 && !merge_msg.len) +printf (_ ("No merge message -- not updating HEAD\n" )); +else if (squash && !option_commit) + ;/* avoid calling update_ref */ +else { +const char *argv_gc_auto[] = {"gc" ,"--auto" ,NULL }; +update_ref (reflog_message.buf,"HEAD" , new_head, head, +0 ,UPDATE_REFS_DIE_ON_ERR ); +/* +* We ignore errors in 'gc --auto', since the +* user should see them. +*/ +close_object_store (the_repository->objects); +run_command_v_opt (argv_gc_auto,RUN_GIT_CMD ); }if (new_head && show_diffstat) {struct diff_options opts;
@@ -893,17 +894,26 @@ static int finish_automerge(struct commit *head,struct object_id result_commit;free_commit_list (common); - parents = remoteheads; -if (!head_subsumed || fast_forward ==FF_NO ) -commit_list_insert (head, &parents); -prepare_to_commit (remoteheads); +if (squash) { +squash_message (head, remoteheads); + parents =commit_list_insert (head, &parents); + }else { + parents = remoteheads; +if (!head_subsumed || fast_forward ==FF_NO ) +commit_list_insert (head, &parents); +prepare_to_commit (remoteheads); + }if (commit_tree (merge_msg.buf, merge_msg.len, result_tree, parents, &result_commit,NULL , sign_commit)) -die (_ ("failed to write commit object" )); -strbuf_addf (&buf,"Merge made by the '%s' strategy." , wt_strategy); +die (squash ?_ ("failed to write commit object on squash" ) : +_ ("failed to write commit object" )); +strbuf_addf (&buf,"Merge made by the '%s' strategy" , wt_strategy); +strbuf_addstr (&buf, squash ?" (squashed)." :"." );finish (head, remoteheads, &result_commit, buf.buf);strbuf_release (&buf);remove_merge_branch_state (the_repository); +if (squash && option_commit) +unlink (git_path_squash_msg (the_repository));return 0 ; }
@@ -1345,14 +1355,13 @@ int cmd_merge(int argc, const char **argv, const char *prefix)if (squash) {if (fast_forward ==FF_NO )die (_ ("You cannot combine --squash with --no-ff." )); -if (option_commit >0 ) -die (_ ("You cannot combine --squash with --commit." )); +/* -* squash can now silently disable option_commit - this is not -* a problem as it is only overriding the default, not a user -* supplied option. +* In order to not break current behavior for --squash, if the user +* does not specify --commit, we assume it's --no-commit */ - option_commit =0 ; +if (option_commit <0 ) + option_commit =0 ; }if (option_commit <0 )
@@ -1510,6 +1519,13 @@ int cmd_merge(int argc, const char **argv, const char *prefix) goto done; } +if (squash && option_commit) { + ret =finish_automerge (head_commit,1 , common, + remoteheads,get_commit_tree_oid (commit), +"Fast-forward" ); + goto done; + } +finish (head_commit, remoteheads, &commit->object.oid, msg.buf);remove_merge_branch_state (the_repository); goto done;
@@ -1682,8 +1698,11 @@ int cmd_merge(int argc, const char **argv, const char *prefix)write_merge_state (remoteheads);if (merge_was_ok) -fprintf (stderr,_ ("Automatic merge went well; " -"stopped before committing as requested\n" )); +if (!option_commit) +fprintf (stderr,_ ("Automatic merge went well; " +"stopped before committing as requested\n" )); +else + ;else ret =suggest_conflicts ();
t/t7600-merge.sh +80 -6
122 lines not on this page · raw message
Signature · 1 line
2.20.1
Quoted 9 lines · Edmundo Carmona Antoranz
Using --squash made git stop regardless of conflicts so that the user could finish the operation with a later call to git-commit.
Now --squash --commit allows for the operation to finish with the new revision if there are no conflicts. If the user does not use --commit, then --no-commit is used as default so that it doesn't break previous git behavior.
What should I do to get this patch to move forward? Either get comments (as the previous versions did... thanks, Junio!) or be accepted? Given that I didn't get a feedback I thought that it had made it (always the optimistic) but I see that it's not in Junio's 'what's cooking' mail from friday so I think it's fair to assume that this version of the patch is not gonna fly.
Thanks in advance!