##// END OF EJS Templates
Revert cfebb175704f, fixing the output of 2 tests
Alexis S. L. Carvalho -
r6283:5a45c82f default
parent child Browse files
Show More
@@ -1,193 +1,193 b''
1 1 # copies.py - copy detection for Mercurial
2 2 #
3 3 # Copyright 2008 Matt Mackall <mpm@selenic.com>
4 4 #
5 5 # This software may be used and distributed according to the terms
6 6 # of the GNU General Public License, incorporated herein by reference.
7 7
8 8 from node import nullid, nullrev
9 9 from i18n import _
10 10 import util, ancestor
11 11
12 12 def _nonoverlap(d1, d2, d3):
13 13 "Return list of elements in d1 not in d2 or d3"
14 14 l = [d for d in d1 if d not in d3 and d not in d2]
15 15 l.sort()
16 16 return l
17 17
18 18 def _dirname(f):
19 19 s = f.rfind("/")
20 20 if s == -1:
21 21 return ""
22 22 return f[:s]
23 23
24 24 def _dirs(files):
25 25 d = {}
26 26 for f in files:
27 27 f = _dirname(f)
28 28 while f not in d:
29 29 d[f] = True
30 30 f = _dirname(f)
31 31 return d
32 32
33 33 def _findoldnames(fctx, limit):
34 34 "find files that path was copied from, back to linkrev limit"
35 35 old = {}
36 36 seen = {}
37 37 orig = fctx.path()
38 38 visit = [fctx]
39 39 while visit:
40 40 fc = visit.pop()
41 41 s = str(fc)
42 42 if s in seen:
43 43 continue
44 44 seen[s] = 1
45 45 if fc.path() != orig and fc.path() not in old:
46 46 old[fc.path()] = 1
47 47 if fc.rev() < limit and fc.rev() is not None:
48 48 continue
49 49 visit += fc.parents()
50 50
51 51 old = old.keys()
52 52 old.sort()
53 53 return old
54 54
55 55 def copies(repo, c1, c2, ca):
56 56 """
57 57 Find moves and copies between context c1 and c2
58 58 """
59 59 # avoid silly behavior for update from empty dir
60 60 if not c1 or not c2:
61 61 return {}, {}
62 62
63 63 rev1, rev2 = c1.rev(), c2.rev()
64 64 if rev1 is None: # c1 is a workingctx
65 65 rev1 = c1.parents()[0].rev()
66 66 if rev2 is None: # c2 is a workingctx
67 67 rev2 = c2.parents()[0].rev()
68 68 pr = repo.changelog.parentrevs
69 69 def parents(rev):
70 70 return [p for p in pr(rev) if p != nullrev]
71 limit = min(ancestor.symmetricdifference(rev1, rev2, parents) + [rev1, rev2])
71 limit = min(ancestor.symmetricdifference(rev1, rev2, parents))
72 72 m1 = c1.manifest()
73 73 m2 = c2.manifest()
74 74 ma = ca.manifest()
75 75
76 76 def makectx(f, n):
77 77 if len(n) != 20: # in a working context?
78 78 if c1.rev() is None:
79 79 return c1.filectx(f)
80 80 return c2.filectx(f)
81 81 return repo.filectx(f, fileid=n)
82 82 ctx = util.cachefunc(makectx)
83 83
84 84 copy = {}
85 85 fullcopy = {}
86 86 diverge = {}
87 87
88 88 def checkcopies(f, m1, m2):
89 89 '''check possible copies of f from m1 to m2'''
90 90 c1 = ctx(f, m1[f])
91 91 for of in _findoldnames(c1, limit):
92 92 fullcopy[f] = of # remember for dir rename detection
93 93 if of in m2: # original file not in other manifest?
94 94 # if the original file is unchanged on the other branch,
95 95 # no merge needed
96 96 if m2[of] != ma.get(of):
97 97 c2 = ctx(of, m2[of])
98 98 ca = c1.ancestor(c2)
99 99 # related and named changed on only one side?
100 100 if ca and ca.path() == f or ca.path() == c2.path():
101 101 if c1 != ca or c2 != ca: # merge needed?
102 102 copy[f] = of
103 103 elif of in ma:
104 104 diverge.setdefault(of, []).append(f)
105 105
106 106 if not repo.ui.configbool("merge", "followcopies", True):
107 107 return {}, {}
108 108
109 109 repo.ui.debug(_(" searching for copies back to rev %d\n") % limit)
110 110
111 111 u1 = _nonoverlap(m1, m2, ma)
112 112 u2 = _nonoverlap(m2, m1, ma)
113 113
114 114 if u1:
115 115 repo.ui.debug(_(" unmatched files in local:\n %s\n")
116 116 % "\n ".join(u1))
117 117 if u2:
118 118 repo.ui.debug(_(" unmatched files in other:\n %s\n")
119 119 % "\n ".join(u2))
120 120
121 121 for f in u1:
122 122 checkcopies(f, m1, m2)
123 123 for f in u2:
124 124 checkcopies(f, m2, m1)
125 125
126 126 diverge2 = {}
127 127 for of, fl in diverge.items():
128 128 if len(fl) == 1:
129 129 del diverge[of] # not actually divergent
130 130 else:
131 131 diverge2.update(dict.fromkeys(fl)) # reverse map for below
132 132
133 133 if fullcopy:
134 134 repo.ui.debug(_(" all copies found (* = to merge, ! = divergent):\n"))
135 135 for f in fullcopy:
136 136 note = ""
137 137 if f in copy: note += "*"
138 138 if f in diverge2: note += "!"
139 139 repo.ui.debug(_(" %s -> %s %s\n") % (f, fullcopy[f], note))
140 140 del diverge2
141 141
142 142 if not fullcopy or not repo.ui.configbool("merge", "followdirs", True):
143 143 return copy, diverge
144 144
145 145 repo.ui.debug(_(" checking for directory renames\n"))
146 146
147 147 # generate a directory move map
148 148 d1, d2 = _dirs(m1), _dirs(m2)
149 149 invalid = {}
150 150 dirmove = {}
151 151
152 152 # examine each file copy for a potential directory move, which is
153 153 # when all the files in a directory are moved to a new directory
154 154 for dst, src in fullcopy.items():
155 155 dsrc, ddst = _dirname(src), _dirname(dst)
156 156 if dsrc in invalid:
157 157 # already seen to be uninteresting
158 158 continue
159 159 elif dsrc in d1 and ddst in d1:
160 160 # directory wasn't entirely moved locally
161 161 invalid[dsrc] = True
162 162 elif dsrc in d2 and ddst in d2:
163 163 # directory wasn't entirely moved remotely
164 164 invalid[dsrc] = True
165 165 elif dsrc in dirmove and dirmove[dsrc] != ddst:
166 166 # files from the same directory moved to two different places
167 167 invalid[dsrc] = True
168 168 else:
169 169 # looks good so far
170 170 dirmove[dsrc + "/"] = ddst + "/"
171 171
172 172 for i in invalid:
173 173 if i in dirmove:
174 174 del dirmove[i]
175 175 del d1, d2, invalid
176 176
177 177 if not dirmove:
178 178 return copy, diverge
179 179
180 180 for d in dirmove:
181 181 repo.ui.debug(_(" dir %s -> %s\n") % (d, dirmove[d]))
182 182
183 183 # check unaccounted nonoverlapping files against directory moves
184 184 for f in u1 + u2:
185 185 if f not in fullcopy:
186 186 for d in dirmove:
187 187 if f.startswith(d):
188 188 # new file added in a directory that was moved, move it
189 189 copy[f] = dirmove[d] + f[len(d):]
190 190 repo.ui.debug(_(" file %s -> %s\n") % (f, copy[f]))
191 191 break
192 192
193 193 return copy, diverge
@@ -1,203 +1,197 b''
1 1 adding start
2 2 adding new
3 3 % new file
4 4 diff --git a/new b/new
5 5 new file mode 100644
6 6 --- /dev/null
7 7 +++ b/new
8 8 @@ -0,0 +1,1 @@
9 9 +new
10 10 % copy
11 11 diff --git a/new b/copy
12 12 copy from new
13 13 copy to copy
14 14 % rename
15 diff --git a/copy b/copy
16 deleted file mode 100644
17 --- a/copy
18 +++ /dev/null
19 @@ -1,1 +0,0 @@
20 -new
21 diff --git a/new b/rename
22 copy from new
23 copy to rename
15 diff --git a/copy b/rename
16 rename from copy
17 rename to rename
24 18 % delete
25 19 diff --git a/rename b/rename
26 20 deleted file mode 100644
27 21 --- a/rename
28 22 +++ /dev/null
29 23 @@ -1,1 +0,0 @@
30 24 -new
31 25 adding src
32 26 % chmod 644
33 27 diff --git a/src b/src
34 28 old mode 100644
35 29 new mode 100755
36 30 % rename+mod+chmod
37 31 diff --git a/src b/dst
38 32 old mode 100755
39 33 new mode 100644
40 34 rename from src
41 35 rename to dst
42 36 --- a/src
43 37 +++ b/dst
44 38 @@ -3,3 +3,4 @@
45 39 3
46 40 4
47 41 5
48 42 +a
49 43 % nonexistent in tip+chmod
50 44 diff --git a/src b/src
51 45 old mode 100644
52 46 new mode 100755
53 47 % binary diff
54 48 diff --git a/binfile.bin b/binfile.bin
55 49 new file mode 100644
56 50 index 0000000000000000000000000000000000000000..37ba3d1c6f17137d9c5f5776fa040caf5fe73ff9
57 51 GIT binary patch
58 52 literal 593
59 53 zc$@)I0<QguP)<h;3K|Lk000e1NJLTq000mG000mO0ssI2kdbIM00009a7bBm000XU
60 54 z000XU0RWnu7ytkO2XskIMF-Uh9TW;VpMjwv0005-Nkl<ZD9@FWPs=e;7{<>W$NUkd
61 55 zX$nnYLt$-$V!?uy+1V%`z&Eh=ah|duER<4|QWhju3gb^nF*8iYobxWG-qqXl=2~5M
62 56 z*IoDB)sG^CfNuoBmqLTVU^<;@nwHP!1wrWd`{(mHo6VNXWtyh{alzqmsH*yYzpvLT
63 57 zLdY<T=ks|woh-`&01!ej#(xbV1f|pI*=%;d-%F*E*X#ZH`4I%6SS+$EJDE&ct=8po
64 58 ziN#{?_j|kD%Cd|oiqds`xm@;oJ-^?NG3Gdqrs?5u*zI;{nogxsx~^|Fn^Y?Gdc6<;
65 59 zfMJ+iF1J`LMx&A2?dEwNW8ClebzPTbIh{@$hS6*`kH@1d%Lo7fA#}N1)oN7`gm$~V
66 60 z+wDx#)OFqMcE{s!JN0-xhG8ItAjVkJwEcb`3WWlJfU2r?;Pd%dmR+q@mSri5q9_W-
67 61 zaR2~ECX?B2w+zELozC0s*6Z~|QG^f{3I#<`?)Q7U-JZ|q5W;9Q8i_=pBuSzunx=U;
68 62 z9C)5jBoYw9^?EHyQl(M}1OlQcCX>lXB*ODN003Z&P17_@)3Pi=i0wb04<W?v-u}7K
69 63 zXmmQA+wDgE!qR9o8jr`%=ab_&uh(l?R=r;Tjiqon91I2-hIu?57~@*4h7h9uORK#=
70 64 fQItJW-{SoTm)8|5##k|m00000NkvXXu0mjf{mKw4
71 65
72 66 % import binary diff
73 67 applying b.diff
74 68
75 69 % rename binary file
76 70 diff --git a/binfile.bin b/renamed.bin
77 71 rename from binfile.bin
78 72 rename to renamed.bin
79 73
80 74 % diff across many revisions
81 75 diff --git a/dst2 b/dst3
82 76 rename from dst2
83 77 rename to dst3
84 78 % reversed
85 79 diff --git a/dst3 b/dst2
86 80 rename from dst3
87 81 rename to dst2
88 82
89 83 % file created before r1 and renamed before r2
90 84 diff --git a/foo b/bar
91 85 rename from foo
92 86 rename to bar
93 87 --- a/foo
94 88 +++ b/bar
95 89 @@ -1,2 +1,3 @@
96 90 a
97 91 b
98 92 +c
99 93 % reversed
100 94 diff --git a/bar b/foo
101 95 rename from bar
102 96 rename to foo
103 97 --- a/bar
104 98 +++ b/foo
105 99 @@ -1,3 +1,2 @@
106 100 a
107 101 b
108 102 -c
109 103
110 104 % file created in r1 and renamed before r2
111 105 diff --git a/foo b/bar
112 106 rename from foo
113 107 rename to bar
114 108 --- a/foo
115 109 +++ b/bar
116 110 @@ -1,1 +1,3 @@
117 111 a
118 112 +b
119 113 +c
120 114 % reversed
121 115 diff --git a/bar b/foo
122 116 rename from bar
123 117 rename to foo
124 118 --- a/bar
125 119 +++ b/foo
126 120 @@ -1,3 +1,1 @@
127 121 a
128 122 -b
129 123 -c
130 124
131 125 % file created after r1 and renamed before r2
132 126 diff --git a/bar b/bar
133 127 new file mode 100644
134 128 --- /dev/null
135 129 +++ b/bar
136 130 @@ -0,0 +1,3 @@
137 131 +a
138 132 +b
139 133 +c
140 134 % reversed
141 135 diff --git a/bar b/bar
142 136 deleted file mode 100644
143 137 --- a/bar
144 138 +++ /dev/null
145 139 @@ -1,3 +0,0 @@
146 140 -a
147 141 -b
148 142 -c
149 143
150 144 % comparing with the working dir
151 145 % there's a copy in the working dir...
152 146 diff --git a/created2 b/created3
153 147 rename from created2
154 148 rename to created3
155 149
156 150 % ...but there's another copy between the original rev and the wd
157 151 diff --git a/created b/created3
158 152 rename from created
159 153 rename to created3
160 154
161 155 % ...but the source of the copy was created after the original rev
162 156 diff --git a/created3 b/created3
163 157 new file mode 100644
164 158 --- /dev/null
165 159 +++ b/created3
166 160 @@ -0,0 +1,1 @@
167 161 +
168 162 % created in parent of wd; renamed in the wd
169 163 diff --git a/brand-new b/brand-new2
170 164 rename from brand-new
171 165 rename to brand-new2
172 166
173 167 % created between r1 and parent of wd; renamed in the wd
174 168 diff --git a/brand-new2 b/brand-new2
175 169 new file mode 100644
176 170 --- /dev/null
177 171 +++ b/brand-new2
178 172 @@ -0,0 +1,1 @@
179 173 +
180 174 % one file is copied to many destinations and removed
181 175 diff --git a/brand-new2 b/brand-new3
182 176 rename from brand-new2
183 177 rename to brand-new3
184 178 diff --git a/brand-new2 b/brand-new3-2
185 179 copy from brand-new2
186 180 copy to brand-new3-2
187 181 % reversed
188 182 diff --git a/brand-new3 b/brand-new2
189 183 rename from brand-new3
190 184 rename to brand-new2
191 185 diff --git a/brand-new3-2 b/brand-new3-2
192 186 deleted file mode 100644
193 187 --- a/brand-new3-2
194 188 +++ /dev/null
195 189 @@ -1,1 +0,0 @@
196 190 -
197 191 % there should be a trailing TAB if there are spaces in the file name
198 192 diff --git a/with spaces b/with spaces
199 193 new file mode 100644
200 194 --- /dev/null
201 195 +++ b/with spaces
202 196 @@ -0,0 +1,1 @@
203 197 +foo
@@ -1,147 +1,147 b''
1 1 adding a
2 2 1 files updated, 0 files merged, 0 files removed, 0 files unresolved
3 3 0 files updated, 0 files merged, 0 files removed, 0 files unresolved
4 4 diff -r 33aaa84a386b a
5 5 --- a/a
6 6 +++ b/a
7 7 @@ -1,1 +1,1 @@
8 8 -a
9 9 +abc
10 10 adding b
11 11 M a
12 12 changeset: 0:33aaa84a386b
13 13 user: test
14 14 date: Mon Jan 12 13:46:40 1970 +0000
15 15 summary: 1
16 16
17 17 resolving manifests
18 18 overwrite False partial False
19 19 ancestor 33aaa84a386b local 33aaa84a386b+ remote 802f095af299
20 searching for copies back to rev 0
20 searching for copies back to rev 1
21 21 unmatched files in other:
22 22 b
23 23 a: versions differ -> m
24 24 b: remote created -> g
25 25 picked tool 'true' for a (binary False symlink False)
26 26 merging a
27 27 my a@33aaa84a386b+ other a@802f095af299 ancestor a@33aaa84a386b
28 28 getting b
29 29 1 files updated, 1 files merged, 0 files removed, 0 files unresolved
30 30 changeset: 1:802f095af299
31 31 tag: tip
32 32 user: test
33 33 date: Mon Jan 12 13:46:40 1970 +0000
34 34 summary: 2
35 35
36 36 resolving manifests
37 37 overwrite False partial False
38 38 ancestor 33aaa84a386b local 802f095af299+ remote 33aaa84a386b
39 39 b: remote deleted -> r
40 40 removing b
41 41 0 files updated, 0 files merged, 1 files removed, 0 files unresolved
42 42 changeset: 0:33aaa84a386b
43 43 user: test
44 44 date: Mon Jan 12 13:46:40 1970 +0000
45 45 summary: 1
46 46
47 47 abort: there is nothing to merge - use "hg update" instead
48 48 failed
49 49 changeset: 0:33aaa84a386b
50 50 user: test
51 51 date: Mon Jan 12 13:46:40 1970 +0000
52 52 summary: 1
53 53
54 54 resolving manifests
55 55 overwrite False partial False
56 56 ancestor 33aaa84a386b local 33aaa84a386b+ remote 802f095af299
57 searching for copies back to rev 0
57 searching for copies back to rev 1
58 58 unmatched files in other:
59 59 b
60 60 a: versions differ -> m
61 61 b: remote created -> g
62 62 picked tool 'true' for a (binary False symlink False)
63 63 merging a
64 64 my a@33aaa84a386b+ other a@802f095af299 ancestor a@33aaa84a386b
65 65 getting b
66 66 1 files updated, 1 files merged, 0 files removed, 0 files unresolved
67 67 changeset: 1:802f095af299
68 68 tag: tip
69 69 user: test
70 70 date: Mon Jan 12 13:46:40 1970 +0000
71 71 summary: 2
72 72
73 73 changeset: 1:802f095af299
74 74 tag: tip
75 75 user: test
76 76 date: Mon Jan 12 13:46:40 1970 +0000
77 77 files: a b
78 78 description:
79 79 2
80 80
81 81
82 82 changeset: 0:33aaa84a386b
83 83 user: test
84 84 date: Mon Jan 12 13:46:40 1970 +0000
85 85 files: a
86 86 description:
87 87 1
88 88
89 89
90 90 diff -r 802f095af299 a
91 91 --- a/a
92 92 +++ b/a
93 93 @@ -1,1 +1,1 @@
94 94 -a2
95 95 +abc
96 96 1 files updated, 0 files merged, 1 files removed, 0 files unresolved
97 97 adding b
98 98 M a
99 99 changeset: 1:802f095af299
100 100 user: test
101 101 date: Mon Jan 12 13:46:40 1970 +0000
102 102 summary: 2
103 103
104 104 abort: update spans branches, use 'hg merge' or 'hg update -C' to lose changes
105 105 failed
106 106 abort: outstanding uncommitted changes
107 107 failed
108 108 resolving manifests
109 109 overwrite False partial False
110 110 ancestor 33aaa84a386b local 802f095af299+ remote 030602aee63d
111 111 searching for copies back to rev 1
112 112 a: versions differ -> m
113 113 b: versions differ -> m
114 114 picked tool 'true' for a (binary False symlink False)
115 115 merging a
116 116 my a@802f095af299+ other a@030602aee63d ancestor a@33aaa84a386b
117 117 picked tool 'true' for b (binary False symlink False)
118 118 merging b
119 119 my b@802f095af299+ other b@030602aee63d ancestor b@000000000000
120 120 0 files updated, 2 files merged, 0 files removed, 0 files unresolved
121 121 (branch merge, don't forget to commit)
122 122 changeset: 1:802f095af299
123 123 user: test
124 124 date: Mon Jan 12 13:46:40 1970 +0000
125 125 summary: 2
126 126
127 127 changeset: 2:030602aee63d
128 128 tag: tip
129 129 parent: 0:33aaa84a386b
130 130 user: test
131 131 date: Mon Jan 12 13:46:40 1970 +0000
132 132 summary: 3
133 133
134 134 diff -r 802f095af299 a
135 135 --- a/a
136 136 +++ b/a
137 137 @@ -1,1 +1,1 @@
138 138 -a2
139 139 +abc
140 140 adding a
141 141 pulling from ../a
142 142 requesting all changes
143 143 adding changesets
144 144 adding manifests
145 145 adding file changes
146 146 added 1 changesets with 1 changes to 1 files
147 147 1 files updated, 0 files merged, 0 files removed, 0 files unresolved
General Comments 0
You need to be logged in to leave comments. Login now