comparison mercurial/patch.py @ 5403:477136fa6571

Always copy the necessary files before applying a git patch This patch removes the "copymod" attribute from the gitpatch class. AFAICS, that attribute was only used to delay the copying of renamed/copied files if there are no other changes to the target, but in this case, if there are changes to the source, we'll end up copying the wrong version. This should fix issue762.
author Alexis S. L. Carvalho <alexis@cecm.usp.br>
date Sat, 06 Oct 2007 15:30:15 -0300
parents 15a108ad7adb
children 9b469bdb1ce1
comparison
equal deleted inserted replaced
5402:ad0b580cad35 5403:477136fa6571
149 def __init__(self, path): 149 def __init__(self, path):
150 self.path = path 150 self.path = path
151 self.oldpath = None 151 self.oldpath = None
152 self.mode = None 152 self.mode = None
153 self.op = 'MODIFY' 153 self.op = 'MODIFY'
154 self.copymod = False
155 self.lineno = 0 154 self.lineno = 0
156 self.binary = False 155 self.binary = False
157 156
158 def reader(fp, firstline): 157 def reader(fp, firstline):
159 if firstline is not None: 158 if firstline is not None:
180 gp = gitpatch(dst) 179 gp = gitpatch(dst)
181 gp.lineno = lineno 180 gp.lineno = lineno
182 elif gp: 181 elif gp:
183 if line.startswith('--- '): 182 if line.startswith('--- '):
184 if gp.op in ('COPY', 'RENAME'): 183 if gp.op in ('COPY', 'RENAME'):
185 gp.copymod = True
186 dopatch |= GP_FILTER 184 dopatch |= GP_FILTER
187 gitpatches.append(gp) 185 gitpatches.append(gp)
188 gp = None 186 gp = None
189 dopatch |= GP_PATCH 187 dopatch |= GP_PATCH
190 continue 188 continue
856 except IOError: 854 except IOError:
857 fp = cStringIO.StringIO(fp.read()) 855 fp = cStringIO.StringIO(fp.read())
858 856
859 (dopatch, gitpatches) = readgitpatch(fp, firstline) 857 (dopatch, gitpatches) = readgitpatch(fp, firstline)
860 for gp in gitpatches: 858 for gp in gitpatches:
861 if gp.copymod: 859 if gp.op in ('COPY', 'RENAME'):
862 copyfile(gp.oldpath, gp.path, basedir=cwd) 860 copyfile(gp.oldpath, gp.path, basedir=cwd)
863 861
864 fp.seek(pos) 862 fp.seek(pos)
865 863
866 return fp, dopatch, gitpatches 864 return fp, dopatch, gitpatches
1028 if cwd: 1026 if cwd:
1029 cfiles = [util.pathto(repo.root, cwd, f) for f in patches.keys()] 1027 cfiles = [util.pathto(repo.root, cwd, f) for f in patches.keys()]
1030 for f in patches: 1028 for f in patches:
1031 ctype, gp = patches[f] 1029 ctype, gp = patches[f]
1032 if ctype == 'RENAME': 1030 if ctype == 'RENAME':
1033 copies.append((gp.oldpath, gp.path, gp.copymod)) 1031 copies.append((gp.oldpath, gp.path))
1034 removes[gp.oldpath] = 1 1032 removes[gp.oldpath] = 1
1035 elif ctype == 'COPY': 1033 elif ctype == 'COPY':
1036 copies.append((gp.oldpath, gp.path, gp.copymod)) 1034 copies.append((gp.oldpath, gp.path))
1037 elif ctype == 'DELETE': 1035 elif ctype == 'DELETE':
1038 removes[gp.path] = 1 1036 removes[gp.path] = 1
1039 for src, dst, after in copies: 1037 for src, dst in copies:
1040 if not after:
1041 copyfile(src, dst, repo.root)
1042 repo.copy(src, dst) 1038 repo.copy(src, dst)
1043 removes = removes.keys() 1039 removes = removes.keys()
1044 if removes: 1040 if removes:
1045 removes.sort() 1041 removes.sort()
1046 repo.remove(removes, True) 1042 repo.remove(removes, True)