From: Linus Torvalds <torvalds@linux-foundation.org>
To: David Kastrup <dak@gnu.org>
Cc: Junio C Hamano <gitster@pobox.com>,
david@lang.hm, git@vger.kernel.org, rob@landley.net
Subject: Re: possible bug in git apply?
Date: Sun, 5 Aug 2007 11:18:19 -0700 (PDT) [thread overview]
Message-ID: <alpine.LFD.0.999.0708051106020.5037@woody.linux-foundation.org> (raw)
In-Reply-To: <85hcndj2b5.fsf@lola.goethe.zz>
On Sun, 5 Aug 2007, David Kastrup wrote:
>
> Which will let the user sit in an empty directory void of . and ..,
> and a parallel directory with the old name elsewhere. Unpretty...
It actually depends on the OS. POSIX allows the case of "rmdir()"
returning EBUSY if the directory is "in use", where "in use" may mean
being somebodys current working directory.
But yes, most UNIXes (Linux very much included) will just remove the
directory, and yes, the user ends up sitting in a directory that is empty
and not reachable from anywhere else.
Easy enough to see:
[torvalds@woody ~]$ mkdir test-me ; cd test-me ; rmdir $(pwd)
[torvalds@woody test-me]$ ls -a
[torvalds@woody test-me]$ pwd
/home/torvalds/test-me
[torvalds@woody test-me]$ /bin/pwd
/bin/pwd: couldn't find directory entry in `..' with matching i-node
(the first "pwd" is a shell built-in, and the shell caches is).
Under Linux, you can also see funky things like this:
[torvalds@woody test-me]$ ls -l /proc/self/cwd
lrwxrwxrwx 1 torvalds torvalds 0 2007-08-05 11:09 /proc/self/cwd -> /home/torvalds/test-me (deleted)
ie khe kernel actually shows you that you're in a deleted directory, that
_used_ to be called "test-me".
> > That said, if we really wanted to get it right, we should do this as
> > a three-phase thing: (1) remove old files (2) create new files (3)
> > for all removals and renames, try to remove source directories that
> > might have become empty.
> >
> > That would fix it properly and for all cases.
>
> Stupid question from someone without good background: why do we need
> two passes in the first place?
For example, a patch that removes a directory structure "x/..." and then
creates a file "x" in its place.
In order for the patch ordering to not matter, you want to do the "remove
old state" in an earlier phase.
And patch order shouldn't matter, since you can have interesting things
like mixing of renames and creates etc (ie maybe it's not "removing" that
directory x, it's just moving all the contents somewhere else, and maybe
the new file "x" is a move from somewhere else).
Criss-crossing renames make it even more interesting.
So git-apply actually does things in more than two phases: there's a whole
another phase that is the "read the patch and create the in-memory
result". The "two phases" above are actually just the two phases concerned
with actually modifying the working tree, there's more phases elsewhere.
Linus
next prev parent reply other threads:[~2007-08-05 18:19 UTC|newest]
Thread overview: 15+ messages / expand[flat|nested] mbox.gz Atom feed top
2007-08-04 19:45 possible bug in git apply? david
2007-08-04 20:00 ` Junio C Hamano
2007-08-04 20:08 ` David Kastrup
2007-08-05 4:48 ` Linus Torvalds
2007-08-05 4:53 ` Linus Torvalds
2007-08-05 5:11 ` Junio C Hamano
2007-08-05 7:55 ` David Kastrup
2007-08-05 16:59 ` Linus Torvalds
2007-08-05 17:53 ` David Kastrup
2007-08-05 18:18 ` Linus Torvalds [this message]
2007-08-05 18:50 ` David Kastrup
2007-08-05 19:20 ` Linus Torvalds
2007-08-05 19:37 ` David Kastrup
2007-08-06 8:29 ` Junio C Hamano
2007-08-06 9:37 ` 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
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=alpine.LFD.0.999.0708051106020.5037@woody.linux-foundation.org \
--to=torvalds@linux-foundation.org \
--cc=dak@gnu.org \
--cc=david@lang.hm \
--cc=git@vger.kernel.org \
--cc=gitster@pobox.com \
--cc=rob@landley.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;
as well as URLs for NNTP newsgroup(s).