[PATCH 3 of 5] patch: introduce changedfiles

Idan Kamara idankk86 at gmail.com
Sat May 7 14:38:44 CDT 2011


On Sat, May 7, 2011 at 9:58 PM, Adrian Buehlmann <adrian at cadifra.com> wrote:

> On 2011-05-06 18:58, Idan Kamara wrote:
> > # HG changeset patch
> > # User Idan Kamara <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?
Does it fall back to Python's open() on pure builds? Btw why is it written
in C and not ctypes?


>
> > +    try:
> > +        changed = set()
> > +        for state, values in iterhunks(fp):
> > +            if state == 'hunk':
> > +                continue
> > +            elif state == 'file':
> > +                afile, bfile, first_hunk = values
> > +                current_file, missing = selectfile(afile, bfile,
> > +                                                   first_hunk, strip)
> > +                changed.add(current_file)
> > +            elif state == 'git':
> > +                for gp in values:
> > +                    gp.path = pathstrip(gp.path, strip - 1)[1]
> > +                    changed.add(gp.path)
> > +            else:
> > +                raise util.Abort(_('unsupported parser state: %s') %
> state)
> > +        return changed
> > +    finally:
> > +        fp.close()
> > +
> >  def _applydiff(ui, fp, patcher, copyfn, changed, strip=1,
> eolmode='strict'):
> >      rejects = 0
> >      err = 0
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://selenic.com/pipermail/mercurial-devel/attachments/20110507/184a2d4c/attachment.htm>


More information about the Mercurial-devel mailing list