comparison mercurial/patch.py @ 5071:35d47b06d4e3

patch: add git symlink support
author Brendan Cully <brendan@kublai.com>
date Sat, 04 Aug 2007 23:07:52 -0700
parents a675f6d5d069
children d4fa6bafc43a
comparison
equal deleted inserted replaced
5070:5023af9fcba4 5071:35d47b06d4e3
200 gp.path = line[8:].rstrip() 200 gp.path = line[8:].rstrip()
201 elif line.startswith('deleted file'): 201 elif line.startswith('deleted file'):
202 gp.op = 'DELETE' 202 gp.op = 'DELETE'
203 elif line.startswith('new file mode '): 203 elif line.startswith('new file mode '):
204 gp.op = 'ADD' 204 gp.op = 'ADD'
205 gp.mode = int(line.rstrip()[-3:], 8) 205 gp.mode = int(line.rstrip()[-6:], 8)
206 elif line.startswith('new mode '): 206 elif line.startswith('new mode '):
207 gp.mode = int(line.rstrip()[-3:], 8) 207 gp.mode = int(line.rstrip()[-6:], 8)
208 elif line.startswith('GIT binary patch'): 208 elif line.startswith('GIT binary patch'):
209 dopatch |= GP_BINARY 209 dopatch |= GP_BINARY
210 gp.binary = True 210 gp.binary = True
211 if gp: 211 if gp:
212 gitpatches.append(gp) 212 gitpatches.append(gp)
1046 repo.remove(removes, True) 1046 repo.remove(removes, True)
1047 for f in patches: 1047 for f in patches:
1048 ctype, gp = patches[f] 1048 ctype, gp = patches[f]
1049 if gp and gp.mode: 1049 if gp and gp.mode:
1050 x = gp.mode & 0100 != 0 1050 x = gp.mode & 0100 != 0
1051 l = gp.mode & 020000 != 0
1051 dst = os.path.join(repo.root, gp.path) 1052 dst = os.path.join(repo.root, gp.path)
1052 # patch won't create empty files 1053 # patch won't create empty files
1053 if ctype == 'ADD' and not os.path.exists(dst): 1054 if ctype == 'ADD' and not os.path.exists(dst):
1054 repo.wwrite(gp.path, '', x and 'x' or '') 1055 repo.wwrite(gp.path, '', x and 'x' or '')
1055 else: 1056 else:
1056 util.set_exec(dst, x) 1057 util.set_link(dst, l)
1058 if not l:
1059 util.set_exec(dst, x)
1057 cmdutil.addremove(repo, cfiles) 1060 cmdutil.addremove(repo, cfiles)
1058 files = patches.keys() 1061 files = patches.keys()
1059 files.extend([r for r in removes if r not in files]) 1062 files.extend([r for r in removes if r not in files])
1060 files.sort() 1063 files.sort()
1061 1064
1143 return 1146 return
1144 1147
1145 if node2: 1148 if node2:
1146 ctx2 = context.changectx(repo, node2) 1149 ctx2 = context.changectx(repo, node2)
1147 execf2 = ctx2.manifest().execf 1150 execf2 = ctx2.manifest().execf
1151 linkf2 = ctx2.manifest().linkf
1148 else: 1152 else:
1149 ctx2 = context.workingctx(repo) 1153 ctx2 = context.workingctx(repo)
1150 execf2 = util.execfunc(repo.root, None) 1154 execf2 = util.execfunc(repo.root, None)
1155 linkf2 = util.linkfunc(repo.root, None)
1151 if execf2 is None: 1156 if execf2 is None:
1152 execf2 = ctx2.parents()[0].manifest().copy().execf 1157 mc = ctx2.parents()[0].manifest().copy()
1158 execf2 = mc.execf
1159 linkf2 = mc.linkf
1153 1160
1154 # returns False if there was no rename between ctx1 and ctx2 1161 # returns False if there was no rename between ctx1 and ctx2
1155 # returns None if the file was created between ctx1 and ctx2 1162 # returns None if the file was created between ctx1 and ctx2
1156 # returns the (file, node) present in ctx1 that was renamed to f in ctx2 1163 # returns the (file, node) present in ctx1 that was renamed to f in ctx2
1157 def renamed(f): 1164 def renamed(f):
1204 if f in man1: 1211 if f in man1:
1205 to = getfilectx(f, ctx1).data() 1212 to = getfilectx(f, ctx1).data()
1206 if f not in removed: 1213 if f not in removed:
1207 tn = getfilectx(f, ctx2).data() 1214 tn = getfilectx(f, ctx2).data()
1208 if opts.git: 1215 if opts.git:
1209 def gitmode(x): 1216 def gitmode(x, l):
1210 return x and '100755' or '100644' 1217 return l and '120000' or (x and '100755' or '100644')
1211 def addmodehdr(header, omode, nmode): 1218 def addmodehdr(header, omode, nmode):
1212 if omode != nmode: 1219 if omode != nmode:
1213 header.append('old mode %s\n' % omode) 1220 header.append('old mode %s\n' % omode)
1214 header.append('new mode %s\n' % nmode) 1221 header.append('new mode %s\n' % nmode)
1215 1222
1216 a, b = f, f 1223 a, b = f, f
1217 if f in added: 1224 if f in added:
1218 mode = gitmode(execf2(f)) 1225 mode = gitmode(execf2(f), linkf2(f))
1219 if f in copied: 1226 if f in copied:
1220 a = copied[f] 1227 a = copied[f]
1221 omode = gitmode(man1.execf(a)) 1228 omode = gitmode(man1.execf(a), man1.linkf(a))
1222 addmodehdr(header, omode, mode) 1229 addmodehdr(header, omode, mode)
1223 if a in removed and a not in gone: 1230 if a in removed and a not in gone:
1224 op = 'rename' 1231 op = 'rename'
1225 gone[a] = 1 1232 gone[a] = 1
1226 else: 1233 else:
1234 dodiff = 'binary' 1241 dodiff = 'binary'
1235 elif f in removed: 1242 elif f in removed:
1236 if f in srcs: 1243 if f in srcs:
1237 dodiff = False 1244 dodiff = False
1238 else: 1245 else:
1239 mode = gitmode(man1.execf(f)) 1246 mode = gitmode(man1.execf(f), man1.linkf(f))
1240 header.append('deleted file mode %s\n' % mode) 1247 header.append('deleted file mode %s\n' % mode)
1241 else: 1248 else:
1242 omode = gitmode(man1.execf(f)) 1249 omode = gitmode(man1.execf(f), man1.linkf(f))
1243 nmode = gitmode(execf2(f)) 1250 nmode = gitmode(execf2(f), linkf2(f))
1244 addmodehdr(header, omode, nmode) 1251 addmodehdr(header, omode, nmode)
1245 if util.binary(to) or util.binary(tn): 1252 if util.binary(to) or util.binary(tn):
1246 dodiff = 'binary' 1253 dodiff = 'binary'
1247 r = None 1254 r = None
1248 header.insert(0, 'diff --git a/%s b/%s\n' % (a, b)) 1255 header.insert(0, 'diff --git a/%s b/%s\n' % (a, b))