comparison mercurial/patch.py @ 6743:86e8187b721a

simplify flag handling add _checklink var to dirstate introduce dirstate.flagfunc switch users of util.execfunc/linkfunc to flagfunc change manifestdict.set to take a flags string change ctx.fileflags to ctx.flags change gitmode func to a dict remove util.execfunc/linkfunc
author Matt Mackall <mpm@selenic.com>
date Thu, 26 Jun 2008 13:46:34 -0500
parents b148e9099133
children f6c00b17387c
comparison
equal deleted inserted replaced
6742:2d54e7c1e69d 6743:86e8187b721a
1191 1191
1192 if not modified and not added and not removed: 1192 if not modified and not added and not removed:
1193 return 1193 return
1194 1194
1195 ctx2 = repo.changectx(node2) 1195 ctx2 = repo.changectx(node2)
1196 if node2:
1197 execf2 = ctx2.manifest().execf
1198 linkf2 = ctx2.manifest().linkf
1199 else:
1200 execf2 = util.execfunc(repo.root, None)
1201 linkf2 = util.linkfunc(repo.root, None)
1202 if execf2 is None:
1203 mc = ctx2.parents()[0].manifest().copy()
1204 execf2 = mc.execf
1205 linkf2 = mc.linkf
1206 1196
1207 if repo.ui.quiet: 1197 if repo.ui.quiet:
1208 r = None 1198 r = None
1209 else: 1199 else:
1210 hexfunc = repo.ui.debugflag and hex or short 1200 hexfunc = repo.ui.debugflag and hex or short
1216 copy[v] = k 1206 copy[v] = k
1217 1207
1218 all = modified + added + removed 1208 all = modified + added + removed
1219 all.sort() 1209 all.sort()
1220 gone = {} 1210 gone = {}
1211
1212 gitmode = {'l': '120000', 'x': '100755', '': '100644'}
1221 1213
1222 for f in all: 1214 for f in all:
1223 to = None 1215 to = None
1224 tn = None 1216 tn = None
1225 dodiff = True 1217 dodiff = True
1228 to = getfilectx(f, ctx1).data() 1220 to = getfilectx(f, ctx1).data()
1229 if f not in removed: 1221 if f not in removed:
1230 tn = getfilectx(f, ctx2).data() 1222 tn = getfilectx(f, ctx2).data()
1231 a, b = f, f 1223 a, b = f, f
1232 if opts.git: 1224 if opts.git:
1233 def gitmode(x, l):
1234 return l and '120000' or (x and '100755' or '100644')
1235 def addmodehdr(header, omode, nmode): 1225 def addmodehdr(header, omode, nmode):
1236 if omode != nmode: 1226 if omode != nmode:
1237 header.append('old mode %s\n' % omode) 1227 header.append('old mode %s\n' % omode)
1238 header.append('new mode %s\n' % nmode) 1228 header.append('new mode %s\n' % nmode)
1239 1229
1240 if f in added: 1230 if f in added:
1241 mode = gitmode(execf2(f), linkf2(f)) 1231 mode = gitmode[ctx2.flags(f)]
1242 if f in copy: 1232 if f in copy:
1243 a = copy[f] 1233 a = copy[f]
1244 omode = gitmode(man1.execf(a), man1.linkf(a)) 1234 omode = gitmode[man1.flags(a)]
1245 addmodehdr(header, omode, mode) 1235 addmodehdr(header, omode, mode)
1246 if a in removed and a not in gone: 1236 if a in removed and a not in gone:
1247 op = 'rename' 1237 op = 'rename'
1248 gone[a] = 1 1238 gone[a] = 1
1249 else: 1239 else:
1258 elif f in removed: 1248 elif f in removed:
1259 # have we already reported a copy above? 1249 # have we already reported a copy above?
1260 if f in copy and copy[f] in added and copy[copy[f]] == f: 1250 if f in copy and copy[f] in added and copy[copy[f]] == f:
1261 dodiff = False 1251 dodiff = False
1262 else: 1252 else:
1263 mode = gitmode(man1.execf(f), man1.linkf(f)) 1253 header.append('deleted file mode %s\n' %
1264 header.append('deleted file mode %s\n' % mode) 1254 gitmode[man1.flags(f)])
1265 else: 1255 else:
1266 omode = gitmode(man1.execf(f), man1.linkf(f)) 1256 omode = gitmode[man1.flags(f)]
1267 nmode = gitmode(execf2(f), linkf2(f)) 1257 nmode = gitmode[ctx2.flags(f)]
1268 addmodehdr(header, omode, nmode) 1258 addmodehdr(header, omode, nmode)
1269 if util.binary(to) or util.binary(tn): 1259 if util.binary(to) or util.binary(tn):
1270 dodiff = 'binary' 1260 dodiff = 'binary'
1271 r = None 1261 r = None
1272 header.insert(0, 'diff --git a/%s b/%s\n' % (a, b)) 1262 header.insert(0, 'diff --git a/%s b/%s\n' % (a, b))