From: Linus Torvalds <torvalds@osdl.org>
To: Junio C Hamano <junkio@cox.net>
Cc: git@vger.kernel.org
Subject: Re: [PATCH] "checkout-cache -m" writes unmerged contents for each stage.
Date: Sun, 17 Apr 2005 19:05:53 -0700 (PDT) [thread overview]
Message-ID: <Pine.LNX.4.58.0504171833450.7211@ppc970.osdl.org> (raw)
In-Reply-To: <7v1x99vwdg.fsf@assigned-by-dhcp.cox.net>
On Sun, 17 Apr 2005, Junio C Hamano wrote:
>
> This is the alternative strategy I mentioned in my previous
> message. A new -m option to checkout-cache causes it to store
> contents of unmerged paths in path~1~, path~2~, and path~3~.
I don't think this is wrong, but it all seems a bit hacky. The reason I
didn't apply your other patch was that I just don't feel quite comfortable
with what is the RightThing(tm) to do yet.
I'm actually fairly certain that the right thing to do is to silently
ignore all unmerged entries. They just aren't "interesting" from a
checkout-cache perspective, least of all when given the "-a" flag. So even
warning about them seems to be pointless.
The other issue is that obviously we _do_ need to have some way to merge
them, but as far as I can tell, we've really got that already in
"show-files --unmerged" together with "cat-file blob xxxx". I do believe
that it's a damn ugly script, and that maybe we could create some helper
plumbing to make it more obvious, but I haven't quite decided what the
right helper interface would be.
Writing files to the current working directory I don't like, especially as
we don't even necessarily write all three files (so with your example
code, if there was a left-over xxx~1~ file from a previous merge, your
merger would really get confused now since it thinks it has an original
file that didn't actually really exist). So I'd much rather write them to
a /tmp directory instead, let the user merge them some way.
I'm actually thinking that maybe the _right_ interface is to do something
like this:
merge-cache <program> <filename>
and what that does is to look up the <filename> in the cache, and if it
has any merge entries, unpack all of them (which may be just one file, of
course) into up to three separate files (mkstemp()), and then execve the
supplied program name with those three files as arguments 1,2,3 (empty
argument if no file), and "filename" as argument 4.
So now the program could be a simple script:
#!/bin/sh
#
# This is the git merge script, called with
#
# $1 - original file (or empty string)
# $2 - file in branch1 (or empty string)
# $3 - file in branch2 (or empty string)
# $4 - pathname in repository
#
#
# Case 1: file removed in both
#
if [ -z "$2" && -z "$3" ]; then
rm -- "$4"
update-cache --remove -- "$4"
exit 0
fi
#
# Case 2: file exists in just one
#
if [ -z "$2" || -z "$3" ] then
cat "$2""$3" > "$4"
update-cache --add -- "$4"
exit 0
fi
#
# Case 3: file exists in both
#
src="$1"
if [ -z "$1" ]; then
src=/den/null
fi
merge "$3" "$src" "$2" && cp "$3" "$4" && update-cache --add -- "$4"
or you could so something fancier.
This would _seem_ to be a very simple way to generate a nice merge (the
merge script can obviously be a lot smarter than the above thing,
including doing nice graphical merge interfaces).
An extension of this might be to make "merge-cache" take several
filenames, and merge them one at a time (stopping if the merge program
returns a failure code). And obviously this also expands trivially to the
normal "-a" case, which would do the same, except it would just call the
merge program for any file it finds that needs merging)
What do you think? I can whip up a "merge-cache" program like that in five
minutes, and it _seems_ like the right interface..
Linus
next prev parent reply other threads:[~2005-04-18 2:00 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2005-04-17 23:03 [PATCH] "checkout-cache -m" writes unmerged contents for each stage Junio C Hamano
2005-04-18 2:05 ` Linus Torvalds [this message]
2005-04-18 2:19 ` Junio C Hamano
2005-04-18 3:05 ` Linus Torvalds
2005-04-18 2:44 ` Junio C Hamano
2005-04-18 2:56 ` Linus Torvalds
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=Pine.LNX.4.58.0504171833450.7211@ppc970.osdl.org \
--to=torvalds@osdl.org \
--cc=git@vger.kernel.org \
--cc=junkio@cox.net \
/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