git@vger.kernel.org mailing list mirror (one of many)
 help / color / mirror / code / Atom feed
From: "Jayati Shrivastava via GitGitGadget" <gitgitgadget@gmail.com>
To: git@vger.kernel.org
Cc: Johannes Schindelin <johannes.schindelin@gmx.de>,
	Hariom verma <hariom18599@gmail.com>,
	Christian Couder <christian.couder@gmail.com>,
	Junio C Hamano <gitster@pobox.com>,
	Jayati Shrivastava <gaurijove@gmail.com>,
	Jayati Shrivastava <gaurijove@gmail.com>
Subject: [PATCH v3] sequencer.c: use reverse_commit_list() helper
Date: Wed, 16 Mar 2022 11:20:23 +0000	[thread overview]
Message-ID: <pull.1177.v3.git.1647429623830.gitgitgadget@gmail.com> (raw)
In-Reply-To: <pull.1177.v2.git.1647427356490.gitgitgadget@gmail.com>

From: Jayati Shrivastava <gaurijove@gmail.com>

Instead of creating a new allocation, reverse the
original list in-place by calling the
reverse_commit_list() helper. The original code
discards the list "bases" after storing its
reverse copy in a newly created list "reversed".
If the code that followed from here used both
"bases" and "reversed", the modification would not
have worked, but since the original list "bases"
gets discarded, we can simply reverse "bases"
in-place with the reverse_commit_list() helper and
reuse the same variable in the code that follows.

builtin/merge.c has been left unmodified, since in
its case, the original list is needed separately
from its reverse copy by the code.

Signed-off-by: Jayati Shrivastava <gaurijove@gmail.com>
---
    Use reverse_commit_list helper function for in-place list reversal
    
    This patch address https://github.com/gitgitgadget/git/issues/1156
    Changes since v2:
    
     * updated the commit message to explain why builtin/merge.c has not
       been modified

Published-As: https://github.com/gitgitgadget/git/releases/tag/pr-1177%2Fvictorphoenix3%2Freverse-list-v3
Fetch-It-Via: git fetch https://github.com/gitgitgadget/git pr-1177/victorphoenix3/reverse-list-v3
Pull-Request: https://github.com/gitgitgadget/git/pull/1177

Range-diff vs v2:

 1:  f794bcd8bda ! 1:  6dd0d92096b sequencer.c: use reverse_commit_list() helper
     @@ Metadata
       ## Commit message ##
          sequencer.c: use reverse_commit_list() helper
      
     -    Instead of creating a new allocation, reverse the original
     -    list in-place by calling the reverse_commit_list() helper.
     -    The original code discards the list "bases" after storing
     -    its reverse copy in a newly created list "reversed". If the
     -    code that followed from here used both "bases" and "reversed",
     -    the modification would not have worked, but since the original
     -    list "bases" gets discarded, we can simply reverse "bases"
     -    in-place with the reverse_commit_list() helper and reuse the
     -    same variable in the code that follows.
     +    Instead of creating a new allocation, reverse the
     +    original list in-place by calling the
     +    reverse_commit_list() helper. The original code
     +    discards the list "bases" after storing its
     +    reverse copy in a newly created list "reversed".
     +    If the code that followed from here used both
     +    "bases" and "reversed", the modification would not
     +    have worked, but since the original list "bases"
     +    gets discarded, we can simply reverse "bases"
     +    in-place with the reverse_commit_list() helper and
     +    reuse the same variable in the code that follows.
     +
     +    builtin/merge.c has been left unmodified, since in
     +    its case, the original list is needed separately
     +    from its reverse copy by the code.
      
          Signed-off-by: Jayati Shrivastava <gaurijove@gmail.com>
      


 sequencer.c | 10 ++++------
 1 file changed, 4 insertions(+), 6 deletions(-)

diff --git a/sequencer.c b/sequencer.c
index 35006c0cea6..bccbb9e3522 100644
--- a/sequencer.c
+++ b/sequencer.c
@@ -3749,7 +3749,7 @@ static int do_merge(struct repository *r,
 	int run_commit_flags = 0;
 	struct strbuf ref_name = STRBUF_INIT;
 	struct commit *head_commit, *merge_commit, *i;
-	struct commit_list *bases, *j, *reversed = NULL;
+	struct commit_list *bases, *j;
 	struct commit_list *to_merge = NULL, **tail = &to_merge;
 	const char *strategy = !opts->xopts_nr &&
 		(!opts->strategy ||
@@ -3984,9 +3984,7 @@ static int do_merge(struct repository *r,
 		      git_path_merge_head(r), 0);
 	write_message("no-ff", 5, git_path_merge_mode(r), 0);
 
-	for (j = bases; j; j = j->next)
-		commit_list_insert(j->item, &reversed);
-	free_commit_list(bases);
+	bases = reverse_commit_list(bases);
 
 	repo_read_index(r);
 	init_merge_options(&o, r);
@@ -4002,10 +4000,10 @@ static int do_merge(struct repository *r,
 		 * update the index and working copy immediately.
 		 */
 		ret = merge_ort_recursive(&o,
-					  head_commit, merge_commit, reversed,
+					  head_commit, merge_commit, bases,
 					  &i);
 	} else {
-		ret = merge_recursive(&o, head_commit, merge_commit, reversed,
+		ret = merge_recursive(&o, head_commit, merge_commit, bases,
 				      &i);
 	}
 	if (ret <= 0)

base-commit: b896f729e240d250cf56899e6a0073f6aa469f5d
-- 
gitgitgadget

  reply	other threads:[~2022-03-16 11:20 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-03-15 19:41 [PATCH] Use reverse_commit_list helper function for in-place list reversal Jayati Shrivastava via GitGitGadget
2022-03-15 22:53 ` Junio C Hamano
2022-03-16 10:42 ` [PATCH v2] sequencer.c: use reverse_commit_list() helper Jayati Shrivastava via GitGitGadget
2022-03-16 11:20   ` Jayati Shrivastava via GitGitGadget [this message]
2022-03-16 19:44     ` [PATCH v3] " Junio C Hamano

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: http://vger.kernel.org/majordomo-info.html

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=pull.1177.v3.git.1647429623830.gitgitgadget@gmail.com \
    --to=gitgitgadget@gmail.com \
    --cc=christian.couder@gmail.com \
    --cc=gaurijove@gmail.com \
    --cc=git@vger.kernel.org \
    --cc=gitster@pobox.com \
    --cc=hariom18599@gmail.com \
    --cc=johannes.schindelin@gmx.de \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://80x24.org/mirrors/git.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).