Commit Graph

547 Commits

Author SHA1 Message Date
timeless
f77cdcd3b1 pycompat: switch to util.stringio for py3 compat 2016-04-10 20:55:37 +00:00
Julien Cristau
1c82b3fc6d patch: when importing from email, RFC2047-decode From/Subject headers
Reported at https://bugs.debian.org/737498
2016-03-03 18:34:19 +01:00
Martin von Zweigbergk
216d0e41ef diff: don't crash when merged-in addition is copied
Similar to what was explained in the previous commit, the diff code
expected copy source to be in "ctx1", which is not always the case
during a merge. This has been broken since before hg 2.0.

Also similar to the previous commit, we fix the problem by fixing up
the copy dict.
2016-01-14 10:22:55 -08:00
Martin von Zweigbergk
0c3407d70e diff: don't crash when merged-in addition was removed (issue4786)
During a merge, if the user removes a file that came from parent 2 and
did not exist in parent 1, the file's status will be "removed". This
surprises the diff code, which crashes because it expects removed
files exist in parent 1. This has been broken since ff976121fb34
(trydiff: use 'not in addedset' for symmetry with 'not in removedset',
2014-12-23).

Fix by fixing up the list of removed file, similar to how we currently
fix up the list of modified and added files during a merge.
2016-01-14 10:14:24 -08:00
Martin von Zweigbergk
cf817770b1 diff: move status fixup earlier, out of _filepairs()
This prepares for future patches, and it also lets us remove the ugly
"ctx1" argument to _filepairs() (ugly because of its assymmetry --
there's no "ctx2" argument).
2016-01-14 10:02:34 -08:00
Bryan O'Sullivan
a33fafdc2a with: use context manager for I/O in changedfiles in patch 2016-01-15 13:14:50 -08:00
Gregory Szorc
090eb4dcbe patch: use absolute_import 2015-12-21 21:33:52 -08:00
timeless
b7d4dff7f3 record: fix hunk handling to remember the current function 2015-12-17 20:13:29 +00:00
Mateusz Kwapich
dcddc82bed patch: disable nobinary when HGPLAIN=1
The diff output without binaries is definitely great for interactive users - a
binary patch is not meaningful for them. Although setting diff.nobinary flag
can break the automation. Let's force full output for automation.
2015-12-17 11:00:06 -08:00
Laurent Charignon
1409af5e69 commit: add a way to return more information from the chunkselector
Before this patch, the chunkselector for record or crecord was used to return
the list of hunks that were selected by the user. The goal of this series is to
reintroduce the toggle amend feature for crecord. To do so, we need to be able
to return more than just the selected hunks from the chunkselector but also
the information: is amend mode toggled. This patch adds a new return value for
chunkselectors that will be used to implement the toggle amend feature in
crecord.
2015-11-30 16:35:21 -08:00
Mads Kiilerich
09567db49a spelling: trivial spell checking 2015-10-17 00:58:46 +02:00
Pierre-Yves David
30913031d4 error: get Abort from 'error' instead of 'util'
The home of 'Abort' is 'error' not 'util' however, a lot of code seems to be
confused about that and gives all the credit to 'util' instead of the
hardworking 'error'. In a spirit of equity, we break the cycle of injustice and
give back to 'error' the respect it deserves. And screw that 'util' poser.

For great justice.
2015-10-08 12:55:45 -07:00
Pierre-Yves David
240fce0b19 extract: parse 'nodeid' using the generic mechanism
Parsing 'nodeid' is very simple and a good first test.
2015-10-06 02:23:21 -07:00
Pierre-Yves David
6eaa931821 extract: parse 'branch' using the generic mechanism
Parsing 'branch' is very simple and a good first test.
2015-10-06 02:22:23 -07:00
Pierre-Yves David
2602f6923f extract: parse 'date' using the generic mechanism
Parsing 'date' is very simple and a good first test.
2015-10-07 01:13:36 -07:00
Pierre-Yves David
4ae623122e extract: add some facility for extensible header parsing
We need a way for extension to extend the header we can parse. We start with a
very simple mechanism that will be used in the next changeset.
2015-10-07 01:20:49 -07:00
Pierre-Yves David
b85c4695a2 extract: remove the 'user' variable
It is not heavily used enough to justify being something other than a
dictionary entry.
2015-10-06 02:16:24 -07:00
Pierre-Yves David
1f322a05ad extract: use a single return
The differences between both returns are now very thin, we factor out
that part.
2015-10-06 02:11:09 -07:00
Pierre-Yves David
159f2b3f21 extract: move 'nodeid' assignment where it is parsed
The is one setter and no consumer, we can move it there directly.
2015-10-07 00:50:53 -07:00
Pierre-Yves David
b6f2794f84 extract: move 'date' assignment where it is parsed
There is one setter and no consumer, we can move it there directly.
2015-10-06 02:08:32 -07:00
Pierre-Yves David
6386f9c739 extract: assign user to 'data' earlier
This is used in both case, we can assign it once.
2015-10-06 02:07:33 -07:00
Pierre-Yves David
cf6731af5a extract: move 'branch' assignment where it is parsed
There is one setter and no consumer, we can move it there directly.
2015-10-06 02:06:36 -07:00
Pierre-Yves David
43416c9684 extract: directly assign parent to data dictionary
The temporary variables are not adding anything.
2015-10-06 02:05:56 -07:00
Pierre-Yves David
3351bc88a4 extract: assign message only once
This return is shared between the two cases. We can move it earlier.
2015-10-06 02:04:46 -07:00
Pierre-Yves David
ab23538b10 extract: simplify parents assignement
We move to the more standard style of:

  value = default
  if special:
      value = other

This is more consistent and compact.
2015-10-06 02:04:06 -07:00
Pierre-Yves David
ec1d4cc8b3 patch: move 'extract' return to a dictionnary
The final goal here is to be able to parse, return and process arbitrary data
from patch. This mirror the recently added ability to add arbitrary data to
patch headers.

The first step is to return something more flexible, so we return a dict without
changing any other logic.
2015-10-06 02:01:53 -07:00
Matt Mackall
5e1b4ad958 urls: bulk-change primary website URLs 2015-09-30 15:43:49 -05:00
Gregory Szorc
5380dea2a7 global: mass rewrite to use modern exception syntax
Python 2.6 introduced the "except type as instance" syntax, replacing
the "except type, instance" syntax that came before. Python 3 dropped
support for the latter syntax. Since we no longer support Python 2.4 or
2.5, we have no need to continue supporting the "except type, instance".

This patch mass rewrites the exception syntax to be Python 2.6+ and
Python 3 compatible.

This patch was produced by running `2to3 -f except -w -n .`.
2015-06-23 22:20:08 -07:00
Gregory Szorc
3aa1c73868 global: mass rewrite to use modern octal syntax
Python 2.6 introduced a new octal syntax: "0oXXX", replacing "0XXX". The
old syntax is not recognized in Python 3 and will result in a parse
error.

Mass rewrite all instances of the old octal syntax to the new syntax.

This patch was generated by `2to3 -f numliterals -w -n .` and the diff
was selectively recorded to exclude changes to "<N>l" syntax conversion,
which will be handled separately.
2015-06-23 22:30:33 -07:00
Gregory Szorc
be5724ac71 patch: remove email import workaround for Python 2.4
Python 2.6 provides access to the sub-modules just fine. This workaround
is no longer needed since we no longer support Python 2.4.
2015-06-22 10:09:08 -07:00
Matt Mackall
7c6674833f patch: add fuzz config flag (issue4697) 2015-06-18 15:42:40 -05:00
Laurent Charignon
1ca77932d5 record: exiting editor with non-zero status should not stop recording session
Before this patch, exiting a hunk edit in record with a non-zero status lead
to the end of the recording session, losing previously-selected hunks to record.
This patch introduces the more desirable behavior of warning the user and
continuing the recording session.
2015-06-05 13:31:18 -07:00
Laurent Charignon
f9d447f8e4 revert: add an experimental config to use inverted selection
We had a discussion on the list about the interactive ui for revert. This patch
adds a flag to allow people to test the second alternative (referred to as
proposition 2 on the mailing list). It effectively inverts the signs in the
2015-05-29 13:11:52 -07:00
Laurent Charignon
9b866fafac record: add default value for operation argument
This patch is part of a series of patches to change the recording ui to reflect
the operation currently running (commit, shelve, revert ...).
This patch adds the default value of the operation argument for record's
standard and curses interface to match what is displayed in the interface
as of today.
2015-05-27 15:56:10 -07:00
Laurent Charignon
92c99cc1a7 record: add an operation arguments to customize recording ui
This patch is part of a series of patches to change the recording ui to reflect
the operation currently running (commit, shelve, revert ...).
This patch adds a new argument to the recording function to reflect in the UI
what operation we are running.
2015-05-27 15:49:24 -07:00
Augie Fackler
a5b17bd9d1 cleanup: use __builtins__.any instead of util.any
any() is available in all Python versions we support now.
2015-05-16 14:30:07 -04:00
Pierre-Yves David
27d9d4e153 patch: remove duplicated import of cStringIO
It is already imported a couple of line above.
2015-05-17 17:27:10 -07:00
Martin von Zweigbergk
4127f67694 util: drop alias for collections.deque
Now that util.deque is just an alias for collections.deque, let's just
remove it.
2015-05-16 11:28:04 -07:00
Laurent Charignon
6fc9e8be66 record: edit patch of newly added files (issue4304)
I tried to fix this issue in the past and had to revert the fix. This is a
second attempt without the regression we found with the first one.

record defines special headers (of file) as headers whose hunk are not shown
to the user for editing, they are used to represent deleted, moved and new
files. Since we want to authorize editing the patch of newly added file we
make the newly added file with some content not special anymore. This entails
that we have to save their content before applying the backup to be able to
revert it if the patch does not apply properly.
We reintroduce the test showing that newly added files can be edited and that
their content is shown to the user.
2015-04-23 14:27:26 -07:00
Laurent Charignon
4fc3c4c465 record: fix record with change on moved file crashes (issue4619)
reverting fe807064739c, add a test to prevent the issue from coming back.
2015-04-22 13:56:30 -07:00
Durham Goode
cd579fe2e0 diff: pass the diff matcher to the copy logic
This passes the existing diff matcher instance down to the copy logic so copy
tracing can be more efficient when possible and only trace copies for matching
files.

This only actually affects forwardcopies (i.e. Given A<-B<-C<-D, it works for
'hg diff -r B -r D foo.txt', but not for 'hg diff -r D -r B foo.txt') since
backward copies require walking all histories, and not just the individual
file's.

This reduces 'hg diff -r A -r B foo.txt' time from 15s to 1s when A and B have
80,000 files different.
2015-04-16 11:31:48 -07:00
Siddharth Agarwal
53fe8ecbd4 patch.diff: restrict matcher to relative root in certain cases
Previously we'd request all results, then filter by relative root. This is
clearly inefficient, so we now restrict the matcher to the relative root for
certain easy cases.

The particular case here is when the matcher matches all files. In that case we
can simply create a matcher by the relative root.

This is purely an optimization and has no impact on correctness.
2015-03-17 15:46:36 -07:00
Siddharth Agarwal
633aa5fbea patch.diff: add support for diffs relative to a subdirectory
For now this implementation is pretty naive -- it filters out files right
before passing them into trydiff. In upcoming patches we'll add some more
smarts.
2015-03-17 13:41:24 -07:00
Siddharth Agarwal
1ba05f7f8a patch.trydiff: add support for stripping a relative root
This assumes that if relroot is not None, all the files in modified, added and
removed start with it. In upcoming patches we'll follow that.
2015-03-17 12:59:41 -07:00
Siddharth Agarwal
4a073b9113 patch._applydiff: resolve prefix with respect to the cwd
This has several advantages compared to resolving it relative to the root:

- '--prefix .' works as expected.
- consistent with upcoming 'hg diff' option to produce relative patches

(I made sure to put in the (glob) annotations this time!)
2015-03-19 10:18:05 -07:00
Siddharth Agarwal
400fb488cd patch.pathtransform: prepend prefix even if strip is 0
Silly oversight by me.
2015-03-18 20:59:06 -07:00
Siddharth Agarwal
598b5c20d8 patch.trydiff: add a docstring
It took me a bit to figure out what this function actually does.
2015-03-17 13:06:15 -07:00
Laurent Charignon
2716ef87d7 record: add comparison methods for recordhunk class 2015-03-13 14:08:30 -07:00
Laurent Charignon
62f1f68490 record: change interface of the filtering function
This way filtering functions accept chunks and return chunks
2015-03-12 17:51:37 -07:00
Jordi Gutiérrez Hermoso
8eb132f5ea style: kill ersatz if-else ternary operators
Although Python supports `X = Y if COND else Z`, this was only
introduced in Python 2.5. Since we have to support Python 2.4, it was
a very common thing to write instead `X = COND and Y or Z`, which is a
bit obscure at a glance. It requires some intricate knowledge of
Python to understand how to parse these one-liners.

We change instead all of these one-liners to 4-liners. This was
executed with the following perlism:

    find -name "*.py" -exec perl -pi -e 's,(\s*)([\.\w]+) = \(?(\S+)\s+and\s+(\S*)\)?\s+or\s+(\S*)$,$1if $3:\n$1    $2 = $4\n$1else:\n$1    $2 = $5,' {} \;

I tweaked the following cases from the automatic Perl output:

    prev = (parents and parents[0]) or nullid
    port = (use_ssl and 443 or 80)
    cwd = (pats and repo.getcwd()) or ''
    rename = fctx and webutil.renamelink(fctx) or []
    ctx = fctx and fctx or ctx
    self.base = (mapfile and os.path.dirname(mapfile)) or ''

I also added some newlines wherever they seemd appropriate for readability

There are probably a few ersatz ternary operators still in the code
somewhere, lurking away from the power of a simple regex.
2015-03-13 17:00:06 -04:00