comparison mercurial/patch.py @ 5264:0fc16031bb45

Make hg diff --git -r revA:revB detect (inverted) copies if revA > revB
author Alexis S. L. Carvalho <alexis@cecm.usp.br>
date Tue, 28 Aug 2007 22:48:25 -0300
parents d4fa6bafc43a
children 15a108ad7adb
comparison
equal deleted inserted replaced
5263:8040f2e4cad0 5264:0fc16031bb45
1159 linkf2 = mc.linkf 1159 linkf2 = mc.linkf
1160 1160
1161 # returns False if there was no rename between ctx1 and ctx2 1161 # returns False if there was no rename between ctx1 and ctx2
1162 # returns None if the file was created between ctx1 and ctx2 1162 # returns None if the file was created between ctx1 and ctx2
1163 # 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
1164 def renamed(f): 1164 # This will only really work if c1 is the Nth 1st parent of c2.
1165 startrev = ctx1.rev() 1165 def renamed(c1, c2, man, f):
1166 c = ctx2 1166 startrev = c1.rev()
1167 c = c2
1167 crev = c.rev() 1168 crev = c.rev()
1168 if crev is None: 1169 if crev is None:
1169 crev = repo.changelog.count() 1170 crev = repo.changelog.count()
1170 orig = f 1171 orig = f
1171 while crev > startrev: 1172 while crev > startrev:
1177 if src: 1178 if src:
1178 f = src[0] 1179 f = src[0]
1179 crev = c.parents()[0].rev() 1180 crev = c.parents()[0].rev()
1180 # try to reuse 1181 # try to reuse
1181 c = getctx(crev) 1182 c = getctx(crev)
1182 if f not in man1: 1183 if f not in man:
1183 return None 1184 return None
1184 if f == orig: 1185 if f == orig:
1185 return False 1186 return False
1186 return f 1187 return f
1187 1188
1191 hexfunc = repo.ui.debugflag and hex or short 1192 hexfunc = repo.ui.debugflag and hex or short
1192 r = [hexfunc(node) for node in [node1, node2] if node] 1193 r = [hexfunc(node) for node in [node1, node2] if node]
1193 1194
1194 if opts.git: 1195 if opts.git:
1195 copied = {} 1196 copied = {}
1196 for f in added: 1197 c1, c2 = ctx1, ctx2
1197 src = renamed(f) 1198 files = added
1199 man = man1
1200 if node2 and ctx1.rev() >= ctx2.rev():
1201 # renamed() starts at c2 and walks back in history until c1.
1202 # Since ctx1.rev() >= ctx2.rev(), invert ctx2 and ctx1 to
1203 # detect (inverted) copies.
1204 c1, c2 = ctx2, ctx1
1205 files = removed
1206 man = ctx2.manifest()
1207 for f in files:
1208 src = renamed(c1, c2, man, f)
1198 if src: 1209 if src:
1199 copied[f] = src 1210 copied[f] = src
1200 srcs = [x[1] for x in copied.items()] 1211 if ctx1 == c2:
1212 # invert the copied dict
1213 copied = dict([(v, k) for (k, v) in copied.iteritems()])
1214 # If we've renamed file foo to bar (copied['bar'] = 'foo'),
1215 # avoid showing a diff for foo if we're going to show
1216 # the rename to bar.
1217 srcs = [x[1] for x in copied.iteritems() if x[0] in added]
1201 1218
1202 all = modified + added + removed 1219 all = modified + added + removed
1203 all.sort() 1220 all.sort()
1204 gone = {} 1221 gone = {}
1205 1222