Mercurial > hg
annotate mercurial/copies.py @ 6311:a079cf630065
Add default local() and cancopy() methods to repository base class
author | John Mulligan <phlogistonjohn@asynchrono.us> |
---|---|
date | Sat, 15 Mar 2008 15:23:20 -0400 |
parents | 5a45c82fc7da |
children | 3ee6f1fce94a |
rev | line source |
---|---|
6274
f3f383efbeae
copies: move findcopies code to its own module
Matt Mackall <mpm@selenic.com>
parents:
diff
changeset
|
1 # copies.py - copy detection for Mercurial |
f3f383efbeae
copies: move findcopies code to its own module
Matt Mackall <mpm@selenic.com>
parents:
diff
changeset
|
2 # |
f3f383efbeae
copies: move findcopies code to its own module
Matt Mackall <mpm@selenic.com>
parents:
diff
changeset
|
3 # Copyright 2008 Matt Mackall <mpm@selenic.com> |
f3f383efbeae
copies: move findcopies code to its own module
Matt Mackall <mpm@selenic.com>
parents:
diff
changeset
|
4 # |
f3f383efbeae
copies: move findcopies code to its own module
Matt Mackall <mpm@selenic.com>
parents:
diff
changeset
|
5 # This software may be used and distributed according to the terms |
f3f383efbeae
copies: move findcopies code to its own module
Matt Mackall <mpm@selenic.com>
parents:
diff
changeset
|
6 # of the GNU General Public License, incorporated herein by reference. |
f3f383efbeae
copies: move findcopies code to its own module
Matt Mackall <mpm@selenic.com>
parents:
diff
changeset
|
7 |
f3f383efbeae
copies: move findcopies code to its own module
Matt Mackall <mpm@selenic.com>
parents:
diff
changeset
|
8 from node import nullid, nullrev |
f3f383efbeae
copies: move findcopies code to its own module
Matt Mackall <mpm@selenic.com>
parents:
diff
changeset
|
9 from i18n import _ |
f3f383efbeae
copies: move findcopies code to its own module
Matt Mackall <mpm@selenic.com>
parents:
diff
changeset
|
10 import util, ancestor |
f3f383efbeae
copies: move findcopies code to its own module
Matt Mackall <mpm@selenic.com>
parents:
diff
changeset
|
11 |
f3f383efbeae
copies: move findcopies code to its own module
Matt Mackall <mpm@selenic.com>
parents:
diff
changeset
|
12 def _nonoverlap(d1, d2, d3): |
f3f383efbeae
copies: move findcopies code to its own module
Matt Mackall <mpm@selenic.com>
parents:
diff
changeset
|
13 "Return list of elements in d1 not in d2 or d3" |
f3f383efbeae
copies: move findcopies code to its own module
Matt Mackall <mpm@selenic.com>
parents:
diff
changeset
|
14 l = [d for d in d1 if d not in d3 and d not in d2] |
f3f383efbeae
copies: move findcopies code to its own module
Matt Mackall <mpm@selenic.com>
parents:
diff
changeset
|
15 l.sort() |
f3f383efbeae
copies: move findcopies code to its own module
Matt Mackall <mpm@selenic.com>
parents:
diff
changeset
|
16 return l |
f3f383efbeae
copies: move findcopies code to its own module
Matt Mackall <mpm@selenic.com>
parents:
diff
changeset
|
17 |
f3f383efbeae
copies: move findcopies code to its own module
Matt Mackall <mpm@selenic.com>
parents:
diff
changeset
|
18 def _dirname(f): |
f3f383efbeae
copies: move findcopies code to its own module
Matt Mackall <mpm@selenic.com>
parents:
diff
changeset
|
19 s = f.rfind("/") |
f3f383efbeae
copies: move findcopies code to its own module
Matt Mackall <mpm@selenic.com>
parents:
diff
changeset
|
20 if s == -1: |
f3f383efbeae
copies: move findcopies code to its own module
Matt Mackall <mpm@selenic.com>
parents:
diff
changeset
|
21 return "" |
f3f383efbeae
copies: move findcopies code to its own module
Matt Mackall <mpm@selenic.com>
parents:
diff
changeset
|
22 return f[:s] |
f3f383efbeae
copies: move findcopies code to its own module
Matt Mackall <mpm@selenic.com>
parents:
diff
changeset
|
23 |
f3f383efbeae
copies: move findcopies code to its own module
Matt Mackall <mpm@selenic.com>
parents:
diff
changeset
|
24 def _dirs(files): |
f3f383efbeae
copies: move findcopies code to its own module
Matt Mackall <mpm@selenic.com>
parents:
diff
changeset
|
25 d = {} |
f3f383efbeae
copies: move findcopies code to its own module
Matt Mackall <mpm@selenic.com>
parents:
diff
changeset
|
26 for f in files: |
f3f383efbeae
copies: move findcopies code to its own module
Matt Mackall <mpm@selenic.com>
parents:
diff
changeset
|
27 f = _dirname(f) |
f3f383efbeae
copies: move findcopies code to its own module
Matt Mackall <mpm@selenic.com>
parents:
diff
changeset
|
28 while f not in d: |
f3f383efbeae
copies: move findcopies code to its own module
Matt Mackall <mpm@selenic.com>
parents:
diff
changeset
|
29 d[f] = True |
f3f383efbeae
copies: move findcopies code to its own module
Matt Mackall <mpm@selenic.com>
parents:
diff
changeset
|
30 f = _dirname(f) |
f3f383efbeae
copies: move findcopies code to its own module
Matt Mackall <mpm@selenic.com>
parents:
diff
changeset
|
31 return d |
f3f383efbeae
copies: move findcopies code to its own module
Matt Mackall <mpm@selenic.com>
parents:
diff
changeset
|
32 |
f3f383efbeae
copies: move findcopies code to its own module
Matt Mackall <mpm@selenic.com>
parents:
diff
changeset
|
33 def _findoldnames(fctx, limit): |
f3f383efbeae
copies: move findcopies code to its own module
Matt Mackall <mpm@selenic.com>
parents:
diff
changeset
|
34 "find files that path was copied from, back to linkrev limit" |
f3f383efbeae
copies: move findcopies code to its own module
Matt Mackall <mpm@selenic.com>
parents:
diff
changeset
|
35 old = {} |
f3f383efbeae
copies: move findcopies code to its own module
Matt Mackall <mpm@selenic.com>
parents:
diff
changeset
|
36 seen = {} |
f3f383efbeae
copies: move findcopies code to its own module
Matt Mackall <mpm@selenic.com>
parents:
diff
changeset
|
37 orig = fctx.path() |
f3f383efbeae
copies: move findcopies code to its own module
Matt Mackall <mpm@selenic.com>
parents:
diff
changeset
|
38 visit = [fctx] |
f3f383efbeae
copies: move findcopies code to its own module
Matt Mackall <mpm@selenic.com>
parents:
diff
changeset
|
39 while visit: |
f3f383efbeae
copies: move findcopies code to its own module
Matt Mackall <mpm@selenic.com>
parents:
diff
changeset
|
40 fc = visit.pop() |
f3f383efbeae
copies: move findcopies code to its own module
Matt Mackall <mpm@selenic.com>
parents:
diff
changeset
|
41 s = str(fc) |
f3f383efbeae
copies: move findcopies code to its own module
Matt Mackall <mpm@selenic.com>
parents:
diff
changeset
|
42 if s in seen: |
f3f383efbeae
copies: move findcopies code to its own module
Matt Mackall <mpm@selenic.com>
parents:
diff
changeset
|
43 continue |
f3f383efbeae
copies: move findcopies code to its own module
Matt Mackall <mpm@selenic.com>
parents:
diff
changeset
|
44 seen[s] = 1 |
f3f383efbeae
copies: move findcopies code to its own module
Matt Mackall <mpm@selenic.com>
parents:
diff
changeset
|
45 if fc.path() != orig and fc.path() not in old: |
f3f383efbeae
copies: move findcopies code to its own module
Matt Mackall <mpm@selenic.com>
parents:
diff
changeset
|
46 old[fc.path()] = 1 |
f3f383efbeae
copies: move findcopies code to its own module
Matt Mackall <mpm@selenic.com>
parents:
diff
changeset
|
47 if fc.rev() < limit and fc.rev() is not None: |
f3f383efbeae
copies: move findcopies code to its own module
Matt Mackall <mpm@selenic.com>
parents:
diff
changeset
|
48 continue |
f3f383efbeae
copies: move findcopies code to its own module
Matt Mackall <mpm@selenic.com>
parents:
diff
changeset
|
49 visit += fc.parents() |
f3f383efbeae
copies: move findcopies code to its own module
Matt Mackall <mpm@selenic.com>
parents:
diff
changeset
|
50 |
f3f383efbeae
copies: move findcopies code to its own module
Matt Mackall <mpm@selenic.com>
parents:
diff
changeset
|
51 old = old.keys() |
f3f383efbeae
copies: move findcopies code to its own module
Matt Mackall <mpm@selenic.com>
parents:
diff
changeset
|
52 old.sort() |
f3f383efbeae
copies: move findcopies code to its own module
Matt Mackall <mpm@selenic.com>
parents:
diff
changeset
|
53 return old |
f3f383efbeae
copies: move findcopies code to its own module
Matt Mackall <mpm@selenic.com>
parents:
diff
changeset
|
54 |
f3f383efbeae
copies: move findcopies code to its own module
Matt Mackall <mpm@selenic.com>
parents:
diff
changeset
|
55 def copies(repo, c1, c2, ca): |
f3f383efbeae
copies: move findcopies code to its own module
Matt Mackall <mpm@selenic.com>
parents:
diff
changeset
|
56 """ |
f3f383efbeae
copies: move findcopies code to its own module
Matt Mackall <mpm@selenic.com>
parents:
diff
changeset
|
57 Find moves and copies between context c1 and c2 |
f3f383efbeae
copies: move findcopies code to its own module
Matt Mackall <mpm@selenic.com>
parents:
diff
changeset
|
58 """ |
f3f383efbeae
copies: move findcopies code to its own module
Matt Mackall <mpm@selenic.com>
parents:
diff
changeset
|
59 # avoid silly behavior for update from empty dir |
6275
fda369b5779c
diff: use copy smarts from copies.py
Matt Mackall <mpm@selenic.com>
parents:
6274
diff
changeset
|
60 if not c1 or not c2: |
6274
f3f383efbeae
copies: move findcopies code to its own module
Matt Mackall <mpm@selenic.com>
parents:
diff
changeset
|
61 return {}, {} |
f3f383efbeae
copies: move findcopies code to its own module
Matt Mackall <mpm@selenic.com>
parents:
diff
changeset
|
62 |
f3f383efbeae
copies: move findcopies code to its own module
Matt Mackall <mpm@selenic.com>
parents:
diff
changeset
|
63 rev1, rev2 = c1.rev(), c2.rev() |
f3f383efbeae
copies: move findcopies code to its own module
Matt Mackall <mpm@selenic.com>
parents:
diff
changeset
|
64 if rev1 is None: # c1 is a workingctx |
f3f383efbeae
copies: move findcopies code to its own module
Matt Mackall <mpm@selenic.com>
parents:
diff
changeset
|
65 rev1 = c1.parents()[0].rev() |
f3f383efbeae
copies: move findcopies code to its own module
Matt Mackall <mpm@selenic.com>
parents:
diff
changeset
|
66 if rev2 is None: # c2 is a workingctx |
f3f383efbeae
copies: move findcopies code to its own module
Matt Mackall <mpm@selenic.com>
parents:
diff
changeset
|
67 rev2 = c2.parents()[0].rev() |
f3f383efbeae
copies: move findcopies code to its own module
Matt Mackall <mpm@selenic.com>
parents:
diff
changeset
|
68 pr = repo.changelog.parentrevs |
f3f383efbeae
copies: move findcopies code to its own module
Matt Mackall <mpm@selenic.com>
parents:
diff
changeset
|
69 def parents(rev): |
f3f383efbeae
copies: move findcopies code to its own module
Matt Mackall <mpm@selenic.com>
parents:
diff
changeset
|
70 return [p for p in pr(rev) if p != nullrev] |
6283
5a45c82fc7da
Revert cfebb175704f, fixing the output of 2 tests
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
6277
diff
changeset
|
71 limit = min(ancestor.symmetricdifference(rev1, rev2, parents)) |
6274
f3f383efbeae
copies: move findcopies code to its own module
Matt Mackall <mpm@selenic.com>
parents:
diff
changeset
|
72 m1 = c1.manifest() |
f3f383efbeae
copies: move findcopies code to its own module
Matt Mackall <mpm@selenic.com>
parents:
diff
changeset
|
73 m2 = c2.manifest() |
f3f383efbeae
copies: move findcopies code to its own module
Matt Mackall <mpm@selenic.com>
parents:
diff
changeset
|
74 ma = ca.manifest() |
f3f383efbeae
copies: move findcopies code to its own module
Matt Mackall <mpm@selenic.com>
parents:
diff
changeset
|
75 |
f3f383efbeae
copies: move findcopies code to its own module
Matt Mackall <mpm@selenic.com>
parents:
diff
changeset
|
76 def makectx(f, n): |
f3f383efbeae
copies: move findcopies code to its own module
Matt Mackall <mpm@selenic.com>
parents:
diff
changeset
|
77 if len(n) != 20: # in a working context? |
f3f383efbeae
copies: move findcopies code to its own module
Matt Mackall <mpm@selenic.com>
parents:
diff
changeset
|
78 if c1.rev() is None: |
f3f383efbeae
copies: move findcopies code to its own module
Matt Mackall <mpm@selenic.com>
parents:
diff
changeset
|
79 return c1.filectx(f) |
f3f383efbeae
copies: move findcopies code to its own module
Matt Mackall <mpm@selenic.com>
parents:
diff
changeset
|
80 return c2.filectx(f) |
f3f383efbeae
copies: move findcopies code to its own module
Matt Mackall <mpm@selenic.com>
parents:
diff
changeset
|
81 return repo.filectx(f, fileid=n) |
f3f383efbeae
copies: move findcopies code to its own module
Matt Mackall <mpm@selenic.com>
parents:
diff
changeset
|
82 ctx = util.cachefunc(makectx) |
f3f383efbeae
copies: move findcopies code to its own module
Matt Mackall <mpm@selenic.com>
parents:
diff
changeset
|
83 |
f3f383efbeae
copies: move findcopies code to its own module
Matt Mackall <mpm@selenic.com>
parents:
diff
changeset
|
84 copy = {} |
f3f383efbeae
copies: move findcopies code to its own module
Matt Mackall <mpm@selenic.com>
parents:
diff
changeset
|
85 fullcopy = {} |
f3f383efbeae
copies: move findcopies code to its own module
Matt Mackall <mpm@selenic.com>
parents:
diff
changeset
|
86 diverge = {} |
f3f383efbeae
copies: move findcopies code to its own module
Matt Mackall <mpm@selenic.com>
parents:
diff
changeset
|
87 |
f3f383efbeae
copies: move findcopies code to its own module
Matt Mackall <mpm@selenic.com>
parents:
diff
changeset
|
88 def checkcopies(f, m1, m2): |
f3f383efbeae
copies: move findcopies code to its own module
Matt Mackall <mpm@selenic.com>
parents:
diff
changeset
|
89 '''check possible copies of f from m1 to m2''' |
f3f383efbeae
copies: move findcopies code to its own module
Matt Mackall <mpm@selenic.com>
parents:
diff
changeset
|
90 c1 = ctx(f, m1[f]) |
f3f383efbeae
copies: move findcopies code to its own module
Matt Mackall <mpm@selenic.com>
parents:
diff
changeset
|
91 for of in _findoldnames(c1, limit): |
f3f383efbeae
copies: move findcopies code to its own module
Matt Mackall <mpm@selenic.com>
parents:
diff
changeset
|
92 fullcopy[f] = of # remember for dir rename detection |
f3f383efbeae
copies: move findcopies code to its own module
Matt Mackall <mpm@selenic.com>
parents:
diff
changeset
|
93 if of in m2: # original file not in other manifest? |
f3f383efbeae
copies: move findcopies code to its own module
Matt Mackall <mpm@selenic.com>
parents:
diff
changeset
|
94 # if the original file is unchanged on the other branch, |
f3f383efbeae
copies: move findcopies code to its own module
Matt Mackall <mpm@selenic.com>
parents:
diff
changeset
|
95 # no merge needed |
f3f383efbeae
copies: move findcopies code to its own module
Matt Mackall <mpm@selenic.com>
parents:
diff
changeset
|
96 if m2[of] != ma.get(of): |
f3f383efbeae
copies: move findcopies code to its own module
Matt Mackall <mpm@selenic.com>
parents:
diff
changeset
|
97 c2 = ctx(of, m2[of]) |
f3f383efbeae
copies: move findcopies code to its own module
Matt Mackall <mpm@selenic.com>
parents:
diff
changeset
|
98 ca = c1.ancestor(c2) |
f3f383efbeae
copies: move findcopies code to its own module
Matt Mackall <mpm@selenic.com>
parents:
diff
changeset
|
99 # related and named changed on only one side? |
f3f383efbeae
copies: move findcopies code to its own module
Matt Mackall <mpm@selenic.com>
parents:
diff
changeset
|
100 if ca and ca.path() == f or ca.path() == c2.path(): |
f3f383efbeae
copies: move findcopies code to its own module
Matt Mackall <mpm@selenic.com>
parents:
diff
changeset
|
101 if c1 != ca or c2 != ca: # merge needed? |
f3f383efbeae
copies: move findcopies code to its own module
Matt Mackall <mpm@selenic.com>
parents:
diff
changeset
|
102 copy[f] = of |
f3f383efbeae
copies: move findcopies code to its own module
Matt Mackall <mpm@selenic.com>
parents:
diff
changeset
|
103 elif of in ma: |
f3f383efbeae
copies: move findcopies code to its own module
Matt Mackall <mpm@selenic.com>
parents:
diff
changeset
|
104 diverge.setdefault(of, []).append(f) |
f3f383efbeae
copies: move findcopies code to its own module
Matt Mackall <mpm@selenic.com>
parents:
diff
changeset
|
105 |
f3f383efbeae
copies: move findcopies code to its own module
Matt Mackall <mpm@selenic.com>
parents:
diff
changeset
|
106 if not repo.ui.configbool("merge", "followcopies", True): |
f3f383efbeae
copies: move findcopies code to its own module
Matt Mackall <mpm@selenic.com>
parents:
diff
changeset
|
107 return {}, {} |
f3f383efbeae
copies: move findcopies code to its own module
Matt Mackall <mpm@selenic.com>
parents:
diff
changeset
|
108 |
f3f383efbeae
copies: move findcopies code to its own module
Matt Mackall <mpm@selenic.com>
parents:
diff
changeset
|
109 repo.ui.debug(_(" searching for copies back to rev %d\n") % limit) |
f3f383efbeae
copies: move findcopies code to its own module
Matt Mackall <mpm@selenic.com>
parents:
diff
changeset
|
110 |
f3f383efbeae
copies: move findcopies code to its own module
Matt Mackall <mpm@selenic.com>
parents:
diff
changeset
|
111 u1 = _nonoverlap(m1, m2, ma) |
f3f383efbeae
copies: move findcopies code to its own module
Matt Mackall <mpm@selenic.com>
parents:
diff
changeset
|
112 u2 = _nonoverlap(m2, m1, ma) |
f3f383efbeae
copies: move findcopies code to its own module
Matt Mackall <mpm@selenic.com>
parents:
diff
changeset
|
113 |
f3f383efbeae
copies: move findcopies code to its own module
Matt Mackall <mpm@selenic.com>
parents:
diff
changeset
|
114 if u1: |
f3f383efbeae
copies: move findcopies code to its own module
Matt Mackall <mpm@selenic.com>
parents:
diff
changeset
|
115 repo.ui.debug(_(" unmatched files in local:\n %s\n") |
f3f383efbeae
copies: move findcopies code to its own module
Matt Mackall <mpm@selenic.com>
parents:
diff
changeset
|
116 % "\n ".join(u1)) |
f3f383efbeae
copies: move findcopies code to its own module
Matt Mackall <mpm@selenic.com>
parents:
diff
changeset
|
117 if u2: |
f3f383efbeae
copies: move findcopies code to its own module
Matt Mackall <mpm@selenic.com>
parents:
diff
changeset
|
118 repo.ui.debug(_(" unmatched files in other:\n %s\n") |
f3f383efbeae
copies: move findcopies code to its own module
Matt Mackall <mpm@selenic.com>
parents:
diff
changeset
|
119 % "\n ".join(u2)) |
f3f383efbeae
copies: move findcopies code to its own module
Matt Mackall <mpm@selenic.com>
parents:
diff
changeset
|
120 |
f3f383efbeae
copies: move findcopies code to its own module
Matt Mackall <mpm@selenic.com>
parents:
diff
changeset
|
121 for f in u1: |
f3f383efbeae
copies: move findcopies code to its own module
Matt Mackall <mpm@selenic.com>
parents:
diff
changeset
|
122 checkcopies(f, m1, m2) |
f3f383efbeae
copies: move findcopies code to its own module
Matt Mackall <mpm@selenic.com>
parents:
diff
changeset
|
123 for f in u2: |
f3f383efbeae
copies: move findcopies code to its own module
Matt Mackall <mpm@selenic.com>
parents:
diff
changeset
|
124 checkcopies(f, m2, m1) |
f3f383efbeae
copies: move findcopies code to its own module
Matt Mackall <mpm@selenic.com>
parents:
diff
changeset
|
125 |
f3f383efbeae
copies: move findcopies code to its own module
Matt Mackall <mpm@selenic.com>
parents:
diff
changeset
|
126 diverge2 = {} |
f3f383efbeae
copies: move findcopies code to its own module
Matt Mackall <mpm@selenic.com>
parents:
diff
changeset
|
127 for of, fl in diverge.items(): |
f3f383efbeae
copies: move findcopies code to its own module
Matt Mackall <mpm@selenic.com>
parents:
diff
changeset
|
128 if len(fl) == 1: |
f3f383efbeae
copies: move findcopies code to its own module
Matt Mackall <mpm@selenic.com>
parents:
diff
changeset
|
129 del diverge[of] # not actually divergent |
f3f383efbeae
copies: move findcopies code to its own module
Matt Mackall <mpm@selenic.com>
parents:
diff
changeset
|
130 else: |
f3f383efbeae
copies: move findcopies code to its own module
Matt Mackall <mpm@selenic.com>
parents:
diff
changeset
|
131 diverge2.update(dict.fromkeys(fl)) # reverse map for below |
f3f383efbeae
copies: move findcopies code to its own module
Matt Mackall <mpm@selenic.com>
parents:
diff
changeset
|
132 |
f3f383efbeae
copies: move findcopies code to its own module
Matt Mackall <mpm@selenic.com>
parents:
diff
changeset
|
133 if fullcopy: |
f3f383efbeae
copies: move findcopies code to its own module
Matt Mackall <mpm@selenic.com>
parents:
diff
changeset
|
134 repo.ui.debug(_(" all copies found (* = to merge, ! = divergent):\n")) |
f3f383efbeae
copies: move findcopies code to its own module
Matt Mackall <mpm@selenic.com>
parents:
diff
changeset
|
135 for f in fullcopy: |
f3f383efbeae
copies: move findcopies code to its own module
Matt Mackall <mpm@selenic.com>
parents:
diff
changeset
|
136 note = "" |
f3f383efbeae
copies: move findcopies code to its own module
Matt Mackall <mpm@selenic.com>
parents:
diff
changeset
|
137 if f in copy: note += "*" |
f3f383efbeae
copies: move findcopies code to its own module
Matt Mackall <mpm@selenic.com>
parents:
diff
changeset
|
138 if f in diverge2: note += "!" |
f3f383efbeae
copies: move findcopies code to its own module
Matt Mackall <mpm@selenic.com>
parents:
diff
changeset
|
139 repo.ui.debug(_(" %s -> %s %s\n") % (f, fullcopy[f], note)) |
f3f383efbeae
copies: move findcopies code to its own module
Matt Mackall <mpm@selenic.com>
parents:
diff
changeset
|
140 del diverge2 |
f3f383efbeae
copies: move findcopies code to its own module
Matt Mackall <mpm@selenic.com>
parents:
diff
changeset
|
141 |
f3f383efbeae
copies: move findcopies code to its own module
Matt Mackall <mpm@selenic.com>
parents:
diff
changeset
|
142 if not fullcopy or not repo.ui.configbool("merge", "followdirs", True): |
f3f383efbeae
copies: move findcopies code to its own module
Matt Mackall <mpm@selenic.com>
parents:
diff
changeset
|
143 return copy, diverge |
f3f383efbeae
copies: move findcopies code to its own module
Matt Mackall <mpm@selenic.com>
parents:
diff
changeset
|
144 |
f3f383efbeae
copies: move findcopies code to its own module
Matt Mackall <mpm@selenic.com>
parents:
diff
changeset
|
145 repo.ui.debug(_(" checking for directory renames\n")) |
f3f383efbeae
copies: move findcopies code to its own module
Matt Mackall <mpm@selenic.com>
parents:
diff
changeset
|
146 |
f3f383efbeae
copies: move findcopies code to its own module
Matt Mackall <mpm@selenic.com>
parents:
diff
changeset
|
147 # generate a directory move map |
f3f383efbeae
copies: move findcopies code to its own module
Matt Mackall <mpm@selenic.com>
parents:
diff
changeset
|
148 d1, d2 = _dirs(m1), _dirs(m2) |
f3f383efbeae
copies: move findcopies code to its own module
Matt Mackall <mpm@selenic.com>
parents:
diff
changeset
|
149 invalid = {} |
f3f383efbeae
copies: move findcopies code to its own module
Matt Mackall <mpm@selenic.com>
parents:
diff
changeset
|
150 dirmove = {} |
f3f383efbeae
copies: move findcopies code to its own module
Matt Mackall <mpm@selenic.com>
parents:
diff
changeset
|
151 |
f3f383efbeae
copies: move findcopies code to its own module
Matt Mackall <mpm@selenic.com>
parents:
diff
changeset
|
152 # examine each file copy for a potential directory move, which is |
f3f383efbeae
copies: move findcopies code to its own module
Matt Mackall <mpm@selenic.com>
parents:
diff
changeset
|
153 # when all the files in a directory are moved to a new directory |
f3f383efbeae
copies: move findcopies code to its own module
Matt Mackall <mpm@selenic.com>
parents:
diff
changeset
|
154 for dst, src in fullcopy.items(): |
f3f383efbeae
copies: move findcopies code to its own module
Matt Mackall <mpm@selenic.com>
parents:
diff
changeset
|
155 dsrc, ddst = _dirname(src), _dirname(dst) |
f3f383efbeae
copies: move findcopies code to its own module
Matt Mackall <mpm@selenic.com>
parents:
diff
changeset
|
156 if dsrc in invalid: |
f3f383efbeae
copies: move findcopies code to its own module
Matt Mackall <mpm@selenic.com>
parents:
diff
changeset
|
157 # already seen to be uninteresting |
f3f383efbeae
copies: move findcopies code to its own module
Matt Mackall <mpm@selenic.com>
parents:
diff
changeset
|
158 continue |
f3f383efbeae
copies: move findcopies code to its own module
Matt Mackall <mpm@selenic.com>
parents:
diff
changeset
|
159 elif dsrc in d1 and ddst in d1: |
f3f383efbeae
copies: move findcopies code to its own module
Matt Mackall <mpm@selenic.com>
parents:
diff
changeset
|
160 # directory wasn't entirely moved locally |
f3f383efbeae
copies: move findcopies code to its own module
Matt Mackall <mpm@selenic.com>
parents:
diff
changeset
|
161 invalid[dsrc] = True |
f3f383efbeae
copies: move findcopies code to its own module
Matt Mackall <mpm@selenic.com>
parents:
diff
changeset
|
162 elif dsrc in d2 and ddst in d2: |
f3f383efbeae
copies: move findcopies code to its own module
Matt Mackall <mpm@selenic.com>
parents:
diff
changeset
|
163 # directory wasn't entirely moved remotely |
f3f383efbeae
copies: move findcopies code to its own module
Matt Mackall <mpm@selenic.com>
parents:
diff
changeset
|
164 invalid[dsrc] = True |
f3f383efbeae
copies: move findcopies code to its own module
Matt Mackall <mpm@selenic.com>
parents:
diff
changeset
|
165 elif dsrc in dirmove and dirmove[dsrc] != ddst: |
f3f383efbeae
copies: move findcopies code to its own module
Matt Mackall <mpm@selenic.com>
parents:
diff
changeset
|
166 # files from the same directory moved to two different places |
f3f383efbeae
copies: move findcopies code to its own module
Matt Mackall <mpm@selenic.com>
parents:
diff
changeset
|
167 invalid[dsrc] = True |
f3f383efbeae
copies: move findcopies code to its own module
Matt Mackall <mpm@selenic.com>
parents:
diff
changeset
|
168 else: |
f3f383efbeae
copies: move findcopies code to its own module
Matt Mackall <mpm@selenic.com>
parents:
diff
changeset
|
169 # looks good so far |
f3f383efbeae
copies: move findcopies code to its own module
Matt Mackall <mpm@selenic.com>
parents:
diff
changeset
|
170 dirmove[dsrc + "/"] = ddst + "/" |
f3f383efbeae
copies: move findcopies code to its own module
Matt Mackall <mpm@selenic.com>
parents:
diff
changeset
|
171 |
f3f383efbeae
copies: move findcopies code to its own module
Matt Mackall <mpm@selenic.com>
parents:
diff
changeset
|
172 for i in invalid: |
f3f383efbeae
copies: move findcopies code to its own module
Matt Mackall <mpm@selenic.com>
parents:
diff
changeset
|
173 if i in dirmove: |
f3f383efbeae
copies: move findcopies code to its own module
Matt Mackall <mpm@selenic.com>
parents:
diff
changeset
|
174 del dirmove[i] |
f3f383efbeae
copies: move findcopies code to its own module
Matt Mackall <mpm@selenic.com>
parents:
diff
changeset
|
175 del d1, d2, invalid |
f3f383efbeae
copies: move findcopies code to its own module
Matt Mackall <mpm@selenic.com>
parents:
diff
changeset
|
176 |
f3f383efbeae
copies: move findcopies code to its own module
Matt Mackall <mpm@selenic.com>
parents:
diff
changeset
|
177 if not dirmove: |
f3f383efbeae
copies: move findcopies code to its own module
Matt Mackall <mpm@selenic.com>
parents:
diff
changeset
|
178 return copy, diverge |
f3f383efbeae
copies: move findcopies code to its own module
Matt Mackall <mpm@selenic.com>
parents:
diff
changeset
|
179 |
f3f383efbeae
copies: move findcopies code to its own module
Matt Mackall <mpm@selenic.com>
parents:
diff
changeset
|
180 for d in dirmove: |
f3f383efbeae
copies: move findcopies code to its own module
Matt Mackall <mpm@selenic.com>
parents:
diff
changeset
|
181 repo.ui.debug(_(" dir %s -> %s\n") % (d, dirmove[d])) |
f3f383efbeae
copies: move findcopies code to its own module
Matt Mackall <mpm@selenic.com>
parents:
diff
changeset
|
182 |
f3f383efbeae
copies: move findcopies code to its own module
Matt Mackall <mpm@selenic.com>
parents:
diff
changeset
|
183 # check unaccounted nonoverlapping files against directory moves |
f3f383efbeae
copies: move findcopies code to its own module
Matt Mackall <mpm@selenic.com>
parents:
diff
changeset
|
184 for f in u1 + u2: |
f3f383efbeae
copies: move findcopies code to its own module
Matt Mackall <mpm@selenic.com>
parents:
diff
changeset
|
185 if f not in fullcopy: |
f3f383efbeae
copies: move findcopies code to its own module
Matt Mackall <mpm@selenic.com>
parents:
diff
changeset
|
186 for d in dirmove: |
f3f383efbeae
copies: move findcopies code to its own module
Matt Mackall <mpm@selenic.com>
parents:
diff
changeset
|
187 if f.startswith(d): |
f3f383efbeae
copies: move findcopies code to its own module
Matt Mackall <mpm@selenic.com>
parents:
diff
changeset
|
188 # new file added in a directory that was moved, move it |
f3f383efbeae
copies: move findcopies code to its own module
Matt Mackall <mpm@selenic.com>
parents:
diff
changeset
|
189 copy[f] = dirmove[d] + f[len(d):] |
f3f383efbeae
copies: move findcopies code to its own module
Matt Mackall <mpm@selenic.com>
parents:
diff
changeset
|
190 repo.ui.debug(_(" file %s -> %s\n") % (f, copy[f])) |
f3f383efbeae
copies: move findcopies code to its own module
Matt Mackall <mpm@selenic.com>
parents:
diff
changeset
|
191 break |
f3f383efbeae
copies: move findcopies code to its own module
Matt Mackall <mpm@selenic.com>
parents:
diff
changeset
|
192 |
f3f383efbeae
copies: move findcopies code to its own module
Matt Mackall <mpm@selenic.com>
parents:
diff
changeset
|
193 return copy, diverge |