52 |
52 |
53 def diffordiffstat(ui, repo, diffopts, node1, node2, match, |
53 def diffordiffstat(ui, repo, diffopts, node1, node2, match, |
54 changes=None, stat=False, fp=None, prefix='', |
54 changes=None, stat=False, fp=None, prefix='', |
55 root='', listsubrepos=False, hunksfilterfn=None): |
55 root='', listsubrepos=False, hunksfilterfn=None): |
56 '''show diff or diffstat.''' |
56 '''show diff or diffstat.''' |
57 if fp is None: |
|
58 write = ui.write |
|
59 else: |
|
60 def write(s, **kw): |
|
61 fp.write(s) |
|
62 |
|
63 if root: |
57 if root: |
64 relroot = pathutil.canonpath(repo.root, repo.getcwd(), root) |
58 relroot = pathutil.canonpath(repo.root, repo.getcwd(), root) |
65 else: |
59 else: |
66 relroot = '' |
60 relroot = '' |
67 if relroot != '': |
61 if relroot != '': |
83 chunks = patch.diff(repo, node1, node2, match, changes, opts=diffopts, |
77 chunks = patch.diff(repo, node1, node2, match, changes, opts=diffopts, |
84 prefix=prefix, relroot=relroot, |
78 prefix=prefix, relroot=relroot, |
85 hunksfilterfn=hunksfilterfn) |
79 hunksfilterfn=hunksfilterfn) |
86 |
80 |
87 if fp is not None or ui.canwritewithoutlabels(): |
81 if fp is not None or ui.canwritewithoutlabels(): |
|
82 out = fp or ui |
88 if stat: |
83 if stat: |
89 chunks = patch.diffstat(util.iterlines(chunks), width=width) |
84 chunks = patch.diffstat(util.iterlines(chunks), width=width) |
90 for chunk in util.filechunkiter(util.chunkbuffer(chunks)): |
85 for chunk in util.filechunkiter(util.chunkbuffer(chunks)): |
91 write(chunk) |
86 out.write(chunk) |
92 else: |
87 else: |
93 if stat: |
88 if stat: |
94 chunks = patch.diffstatui(util.iterlines(chunks), width=width) |
89 chunks = patch.diffstatui(util.iterlines(chunks), width=width) |
95 else: |
90 else: |
96 chunks = patch.difflabel(lambda chunks, **kwargs: chunks, chunks, |
91 chunks = patch.difflabel(lambda chunks, **kwargs: chunks, chunks, |
98 if ui.canbatchlabeledwrites(): |
93 if ui.canbatchlabeledwrites(): |
99 def gen(): |
94 def gen(): |
100 for chunk, label in chunks: |
95 for chunk, label in chunks: |
101 yield ui.label(chunk, label=label) |
96 yield ui.label(chunk, label=label) |
102 for chunk in util.filechunkiter(util.chunkbuffer(gen())): |
97 for chunk in util.filechunkiter(util.chunkbuffer(gen())): |
103 write(chunk) |
98 ui.write(chunk) |
104 else: |
99 else: |
105 for chunk, label in chunks: |
100 for chunk, label in chunks: |
106 write(chunk, label=label) |
101 ui.write(chunk, label=label) |
107 |
102 |
108 if listsubrepos: |
103 if listsubrepos: |
109 ctx1 = repo[node1] |
104 ctx1 = repo[node1] |
110 ctx2 = repo[node2] |
105 ctx2 = repo[node2] |
111 for subpath, sub in scmutil.itersubrepos(ctx1, ctx2): |
106 for subpath, sub in scmutil.itersubrepos(ctx1, ctx2): |