Commit Graph

240 Commits

Author SHA1 Message Date
Matt Mackall
cd3ef170f7 Merge with stable 2010-01-19 22:45:09 -06:00
Matt Mackall
595d66f424 Update license to GPLv2+ 2010-01-19 22:20:08 -06:00
Patrick Mezard
c6da65973e patch: explicitely close input patch files when leaving
If applydiff() raises an exception, the opened patch file is kept alive in the
exception context. If it is a temporary file (for instance supplied by import
command with stdin input), Windows cannot clean it up.
2010-01-03 19:47:07 +01:00
Greg Onufer
5056bcbd9e patch: better handling of sequence of offset patch hunks (issue1941)
The built-in patch implementation applied the hunks to the wrong lines of the
file if the file in the repo has been modified to skew the patch line numbers
and the file contains repetitive sequences of lines.
2009-12-09 16:56:00 -08:00
Yannick Gingras
ed1d8b7e7a diff: add --inverse option
Most of the time, one can reverse a diff by swapping the revisions passed with
-r but it happens that if you use the global -R, and diff against the tip of
the current repo, you can't swap the revisions. One use-case for that is
reviewing changes from a bundle before unbundling. One could also pipe the
output of `hg diff` to a command line filter that reverses the diff, but that
would remove the benefit from color diffs. Therefore, having an option in
`hg diff` to reverse a diff is a good thing.

The option flag selection was tricky. GNU patch uses -R/--reverse but -R is
already used as a global option and --reverse would make --rev ambiguous.
2009-11-05 15:18:56 +01:00
Dirkjan Ochtman
12c5890a70 kill trailing whitespace 2009-11-05 10:44:36 +01:00
Benoit Boissinot
01d3fbbbd0 patch: use the public ctx API instead of the internals 2009-10-31 18:02:34 +01:00
Benoit Boissinot
9015e8911f patch: don't use mutable object as default argument 2009-10-31 18:02:13 +01:00
Benoit Boissinot
1c058dc6e9 patch: initialize all attributes of the hunk class 2009-10-31 18:01:08 +01:00
Benoit Boissinot
667b87aaec patch: simplify logic 2009-10-31 18:00:05 +01:00
Brodie Rao
7c2f2247c5 diffstat: with --git, mark binary files with Bin
Normally, diffs without any text insertions or deletions are reported
as having 0 lines changed by stock diffstat. Compatibility is
preserved with stock diffstat in this case, but when using --git,
binary files are marked with Bin as a means of clarification.

git diff --stat does something similar, though it also includes the
old and new file sizes.
2009-10-25 02:53:33 +02:00
Brodie Rao
cd4a91c73f diffstat: print 0 instead of nothing for 0 adds or removes
This is in line with how the stock diffstat behaves when processing a
single diff with no line modifications (like a binary diff).
2009-10-25 02:35:35 +02:00
Patrick Mezard
990e7895a0 Merge with crew-stable 2009-10-16 00:06:23 +02:00
Patrick Mezard
7b9a712086 patch: handle symlink updates/replacements (issue1785) 2009-10-15 23:15:30 +02:00
Patrick Mezard
5c89cb752a patch: handle symlinks without symlinkhunk
Symlink creations and deletions were handled with a special symlinkhunk object,
working like a binary hunk. However, this model does not support symlink
updates or replacements, so we teach regular hunks how to handle symlinks.
2009-10-15 23:15:30 +02:00
Patrick Mezard
a7d029beb4 patch: do not swallow header-like patch first line (issue1859)
Current solution is hackish but looks like a good trade-off short of rewriting
patch.extract() significantly.
2009-10-08 23:42:33 +02:00
Matt Mackall
b6547e5312 Merge with stable 2009-10-11 13:54:19 -05:00
Martin Geisler
9f1896c083 do not attempt to translate ui.debug output 2009-09-19 01:15:38 +02:00
Nicolas Dumazet
908bc54270 patch: remove the unused, broken reverse() function 2009-08-23 14:32:58 +02:00
Nicolas Dumazet
1291ef7c74 patch: readgitpatch: remove unused variable 'src' 2009-08-24 14:40:21 +02:00
Bill Barry
5c4fb9e616 fix issue 1763: strip chars from end of line when parsing gitpatch lines 2009-07-24 15:53:40 -06:00
Brendan Cully
31a596d574 Make patch.diff filelog cache LRU of 20 files. Fixes issue1738.
20 files is as fast as 200 for hg diff -r 28015:30103 of mozilla-central.
Ideally we'd use util.lrucachefunc, but the interface doesn't quite work.
2009-07-14 16:50:37 -07:00
Martin Geisler
f5e48ed894 patch: marked string for translation 2009-08-10 23:02:58 +02:00
Brodie Rao
5c00bff54a diffstat: scale adds/removes proportionally to graph width
The previous method of scaling had a tendency to include graph lines that
went past the output width when the file with the most changes had a very
large number of changes.
2009-08-10 22:59:29 +02:00
Brendan Cully
dcdbd19aef patch: create file even if source is not /dev/null
as long as the first hunk is -0,0 and the source and destination have the
same name. Matt found a patch like this, and /usr/bin/patch accepts it.
2009-08-07 19:27:54 -07:00
Matt Mackall
eba820848f Merge with crew 2009-07-27 18:38:20 -05:00
Brendan Cully
330d2aecf7 Merge with crew-stable 2009-07-14 16:51:52 -07:00
Alejandro Santos
1ef2fb42a7 compat: use 'key' argument instead of 'cmp' when sorting a list 2009-07-05 11:02:00 +02:00
Alejandro Santos
77d606ac51 compat: use open() instead of file() everywhere 2009-07-05 11:01:30 +02:00
Alejandro Santos
3183e52503 compat: use // for integer division 2009-07-05 11:00:44 +02:00
Simon Heimberg
66c4ab1cbf patch: use new style class in linereader 2009-06-22 12:05:11 +02:00
Dirkjan Ochtman
605b944edf kill trailing whitespace 2009-06-19 13:47:50 +02:00
Colin Caughie
53aca7b1bf Fixed patch.eol bug that truncated all patched lines to one character
Also updated the import-eol test to test with lines longer than one character,
and also empty lines.
2009-06-16 16:22:42 +01:00
Patrick Mezard
c1548a6a3e Add patch.eol to ignore EOLs when patching (issue1019)
The intent is to fix many issues involving patching when win32ext is enabled.
With win32ext, the working directory and repository files EOLs are not the same
which means that patches made on a non-win32ext host do not apply cleanly
because of EOLs discrepancies. A theorically correct approach would be
transform either the patched file or the patch content with the
encoding/decoding filters used by win32ext. This solution is tricky to
implement and invasive, instead we prefer to address the win32ext case, by
offering a way to ignore input EOLs when patching and rewriting them when
saving the patched result.
2009-06-15 00:03:26 +02:00
Benoit Boissinot
125a85ec87 use new style classes 2009-06-10 15:10:21 +02:00
timeless
fb33de67af Generally replace "file name" with "filename" in help and comments. 2009-06-09 09:25:17 -04:00
Martin Geisler
5b4e5428df replace "i in range(len(xs))" with "i, x in enumerate(xs)"
The remaining occurrences should be the ones where "xs" is mutated or
where "i" is used for index arithmetic.
2009-05-26 22:59:52 +02:00
Patrick Mezard
270c4ac7da Merge with crew-stable 2010-01-03 20:36:30 +01:00
Patrick Mezard
d6ce43b965 patch: support diff data loss detection and upgrade
In worst case, generating diff in upgrade mode can be two times more expensive
than generating it in git mode directly: we may have to regenerate the whole
diff again whenever a git feature is detected. Also, the first diff attempt is
completely buffered instead of being streamed. That said, even without having
profiled it yet, I am convinced we can fast-path the upgrade mode if necessary
were it to be used in regular diff commands, and not only in mq where avoiding
data loss is worth the price.
2010-01-01 20:54:05 +01:00
Patrick Mezard
9a59d5af22 patch: make git diffline generation more explicit 2009-12-29 16:00:38 +01:00
Patrick Mezard
bf3c546c3f Merge with crew-stable 2009-12-24 00:01:13 +01:00
Patrick Mezard
32212929f1 patch: drop unused hunk.newctrl() 2009-12-23 19:31:48 +01:00
Patrick Mezard
cd49284bae patch: drop eol normalization fast-path for 'lf' and 'crlf'
With eolmode set to 'lf' or 'crlf' we avoided the hunk duplication and
normalization by reading the input patch in text mode. Dropping this
optimization simplifies code expectations for a small overhead.

The change in test-mq-eol comes from a tolerance to CRLF instead of LF for last
lines without newlines being broken by this revision. This tolerance was only
partially supported and will be added again in a better way.
2009-12-23 19:31:48 +01:00
Patrick Mezard
7d0eedb075 patch: fix eolmode=auto with new files
If target file does not exist or has no eol, current code was normalizing eols
to LF. Preserve patch file eols instead.
2009-12-23 19:31:47 +01:00
Martin Geisler
8a5bf57c34 patch: implement patch.eol=auto mode
EOLs in patched files are restored to their original value after
patching. We use the first EOL found in the file, files with
inconsistent EOLs will thus be normalized during this process.
2009-12-20 17:18:04 +01:00
Martin Geisler
6e4790ea0c patch: propagate eolmode down to patchfile
The old code mapped the value of eolmode ('strict', 'crlf' or 'lf') to
eol (None, '\r\n' or '\n') at the entry point in internalpatch. The
value of eol was then used directly as the desired EOL in patchfile.

We now delay the mapping and let patchfile do it instead. This allows
for more complicated behavior where it does not make sense to map
eolmode directly to the target EOLs.
2009-12-20 17:18:02 +01:00
Martin Geisler
0a365d5ca2 use 'x is None' instead of 'x == None'
The built-in None object is a singleton and it is therefore safe to
compare memory addresses with is. It is also faster, how much depends
on the object being compared. For a simple type like str I get:

            | s = "foo" | s = None
  ----------+-----------+----------
  s == None | 0.25 usec | 0.21 usec
  s is None | 0.17 usec | 0.17 usec
2009-05-20 00:52:46 +02:00
Martin Geisler
d4730b32a3 patch: simplify Boolean expression slightly
The context variable is either True, False or None. Abbreviate it as C
and we get the following truth table where the second column is the
original expression and the third column is the new expression:

  C     | C or C == None | C is not False
  True  | True           | True
  False | False          | False
  None  | True           | True
2009-05-20 00:43:23 +02:00
Benoit Boissinot
a59b10003e patch: use set instead of dict 2009-05-17 03:28:49 +02:00
Matt Mackall
06f4d7f9fa patch: copy copies dict before changing it (issue1651) 2009-05-14 13:20:40 -05:00