# [PATCH] Avoid excessive rewrites in merge-recursive

4 messages from 2007-04-25 to 2007-04-26. Participants: Alex Riesen, Junio C Hamano.
Thread: https://gitlist.dev/t/7845

## Alex Riesen, 2007-04-25 20:06

Subject: [PATCH] Avoid excessive rewrites in merge-recursive
Message-ID: <20070425200659.GA30061@steel.home>
URL: https://gitlist.dev/e/20070425200659.GA30061%40steel.home

```
If a file is changed in one branch, and renamed and changed to the
same content in another branch than we can skip the rewrite of this
file in the working directory, as the content does not change.

Signed-off-by: Alex Riesen <raa.lkml@gmail.com>
---

Just as you may have thought merge-recursive cannot get any uglier
someone comes and does just this: puts another level of indentation.

It is a nice speed up, though. Besides, I had some directories moved
between branches, and the rewrites caused a rebuild of hefty 8000
objects, which in windows terms is around 2 hours.

 merge-recursive.c |   32 +++++++++++++++++++-------------
 1 files changed, 19 insertions(+), 13 deletions(-)

diff --git a/merge-recursive.c b/merge-recursive.c
index 403a4c8..37f1ba9 100644
--- a/merge-recursive.c
+++ b/merge-recursive.c
@@ -1342,20 +1342,26 @@ static int process_renames(struct path_list *a_renames,
 				mfi = merge_file(o, a, b,
 						a_branch, b_branch);
 
-				if (mfi.merge || !mfi.clean)
-					output(1, "Renamed %s => %s", ren1_src, ren1_dst);
-				if (mfi.merge)
-					output(2, "Auto-merged %s", ren1_dst);
-				if (!mfi.clean) {
-					output(1, "CONFLICT (rename/modify): Merge conflict in %s",
-					       ren1_dst);
-					clean_merge = 0;
-
-					if (!index_only)
-						update_stages(ren1_dst,
-								o, a, b, 1);
+				if (mfi.merge && mfi.clean &&
+				    sha_eq(mfi.sha, ren1->pair->two->sha1) &&
+				    mfi.mode == ren1->pair->two->mode)
+					output(3, "Skipped %s (merged same as existing)", ren1_dst);
+				else {
+					if (mfi.merge || !mfi.clean)
+						output(1, "Renamed %s => %s", ren1_src, ren1_dst);
+					if (mfi.merge)
+						output(2, "Auto-merged %s", ren1_dst);
+					if (!mfi.clean) {
+						output(1, "CONFLICT (rename/modify): Merge conflict in %s",
+						       ren1_dst);
+						clean_merge = 0;
+
+						if (!index_only)
+							update_stages(ren1_dst,
+								      o, a, b, 1);
+					}
+					update_file(mfi.clean, mfi.sha, mfi.mode, ren1_dst);
 				}
-				update_file(mfi.clean, mfi.sha, mfi.mode, ren1_dst);
 			}
 		}
 	}
-- 
1.5.2.rc0.63.gdfc8-dirty

```

## Junio C Hamano, 2007-04-25 21:18

Subject: Re: [PATCH] Avoid excessive rewrites in merge-recursive
Message-ID: <7vodlcup9e.fsf@assigned-by-dhcp.cox.net>
URL: https://gitlist.dev/e/7vodlcup9e.fsf%40assigned-by-dhcp.cox.net
In-Reply-To: <20070425200659.GA30061@steel.home>

```
Alex Riesen <raa.lkml@gmail.com> writes:

> Just as you may have thought merge-recursive cannot get any uglier
> someone comes and does just this: puts another level of indentation.

It really was painful for me the last time I touched the file,
so I share that feeling.  The complexity of this program is
getting out of hand.

Probably we would want a refactoring before doing something like
this.

```

## Alex Riesen, 2007-04-25 22:13

Subject: Re: [PATCH] Avoid excessive rewrites in merge-recursive
Message-ID: <20070425221341.GH30061@steel.home>
URL: https://gitlist.dev/e/20070425221341.GH30061%40steel.home
In-Reply-To: <7vodlcup9e.fsf@assigned-by-dhcp.cox.net>

```
Junio C Hamano, Wed, Apr 25, 2007 23:18:21 +0200:
> 
> > Just as you may have thought merge-recursive cannot get any uglier
> > someone comes and does just this: puts another level of indentation.
> 
> It really was painful for me the last time I touched the file,
> so I share that feeling.  The complexity of this program is
> getting out of hand.
> 
> Probably we would want a refactoring before doing something like
> this.
> 

I want. I just can't afford something like this lately.
I'm even saving on "am"s and "not"s! :)

```

## Alex Riesen, 2007-04-26 19:13

Subject: [PATCH] Ignore merged status of the file-level merge
Message-ID: <20070426191349.GA9964@steel.home>
URL: https://gitlist.dev/e/20070426191349.GA9964%40steel.home
In-Reply-To: <20070425200659.GA30061@steel.home>

```
as it is not relevant for whether the result should be written.
Even if no real merge happened, there might be _no_ reason to
rewrite the working tree file. Maybe even more so.

Signed-off-by: Alex Riesen <raa.lkml@gmail.com>
---

 merge-recursive.c |    2 +-
 1 files changed, 1 insertions(+), 1 deletions(-)

diff --git a/merge-recursive.c b/merge-recursive.c
index 094ac59..8f72b2c 100644
--- a/merge-recursive.c
+++ b/merge-recursive.c
@@ -1342,7 +1342,7 @@ static int process_renames(struct path_list *a_renames,
 				mfi = merge_file(o, a, b,
 						a_branch, b_branch);
 
-				if (mfi.merge && mfi.clean &&
+				if (mfi.clean &&
 				    sha_eq(mfi.sha, ren1->pair->two->sha1) &&
 				    mfi.mode == ren1->pair->two->mode)
 					/*
-- 
1.5.2.rc0.65.g92b0b

```
