Show More
@@ -128,7 +128,7 b' copy <source> <dest>::' | |||||
128 |
|
128 | |||
129 | This command takes effect for the next commit. |
|
129 | This command takes effect for the next commit. | |
130 |
|
130 | |||
131 | diff [-r revision] [-r revision] [files ...]:: |
|
131 | diff [-a] [-r revision] [-r revision] [files ...]:: | |
132 | Show differences between revisions for the specified files. |
|
132 | Show differences between revisions for the specified files. | |
133 |
|
133 | |||
134 | Differences between files are shown using the unified diff format. |
|
134 | Differences between files are shown using the unified diff format. | |
@@ -139,7 +139,12 b' diff [-r revision] [-r revision] [files ' | |||||
139 | revisions are specified, the working directory files are compared |
|
139 | revisions are specified, the working directory files are compared | |
140 | to its parent. |
|
140 | to its parent. | |
141 |
|
141 | |||
|
142 | Without the -a option, diff will avoid generating diffs of files | |||
|
143 | it detects as binary. With -a, diff will generate a diff anyway, | |||
|
144 | probably with undesirable results. | |||
|
145 | ||||
142 | options: |
|
146 | options: | |
|
147 | -a, --text treat all files as text | |||
143 | -I, --include <pat> include names matching the given patterns |
|
148 | -I, --include <pat> include names matching the given patterns | |
144 | -X, --exclude <pat> exclude names matching the given patterns |
|
149 | -X, --exclude <pat> exclude names matching the given patterns | |
145 |
|
150 | |||
@@ -161,8 +166,12 b' export [-o filespec] [revision] ...::' | |||||
161 | %n zero-padded sequence number, starting at 1 |
|
166 | %n zero-padded sequence number, starting at 1 | |
162 | %r zero-padded changeset revision number |
|
167 | %r zero-padded changeset revision number | |
163 |
|
168 | |||
164 | Options: |
|
169 | Without the -a option, export will avoid generating diffs of files | |
|
170 | it detects as binary. With -a, export will generate a diff anyway, | |||
|
171 | probably with undesirable results. | |||
165 |
|
172 | |||
|
173 | options: | |||
|
174 | -a, --text treat all files as text | |||
166 | -o, --output <filespec> print output to file with formatted named |
|
175 | -o, --output <filespec> print output to file with formatted named | |
167 |
|
176 | |||
168 | forget [options] [files]:: |
|
177 | forget [options] [files]:: |
@@ -141,7 +141,7 b' def make_file(repo, r, pat, node=None,' | |||||
141 | mode) |
|
141 | mode) | |
142 |
|
142 | |||
143 | def dodiff(fp, ui, repo, node1, node2, files=None, match=util.always, |
|
143 | def dodiff(fp, ui, repo, node1, node2, files=None, match=util.always, | |
144 | changes=None): |
|
144 | changes=None, text=False): | |
145 | def date(c): |
|
145 | def date(c): | |
146 | return time.asctime(time.gmtime(float(c[2].split(' ')[0]))) |
|
146 | return time.asctime(time.gmtime(float(c[2].split(' ')[0]))) | |
147 |
|
147 | |||
@@ -183,15 +183,15 b' def dodiff(fp, ui, repo, node1, node2, f' | |||||
183 | if f in mmap: |
|
183 | if f in mmap: | |
184 | to = repo.file(f).read(mmap[f]) |
|
184 | to = repo.file(f).read(mmap[f]) | |
185 | tn = read(f) |
|
185 | tn = read(f) | |
186 | fp.write(mdiff.unidiff(to, date1, tn, date2, f, r)) |
|
186 | fp.write(mdiff.unidiff(to, date1, tn, date2, f, r, text=text)) | |
187 | for f in a: |
|
187 | for f in a: | |
188 | to = None |
|
188 | to = None | |
189 | tn = read(f) |
|
189 | tn = read(f) | |
190 | fp.write(mdiff.unidiff(to, date1, tn, date2, f, r)) |
|
190 | fp.write(mdiff.unidiff(to, date1, tn, date2, f, r, text=text)) | |
191 | for f in d: |
|
191 | for f in d: | |
192 | to = repo.file(f).read(mmap[f]) |
|
192 | to = repo.file(f).read(mmap[f]) | |
193 | tn = None |
|
193 | tn = None | |
194 | fp.write(mdiff.unidiff(to, date1, tn, date2, f, r)) |
|
194 | fp.write(mdiff.unidiff(to, date1, tn, date2, f, r, text=text)) | |
195 |
|
195 | |||
196 | def show_changeset(ui, repo, rev=0, changenode=None, filelog=None, brinfo=None): |
|
196 | def show_changeset(ui, repo, rev=0, changenode=None, filelog=None, brinfo=None): | |
197 | """show a single changeset or file revision""" |
|
197 | """show a single changeset or file revision""" | |
@@ -644,11 +644,9 b' def debugwalk(ui, repo, *pats, **opts):' | |||||
644 |
|
644 | |||
645 | def diff(ui, repo, *pats, **opts): |
|
645 | def diff(ui, repo, *pats, **opts): | |
646 | """diff working directory (or selected files)""" |
|
646 | """diff working directory (or selected files)""" | |
647 | revs = [] |
|
647 | node1, node2 = None, None | |
648 | if opts['rev']: |
|
648 | revs = [repo.lookup(x) for x in opts['rev']] | |
649 | revs = map(lambda x: repo.lookup(x), opts['rev']) |
|
|||
650 |
|
649 | |||
651 | node1, node2 = None, None |
|
|||
652 | if len(revs) > 0: |
|
650 | if len(revs) > 0: | |
653 | node1 = revs[0] |
|
651 | node1 = revs[0] | |
654 | if len(revs) > 1: |
|
652 | if len(revs) > 1: | |
@@ -663,7 +661,8 b' def diff(ui, repo, *pats, **opts):' | |||||
663 | for src, abs, rel, exact in results: |
|
661 | for src, abs, rel, exact in results: | |
664 | files.append(abs) |
|
662 | files.append(abs) | |
665 |
|
663 | |||
666 |
dodiff(sys.stdout, ui, repo, node1, node2, files, match=match |
|
664 | dodiff(sys.stdout, ui, repo, node1, node2, files, match=match, | |
|
665 | text=opts['text']) | |||
667 |
|
666 | |||
668 | def doexport(ui, repo, changeset, seqno, total, revwidth, opts): |
|
667 | def doexport(ui, repo, changeset, seqno, total, revwidth, opts): | |
669 | node = repo.lookup(changeset) |
|
668 | node = repo.lookup(changeset) | |
@@ -685,7 +684,7 b' def doexport(ui, repo, changeset, seqno,' | |||||
685 | fp.write(change[4].rstrip()) |
|
684 | fp.write(change[4].rstrip()) | |
686 | fp.write("\n\n") |
|
685 | fp.write("\n\n") | |
687 |
|
686 | |||
688 | dodiff(fp, ui, repo, prev, node) |
|
687 | dodiff(fp, ui, repo, prev, node, text=opts['text']) | |
689 | if fp != sys.stdout: fp.close() |
|
688 | if fp != sys.stdout: fp.close() | |
690 |
|
689 | |||
691 | def export(ui, repo, *changesets, **opts): |
|
690 | def export(ui, repo, *changesets, **opts): | |
@@ -1326,12 +1325,14 b' table = {' | |||||
1326 | "^diff": |
|
1325 | "^diff": | |
1327 | (diff, |
|
1326 | (diff, | |
1328 | [('r', 'rev', [], 'revision'), |
|
1327 | [('r', 'rev', [], 'revision'), | |
|
1328 | ('a', 'text', None, 'treat all files as text'), | |||
1329 | ('I', 'include', [], 'include path in search'), |
|
1329 | ('I', 'include', [], 'include path in search'), | |
1330 | ('X', 'exclude', [], 'exclude path from search')], |
|
1330 | ('X', 'exclude', [], 'exclude path from search')], | |
1331 | 'hg diff [-I] [-X] [-r REV1 [-r REV2]] [FILE]...'), |
|
1331 | 'hg diff [-I] [-X] [-r REV1 [-r REV2]] [FILE]...'), | |
1332 | "^export": |
|
1332 | "^export": | |
1333 | (export, |
|
1333 | (export, | |
1334 |
[('o', 'output', "", 'output to file') |
|
1334 | [('o', 'output', "", 'output to file'), | |
|
1335 | ('a', 'text', None, 'treat all files as text')], | |||
1335 | "hg export [-o OUTFILE] REV..."), |
|
1336 | "hg export [-o OUTFILE] REV..."), | |
1336 | "forget": |
|
1337 | "forget": | |
1337 | (forget, |
|
1338 | (forget, |
@@ -7,12 +7,15 b'' | |||||
7 |
|
7 | |||
8 | import difflib, struct, bdiff |
|
8 | import difflib, struct, bdiff | |
9 | from mpatch import * |
|
9 | from mpatch import * | |
|
10 | from util import * | |||
10 |
|
11 | |||
11 | def unidiff(a, ad, b, bd, fn, r=None): |
|
12 | def unidiff(a, ad, b, bd, fn, r=None, text=False): | |
12 |
|
13 | |||
13 | if not a and not b: return "" |
|
14 | if not a and not b: return "" | |
14 |
|
15 | |||
15 | if a == None: |
|
16 | if not text and (binary(a) or binary(b)): | |
|
17 | l = ['Binary file %s has changed\n' % fn] | |||
|
18 | elif a == None: | |||
16 | b = b.splitlines(1) |
|
19 | b = b.splitlines(1) | |
17 | l1 = "--- %s\t%s\n" % ("/dev/null", ad) |
|
20 | l1 = "--- %s\t%s\n" % ("/dev/null", ad) | |
18 | l2 = "+++ %s\t%s\n" % ("b/" + fn, bd) |
|
21 | l2 = "+++ %s\t%s\n" % ("b/" + fn, bd) |
@@ -9,6 +9,11 b' import os, errno' | |||||
9 | from demandload import * |
|
9 | from demandload import * | |
10 | demandload(globals(), "re") |
|
10 | demandload(globals(), "re") | |
11 |
|
11 | |||
|
12 | def binary(s): | |||
|
13 | if s and '\0' in s[:4096]: | |||
|
14 | return True | |||
|
15 | return False | |||
|
16 | ||||
12 | def unique(g): |
|
17 | def unique(g): | |
13 | seen = {} |
|
18 | seen = {} | |
14 | for f in g: |
|
19 | for f in g: |
General Comments 0
You need to be logged in to leave comments.
Login now