Show More
@@ -98,7 +98,7 b' def diff_parent(ctx):' | |||||
98 | return ctx.p1() |
|
98 | return ctx.p1() | |
99 |
|
99 | |||
100 |
|
100 | |||
101 | def diffordiffstat( |
|
101 | def get_diff_chunks( | |
102 | ui, |
|
102 | ui, | |
103 | repo, |
|
103 | repo, | |
104 | diffopts, |
|
104 | diffopts, | |
@@ -107,14 +107,10 b' def diffordiffstat(' | |||||
107 | match, |
|
107 | match, | |
108 | changes=None, |
|
108 | changes=None, | |
109 | stat=False, |
|
109 | stat=False, | |
110 | fp=None, |
|
|||
111 | graphwidth=0, |
|
|||
112 | prefix=b'', |
|
110 | prefix=b'', | |
113 | root=b'', |
|
111 | root=b'', | |
114 | listsubrepos=False, |
|
|||
115 | hunksfilterfn=None, |
|
112 | hunksfilterfn=None, | |
116 | ): |
|
113 | ): | |
117 | '''show diff or diffstat.''' |
|
|||
118 | if root: |
|
114 | if root: | |
119 | relroot = pathutil.canonpath(repo.root, repo.getcwd(), root) |
|
115 | relroot = pathutil.canonpath(repo.root, repo.getcwd(), root) | |
120 | else: |
|
116 | else: | |
@@ -159,14 +155,11 b' def diffordiffstat(' | |||||
159 |
|
155 | |||
160 | if stat: |
|
156 | if stat: | |
161 | diffopts = diffopts.copy(context=0, noprefix=False) |
|
157 | diffopts = diffopts.copy(context=0, noprefix=False) | |
162 | width = 80 |
|
|||
163 | if not ui.plain(): |
|
|||
164 | width = ui.termwidth() - graphwidth |
|
|||
165 | # If an explicit --root was given, don't respect ui.relative-paths |
|
158 | # If an explicit --root was given, don't respect ui.relative-paths | |
166 | if not relroot: |
|
159 | if not relroot: | |
167 | pathfn = compose(scmutil.getuipathfn(repo), pathfn) |
|
160 | pathfn = compose(scmutil.getuipathfn(repo), pathfn) | |
168 |
|
161 | |||
169 |
|
|
162 | return ctx2.diff( | |
170 | ctx1, |
|
163 | ctx1, | |
171 | match, |
|
164 | match, | |
172 | changes, |
|
165 | changes, | |
@@ -176,6 +169,45 b' def diffordiffstat(' | |||||
176 | hunksfilterfn=hunksfilterfn, |
|
169 | hunksfilterfn=hunksfilterfn, | |
177 | ) |
|
170 | ) | |
178 |
|
171 | |||
|
172 | ||||
|
173 | def diffordiffstat( | |||
|
174 | ui, | |||
|
175 | repo, | |||
|
176 | diffopts, | |||
|
177 | ctx1, | |||
|
178 | ctx2, | |||
|
179 | match, | |||
|
180 | changes=None, | |||
|
181 | stat=False, | |||
|
182 | fp=None, | |||
|
183 | graphwidth=0, | |||
|
184 | prefix=b'', | |||
|
185 | root=b'', | |||
|
186 | listsubrepos=False, | |||
|
187 | hunksfilterfn=None, | |||
|
188 | ): | |||
|
189 | '''show diff or diffstat.''' | |||
|
190 | ||||
|
191 | chunks = get_diff_chunks( | |||
|
192 | ui, | |||
|
193 | repo, | |||
|
194 | diffopts, | |||
|
195 | ctx1, | |||
|
196 | ctx2, | |||
|
197 | match, | |||
|
198 | changes=changes, | |||
|
199 | stat=stat, | |||
|
200 | prefix=prefix, | |||
|
201 | root=root, | |||
|
202 | hunksfilterfn=hunksfilterfn, | |||
|
203 | ) | |||
|
204 | ||||
|
205 | if stat: | |||
|
206 | diffopts = diffopts.copy(context=0, noprefix=False) | |||
|
207 | width = 80 | |||
|
208 | if not ui.plain(): | |||
|
209 | width = ui.termwidth() - graphwidth | |||
|
210 | ||||
179 | if fp is not None or ui.canwritewithoutlabels(): |
|
211 | if fp is not None or ui.canwritewithoutlabels(): | |
180 | out = fp or ui |
|
212 | out = fp or ui | |
181 | if stat: |
|
213 | if stat: | |
@@ -249,6 +281,33 b' class changesetdiffer:' | |||||
249 | hunksfilterfn=self._makehunksfilter(ctx), |
|
281 | hunksfilterfn=self._makehunksfilter(ctx), | |
250 | ) |
|
282 | ) | |
251 |
|
283 | |||
|
284 | def getdiffstats(self, ui, ctx, diffopts, stat=False): | |||
|
285 | chunks = get_diff_chunks( | |||
|
286 | ui, | |||
|
287 | ctx.repo(), | |||
|
288 | diffopts, | |||
|
289 | diff_parent(ctx), | |||
|
290 | ctx, | |||
|
291 | match=self._makefilematcher(ctx), | |||
|
292 | stat=stat, | |||
|
293 | hunksfilterfn=self._makehunksfilter(ctx), | |||
|
294 | ) | |||
|
295 | ||||
|
296 | diffdata = [] | |||
|
297 | for filename, additions, removals, binary in patch.diffstatdata( | |||
|
298 | util.iterlines(chunks) | |||
|
299 | ): | |||
|
300 | diffdata.append( | |||
|
301 | { | |||
|
302 | b"name": filename, | |||
|
303 | b"additions": additions, | |||
|
304 | b"removals": removals, | |||
|
305 | b"binary": binary, | |||
|
306 | } | |||
|
307 | ) | |||
|
308 | ||||
|
309 | return diffdata | |||
|
310 | ||||
252 |
|
311 | |||
253 | def changesetlabels(ctx): |
|
312 | def changesetlabels(ctx): | |
254 | labels = [b'log.changeset', b'changeset.%s' % ctx.phasestr()] |
|
313 | labels = [b'log.changeset', b'changeset.%s' % ctx.phasestr()] | |
@@ -525,9 +584,10 b' class changesetformatter(changesetprinte' | |||||
525 | ) |
|
584 | ) | |
526 |
|
585 | |||
527 | if self._includestat or b'diffstat' in datahint: |
|
586 | if self._includestat or b'diffstat' in datahint: | |
528 | self.ui.pushbuffer() |
|
587 | data = self._differ.getdiffstats( | |
529 |
|
|
588 | self.ui, ctx, self._diffopts, stat=True | |
530 | fm.data(diffstat=self.ui.popbuffer()) |
|
589 | ) | |
|
590 | fm.data(diffstat=fm.formatlist(data, name=b'diffstat')) | |||
531 | if self._includediff or b'diff' in datahint: |
|
591 | if self._includediff or b'diff' in datahint: | |
532 | self.ui.pushbuffer() |
|
592 | self.ui.pushbuffer() | |
533 | self._differ.showdiff(self.ui, ctx, self._diffopts, stat=False) |
|
593 | self._differ.showdiff(self.ui, ctx, self._diffopts, stat=False) |
@@ -766,7 +766,26 b' test CBOR style:' | |||||
766 | ], |
|
766 | ], | |
767 | 'desc': 'third', |
|
767 | 'desc': 'third', | |
768 | 'diff': 'diff -r 29114dbae42b -r 95c24699272e fourth\n--- /dev/null\tThu Jan 01 00:00:00 1970 +0000\n+++ b/fourth\tWed Jan 01 10:01:00 2020 +0000\n@@ -0,0 +1,1 @@\n+second\ndiff -r 29114dbae42b -r 95c24699272e second\n--- a/second\tMon Jan 12 13:46:40 1970 +0000\n+++ /dev/null\tThu Jan 01 00:00:00 1970 +0000\n@@ -1,1 +0,0 @@\n-second\ndiff -r 29114dbae42b -r 95c24699272e third\n--- /dev/null\tThu Jan 01 00:00:00 1970 +0000\n+++ b/third\tWed Jan 01 10:01:00 2020 +0000\n@@ -0,0 +1,1 @@\n+third\n', |
|
768 | 'diff': 'diff -r 29114dbae42b -r 95c24699272e fourth\n--- /dev/null\tThu Jan 01 00:00:00 1970 +0000\n+++ b/fourth\tWed Jan 01 10:01:00 2020 +0000\n@@ -0,0 +1,1 @@\n+second\ndiff -r 29114dbae42b -r 95c24699272e second\n--- a/second\tMon Jan 12 13:46:40 1970 +0000\n+++ /dev/null\tThu Jan 01 00:00:00 1970 +0000\n@@ -1,1 +0,0 @@\n-second\ndiff -r 29114dbae42b -r 95c24699272e third\n--- /dev/null\tThu Jan 01 00:00:00 1970 +0000\n+++ b/third\tWed Jan 01 10:01:00 2020 +0000\n@@ -0,0 +1,1 @@\n+third\n', | |
769 | 'diffstat': ' fourth | 1 +\n second | 1 -\n third | 1 +\n 3 files changed, 2 insertions(+), 1 deletions(-)\n', |
|
769 | 'diffstat': [ | |
|
770 | { | |||
|
771 | 'additions': 1, | |||
|
772 | 'binary': False, | |||
|
773 | 'name': 'fourth', | |||
|
774 | 'removals': 0 | |||
|
775 | }, | |||
|
776 | { | |||
|
777 | 'additions': 0, | |||
|
778 | 'binary': False, | |||
|
779 | 'name': 'second', | |||
|
780 | 'removals': 1 | |||
|
781 | }, | |||
|
782 | { | |||
|
783 | 'additions': 1, | |||
|
784 | 'binary': False, | |||
|
785 | 'name': 'third', | |||
|
786 | 'removals': 0 | |||
|
787 | } | |||
|
788 | ], | |||
770 | 'files': [ |
|
789 | 'files': [ | |
771 | 'fourth', |
|
790 | 'fourth', | |
772 | 'second', |
|
791 | 'second', | |
@@ -820,7 +839,7 b' Test JSON style:' | |||||
820 | "date": [1577872860, 0], |
|
839 | "date": [1577872860, 0], | |
821 | "desc": "third", |
|
840 | "desc": "third", | |
822 | "diff": "diff -r 29114dbae42b -r 95c24699272e fourth\n--- /dev/null\tThu Jan 01 00:00:00 1970 +0000\n+++ b/fourth\tWed Jan 01 10:01:00 2020 +0000\n@@ -0,0 +1,1 @@\n+second\ndiff -r 29114dbae42b -r 95c24699272e second\n--- a/second\tMon Jan 12 13:46:40 1970 +0000\n+++ /dev/null\tThu Jan 01 00:00:00 1970 +0000\n@@ -1,1 +0,0 @@\n-second\ndiff -r 29114dbae42b -r 95c24699272e third\n--- /dev/null\tThu Jan 01 00:00:00 1970 +0000\n+++ b/third\tWed Jan 01 10:01:00 2020 +0000\n@@ -0,0 +1,1 @@\n+third\n", |
|
841 | "diff": "diff -r 29114dbae42b -r 95c24699272e fourth\n--- /dev/null\tThu Jan 01 00:00:00 1970 +0000\n+++ b/fourth\tWed Jan 01 10:01:00 2020 +0000\n@@ -0,0 +1,1 @@\n+second\ndiff -r 29114dbae42b -r 95c24699272e second\n--- a/second\tMon Jan 12 13:46:40 1970 +0000\n+++ /dev/null\tThu Jan 01 00:00:00 1970 +0000\n@@ -1,1 +0,0 @@\n-second\ndiff -r 29114dbae42b -r 95c24699272e third\n--- /dev/null\tThu Jan 01 00:00:00 1970 +0000\n+++ b/third\tWed Jan 01 10:01:00 2020 +0000\n@@ -0,0 +1,1 @@\n+third\n", | |
823 | "diffstat": " fourth | 1 +\n second | 1 -\n third | 1 +\n 3 files changed, 2 insertions(+), 1 deletions(-)\n", |
|
842 | "diffstat": [{"additions": 1, "binary": false, "name": "fourth", "removals": 0}, {"additions": 0, "binary": false, "name": "second", "removals": 1}, {"additions": 1, "binary": false, "name": "third", "removals": 0}], | |
824 | "files": ["fourth", "second", "third"], |
|
843 | "files": ["fourth", "second", "third"], | |
825 | "node": "95c24699272ef57d062b8bccc32c878bf841784a", |
|
844 | "node": "95c24699272ef57d062b8bccc32c878bf841784a", | |
826 | "parents": ["29114dbae42b9f078cf2714dbe3a86bba8ec7453"], |
|
845 | "parents": ["29114dbae42b9f078cf2714dbe3a86bba8ec7453"], | |
@@ -1180,7 +1199,7 b' honor --git but not format-breaking diff' | |||||
1180 |
|
1199 | |||
1181 | $ hg log -r. -T'json(diffstat)' |
|
1200 | $ hg log -r. -T'json(diffstat)' | |
1182 | [ |
|
1201 | [ | |
1183 | {"diffstat": " fourth | 1 +\n second | 1 -\n third | 1 +\n 3 files changed, 2 insertions(+), 1 deletions(-)\n"} |
|
1202 | {"diffstat": [{"additions": 1, "binary": false, "name": "fourth", "removals": 0}, {"additions": 0, "binary": false, "name": "second", "removals": 1}, {"additions": 1, "binary": false, "name": "third", "removals": 0}]} | |
1184 | ] |
|
1203 | ] | |
1185 |
|
1204 | |||
1186 | $ hg log -r. -T'json(manifest)' |
|
1205 | $ hg log -r. -T'json(manifest)' |
General Comments 0
You need to be logged in to leave comments.
Login now