[PATCH 3 of 5] patch: introduce changedfiles

Adrian Buehlmann adrian at cadifra.com
Sat May 7 15:25:09 CDT 2011


On 2011-05-07 21:38, Idan Kamara wrote:
> On Sat, May 7, 2011 at 9:58 PM, Adrian Buehlmann <adrian at cadifra.com
> <mailto:adrian at cadifra.com>> wrote:
> 
>     On 2011-05-06 18:58, Idan Kamara wrote:
>     > # HG changeset patch
>     > # User Idan Kamara <idankk86 at gmail.com <mailto:idankk86 at gmail.com>>
>     > # Date 1304697821 -10800
>     > # Node ID 1365953fe513ea8b9a68d238df5c65565475480c
>     > # Parent  7766361172826971d52df6c19a300d72e7f2abfc
>     > patch: introduce changedfiles
>     >
>     > returns the set of all changed files in a given patch
>     >
>     > diff -r 776636117282 -r 1365953fe513 mercurial/patch.py
>     > --- a/mercurial/patch.py      Fri May 06 18:45:12 2011 +0300
>     > +++ b/mercurial/patch.py      Fri May 06 19:03:41 2011 +0300
>     > @@ -1107,6 +1107,28 @@
>     >      return _applydiff(ui, fp, patchfile, copyfile, changed,
>     strip=strip,
>     >                        eolmode=eolmode)
>     >
>     > +def changedfiles(patchpath, strip=1):
>     > +    fp = open(patchpath, 'rb')
> 
>     Can you please use util.posixfile here?
> 
> 
> Hm sure.
>  
> 
> 
>     Python's plain open() is known to be notoriously crappy on Windows (if I
>     dare say so, since it is in fact Windows' file access which is crappy in
>     the first place).
> 
>     See http://mercurial.selenic.com/wiki/UnlinkingFilesOnWindows
> 
>     However, it might well be that it doesn't really matter in this specific
>     case. But there's no harm done in using util.posixfile instead of open.
> 
> 
> Well if it's harmless and doesn't incur any significant overhead is
> there any reason to keep using plain open() in all the other places?

Lazyness? I'm having an eye on open() calls since I found out how crappy
they are on Windows (the hardlinks on Windows shares saga, see the
archives if you are desperate enough). Most open calls in Mercurial's
code base predate that finding. But I believe I've already extirpated
the more interesting ones.

The first things that now get beaten up by this mode of mine is new
patches, since these are shoved right under my nose on this list. You
have the pleasure of being a victim now. Congrats :-)

> Does it fall back to Python's open() on pure builds? 

It should. A decent GSoC student can look at the source and find it out :-).

But hardcore Windows guys like myself think of pure on Windows as some
nice to have thing. We usually have bigger problems on that platform
than getting pure going.

> Btw why is it written in C and not ctypes?

Because... It's complicated. The C implementation makes use of the
Python C API, which enables an ingenious trick by Bryan that combines it
with some other neatly fitting C runtime function, so it can rule
everything by shoving a file handle opened by windows API CreateFile
under Python (I've already been loudly pondering [1] of sending a patch
for fixing open() to the Python temple, but I stalled on the error
handling and I feared the sledge hammer of the python devs. It would
have symbolic value only anyway, since we have to live with ancient
Python versions).

In fact, I have thought of trying to replicate it by using ctypes. But
it's complicated. And pure is not exactly one of my top problems right now.

(sigh, I already start regretting that I replied :-)

[1]
http://groups.google.com/group/thg-dev/browse_thread/thread/45ace24c0a7d3ba/082d88b2c661856d


More information about the Mercurial-devel mailing list