Commit Graph

455 Commits

Author SHA1 Message Date
Martin von Zweigbergk
f60106670d trydiff: replace dodiff=True/'binary' by binarydiff=False/True 2015-01-07 11:02:10 -08:00
Martin von Zweigbergk
4a8198a6db trydiff: replace 'dodiff = False' by 'continue'
The 'dodiff' variable is initialized to True and may later be set to
either False or "binary". When it's set to False, we skip everything
after that point, so we can simplify by instead continue-ing (the
loop). We can then also drop the 'if dodiff', since it will always be
true.
2015-01-07 10:59:40 -08:00
Martin von Zweigbergk
86561cd4f0 trydiff: make addindexmeta() unconditionally add index meta
The conditional-ness is not clear from the name and there is only one
caller, so it's clearer to check on the call site. Moving it also
makes addindexmeta() no longer close on the 'opts' variable.
2015-01-07 08:54:26 -08:00
Martin von Zweigbergk
590312deed trydiff: remove unused code for git index of "combined diff"
We only ever produce diffs with one pre- and one post-image, so remove
the code for displaying "index" lines for combined diffs.
2015-01-07 08:46:52 -08:00
Martin von Zweigbergk
a92bd0f094 diff: remove dead assignment 2015-01-06 22:55:01 -08:00
Martin von Zweigbergk
d21c241927 trydiff: use 'ctx1.flags()' for symmetry with 'ctx2.flags()' 2014-12-23 16:16:26 -08:00
Martin von Zweigbergk
0154ee1c3e trydiff: use 'not in addedset' for symmetry with 'not in removedset'
With the previous change in place, we can safely use 'addedset'.
2014-12-23 16:25:00 -08:00
Martin von Zweigbergk
a69f913d1d trydiff: simplify checking for additions
In the body of the loop in trydiff(), there are conditions like:

  addedset or (f in modifiedset and to is None)

The second half of that expression is to account for the fact that
merge-in additions appear as additions. By instead fixing up the sets
of modified and added files to compensate for this fact, we can
simplify the body of the loop. It also fixes one case where the
addedset was checked without the additional check (the "have we
already reported a copy above?" case in the code, also see fixed test
case).

The similar condition with 'removedset' in it seems to have served no
purpose even before this change, so it could have been simplified even
before.
2014-12-23 16:12:54 -08:00
Martin von Zweigbergk
12fa2d93ff trydiff: extract 'date2' variable like existing 'date1'
Note that there is a comment saying "ctx2 date may be dynamic". The
comment was introduced in 8ed3d2a60500 (patch: use contexts for diff,
2006-12-25), but it seems like it stopped being dynamic in that very
changeset -- before that changeset, the date seems to have been the
file's mtime, but after the changeset, it seems to be the changeset's
timestamp (current time for workingctx). Since no one seems to have
missed the "dynamicness", let's simplify and extract a date2 for
symmetry with date1.
2014-12-23 14:56:30 -08:00
Martin von Zweigbergk
c7f4a068b8 trydiff: use sets, not lists, for containment checks
This only has a noticeable effect on diffs touching A LOT of
files. For example, it takes

  hg diff -r FIREFOX_AURORA_30_BASE -r FIREFOX_AURORA_35_BASE

from 1m55.465s to 1m32.354s. That diff has over 50k files.
2014-12-23 10:41:45 -08:00
Siddharth Agarwal
113c428a6d patch.difffeatureopts: add a feature for format-changing diffopts
Typically, callers that are interested in this set are also interested in the
others. We still add it as a first-class flag for convenience.
2014-11-18 17:22:03 -08:00
Siddharth Agarwal
542813a378 patch.difffeatureopts: add a feature for whitespace diffopts
These aren't exactly format-breaking features -- just ones for which patches
applied to a repo will produce incorrect commits, In any case, some commands
like record and annotate only care about this feature.
2014-11-18 17:09:26 -08:00
Siddharth Agarwal
8c24c56a7e patch.difffeatureopts: add a feature for diff.git
This deserves to be its own feature -- indeed, this is often the only feature
several commands care about.
2014-11-18 17:10:14 -08:00
Siddharth Agarwal
3864c7a9bb patch: rename diffopts to diffallopts
This is meant to be used when all features are explicitly requested. diffopts
is kept as an alias for now -- it will go away soon.
2014-11-18 21:43:38 -08:00
Siddharth Agarwal
56b105c2c6 patch: add a new function to initialize diffopts by feature
Not all callers are interested in all diffopts -- for example, commands like
record (which use diff internally) break when diffopts like noprefix are
enabled. This function will allow us to add flags that callers can use to
enable only the features they're interested in.
2014-11-18 16:53:22 -08:00
Siddharth Agarwal
e42499560a patch.diffopts: use a dict for initialization
In upcoming patches we'll conditionally add to and remove from the dict.
2014-11-18 16:00:54 -08:00
Siddharth Agarwal
48ef0179c1 patch.trydiff: add support for noprefix 2014-11-12 23:50:21 -08:00
Siddharth Agarwal
37a8021dad patch.diffopts: add support for noprefix
In an upcoming patch we'll enable support as an option to 'hg diff' as well.

The tests reflect the current state of the world -- as we add support we'll see
changes in the test output.
2014-11-13 00:08:44 -08:00
Siddharth Agarwal
ccd6611ec9 patch.diffopts: allow a setting to be forced in plain mode
Upcoming patches will add an option that will almost certainly break diff
output parsers when enabled. Add support for forcing an option to something in
plain mode, as a fallback. Options passed in via the CLI are not affected,
though -- it is assumed that any script passing the option in explicitly knows
what it is doing.
2014-11-12 23:47:25 -08:00
Siddharth Agarwal
dabae3afed patch.diffopts: break get function into if statements
We're going to add another condition here, and with the current structure that
becomes just too confusing.
2014-11-12 23:44:17 -08:00
Jordi Gutiérrez Hermoso
60df7a50e9 patch: enable diff.tab markup for the color extension
The following patch splits up changed lines along tabs (using
re.findall), and gives them a "diff.tab" label. This can be used by
the color extension for colorising tabs, like it does right now with
trailing whitespace.

I also provide corresponding tests.
2014-08-20 15:15:50 -04:00
Mads Kiilerich
4dd236da3f convert: use None value for missing files instead of overloading IOError
The internal API used IOError to indicate that a file should be marked as
removed.

There is some correlation between IOError (especially with ENOENT) and files
that should be removed, but using IOErrors to represent file removal internally
required some hacks.

Instead, use the value None to indicate that the file not is present.

Before, spurious IO errors could cause commits that silently removed files.
They will now be reported like all other IO errors so the root cause can be
fixed.
2014-08-26 22:03:32 +02:00
Sean Farley
c813b41f60 patch: use ctx.node() instead of bare node variable
Future patches will allow patch.diff to take a basectx so node1 (and node2)
could make hexfunc error out. Instead, we'll call the node function on the
context object directly.
2013-08-14 13:10:27 -05:00
Stephen Lee
b831a97d01 diff: add nobinary config to suppress git-style binary diffs 2014-06-21 15:56:49 +10:00
Chinmay Joshi
b97e831462 patch: replace functions in fsbackend to use vfs
Several functions in fsbackend are replaced to use vfs functions.
vfs operations are applied on filename and path is joined by _join().
2014-06-05 15:24:29 +05:30
Pierre-Yves David
b7c330c46d import: add --partial flag to create a changeset despite failed hunks
The `hg import` command gains a `--partial` flag. When specified, a commit will
always be created from a patch import. Any hunk that fails to apply will
create .rej file, same as what `hg qimport` would do. This change is mainly
aimed at preserving changeset metadata when applying a patch, something very
important for reviewers.

In case of failure with `--partial`, `hg import` returns 1 and the following
message is displayed:

    patch applied partially
    (fix the .rej files and run `hg commit --amend`)

When multiple patches are imported, we stop at the first one with failed hunks.

In the future, someone may feel brave enough to tackle a --continue flag to
import.
2014-05-08 17:08:17 -07:00
Matt Mackall
34b49de789 diff: use second filename for --stat reporting on git patches (issue4221) 2014-04-11 16:38:55 -04:00
FUJIWARA Katsunori
0eed53de6c i18n: fix "% inside _()" problems
Before this patch, "contrib/check-code.py" can't detect these
problems, because the regexp pattern to detect "% inside _()" doesn't
suppose the case that format string consists of multiple string
components concatenated implicitly or explicitly,

This patch does below for that regexp pattern to detect "% inside _()"
problems in such case.

  - put "+" into separator part ("[ \t\n]") for explicit concatenation
    ("...." + "...." style)

  - enclose "component and separator" part by "(?:....)+" for
    concatenation itself ("...." "...." or "...." + "....")
2014-04-01 02:46:03 +09:00
Nicolas Vigier
a9bf6787d2 patch: add support for git delta hunks
When creating patches modifying binary files using "git format-patch",
git creates 'literal' and 'delta' hunks. Mercurial currently supports
'literal' hunks only, which makes it impossible to import patches with
'delta' hunks.

This changeset adds support for 'delta' hunks. It is a reimplementation
of patch-delta.c from git :
http://git.kernel.org/cgit/git/git.git/tree/patch-delta.c
2013-11-27 18:39:00 +01:00
Augie Fackler
fb91efd733 makememctx: move from patch to context to break import cycle 2013-11-06 22:09:15 -05:00
Johan Bjork
6055bcdec2 patch: ensure valid git diffs if source/destination file is missing (issue4046)
This is arguably a workaround, a better fix may be in the repo to
ensure that it won't list a file 'modified' unless there is a file
context for the previous version.
2013-10-13 08:38:30 -04:00
Augie Fackler
cdf1bbd9e1 merge with stable 2013-10-07 17:47:55 -04:00
Johan Bjork
bbce7855f8 patch: Fix nullid for binary git diffs (issue4054)
The index for an empty file in git is not 0, but sha-1("blobl 0\0").
2013-10-07 17:47:19 -04:00
Matt Mackall
aa456e3925 import: cut commit messages at --- unconditionally (issue2148)
We used to do this based on X-mailer: mentioning git, but git doesn't
put X-mailer in its git-format-patch output.
2013-07-27 19:31:14 -05:00
Augie Fackler
67877b90cc python2.4: fix imports of sub-packages of the email package
These all have an obvious comment so if/when we finally ditch Python
2.4 we can eradicate them easily.
2013-09-24 15:10:32 -04:00
Augie Fackler
897a535360 patch: correct import of email module 2013-09-20 10:15:51 -04:00
Siddharth Agarwal
4340781945 patch: use scmutil.marktouched instead of scmutil.addremove
addremove required paths relative to the cwd, which meant a lot of extra code
that transformed paths into relative ones. That code is now gone as well.
2013-04-04 13:45:21 -07:00
Sean Farley
0a28dbdae7 patch: match 'diff --git a/' instead of 'diff --git'
This reduces the likelihood of a traceback when trying to email a
patch that happens to have 'diff --git' at the beginning of a line
in the description, as this patch did:

http://markmail.org/message/wxpgowxd7ucxygwe
2013-03-22 17:27:06 -05:00
Johan Bjork
7b64b304ec diff: fix binary file removals in git mode.
With the previous version, a binary file removal diff generated with
2013-03-04 22:34:11 +00:00
Mads Kiilerich
275333d6c9 util: fold ENOENT check into unlinkpath, controlled by new ignoremissing flag
Refactor a common pattern.
2012-12-28 11:55:57 +01:00
Mads Kiilerich
ac8e1fc147 check-code: there must also be whitespace between ')' and operator
The check pattern only checked for whitespace between keyword and operator.

Now it also warns:
 >     x = f(),7
 missing whitespace after ,
 >     x = f()+7
 missing whitespace in expression
2012-12-09 23:33:16 +01:00
Bryan O'Sullivan
0dc2115da0 subrepo: use posixpath when diffing, for consistent paths
This fixes a Windows failure in test-subrepo-recursion.t introduced
by c9345d017402.
2012-11-27 14:58:00 -08:00
Guillermo Pérez
2c1f380e8a diff: move index header generation to patch
In an upcoming patch, we will add index information to all git diffs, not
only binary diffs, so this code needs to be moved to a more appropriate
place.

Also, since this information is used for patch headers, it makes more
sense to be in the patch module, along with other patch-related metadata.
2012-11-15 15:16:41 -08:00
Guillermo Pérez
f655c9c8c8 patch: make _addmodehdr a function under trydiff
addmodehdr is a header helper, same as diffline, so it doesn't
need to be a top-level function and can be nested under trydiff.

In upcoming patches we will generalize this approach for
all headers.
2012-11-15 15:06:32 -08:00
Guillermo Pérez
e12d2e6289 diff: rewrite diffline
Make diffline more readable, using strings with placeholders
rather than appending to a list from many ifs that makes
difficult to understand the actual output format.
2012-11-15 13:57:03 -08:00
Guillermo Pérez
4339c3bf86 diff: swap and simplify diffline args
Args order swapped, since a, b are more important than revs
(which is only used on non-git format), and change to read opts
from context.
2012-11-15 13:52:51 -08:00
Guillermo Pérez
565ed512ac diff: change how quiet mode supresses diffline
Before, quiet mode produced no diffline header for mercurial as a
side effect of not populating "revs". This was a weird side effect,
and we will always need revs for git index header that will be added
in upcoming patches, so now we just check ui.quiet from diffline
directly.
2012-11-15 13:49:04 -08:00
Guillermo Pérez
33e8ab6c12 diff: move diffline to patch module
diffline is not part of diff computation, so it makes more sense
to place it with other header generation in patch module.

In upcoming patches we will generalize this approach for
all headers added in the patch, including the git index
header.
2012-11-15 12:19:03 -08:00
Guillermo Pérez
9482817c96 diff: unify calls to diffline
diffline was called from trydiff for binary diffs and from unidiff
for text diffs. In this patch we unify those calls into one.

diffline is also a header, not part of diff mechanisms, so it makes
sense to remove that responsibility from the mdiff module. In
upcoming patches we will move diffline to patch module and
keep grouping responsibilities.
2012-11-15 12:16:08 -08:00
Guillermo Pérez
d54d996bfb diff: move b85diff to mdiff module
b85diff generates a binary diff, so we move this code to mdiff module
along with unidiff for text diffs. All diffing mechanisms will be in the
same place.

In an upcoming patch we will remove the responsibility to print the
index header from b85diff and move it back to patch, since it's
a patch metadata header, not part of the diff generation.
2012-11-06 14:04:05 -08:00