##// END OF EJS Templates
diff: use copy smarts from copies.py
Matt Mackall -
r6275:fda369b5 default
parent child Browse files
Show More
@@ -97,6 +97,9 b' def symmetricdifference(a, b, pfunc):'
97 # We keep track of the number of revisions in the heap that
97 # We keep track of the number of revisions in the heap that
98 # we may be interested in. We stop walking the graph as soon
98 # we may be interested in. We stop walking the graph as soon
99 # as this number reaches 0.
99 # as this number reaches 0.
100 if a == b:
101 return [a]
102
100 WHITE = 1
103 WHITE = 1
101 BLACK = 2
104 BLACK = 2
102 ALLCOLORS = WHITE | BLACK
105 ALLCOLORS = WHITE | BLACK
@@ -57,7 +57,7 b' def copies(repo, c1, c2, ca):'
57 Find moves and copies between context c1 and c2
57 Find moves and copies between context c1 and c2
58 """
58 """
59 # avoid silly behavior for update from empty dir
59 # avoid silly behavior for update from empty dir
60 if not c1 or not c2 or not ca:
60 if not c1 or not c2:
61 return {}, {}
61 return {}, {}
62
62
63 rev1, rev2 = c1.rev(), c2.rev()
63 rev1, rev2 = c1.rev(), c2.rev()
@@ -100,7 +100,7 b' def manifestmerge(repo, p1, p2, pa, over'
100 repo.ui.debug(" %s: %s -> %s\n" % (f, msg, m))
100 repo.ui.debug(" %s: %s -> %s\n" % (f, msg, m))
101 action.append((f, m) + args)
101 action.append((f, m) + args)
102
102
103 if not (backwards or overwrite):
103 if pa and not (backwards or overwrite):
104 copy, diverge = copies.copies(repo, p1, p2, pa)
104 copy, diverge = copies.copies(repo, p1, p2, pa)
105 copied = dict.fromkeys(copy.values())
105 copied = dict.fromkeys(copy.values())
106 for of, fl in diverge.items():
106 for of, fl in diverge.items():
@@ -8,7 +8,7 b''
8
8
9 from i18n import _
9 from i18n import _
10 from node import hex, nullid, short
10 from node import hex, nullid, short
11 import base85, cmdutil, mdiff, util, context, revlog, diffhelpers
11 import base85, cmdutil, mdiff, util, context, revlog, diffhelpers, copies
12 import cStringIO, email.Parser, os, popen2, re, sha, errno
12 import cStringIO, email.Parser, os, popen2, re, sha, errno
13 import sys, tempfile, zlib
13 import sys, tempfile, zlib
14
14
@@ -1202,36 +1202,6 b' def diff(repo, node1=None, node2=None, f'
1202 execf2 = mc.execf
1202 execf2 = mc.execf
1203 linkf2 = mc.linkf
1203 linkf2 = mc.linkf
1204
1204
1205 # returns False if there was no rename between ctx1 and ctx2
1206 # returns None if the file was created between ctx1 and ctx2
1207 # returns the (file, node) present in ctx1 that was renamed to f in ctx2
1208 # This will only really work if c1 is the Nth 1st parent of c2.
1209 def renamed(c1, c2, man, f):
1210 startrev = c1.rev()
1211 c = c2
1212 crev = c.rev()
1213 if crev is None:
1214 crev = repo.changelog.count()
1215 orig = f
1216 files = (f,)
1217 while crev > startrev:
1218 if f in files:
1219 try:
1220 src = getfilectx(f, c).renamed()
1221 except revlog.LookupError:
1222 return None
1223 if src:
1224 f = src[0]
1225 crev = c.parents()[0].rev()
1226 # try to reuse
1227 c = getctx(crev)
1228 files = c.files()
1229 if f not in man:
1230 return None
1231 if f == orig:
1232 return False
1233 return f
1234
1235 if repo.ui.quiet:
1205 if repo.ui.quiet:
1236 r = None
1206 r = None
1237 else:
1207 else:
@@ -1239,28 +1209,9 b' def diff(repo, node1=None, node2=None, f'
1239 r = [hexfunc(node) for node in [node1, node2] if node]
1209 r = [hexfunc(node) for node in [node1, node2] if node]
1240
1210
1241 if opts.git:
1211 if opts.git:
1242 copied = {}
1212 copy, diverge = copies.copies(repo, ctx1, ctx2, repo.changectx(nullid))
1243 c1, c2 = ctx1, ctx2
1213 for k, v in copy.items():
1244 files = added
1214 copy[v] = k
1245 man = man1
1246 if node2 and ctx1.rev() >= ctx2.rev():
1247 # renamed() starts at c2 and walks back in history until c1.
1248 # Since ctx1.rev() >= ctx2.rev(), invert ctx2 and ctx1 to
1249 # detect (inverted) copies.
1250 c1, c2 = ctx2, ctx1
1251 files = removed
1252 man = ctx2.manifest()
1253 for f in files:
1254 src = renamed(c1, c2, man, f)
1255 if src:
1256 copied[f] = src
1257 if ctx1 == c2:
1258 # invert the copied dict
1259 copied = dict([(v, k) for (k, v) in copied.iteritems()])
1260 # If we've renamed file foo to bar (copied['bar'] = 'foo'),
1261 # avoid showing a diff for foo if we're going to show
1262 # the rename to bar.
1263 srcs = [x[1] for x in copied.iteritems() if x[0] in added]
1264
1215
1265 all = modified + added + removed
1216 all = modified + added + removed
1266 all.sort()
1217 all.sort()
@@ -1286,8 +1237,8 b' def diff(repo, node1=None, node2=None, f'
1286
1237
1287 if f in added:
1238 if f in added:
1288 mode = gitmode(execf2(f), linkf2(f))
1239 mode = gitmode(execf2(f), linkf2(f))
1289 if f in copied:
1240 if f in copy:
1290 a = copied[f]
1241 a = copy[f]
1291 omode = gitmode(man1.execf(a), man1.linkf(a))
1242 omode = gitmode(man1.execf(a), man1.linkf(a))
1292 addmodehdr(header, omode, mode)
1243 addmodehdr(header, omode, mode)
1293 if a in removed and a not in gone:
1244 if a in removed and a not in gone:
@@ -1303,7 +1254,8 b' def diff(repo, node1=None, node2=None, f'
1303 if util.binary(tn):
1254 if util.binary(tn):
1304 dodiff = 'binary'
1255 dodiff = 'binary'
1305 elif f in removed:
1256 elif f in removed:
1306 if f in srcs:
1257 # have we already reported a copy above?
1258 if f in copy and copy[f] in added and copy[copy[f]] == f:
1307 dodiff = False
1259 dodiff = False
1308 else:
1260 else:
1309 mode = gitmode(man1.execf(f), man1.linkf(f))
1261 mode = gitmode(man1.execf(f), man1.linkf(f))
General Comments 0
You need to be logged in to leave comments. Login now