From: Linus Torvalds <torvalds@linux-foundation.org>
To: Junio C Hamano <gitster@pobox.com>,
Git Mailing List <git@vger.kernel.org>
Cc: Al Viro <viro@ZenIV.linux.org.uk>
Subject: buglet: 'git apply' doesn't handle criss-cross renames
Date: Thu, 9 Apr 2009 11:59:38 -0700 (PDT) [thread overview]
Message-ID: <alpine.LFD.2.00.0904091147290.4583@localhost.localdomain> (raw)
Ok, this doesn't come up in real life very much, but it's not impossible,
and I was generating this test-case to show Al how it's probably going to
be a real bitch to teach 'patch' how to handle git rename patches (or git
copy patches) in the general case.
Of course, the way git patches work is that the same source file may show
up several times (due to copies) or as both a source and a destination
(criss-cross renames or just rename + create new file), and we always look
at the _original_ state when we apply a patch fragment. Which makes it
hard for something like GNU "patch" that is purely linear.
And I was going to send Al an example of git doing that, and I was sure
that we had handled this at some point, but maybe I'm just wrong. I didn't
really go back and test it.
The point is, git itself fails here. Although not for any really
fundamental reason - but simply because we are a bit too tight on some
error handling, and do some checks wrong.
Git can _generate_ criss-cross merges correctly (although you have to use
the -B flag to make git try to break the names up):
mv kernel/sched.c a
mv kernel/exit.c kernel/sched.c
mv a kernel/exit.c
git diff -B -M > diff
and we get a nice correct diff:
diff --git a/kernel/sched.c b/kernel/exit.c
similarity index 100%
rename from kernel/sched.c
rename to kernel/exit.c
diff --git a/kernel/exit.c b/kernel/sched.c
similarity index 100%
rename from kernel/exit.c
rename to kernel/sched.c
but if you actually try to apply such a patch, we fail miserably (you need
to got a 'git reset --hard' or similar to get back the original tree to
apply the diff on, obviously):
[torvalds@nehalem linux]$ git apply diff
error: kernel/exit.c: already exists in working directory
error: kernel/sched.c: already exists in working directory
which is really sad.
I don't have a patch for it, and I don't think it's a huge deal in
practice, but I do think it's seriously wrong how we can generate a diff
that we then refuse to apply.
Linus
next reply other threads:[~2009-04-09 19:03 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2009-04-09 18:59 Linus Torvalds [this message]
2009-04-11 15:26 ` [PATCH] tests: test applying criss-cross rename patch Michał Kiedrowicz
2009-04-13 16:47 ` Junio C Hamano
2009-04-13 19:28 ` Junio C Hamano
2009-04-20 14:11 ` Alex Riesen
2009-04-21 7:08 ` Junio C Hamano
2009-04-21 12:41 ` Alex Riesen
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=alpine.LFD.2.00.0904091147290.4583@localhost.localdomain \
--to=torvalds@linux-foundation.org \
--cc=git@vger.kernel.org \
--cc=gitster@pobox.com \
--cc=viro@ZenIV.linux.org.uk \
/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