Commit Graph

313 Commits

Author SHA1 Message Date
Nicolas Dumazet
7f1a963829 pylint, pyflakes: remove unused or duplicate imports 2010-04-14 17:58:10 +09:00
Brendan Cully
76b7a3a26b Merge with stable 2010-04-11 20:59:55 -07:00
Peter Arrenbrecht
7abe6f6609 patch: don't look for headers in diff lines
If you have a diff line that matches a header line, the patch splitter
currently breaks your patch at this line. For example a line like:

  +key: value

This can lead to "malformed patch" exceptions. Now fixed.
2010-04-09 20:34:05 +02:00
Brodie Rao
e504a56477 diff: make use of output labeling 2010-04-02 15:22:06 -05:00
Benoit Boissinot
6173388ed6 patch: warn when the internal patcher fails
hopefully we'll soon fix the remaining failures from the internal patcher, and
not use the external one anymore.
2010-03-22 11:08:42 +01:00
Matt Mackall
092c3572fb Merge with stable 2010-03-20 16:57:24 -05:00
Matt Mackall
453a04eaaf Merge with stable 2010-03-20 10:01:56 -05:00
Benoit Boissinot
879a4a71db patch: more precise NoHunk, raised for every file (issue2102) 2010-03-20 14:47:05 +01:00
Benoit Boissinot
6ed4471107 patch: differentiate start of file with diff --git vs '--- ' 2010-03-20 21:16:22 +01:00
Benoit Boissinot
f5bfcde5cb patch: try harder to find the file to patch on file creation (issue2041)
accept the following patch header:
first line:  foo/a.orig
second line: foo/a
2010-03-19 22:52:38 +01:00
Matt Mackall
ef87d8630d Merge with stable 2010-03-19 16:05:16 -05:00
Benoit Boissinot
223c085b2b patch: second line of a context diff starts with '--- ', not '+++ ' 2010-03-19 12:45:39 +01:00
Benoit Boissinot
0ad95ca3aa patch: enhance diff detection regexp, allow '--- ' in patch message 2010-03-18 18:22:34 +01:00
Brendan Cully
791f92f6bd Merge with stable 2010-03-18 14:36:24 -07:00
Benoit Boissinot
5af4a60795 patch/diff: move diff related code next to each other 2010-03-09 19:04:18 +01:00
Benoit Boissinot
04d99f9fbc patch/diff: move patch.export() to cmdutil.export()
This API change will allow us to break a cycle between patch and cmdutil.
2010-03-08 19:43:24 +01:00
Patrick Mezard
dede247fea patch: fix patching with fuzz and eol normalization 2010-02-22 22:55:58 +01:00
Wagner Bruna
9b81c3ec4d patch, i18n: avoid parameterized messages
Singular message removed for simplicity.
2010-02-19 13:04:11 -02:00
Brendan Cully
de7c8ccdfb import: if in doubt, consume stream until start of diff
This prevents a header-like line in the message body from causing a spurious split.
2010-02-18 10:46:01 -08:00
Patrick Mezard
908955c63c patch: remove useless copy, cleanup 2010-02-14 17:53:23 +01:00
Wagner Bruna
ce83d27cac patch: separate reverse copy data (issue1959) 2010-02-11 11:22:57 -02:00
Brendan Cully
ce047e9ab3 import: import each patch in a file or stream as a separate change
Supports hg export <revrange>, mail messages, and mailboxes.
Does not support multiple patches in a single MIME attachment.
Closes issue167.
2010-02-07 18:06:52 +01:00
Matt Mackall
8d99be19f0 many, many trivial check-code fixups 2010-01-25 00:05:27 -06:00
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
Martin Geisler
750183bdad updated license to be explicit about GPL version 2 2009-04-26 01:08:54 +02:00
Matt Mackall
2f9b02c62d replace util.sort with sorted built-in
This is marginally faster for small and moderately-sized lists
2009-04-26 16:50:44 -05:00
Wagner Bruna
1f15ab3b5a patch, i18n: avoid parameterized plural 2009-04-20 21:16:14 -03:00
Dirkjan Ochtman
049b5daa9b merge with crew-stable 2009-04-04 19:43:00 +02:00
Vsevolod Solovyov
201e56ffbb Fix issue1495, corner case of adding empty files via patching 2009-03-24 23:28:55 +00:00
Matt Mackall
02f3d06343 diffstat: use width 80 by default and avoid division by zero 2009-03-20 14:38:50 -05:00
Peter Arrenbrecht
bc21361ed2 cleanup: drop unused imports 2009-03-23 13:12:07 +01:00
Matt Mackall
2e1730294c patch: teach selectfile about symlinks (issue1438) 2009-02-16 17:37:23 -06:00
Dirkjan Ochtman
a61aacf5f2 patch: no need to instantiate a match catch-all in diff() 2009-02-12 12:35:48 +01:00
Dirkjan Ochtman
5de1ecaba0 merge with mpm 2009-02-07 23:29:12 +01:00
Martin Geisler
fdc5030e00 patch: turned strings with backslashes into raw strings
In Python, the backslash in an unrecognized escape sequence is left
behind, which makes '\.' the same as r'\.'. Relying on this feature is
quite brittle, IMHO.

Removed unnecessary string concatenation as well.
2009-02-04 20:53:38 +01:00
Dirkjan Ochtman
0f821bb2e9 kill some trailing whitespace 2009-01-19 12:59:56 +01:00
Patrick Mezard
7ab8b3fde9 diffstat: don't fail on merges
First version by Alexander Solovyov <piranha@piranha.org.ua>
2009-01-13 20:28:06 +02:00
Benoit Boissinot
11526cacc9 patch: export shouldn't close files received as a parameter
We rely on __del__ to close the fd instead. Patchbomb was relying
on this behaviour, fix it.
Thanks to Manuel Barkhau for reporting it.
2009-01-09 01:36:35 +01:00
Dirkjan Ochtman
25cd3135ab merge with crew-stable 2009-01-03 21:24:31 +01:00
Dirkjan Ochtman
5d131cc7a2 patch: kill some trailing whitespace 2009-01-03 20:33:37 +01:00
Martin Geisler
336bd98e22 use repo.wjoin(f) instead of os.path.join(repo.root, f) 2009-01-02 22:53:33 +01:00
Mads Kiilerich
d775f5aa2a Make util.find_exe alway returns existing file, fixing issue1459
It seems like the old behaviour with different handling for commands with and
without path was intended, but I think this behaviour of util.find_exe is
better:
* Always returns existing file
* or None if command not found - no default
* Windows: Returned file thus always ends with extension from PATHEXT

This fixes http://www.selenic.com/mercurial/bts/issue1459. The change might
fix other unintended behaviour too.
2009-01-25 21:20:13 +01:00
Alexander Solovyov
c1774bb6c3 python implementation of diffstat
Implemented as two functions: diffstat, which yields lines of text,
formatted as a usual diffstat output, and diffstatdata, which is called
inside diffstat to do real performing and yield file names with
appropriate data (numbers of added and removed lines).
2008-12-25 10:48:24 +02:00
Brendan Cully
81d39df2bc Merge with crew-stable 2008-12-14 23:05:18 -08:00
Brendan Cully
6e6159b63f patch: handle git patches that remove symlinks (issue1438) 2008-12-14 23:04:29 -08:00
Bartosz SKOWRON
5c9eae5dcc patch: simplify linereader 2008-12-05 14:51:50 +01:00
Patrick Mezard
1ac6f464a8 patch: catch only IOError from makedirs() 2008-12-11 22:59:35 +01:00
Stefan Rusek
601a15ee5f When applying a git diff, ensure that the target dir exists for new files 2008-12-09 14:27:47 +01:00
Brendan Cully
aad17924e9 import: add similarity option (issue295) 2008-11-22 00:21:57 -08:00
Patrick Mezard
b4165c254b patch: isolate patchfile filesystem calls into methods
This is a first step toward an svn-like patch driver and makes patchfile
monkeypatching much easier. The latter is currently required to support
in-memory patching until the code is refactored.
2008-11-19 13:27:57 +01:00
Patrick Mezard
b023997f48 patch: pass an opener to patchfile 2008-11-19 13:27:57 +01:00