comparison mercurial/patch.py @ 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
comparison
equal deleted inserted replaced
7148:7d84e5b00e29 7149:01a056c54385
146 class patchmeta: 146 class patchmeta:
147 """Patched file metadata 147 """Patched file metadata
148 148
149 'op' is the performed operation within ADD, DELETE, RENAME, MODIFY 149 'op' is the performed operation within ADD, DELETE, RENAME, MODIFY
150 or COPY. 'path' is patched file path. 'oldpath' is set to the 150 or COPY. 'path' is patched file path. 'oldpath' is set to the
151 origin file when 'op' is either COPY or RENAME, None 151 origin file when 'op' is either COPY or RENAME, None otherwise. If
152 otherwise. 'mode' is set to the new mode of patched file or None. 152 file mode is changed, 'mode' is a tuple (islink, isexec) where
153 'islink' is True if the file is a symlink and 'isexec' is True if
154 the file is executable. Otherwise, 'mode' is None.
153 """ 155 """
154 def __init__(self, path): 156 def __init__(self, path):
155 self.path = path 157 self.path = path
156 self.oldpath = None 158 self.oldpath = None
157 self.mode = None 159 self.mode = None
158 self.op = 'MODIFY' 160 self.op = 'MODIFY'
159 self.lineno = 0 161 self.lineno = 0
160 self.binary = False 162 self.binary = False
163
164 def setmode(self, mode):
165 islink = mode & 020000
166 isexec = mode & 0100
167 self.mode = (islink, isexec)
161 168
162 def readgitpatch(fp, firstline=None): 169 def readgitpatch(fp, firstline=None):
163 """extract git-style metadata about patches from <patchname>""" 170 """extract git-style metadata about patches from <patchname>"""
164 171
165 def reader(fp, firstline): 172 def reader(fp, firstline):
206 gp.path = line[8:].rstrip() 213 gp.path = line[8:].rstrip()
207 elif line.startswith('deleted file'): 214 elif line.startswith('deleted file'):
208 gp.op = 'DELETE' 215 gp.op = 'DELETE'
209 elif line.startswith('new file mode '): 216 elif line.startswith('new file mode '):
210 gp.op = 'ADD' 217 gp.op = 'ADD'
211 gp.mode = int(line.rstrip()[-6:], 8) 218 gp.setmode(int(line.rstrip()[-6:], 8))
212 elif line.startswith('new mode '): 219 elif line.startswith('new mode '):
213 gp.mode = int(line.rstrip()[-6:], 8) 220 gp.setmode(int(line.rstrip()[-6:], 8))
214 elif line.startswith('GIT binary patch'): 221 elif line.startswith('GIT binary patch'):
215 dopatch |= GP_BINARY 222 dopatch |= GP_BINARY
216 gp.binary = True 223 gp.binary = True
217 if gp: 224 if gp:
218 gitpatches.append(gp) 225 gitpatches.append(gp)
1094 if removes: 1101 if removes:
1095 repo.remove(util.sort(removes), True) 1102 repo.remove(util.sort(removes), True)
1096 for f in patches: 1103 for f in patches:
1097 ctype, gp = patches[f] 1104 ctype, gp = patches[f]
1098 if gp and gp.mode: 1105 if gp and gp.mode:
1099 flags = '' 1106 islink, isexec = gp.mode
1100 if gp.mode & 0100:
1101 flags = 'x'
1102 elif gp.mode & 020000:
1103 flags = 'l'
1104 dst = os.path.join(repo.root, gp.path) 1107 dst = os.path.join(repo.root, gp.path)
1105 # patch won't create empty files 1108 # patch won't create empty files
1106 if ctype == 'ADD' and not os.path.exists(dst): 1109 if ctype == 'ADD' and not os.path.exists(dst):
1110 flags = (isexec and 'x' or '') + (islink and 'l' or '')
1107 repo.wwrite(gp.path, '', flags) 1111 repo.wwrite(gp.path, '', flags)
1108 else: 1112 else:
1109 util.set_flags(dst, 'l' in flags, 'x' in flags) 1113 util.set_flags(dst, islink, isexec)
1110 cmdutil.addremove(repo, cfiles) 1114 cmdutil.addremove(repo, cfiles)
1111 files = patches.keys() 1115 files = patches.keys()
1112 files.extend([r for r in removes if r not in files]) 1116 files.extend([r for r in removes if r not in files])
1113 return util.sort(files) 1117 return util.sort(files)
1114 1118