Commit Graph

807 Commits

Author SHA1 Message Date
Yuya Nishihara
664cff6605 cmdutil: do not duplicate stdout by makefileobj()
It made output order unpredictable because two separate buffers are flushed
individually. Let's use a thin wrapper that just sends close() to black hole.
2015-12-13 20:07:19 +09:00
Yuya Nishihara
db7707d747 cmdutil: reimplement file wrapper that disables close()
There's no need to dynamically create wrappedfileobj class and define
close() as lambda. Also, __iter__() was missing.
2015-12-13 20:01:11 +09:00
Yuya Nishihara
3a0b98410a export: remove useless comparison between file object and string
It was introduced at fa80944106df, where "template" argument could be a file
object. After that, 426525670e45 added "len(template)", so "template" must be
a string now. Therefore, "fp != template" should always be True.

It seems fa80944106df was intended to work around a bug in TortoiseHg, and
I'm sure I've fixed it completely in TortoiseHg source.

https://selenic.com/pipermail/mercurial-devel/2011-February/028467.html
2015-12-13 19:57:54 +09:00
Yuya Nishihara
00a04ad77b export: do not print '<fdopen>' as an output filename
Because makefileobj() duplicates or wraps stdout, "fp != sys.stdout" didn't
work correctly. Python doc states that special file objects are named in the
form '<...>', and absolute filenames should never start with '<', we can
ignore names start with '<'. We can't test fp.fileno() because fp may be a
command-server channel.

https://docs.python.org/2.7/library/stdtypes.html#file.name

In the test output, "exporting patch:" line is printed after patch content.
This is caused by fdopen() and will be fixed by the subsequent patch.
2015-12-13 19:47:46 +09:00
timeless
1054dbcfef record: turn on showfunc
Always try to give diff context when doing an interactive record
2015-12-17 14:38:22 +00:00
Matt Mackall
e9718e4615 merge with stable 2015-12-16 17:40:01 -06:00
Siddharth Agarwal
7191433ea2 record: don't dereference symlinks while copying over stat data
Previously, we could be calling os.utime or os.chflags (via shutil.copystat) on
a symlink. These functions dereference symlinks, so this would have caused the
timestamp of the target to be set. On a read-only or similarly weird
filesystem, this might cause an exception to be raised.

This is pretty hard to test because conjuring up a read-only filesystem for
test purposes is non-trivial.
2015-12-12 10:58:05 -08:00
Mads Kiilerich
09567db49a spelling: trivial spell checking 2015-10-17 00:58:46 +02:00
FUJIWARA Katsunori
36207b46bf cmdutil: make in-memory changes visible to external editor (issue4378)
Before this patch, external editor process for the commit log can't
view some in-memory changes (especially, of dirstate), because they
aren't written out until the end of transaction (or wlock).

This causes unexpected output of Mercurial commands spawned from that
editor process.

To make in-memory changes visible to external editor process, this
patch does:

  - write (or schedule to write) in-memory dirstate changes, and
  - set HG_PENDING environment variable, if:
    - a transaction is running, and
    - there are in-memory changes to be visible

"hg diff" spawned from external editor process for "hg qrefresh"
shows:

  - "changes newly imported into the topmost" before ab68b153ce34(*)
  - "all changes recorded in the topmost by refreshing" after this patch

(*) ab68b153ce34 changed steps invoking editor process

Even though backward compatibility may be broken, the latter behavior
looks reasonable, because "hg diff" spawned from the editor process
consistently shows "what changes new revision records" regardless of
invocation context.

In fact, issue4378 itself should be resolved by b46029eb5b29, which
made 'repo.transaction()' write in-memory dirstate changes out
explicitly before starting transaction. It also made "hg qrefresh"
imply 'dirstate.write()' before external editor invocation in call
chain below.

  - mq.queue.refresh
    - strip.strip
      - repair.strip
        - localrepository.transaction
          - dirstate.write
    - localrepository.commit
      - invoke external editor

Though, this patch has '(issue4378)' in own summary line to indicate
that issues like issue4378 should be fixed by this.

BTW, this patch adds '-m' option to a 'hg ci --amend' execution in
'test-commit-amend.t', to avoid invoking external editor process.

In this case, "unsure" states may be changed to "clean" according to
timestamp or so on. These changes should be written into pending file,
if external editor invocation is required,

Then, writing dirstate changes out breaks stability of test, because
it shows "transaction abort!/rollback completed" occasionally.

Aborting after editor process invocation while commands below may
cause similar instability of tests, too (AFAIK, there is no more such
one, at this revision)

  - commit --amend
    - without --message/--logfile

  - import
    - without --message/--logfile,
    - without --no-commit,
    - without --bypass,
    - one of below, and
      - patch has no description text, or
      - with --edit
    - aborting at the 1st patch, which adds or removes file(s)
      - if it only changes existing files, status is checked only for
        changed files by 'scmutil.matchfiles()', and transition from
        "unsure" to "normal" in dirstate doesn't occur (= dirstate
        isn't changed, and written out)
      - aborting at the 2nd or later patch implies other pending
        changes (e.g. changelog), and always causes showing
        "transaction abort!/rollback completed"
2015-10-17 01:15:34 +09:00
FUJIWARA Katsunori
811ef7c75f dirstateguard: remove layering violation around saving/restoring backup
This violation, which passes 'repo' object to dirstate, was introduced
by afd0ae63d624 and c26227275f1e.
2015-10-17 01:15:33 +09:00
Tony Tung
4c1f5709e1 commit: abort when a committemplate is not changed
If a committemplate is provided and no message is provided on the
command line, and no edits are made to the commit template, then abort
the commit.
2015-10-09 21:44:54 -07:00
Augie Fackler
0a19647501 merge: have merge.update use a matcher instead of partial fn
This is relatively rarely used functionality, but migrating this to a
matcher will make future work on narrow clones more feasible.
2015-12-14 18:54:03 -05:00
Yuya Nishihara
10b6f5819b graphlog: make node symbol templatable by ui.graphnodetemplate option
New ui.graphnodetemplate option allows us to colorize a node symbol by phase
or branch,

  [ui]
  graphnodetemplate = {label('graphnode.{phase}', graphnode)}
  [color]
  graphnode.draft = yellow bold

or use a variety of unicode emoji characters, and so on. (You'll need less-481
to display non-BMP unicode character.)

  [ui]
  graphnodetemplate = {ifeq(obsolete, 'stable', graphnode, '\xf0\x9f\x92\xa9')}
2015-11-14 17:25:43 +09:00
Yuya Nishihara
f981890d2b graphlog: extract "graphnode" template keyword that represents node symbol
This provides a default node symbol. Tests will be added later.

"showparents" variable is renamed to "wpnodes" to avoid confusion with the
existing showparents() function.
2015-11-14 16:58:18 +09:00
Yuya Nishihara
78ebbc20b2 graphlog: move creation of workingdir-parent nodes to displaygraph()
Future patches will make a node symbol templatable. Because arguments of a
templatekw function are repo and ctx, "showparents" list will have to be
built from a repo object by that function.
2015-11-14 16:45:15 +09: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
Mike Edgar
8e7be9d666 commit: preserve extra when amending with commit --amend
The new extra propagation needs to be accounted for in cmdutil.amend,
when checking for a no-changes fast-path.
2015-11-28 04:11:57 -05:00
Gregory Szorc
b184853d7f ui: remove labeled argument from popbuffer
It was moved to pushbuffer and currently does nothing.
2015-11-24 11:23:10 -08:00
Gregory Szorc
9a0cab7d0b cmdutil: pass labeled=True to pushbuffer()
This doesn't yet change behavior because labeling is still performed
at popbuffer time.

Surprisingly, this is the only in-tree consumer that passes
labeled=True.
2015-11-22 14:13:25 -08:00
Gregory Szorc
dbea71eee2 cmdutil.changeset_printer: pass context into showpatch()
Before, we passed the node then subsequently performed a lookup on
repo.changelog. We already has the context available, so just pass it
in.

This does result in a small performance win. But I doubt it will show
up anywhere because diff[stat] calculation will dwarf the time spent
to create a changectx. Still, we should be creating fewer changectx
out of principle.
2015-11-14 17:44:01 -08:00
Gregory Szorc
5e2a52d9ca exchange: move bundle specification parsing from cmdutil
Clone bundles require a well-defined string to specify the type of
bundle that is listed so clients can filter compatible file types. The
`hg bundle` command and cmdutil.parsebundletype() already establish the
beginnings of a bundle specification format.

As part of formalizing this format specification so it can be used by
clone bundles, we move the specification parsing bits verbatim to
exchange.py, which is a more suitable place than cmdutil.py. A
subsequent patch will refactor this code to make it more appropriate as
a general API.
2015-10-13 11:43:21 -07:00
FUJIWARA Katsunori
af664f3cc0 dirstate: move code paths for backup from dirstateguard to dirstate
This can centralize the logic to write in-memory changes out correctly
according to transaction activity into dirstate.

Passing 'repo' object to newly added functions is needed to examine
current transaction activity in subsequent patches, because 'dirstate'
itself doesn't have direct reference to it.
2015-10-14 02:49:17 +09: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
FUJIWARA Katsunori
05986aa7a1 cmdutil: stop tryimportone from using dirstateguard (BC)
There is no user of 'cmdutil.tryimportone()' other than
'commands.import_()', which can restore dirstate at failure of
applying patches by transaction or dirstateguard.

Therefore, it is reasonable to stop 'tryimportone()' from using
redundant 'dirstateguard', even though it changes behavior of
'tryimportone()'.

After this patch, 3rd party extensions should use 'dirstateguard' or
so explicitly, if they want to restore dirstate at failure of
importing a patch.
2015-10-09 03:53:46 +09:00
FUJIWARA Katsunori
f2187903e7 dirstate: remove meaningless dirstateguard
Previous patch made dirstate changes in a transaction scope "all or
nothing". Therefore, 'dirstateguard' is meaningless, if its scope is
as same as one of the related transaction.

This patch removes such meaningless 'dirstateguard' usage.
2015-10-09 03:53:46 +09:00
Pierre-Yves David
e5e36f8235 import: allow processing of extra part header after import
As we have a way for extension to add more header, we need a way for them to
actually process them. We add a basic hook point to do extra work after the
import have been committed.
2015-10-07 13:05:25 -07:00
Pierre-Yves David
684d4c614d import: allow processing of extra part header during import
As we have a way for extension to add more header, we need a way for them to
actually process them. We add a basic hook points to alter the changeset
(especially extra) before we commit. There would be more to do for a full
featured hooking, but this currently fit my needs.
2015-10-06 09:51:24 -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
Pierre-Yves David
d6432f70b8 export: introduce a generic way to add patch header on export
Extensions currently have no easy way to add data to exported
patch. This is now fixed using a generic mechanism in the same fashion
used by bundle2. Tests are coming in the next changeset with its first
user.
2015-10-05 23:17:01 -07:00
Pierre-Yves David
232a6cb371 bundle: use bundle2 if repository uses general delta
As bundle1 does not support generaldelta, this would mean recomputing delta at
bundle time. This is similar to what we do for strip and shelve and was tracked
as issue4865.
2015-10-01 20:31:43 -07:00
Pierre-Yves David
f1e9601240 parsebundletype: add a comment for future generation 2015-10-01 20:21:16 -07:00
Pierre-Yves David
8f390ad0b6 bundle: extend the format of --type to support version and compression
We had some basic undocumented support for uncompressed bundle2 support. We now
have an official extensible syntax to specify both format type and compression
(eg: bzip2-v2).

In practice, this changeset introduce the 'v1' and 'v2' identifier to make it
possible to combine format and compression. The default format is still 'v1'.
We'll care about picking 'v1' or 'v2' in regard with general delta in the next
changesets.
2015-10-01 19:16:00 -07:00
Pierre-Yves David
63b3b90838 bundle: extract the parsing of the bundle type in a function
We are going to introduce significant extensions of the bundle parsing code to
support creation of bundle2 through the bundle command. As an early step, we
extract the logic in its own function.
2015-10-01 18:01:24 -07:00
Yuya Nishihara
dc974fcbf0 templatekw: port implementation of showparents() from changeset_templater
It isn't cool, but we can peek at ui flag via repo.ui. So, it is possible
to implement showparents() in templatekw, and therefore we can eliminate the
dockeywords hack.
2015-09-26 12:38:02 +09:00
Yuya Nishihara
c09856f19f changeset_printer: move _meaningful_parentrevs() to scmutil
It will be used by templatekw.
2015-09-26 12:29:09 +09:00
timeless@mozdev.org
51da91c959 cmdutil: handle multiline translations of HG: messages safely
Before this, if a localizer/localization included a multiline
message, and didn't prefix the intermediate lines with 'HG: ',
then the line would be a candidate for inclusion in the commit
message -- which isn't ideal.
2015-09-30 12:36:30 -04:00
timeless@mozdev.org
2993615080 cmdutil: remove HG: prefix from translation strings 2015-09-25 03:44:15 -04:00
Pierre-Yves David
124b8948d8 addremove: remove a mutable default argument
Mutable default arguments are know to the state of California to cause bugs.
2015-09-24 01:58:33 -07:00
Matt Harbison
99ffdaafef extdiff: enable -I/-X with --patch
Not sure how useful this really is, but it's trivial to add and ignoring the
existing arguments supported seems like a bad UI.
2015-09-09 22:27:48 -04:00
Matt Mackall
5b498724ca templater: add new docheader/footer components for XML (issue4135)
The existing header/footer components were templated per-changeset,
and thus couldn't be correctly printed for an empty log
2015-08-26 16:27:14 -05:00
Durham Goode
94ca2e4c06 add: pass full=False to dirstate walk
Previously cmdutil.add would call wctx.walk(), which under the hood calls
dirstate.walk with full=True. This means it returns all of the clean files
(which we don't need when computing the add set), as well as the unclean files.
This results in 1) a lot more work being done and 2) this code path
circumventing the hgwatchman extension, resulting in worse performance in
hgwatchman environments ('hg add .' went from 9s to 1.8s).
2015-09-09 09:07:27 -07:00
timeless@mozdev.org
52eae47139 spelling: behaviour -> behavior 2015-08-28 10:53:55 -04:00
Matt Mackall
ca5b5bbb7b templater: move verbosity-to-template matcher to constructor
We're going to reuse this and it's silly for it to be done per-cset anyway.
2015-08-25 13:38:20 -05:00
Matt Mackall
240305489f templater: remove pseudo-ternary 2015-08-25 12:59:08 -05:00
Matt Mackall
9d8dac9846 templater: fix variable name that shadows built-in 2015-08-25 12:57:21 -05:00
Matt Mackall
c43a857672 templater: minor whitespace tweaks 2015-08-25 09:38:06 -05:00
Christian Delahousse
f5b2078fe3 revert: allow configuring the .orig file location 2015-11-12 17:00:08 -06:00
Christian Delahousse
71afd0e97f cmdutil: add origbackuppath helper 2015-11-12 16:56:06 -06:00
Gregory Szorc
a935029795 cmdutil: break import cycle
This was the easiest place to break the chain, as there were only
2 uses of the imported module in the file.
2015-08-08 00:47:19 -07:00
FUJIWARA Katsunori
10e6e169f7 cmdutil: allow callers of cmdutil.dorecord to omit suggestion
Interactive committing under non-interactive mode shows command
suggestion, but sometimes it is meaningless.

  command      suggestion usability
  ------------ ---------- -----------
  record       commit
  commit -i    commit     meaningless
  qrecord      qnew
  qnew -i      qnew       meaningless
  qrefersh -i  qrefresh   meaningless
  shelve -i    commit     incorrect
  ------------ ---------- -----------

This patch allows callers of 'cmdutil.dorecord()' to omit meaningless
suggestion by passing None or so for 'cmdsuggest' argument of it.

This is a preparation for subsequent patches, which fix each
suggestion issues above.
2015-07-15 03:43:16 +09:00