9front - general discussion about 9front
 help / color / mirror / Atom feed
From: igor@9lab.org
To: 9front@9front.org
Cc: ori@eigenstate.org, igor@9lab.org
Subject: [9front] [PATCH] git/merge: fix merge if directory of merged file does not exist
Date: Tue, 19 Apr 2022 13:27:09 +0200	[thread overview]
Message-ID: <16252894EB4E4869BAF9B5658115F8FF@9lab.org> (raw)

[-- Attachment #1: Type: text/plain, Size: 2848 bytes --]

When merging from branch `front` to `test` the following test case
fails:

<testcase>
  term% git/init merge.fail.git
  term% cd merge.fail.git
  term% mkdir A
  term% cp /sys/src/cmd/xargs.c A/
  term% git/add A/xargs.c
  term% git/commit -m 'Meh...' A/xargs.c
  heads/front: 5c36636e55aac3341ce42afee51b73106e8f1bc5
  term% git/branch -n test
  refs/heads/test: 5c36636e55aac3341ce42afee51b73106e8f1bc5
  term% mkdir X
  term% cp /sys/src/cmd/xargs.c X/
  term% git/add X/xargs.c
  term% git/commit -m 'Nein...' X/xargs.c
  heads/test: 6dc8fecb03f15e1c018c51306d25b10919e8fbe4
  term% git/branch front
  refs/heads/front: 5c36636e55aac3341ce42afee51b73106e8f1bc5
  term% mkdir A/B
  term% cp /sys/src/cmd/xargs.c A/B/
  term% git/add A/B/xargs.c
  term% git/commit -m 'NeinNein...' A/B/xargs.c
  heads/front: 3ca03f92152ed170e12b1ce2416ababbc18ffe54
  term% git/branch test
  refs/heads/test: 6dc8fecb03f15e1c018c51306d25b10919e8fbe4
  term% mkdir X/Y
  term% cp /sys/src/cmd/xargs.c X/Y/
  term% git/add X/Y/xargs.c
  term% git/commit -m  'NeinNeinNein...' X/Y/xargs.c
  heads/test: a81075176ae6dbd6f501e6ea43fd878a29b9c60d
  term% git/branch front
  refs/heads/front: 3ca03f92152ed170e12b1ce2416ababbc18ffe54
  term% git/branch test
  refs/heads/test: a81075176ae6dbd6f501e6ea43fd878a29b9c60d
  term% git/merge front
  /sys/lib/git/common.rc:88: > can't create: ./A/B/.tmp: './A/B' does not exist
</testcase>

The problem is a redirect in `/sys/lib/git/common.rc` that assumes the
directory component of the file that contains the diff exists:

<sys/lib/git/common.rc>
fn merge1 {@{
	rfork e
	n=$pid
	out=$1
	ours=$2
	base=$3
	theirs=$4
	tmp=$out.tmp
	while(test -f $tmp){
		tmp=$tmp.$n
		n=`{echo $n + 1 | hoc}
	}

	if(! test -f $ours)
		ours=/dev/null
	if(! test -f $base)
		base=/dev/null
	if(! test -f $theirs)
		theirs=/dev/null
	if(! ape/diff3 -3 -m $ours $base $theirs > $tmp)
		echo merge needed: $out >[1=2]
^^^^^^^^^^^^^^^^
IF THE FOLDER WHERE $tmp LIVES DOES NOT EXIST A REDIRECT
TO `> $tmp` FAILS TRIPPING UP THE MERGE

	if(mergeperm $ours $base $theirs){
		mv $tmp $out
		git/add $out
		chmod $mergedperms $out
	}
	if not {
		rm -f $tmp $out
		git/rm $out
	}
}}
</sys/lib/git/common.rc>

A solution is to check if the folder exists and create it via `mkdir -p`
in case it doesn't.

Can someone have a look and confirm this is the right solution and not
a hack. If this is Ok plz let me know and I can push the fix.

Thanks.

Cheers,
Igor

---
diff 45f713a2bc2961b3c920aed616188591612da210 3c2aa08560fba8a69e09731e3e5d72f7003021e3
--- a/sys/lib/git/common.rc	Sun Apr 17 23:25:04 2022
+++ b/sys/lib/git/common.rc	Tue Apr 19 13:19:00 2022
@@ -76,7 +76,8 @@
 		tmp=$tmp.$n
 		n=`{echo $n + 1 | hoc}
 	}
-
+	if(! test -d `{basename -d $tmp})
+		mkdir -p `{basename -d $tmp}
 	if(! test -f $ours)
 		ours=/dev/null
 	if(! test -f $base)

[-- Attachment #2: git.merge.patch --]
[-- Type: text/plain, Size: 2843 bytes --]

From: Igor Böhm <igor@9lab.org>
Date: Tue, 19 Apr 2022 11:19:00 +0000
Subject: [PATCH] git/merge: fix merge if directory of merged file does not exist


When merging from `front` to `test` branch the following test
case fails:

<testcase>
  term% git/init merge.fail.git
  term% cd merge.fail.git
  term% mkdir A
  term% cp /sys/src/cmd/xargs.c A/
  term% git/add A/xargs.c
  term% git/commit -m 'Meh...' A/xargs.c
  heads/front: 5c36636e55aac3341ce42afee51b73106e8f1bc5
  term% git/branch -n test
  refs/heads/test: 5c36636e55aac3341ce42afee51b73106e8f1bc5
  term% mkdir X
  term% cp /sys/src/cmd/xargs.c X/
  term% git/add X/xargs.c
  term% git/commit -m 'Nein...' X/xargs.c
  heads/test: 6dc8fecb03f15e1c018c51306d25b10919e8fbe4
  term% git/branch front
  refs/heads/front: 5c36636e55aac3341ce42afee51b73106e8f1bc5
  term% mkdir A/B
  term% cp /sys/src/cmd/xargs.c A/B/
  term% git/add A/B/xargs.c
  term% git/commit -m 'NeinNein...' A/B/xargs.c
  heads/front: 3ca03f92152ed170e12b1ce2416ababbc18ffe54
  term% git/branch test
  refs/heads/test: 6dc8fecb03f15e1c018c51306d25b10919e8fbe4
  term% mkdir X/Y
  term% cp /sys/src/cmd/xargs.c X/Y/
  term% git/add X/Y/xargs.c
  term% git/commit -m  'NeinNeinNein...' X/Y/xargs.c
  heads/test: a81075176ae6dbd6f501e6ea43fd878a29b9c60d
  term% git/branch front
  refs/heads/front: 3ca03f92152ed170e12b1ce2416ababbc18ffe54
  term% git/branch test
  refs/heads/test: a81075176ae6dbd6f501e6ea43fd878a29b9c60d
  term% git/merge front
  /sys/lib/git/common.rc:88: > can't create: ./A/B/.tmp: './A/B' does not exist
</testcase>

The problem is a redirect in `/sys/lib/git/common.rc` that assumes the
directory component of the file that contains the diff exists:

<sys/lib/git/common.rc>
fn merge1 {@{
	rfork e
	n=$pid
	out=$1
	ours=$2
	base=$3
	theirs=$4
	tmp=$out.tmp
	while(test -f $tmp){
		tmp=$tmp.$n
		n=`{echo $n + 1 | hoc}
	}

	if(! test -f $ours)
		ours=/dev/null
	if(! test -f $base)
		base=/dev/null
	if(! test -f $theirs)
		theirs=/dev/null
	if(! ape/diff3 -3 -m $ours $base $theirs > $tmp)
		echo merge needed: $out >[1=2]
^^^^^^^^^^^^^^^^
IF THE FOLDER WHERE $tmp LIVES DOES NOT EXIST A REDIRECT
TO `> $tmp` FAILS TRIPPING UP THE MERGE

	if(mergeperm $ours $base $theirs){
		mv $tmp $out
		git/add $out
		chmod $mergedperms $out
	}
	if not {
		rm -f $tmp $out
		git/rm $out
	}
}}
</sys/lib/git/common.rc>

A solution is to check if the folder exists and create it via `mkdir -p`
in case it doesn't.
---
diff 45f713a2bc2961b3c920aed616188591612da210 3c2aa08560fba8a69e09731e3e5d72f7003021e3
--- a/sys/lib/git/common.rc	Sun Apr 17 23:25:04 2022
+++ b/sys/lib/git/common.rc	Tue Apr 19 13:19:00 2022
@@ -76,7 +76,8 @@
 		tmp=$tmp.$n
 		n=`{echo $n + 1 | hoc}
 	}
-
+	if(! test -d `{basename -d $tmp})
+		mkdir -p `{basename -d $tmp}
 	if(! test -f $ours)
 		ours=/dev/null
 	if(! test -f $base)

             reply	other threads:[~2022-04-19 11:28 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-04-19 11:27 igor [this message]
2022-04-19 13:51 ` ori
2022-04-19 13:58   ` igor

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

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

  git send-email \
    --in-reply-to=16252894EB4E4869BAF9B5658115F8FF@9lab.org \
    --to=igor@9lab.org \
    --cc=9front@9front.org \
    --cc=ori@eigenstate.org \
    /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.
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 NNTP newsgroup(s).