Show More
@@ -0,0 +1,46 b'' | |||||
|
1 | #!/bin/sh | |||
|
2 | ||||
|
3 | hg init a | |||
|
4 | cd a | |||
|
5 | ||||
|
6 | echo start > start | |||
|
7 | hg ci -Amstart -d '0 0' | |||
|
8 | echo new > new | |||
|
9 | hg ci -Amnew -d '0 0' | |||
|
10 | echo '% new file' | |||
|
11 | hg diff --git -r 0 | sed "s/\(\(---\|+++\) [a-zA-Z0-9_/.-]*\).*/\1/" | |||
|
12 | ||||
|
13 | hg cp new copy | |||
|
14 | hg ci -mcopy -d '0 0' | |||
|
15 | echo '% copy' | |||
|
16 | hg diff --git -r 1:tip | sed "s/\(\(---\|+++\) [a-zA-Z0-9_/.-]*\).*/\1/" | |||
|
17 | ||||
|
18 | hg mv copy rename | |||
|
19 | hg ci -mrename -d '0 0' | |||
|
20 | echo '% rename' | |||
|
21 | hg diff --git -r 2:tip | sed "s/\(\(---\|+++\) [a-zA-Z0-9_/.-]*\).*/\1/" | |||
|
22 | ||||
|
23 | hg rm rename | |||
|
24 | hg ci -mdelete -d '0 0' | |||
|
25 | echo '% delete' | |||
|
26 | hg diff --git -r 3:tip | sed "s/\(\(---\|+++\) [a-zA-Z0-9_/.-]*\).*/\1/" | |||
|
27 | ||||
|
28 | cat > src <<EOF | |||
|
29 | 1 | |||
|
30 | 2 | |||
|
31 | 3 | |||
|
32 | 4 | |||
|
33 | 5 | |||
|
34 | EOF | |||
|
35 | hg ci -Amsrc -d '0 0' | |||
|
36 | chmod +x src | |||
|
37 | hg ci -munexec -d '0 0' | |||
|
38 | echo '% chmod 644' | |||
|
39 | hg diff --git -r 5:tip | sed "s/\(\(---\|+++\) [a-zA-Z0-9_/.-]*\).*/\1/" | |||
|
40 | ||||
|
41 | hg mv src dst | |||
|
42 | chmod -x dst | |||
|
43 | echo a >> dst | |||
|
44 | hg ci -mrenamemod -d '0 0' | |||
|
45 | echo '% rename+mod+chmod' | |||
|
46 | hg diff --git -r 6:tip | sed "s/\(\(---\|+++\) [a-zA-Z0-9_/.-]*\).*/\1/" |
@@ -0,0 +1,42 b'' | |||||
|
1 | adding start | |||
|
2 | adding new | |||
|
3 | % new file | |||
|
4 | diff --git a/new b/new | |||
|
5 | new file mode 100644 | |||
|
6 | --- /dev/null | |||
|
7 | +++ b/new | |||
|
8 | @@ -0,0 +1,1 @@ | |||
|
9 | +new | |||
|
10 | % copy | |||
|
11 | diff --git a/new b/copy | |||
|
12 | copy from new | |||
|
13 | copy to copy | |||
|
14 | % rename | |||
|
15 | diff --git a/copy b/rename | |||
|
16 | rename from copy | |||
|
17 | rename to rename | |||
|
18 | % delete | |||
|
19 | diff --git a/rename b/rename | |||
|
20 | deleted file mode 100644 | |||
|
21 | --- a/rename | |||
|
22 | +++ /dev/null | |||
|
23 | @@ -1,1 +0,0 @@ | |||
|
24 | -new | |||
|
25 | adding src | |||
|
26 | % chmod 644 | |||
|
27 | diff --git a/src b/src | |||
|
28 | old mode 100644 | |||
|
29 | new mode 100755 | |||
|
30 | % rename+mod+chmod | |||
|
31 | diff --git a/src b/dst | |||
|
32 | old mode 100755 | |||
|
33 | new mode 100644 | |||
|
34 | rename from src | |||
|
35 | rename to dst | |||
|
36 | --- a/dst | |||
|
37 | +++ b/dst | |||
|
38 | @@ -3,3 +3,4 @@ 3 | |||
|
39 | 3 | |||
|
40 | 4 | |||
|
41 | 5 | |||
|
42 | +a |
@@ -2877,6 +2877,7 b' table = {' | |||||
2877 | ('a', 'text', None, _('treat all files as text')), |
|
2877 | ('a', 'text', None, _('treat all files as text')), | |
2878 | ('p', 'show-function', None, |
|
2878 | ('p', 'show-function', None, | |
2879 | _('show which function each change is in')), |
|
2879 | _('show which function each change is in')), | |
|
2880 | ('g', 'git', None, _('use git extended diff format')), | |||
2880 | ('w', 'ignore-all-space', None, |
|
2881 | ('w', 'ignore-all-space', None, | |
2881 | _('ignore white space when comparing lines')), |
|
2882 | _('ignore white space when comparing lines')), | |
2882 | ('b', 'ignore-space-change', None, |
|
2883 | ('b', 'ignore-space-change', None, |
@@ -23,6 +23,7 b' class diffopts(object):' | |||||
23 | '''context is the number of context lines |
|
23 | '''context is the number of context lines | |
24 | text treats all files as text |
|
24 | text treats all files as text | |
25 | showfunc enables diff -p output |
|
25 | showfunc enables diff -p output | |
|
26 | git enables the git extended patch format | |||
26 | ignorews ignores all whitespace changes in the diff |
|
27 | ignorews ignores all whitespace changes in the diff | |
27 | ignorewsamount ignores changes in the amount of whitespace |
|
28 | ignorewsamount ignores changes in the amount of whitespace | |
28 | ignoreblanklines ignores changes whose lines are all blank''' |
|
29 | ignoreblanklines ignores changes whose lines are all blank''' | |
@@ -31,6 +32,7 b' class diffopts(object):' | |||||
31 | 'context': 3, |
|
32 | 'context': 3, | |
32 | 'text': False, |
|
33 | 'text': False, | |
33 | 'showfunc': True, |
|
34 | 'showfunc': True, | |
|
35 | 'git': False, | |||
34 | 'ignorews': False, |
|
36 | 'ignorews': False, | |
35 | 'ignorewsamount': False, |
|
37 | 'ignorewsamount': False, | |
36 | 'ignoreblanklines': False, |
|
38 | 'ignoreblanklines': False, |
@@ -298,6 +298,9 b' def diff(repo, node1=None, node2=None, f' | |||||
298 | return _date2 |
|
298 | return _date2 | |
299 | def read(f): |
|
299 | def read(f): | |
300 | return repo.file(f).read(mmap2[f]) |
|
300 | return repo.file(f).read(mmap2[f]) | |
|
301 | def renamed(f): | |||
|
302 | src = repo.file(f).renamed(mmap2[f]) | |||
|
303 | return src and src[0] or None | |||
301 | else: |
|
304 | else: | |
302 | tz = util.makedate()[1] |
|
305 | tz = util.makedate()[1] | |
303 | _date2 = util.datestr() |
|
306 | _date2 = util.datestr() | |
@@ -309,6 +312,8 b' def diff(repo, node1=None, node2=None, f' | |||||
309 | return _date2 |
|
312 | return _date2 | |
310 | def read(f): |
|
313 | def read(f): | |
311 | return repo.wread(f) |
|
314 | return repo.wread(f) | |
|
315 | def renamed(f): | |||
|
316 | return repo.dirstate.copies.get(f) | |||
312 |
|
317 | |||
313 | if repo.ui.quiet: |
|
318 | if repo.ui.quiet: | |
314 | r = None |
|
319 | r = None | |
@@ -316,16 +321,65 b' def diff(repo, node1=None, node2=None, f' | |||||
316 | hexfunc = repo.ui.verbose and hex or short |
|
321 | hexfunc = repo.ui.verbose and hex or short | |
317 | r = [hexfunc(node) for node in [node1, node2] if node] |
|
322 | r = [hexfunc(node) for node in [node1, node2] if node] | |
318 |
|
323 | |||
|
324 | if opts.git: | |||
|
325 | copied = {} | |||
|
326 | for f in added: | |||
|
327 | src = renamed(f) | |||
|
328 | if src: | |||
|
329 | copied[f] = src | |||
|
330 | srcs = [x[1] for x in copied.items()] | |||
|
331 | ||||
319 | all = modified + added + removed |
|
332 | all = modified + added + removed | |
320 | all.sort() |
|
333 | all.sort() | |
321 | for f in all: |
|
334 | for f in all: | |
322 | to = None |
|
335 | to = None | |
323 | tn = None |
|
336 | tn = None | |
|
337 | dodiff = True | |||
324 | if f in mmap: |
|
338 | if f in mmap: | |
325 | to = repo.file(f).read(mmap[f]) |
|
339 | to = repo.file(f).read(mmap[f]) | |
326 | if f not in removed: |
|
340 | if f not in removed: | |
327 | tn = read(f) |
|
341 | tn = read(f) | |
328 | fp.write(mdiff.unidiff(to, date1, tn, date2(f), f, r, opts=opts)) |
|
342 | if opts.git: | |
|
343 | def gitmode(x): | |||
|
344 | return x and '100755' or '100644' | |||
|
345 | def addmodehdr(header, omode, nmode): | |||
|
346 | if omode != nmode: | |||
|
347 | header.append('old mode %s\n' % omode) | |||
|
348 | header.append('new mode %s\n' % nmode) | |||
|
349 | ||||
|
350 | a, b = f, f | |||
|
351 | header = [] | |||
|
352 | if f in added: | |||
|
353 | if node2: | |||
|
354 | mode = gitmode(mmap2.execf(f)) | |||
|
355 | else: | |||
|
356 | mode = gitmode(util.is_exec(repo.wjoin(f), None)) | |||
|
357 | if f in copied: | |||
|
358 | a = copied[f] | |||
|
359 | omode = gitmode(mmap.execf(a)) | |||
|
360 | addmodehdr(header, omode, mode) | |||
|
361 | op = a in removed and 'rename' or 'copy' | |||
|
362 | header.append('%s from %s\n' % (op, a)) | |||
|
363 | header.append('%s to %s\n' % (op, f)) | |||
|
364 | to = repo.file(a).read(mmap[a]) | |||
|
365 | else: | |||
|
366 | header.append('new file mode %s\n' % mode) | |||
|
367 | elif f in removed: | |||
|
368 | if f in srcs: | |||
|
369 | dodiff = False | |||
|
370 | else: | |||
|
371 | mode = gitmode(mmap.execf(f)) | |||
|
372 | header.append('deleted file mode %s\n' % mode) | |||
|
373 | else: | |||
|
374 | omode = gitmode(mmap.execf(f)) | |||
|
375 | nmode = gitmode(util.is_exec(repo.wjoin(f), mmap.execf(f))) | |||
|
376 | addmodehdr(header, omode, nmode) | |||
|
377 | r = None | |||
|
378 | if dodiff: | |||
|
379 | header.insert(0, 'diff --git a/%s b/%s\n' % (a, b)) | |||
|
380 | fp.write(''.join(header)) | |||
|
381 | if dodiff: | |||
|
382 | fp.write(mdiff.unidiff(to, date1, tn, date2(f), f, r, opts=opts)) | |||
329 |
|
383 | |||
330 | def export(repo, revs, template='hg-%h.patch', fp=None, switch_parent=False, |
|
384 | def export(repo, revs, template='hg-%h.patch', fp=None, switch_parent=False, | |
331 | opts=None): |
|
385 | opts=None): |
@@ -174,6 +174,8 b' class ui(object):' | |||||
174 | text=opts.get('text'), |
|
174 | text=opts.get('text'), | |
175 | showfunc=(opts.get('show_function') or |
|
175 | showfunc=(opts.get('show_function') or | |
176 | self.configbool('diff', 'showfunc', None)), |
|
176 | self.configbool('diff', 'showfunc', None)), | |
|
177 | git=(opts.get('git') or | |||
|
178 | self.configbool('diff', 'git', None)), | |||
177 | ignorews=(opts.get('ignore_all_space') or |
|
179 | ignorews=(opts.get('ignore_all_space') or | |
178 | self.configbool('diff', 'ignorews', None)), |
|
180 | self.configbool('diff', 'ignorews', None)), | |
179 | ignorewsamount=(opts.get('ignore_space_change') or |
|
181 | ignorewsamount=(opts.get('ignore_space_change') or |
@@ -176,6 +176,7 b' options:' | |||||
176 | -r --rev revision |
|
176 | -r --rev revision | |
177 | -a --text treat all files as text |
|
177 | -a --text treat all files as text | |
178 | -p --show-function show which function each change is in |
|
178 | -p --show-function show which function each change is in | |
|
179 | -g --git use git extended diff format | |||
179 | -w --ignore-all-space ignore white space when comparing lines |
|
180 | -w --ignore-all-space ignore white space when comparing lines | |
180 | -b --ignore-space-change ignore changes in the amount of white space |
|
181 | -b --ignore-space-change ignore changes in the amount of white space | |
181 | -B --ignore-blank-lines ignore changes whose lines are all blank |
|
182 | -B --ignore-blank-lines ignore changes whose lines are all blank |
General Comments 0
You need to be logged in to leave comments.
Login now