Commit Graph

18744 Commits

Author SHA1 Message Date
Yuya Nishihara
afe324b8ba revset: filter first/last members by __and__ operation
This replaces 'if y in subset' with '& subset'. first(null) and last(wdir())
are fixed thanks to fullreposet.__and__.

This also revealed that first() and last() don't follow the order of the
input set. 'ls & subset' is valid only if the ordering requirement is 'define'
or 'any'.

No performance regression observed:

  revset #0: limit(0:9999, 100, 9000)
  0) 0.001164
  1) 0.001135
  revset #2: 9000 & limit(0:9999, 100, 9000)
  0) 0.001224
  1) 0.001181
  revset #3: last(0:9999, 100)
  0) 0.000237
  1) 0.000199
2017-06-10 19:41:42 +09:00
Yuya Nishihara
1912966e67 revset: reject negative number to select first/last n members
Negative 'lim' doesn't make sense here, and it makes things complicated
when using list[:lim].
2017-06-10 18:35:11 +09:00
Yuya Nishihara
352ebafde5 revset: fix order of last() n members where n > 1 (BC)
last() is implemented using a reversed iterator, so the result should be
reversed again.

I've marked this as BC since it's quite old bug seen in 3.0. The first bad
revision is 1ef0875a62f8 "revset: changed last implementation to use lazy
classes."
2017-06-10 18:04:56 +09:00
Yuya Nishihara
2fce781b0d debugrevspec: add option to suppress list of computed revisions
Test will be added later.
2017-06-10 20:14:23 +09:00
Yuya Nishihara
3299c032dd debugrevspec: add option to print representation of smartset object
It's possible by -v, but -v also prints a parsed tree. Test will be added
later.
2017-06-10 20:03:35 +09:00
Pierre-Yves David
aa94a21603 bookmarks: make sure we close the bookmark file after reading
We previously lacked an explicit close of the bookmark file.
2017-06-10 01:59:22 +01:00
Pierre-Yves David
ea7c976173 bookmarks: rephrase a comment to be shorted and clearer
The initial motivation is that I need an initial level of indent in the next
changeset o:-) It turn out I like the new version better.
2017-06-10 01:55:01 +01:00
Pierre-Yves David
2f46ffacac checkheads: use a "lazyancestors" object for allfuturecommon
Instead of walking all ancestors to compute the full set we now check membership
lazily. This massively speed.

On a million-ish revision repository, this remove 14 seconds from the push logic,
making the checkheads function disappear from profile.
2017-06-05 13:44:15 +01:00
Pierre-Yves David
8eeebc599c checkheads: use "revnum" in the "allfuturecommon" set
The obsolete post-processing needs to know the extend of the pushed set. The
way it is implemented is... suboptimal. It build a full set of all nodes in the
pushset and it does so using changectx. We have much better API for this now.
The simplest is to use the existing lazy ancestors computation. That logic uses
revnum and not node (for good reason) so we start with updating the
post-processing code to handle a "allfuturecommon" set containing revision
numbers.
2017-06-05 13:37:04 +01:00
Pierre-Yves David
12f527e6f1 checkheads: use 'nodemap.get' to convert nodes to revs
We are about to call 'torev' on node that might be locally missing. In this
case, 'nodemap.revs' will return None (something valid in our usecase) while
'changelog.rev' would raise an exception.

We make this change in a distinct changeset to show it does not impact the
tests.
2017-06-05 15:20:20 +01:00
Pierre-Yves David
a0b8c4a72d checkheads: pass "ispushed" function to the obsmarkers logic
We are about to make "allfuturecommon" a set of revs instead of a set of nodes.
The function updated in this patch do not needs to know about these details so
we just pass it a 'ispushed(node)' function. This will simplify the next
changeset.
2017-06-05 15:17:47 +01:00
Pierre-Yves David
2fdfd87513 profile: drop maybeprofile
It seems sufficiently simple to use "profile(enabled=X)" to not justify having
a dedicated context manager just to read the config.

(I do not have a too strong opinion about this).
2017-06-09 12:29:29 +01:00
Pierre-Yves David
81c8d3b7b6 profile: support --profile in alias and abbreviated version (--prof)
We now process the "--profile" a second time after alias has been processed and
the command argument fully parsed. If appropriate we enable profiling at that
time.

In these situation, the --profile will cover less than if the full --profile
flag was passed on the command line. This is better than the previous behavior
(flag ignored) and still fullfil multiple valid usecases.
2017-06-09 12:36:07 +01:00
Pierre-Yves David
4dacb46437 profile: make the contextmanager object available to the callers
This will allow calling methods on the object in the code using the context
manager.
2017-06-09 11:42:45 +01:00
Pierre-Yves David
39ee1a16c0 profile: introduce a knob to control if the context is actually profiling
This is a step toward allowing context where the profiling in enabled
withing the context range.

This also open the way to kill the dedicated "maybeprofile" context manager
and keep only one of 'profile' and 'maybeprofile'.
2017-06-09 11:41:47 +01:00
Pierre-Yves David
669f0c9a69 profile: introduce a "start" method to the profile context
The start method is doing all profiler setup and activation. It is currently
unconditionally called by '__init__' but this will be made more flexible in
later changesets.
2017-06-09 11:39:53 +01:00
Pierre-Yves David
1999d809be profile: upgrade the "profile" context manager to a full class
So far we have been able to use a simple decorator for this. However using the
current context manager makes the scope of the profiling in dispatch
constrainted and the time frame to decide to enable profiling quite limited
(using "maybeprofile")

This is the first step toward the ability to enable the profiling from within
the profiling scope. eg::

  with maybeprofiling(ui) as profiler:
      ...
      bar.foo():
      ...
      if options['profile']:
          profiler.start()
      ...
      fooz()
      ...

My target usecase is adding support for  "--profile" to alias definitions with
effect.  These are to be used with "profiling.output=blackbox" to gather data
about operation that get slow from time to time (eg: pull being minutes instead
of seconds from time to time).

Of course, in such case, the scope of the profiling would be smaller since
profiler would be started after running extensions 'reposetup' (and other
potentially costly logic), but these are not relevant for my target usecase
(multiple second commits, multiple tens of seconds pull).

Currently adding '--profile' to a command through alias requires to re-spin a
Mercurial binary (using "!$HG" in alias), which as a significant performance
impact, especially in context where startup performance is being worked on...

An alternative approach would be to stop using the context manager in dispatch
and move back to a try/finally setup.
2017-06-08 01:38:48 +01:00
Sean Farley
e7d53c6c2e memctx: always use cache for filectxfn
I don't see a downside to doing this unless I'm missing something.
Thanks to foozy for correcting my previous bad logic.
2017-06-10 16:00:18 -07:00
Jun Wu
db8bfa3842 obsstore: do not load all markers to detect duplication
This will make duplication detection something like O(newmarkers) instead of
O(obsstore).
2017-06-02 20:49:42 -07:00
Siddharth Agarwal
e0e3b8e4ce filestat: move __init__ to frompath constructor
We're going to add a `fromfp` constructor soon, and this also allows a filestat
object for a non-existent file to be created.
2017-06-10 14:09:54 -07:00
Pierre-Yves David
c82b13f1cf setdiscovery: improves logged message
The 'srvheads' list contains all server heads including the common ones. We
adjust 'ui.log' message to provide more useful information about server heads
locally unknown. The performance impact of turning the list to set is
negligible (about 1e-4s) compared to the rest of the discovery cost, so I'm
taking the easy path.
2017-06-10 18:47:09 +01:00
Brandon McCaig
0309412bc4 bisect: improve option validation message 2017-06-09 20:12:39 -04:00
Sean Farley
1221c3301c context: inline makememctx (API)
I have always thought it weird that we have a helper method instead of
just using __init__. So, I ripped it out.
2017-06-10 10:24:33 -04:00
Sean Farley
e67eb8ee09 context: add convenience method for returning a memfilectx from a patch
This is mostly a copy of what makememctx does but refactored to make it
behave more like our other convenience methods.
2017-06-09 13:39:13 -07:00
Sean Farley
90b054fc18 memctx: refactor inline getfilectx into convenience method
No actual logic is changing, just moving code so __init__ is easier to
read.
2017-06-09 13:25:02 -07:00
Gregory Szorc
fa21f12af8 hgweb: refresh styling of gitweb's search form
gitweb was missing the hint hover box. So that was added.

Also, the positioning of the form was absolute and it didn't
vertically align on all pages. The element has been moved inline
with the navigation links (which now are contained in a div) and
flexbox is used to obtain sane alignment of the navigation links
and search form. For those new to flexbox,
"justify-content: space-between" basically says to maximize space
elements. You can use it to easily get left and right justified
containers without having to worry about width, floating, etc.
"align-items: center" centers all items in a cross-axis. I've
literally wasted hours trying to figure out both these problems
before flexbox. Flexbox is amazing.

Flexbox has been supported by Chrome and Firefox for a few years.
But it is only supported by IE 11. I'm willing to wager that
people using this either won't be using IE or will be using IE 11.
So I'm willing to be a bit aggressive in adopting flexbox because
it makes CSS alignment so much easier.
2017-06-09 13:55:51 -07:00
Gregory Szorc
1e2e56cc41 hgweb: consistently add search form to all gitweb pages
Paper has it on all pages. Not sure why gitweb doesn't. I think it
should be everywhere because it is a useful feature.

Also, we weren't consistently adding the HTML in the same place. This
was OK since the element is absolutely positioned. But this bothered
me a bit, so I went ahead and fixed it.
2017-06-09 13:45:36 -07:00
Gregory Szorc
4d72365e92 hgweb: consolidate search form for gitweb 2017-06-09 13:42:38 -07:00
Gregory Szorc
734d5b7555 hgweb: consolidate search form for monoblue
Same deal as for paper.
2017-06-09 13:41:10 -07:00
Gregory Szorc
3816d83a29 hgweb: consolidate search form for paper
AFAICT this was mostly a bunch of copy pasta. The only variation is
some pages defined a "value" attribute. The "query" variable will
just be empty on pages that don't accept it. So let's consolidate
the template and remove the redundancy.
2017-06-09 13:59:13 -07:00
Pulkit Goyal
8f8ec8b0ec py3: use pycompat.bytestr() instead of str() 2017-06-08 00:51:46 +05:30
Pulkit Goyal
228f493dac py3: convert bool variables to bytes 2017-06-02 16:57:21 +05:30
FUJIWARA Katsunori
457ca6840f context: avoid writing outdated dirstate out (issue5584)
Before this patch, workingctx.status() may cause writing outdated
dirstate out, if:

  - .hg/dirstate is changed simultaneously after last loading it,
  - there is any file, which should be dirstate.normal()-ed

Typical issue case is:

  - the working directory is updated by "hg update"
  - .hg/dirstate is updated in background (e.g. fsmonitor)

This patch compares identities of dirstate before and after
acquisition of wlock, and avoids writing outdated dirstate out, if
change of .hg/dirstate is detected.
2017-06-09 13:07:49 +09:00
FUJIWARA Katsunori
a3a205cf6c dirstate: add identity information to detect simultaneous changing in storage
This identity is used to examine whether dirstate is simultaneously
changed in storage after previous caching (see issue5584 for detail).

util.cachestat can't be used for this purpose, because it has no
valuable information on Windows.

On the other hand, util.filestat can detect changing dirstate in
storage certainly, regardless of platforms.

    https://www.mercurial-scm.org/wiki/ExactCacheValidationPlan

Strictly speaking, if underlying filesystem doesn't support
ctime/mtime, util.filestat can't detect simultaneous changing in
storage as expected. But simultaneous changing on such (very rare)
platform can't be detected regardless of this patch series.

Therefore, util.filestat should be reasonable identity for almost all
usecases.
2017-06-09 13:07:48 +09:00
FUJIWARA Katsunori
f010ae3777 util: make filestat.__eq__ return True if both of self and old have None stat
For convenience to compare two filestat objects regardless of
None-ness of stat field.
2017-06-09 13:07:48 +09:00
FUJIWARA Katsunori
534d75d626 vfs: create copy at renaming to avoid file stat ambiguity if needed
In order to fix issue5418, 0d920bcb0fd1 made vfs.rename(checkambig=True)
omit advancing mtime of renamed file, if renamed file is owned by
another (EPERM is raised in this case).

But this omission causes rewinding mtime at restoration in such
situation, and makes avoiding file stat ambiguity difficult, because
ExactCacheValidationPlan assumes that mtime should be advanced, if a
file is changed in same ctime.

    https://www.mercurial-scm.org/wiki/ExactCacheValidationPlan

Ambiguity of file stat also requires issue5584 to be fixed with other
than file stat, but "hash of file", "generation ID" and so on were
already rejected ideas (please see original RFC linked from "Outline
of issue" in ExactCacheValidationPlan page).

This omission occurs:

  - only for non append-only files (dirstate, bookmarks, and phaseroots), and
  - only if previous transaction is rollbacked by another user

The latter means "sharing a repository clone via group permission".
This is reasonable usecase, but not ordinary for many users, IMHO.
"hg rollback" itself has been deprecated since Mercurial 2.7, too.

Therefore, increasing the cost at rollbacking previous transaction
executed by another a little seems reasonable, for avoidance of file
stat ambiguity.

This patch does:

  - create copy of (already renamed) source file, if advancing mtime
    fails for EPERM
  - rename from copied file to destination file, and
  - advance mtime of renamed file, which is now owned by current user

This patch also factors "self.join(src)" out to reduce redundancy.
2017-06-09 12:58:18 +09:00
FUJIWARA Katsunori
f7f00ec91e vfs: factor out "rename and avoid ambiguity" to reuse
This makes subsequent patch simple.
2017-06-09 12:58:18 +09:00
FUJIWARA Katsunori
49b9b7a367 util: make filestat.avoidambig() return whether ambiguity is avoided or not 2017-06-09 12:58:17 +09:00
Gregory Szorc
c8a15a9f84 debugcommands: issue warning when repo has secret changesets (issue5589)
This seems like a prudent thing to do. As the inline comment says,
we may want to make this abort once the functionality is stabilized
as part of `hg bundle`. Let's save that debate for another day.
2017-06-09 10:42:19 -07:00
Gregory Szorc
bc8582fc01 streamclone: consider secret changesets (BC) (issue5589)
Previously, a repo containing secret changesets would be served via
stream clone, transferring those secret changesets. While secret
changesets aren't meant to imply strong security (if you really
want to keep them secret, others shouldn't have read access to the
repo), we should at least make an effort to protect secret changesets
when possible.

After this commit, we no longer serve stream clones for repos
containing secret changesets by default. This is backwards
incompatible behavior. In case anyone is relying on the behavior,
we provide a config option to opt into the old behavior.

Note that this defense is only beneficial for remote repos
accessed via the wire protocol: if a client has access to the
files backing a repo, they can get to the raw data and see secret
revisions.
2017-06-09 10:41:13 -07:00
Yuya Nishihara
91bdea4c9e json: pass formatting options recursively
This bug was introduced in 469914605447. It's okay to escape <>, but is
unnecessary for command output.
2017-06-09 21:33:15 +09:00
Yuya Nishihara
6eaf988ce2 json: avoid extra string manipulation of dict keys
A key must be string per JSON spec, and that's also true for template dicts.
2017-04-23 13:40:18 +09:00
Yuya Nishihara
03fcc62be8 templatefilers: correct filename in header comment 2017-06-09 21:28:22 +09:00
Gregory Szorc
1e94780ad6 repoview: remove special casing of "requirements"
At the time this code was introduced (7d207cb7e38a), the inline comment
was true. This changed in 2f304c7e2233. The proxy is no longer needed.
2017-06-08 20:28:13 -07:00
Pierre-Yves David
8cfc531081 bookmarks: move variable initialization earlier
Since we no longer set '_clean = False' during the initialization loop, we can
move the attribute assignment earlier in the function for clarity.

(no speed improvement expected or measured ;-) )
2017-06-07 19:32:16 +01:00
Pierre-Yves David
64f252f86d bookmarks: directly use base dict 'setitem'
The bmstore '__setitem__' method is setting an extra flag that is not needed
during initialization. Skipping the method will allow further cleanup and yield
some speedup as a side effect.

Before:
! wall 0.009120 comb 0.010000 user 0.010000 sys 0.000000 (best of 312)

After:
! wall 0.007874 comb 0.010000 user 0.010000 sys 0.000000 (best of 360)
2017-06-07 19:13:09 +01:00
Pierre-Yves David
64590e83af bookmarks: rely on exception for malformed lines
Since we already have an exception context open, for other thing, we can
simplify the code a bit and rely on exception handling for invalid lines.

Speed is not the main motivation for this changes. However as I'm in the middle
of benchmarking things we can see a small positive impact.

Before:
! wall 0.009358 comb 0.000000 user 0.000000 sys 0.000000 (best of 303)

After:
! wall 0.009173 comb 0.010000 user 0.010000 sys 0.000000 (best of 310)
2017-06-07 19:22:39 +01:00
Pierre-Yves David
c876bd5bd3 bookmarks: explicitly convert to 'node' during initialization
We know the content of the file is supposed to be full hex. So we can do the
translation ourselves and directly check if the node is known.

As nice side effect we now have proper error handling for invalid node value.

Before:
! wall 0.021580 comb 0.020000 user 0.020000 sys 0.000000 (best of 134)

After:
! wall 0.009342 comb 0.010000 user 0.010000 sys 0.000000 (best of 302)
2017-06-07 22:26:43 +01:00
Pierre-Yves David
56320b18e8 bookmarks: prefetch 'lookup' outside of the loop
Skipping the attribute lookup up raise a significant speedup.

Example on a repository with about 4000 bookmarks.

Before:
! wall 0.026027 comb 0.020000 user 0.020000 sys 0.000000 (best of 112)
After:
! wall 0.021580 comb 0.020000 user 0.020000 sys 0.000000 (best of 134)

(This is also in its own changeset to clarify the perf win from another coming
changesets)
2017-06-07 19:21:02 +01:00
Gregory Szorc
2c7b5a6b43 localrepo: move filtername to __init__
This is obviously an instance attribute, not a type attribute. The
modern Python style is to use __init__ for defining these.

This exposes statichttprepo as inheriting from localrepository
without calling its __init__. As a result, its __init__ defines
a lot of variables that methods on localrepository's methods need.
But factoring the common bits into a separate class is for another
day.
2017-06-08 23:23:37 -07:00