Mercurial > hg
changeset 7149:01a056c54385
patch: patchmeta gives (islink, isexec) tuple instead of int mode
author | Patrick Mezard <pmezard@gmail.com> |
---|---|
date | Sat, 18 Oct 2008 23:45:45 +0200 |
parents | 7d84e5b00e29 |
children | 6d1d61bb2984 |
files | mercurial/patch.py |
diffstat | 1 files changed, 14 insertions(+), 10 deletions(-) [+] |
line wrap: on
line diff
--- a/mercurial/patch.py Sat Oct 18 23:45:45 2008 +0200 +++ b/mercurial/patch.py Sat Oct 18 23:45:45 2008 +0200 @@ -148,8 +148,10 @@ 'op' is the performed operation within ADD, DELETE, RENAME, MODIFY or COPY. 'path' is patched file path. 'oldpath' is set to the - origin file when 'op' is either COPY or RENAME, None - otherwise. 'mode' is set to the new mode of patched file or None. + origin file when 'op' is either COPY or RENAME, None otherwise. If + file mode is changed, 'mode' is a tuple (islink, isexec) where + 'islink' is True if the file is a symlink and 'isexec' is True if + the file is executable. Otherwise, 'mode' is None. """ def __init__(self, path): self.path = path @@ -159,6 +161,11 @@ self.lineno = 0 self.binary = False + def setmode(self, mode): + islink = mode & 020000 + isexec = mode & 0100 + self.mode = (islink, isexec) + def readgitpatch(fp, firstline=None): """extract git-style metadata about patches from <patchname>""" @@ -208,9 +215,9 @@ gp.op = 'DELETE' elif line.startswith('new file mode '): gp.op = 'ADD' - gp.mode = int(line.rstrip()[-6:], 8) + gp.setmode(int(line.rstrip()[-6:], 8)) elif line.startswith('new mode '): - gp.mode = int(line.rstrip()[-6:], 8) + gp.setmode(int(line.rstrip()[-6:], 8)) elif line.startswith('GIT binary patch'): dopatch |= GP_BINARY gp.binary = True @@ -1096,17 +1103,14 @@ for f in patches: ctype, gp = patches[f] if gp and gp.mode: - flags = '' - if gp.mode & 0100: - flags = 'x' - elif gp.mode & 020000: - flags = 'l' + islink, isexec = gp.mode dst = os.path.join(repo.root, gp.path) # patch won't create empty files if ctype == 'ADD' and not os.path.exists(dst): + flags = (isexec and 'x' or '') + (islink and 'l' or '') repo.wwrite(gp.path, '', flags) else: - util.set_flags(dst, 'l' in flags, 'x' in flags) + util.set_flags(dst, islink, isexec) cmdutil.addremove(repo, cfiles) files = patches.keys() files.extend([r for r in removes if r not in files])