Commit Graph

484 Commits

Author SHA1 Message Date
Yuya Nishihara
4563e16232 parsers: switch to policy importer
# no-check-commit
2016-08-13 12:23:56 +09:00
Augie Fackler
8197ec1496 dirstate: mark {begin,end}parentchange as deprecated (API) 2017-05-18 17:13:32 -04:00
Augie Fackler
dae08b1747 dirstate: introduce new context manager for marking dirstate parent changes 2017-05-18 17:10:30 -04:00
Yuya Nishihara
cbe21a1cc9 osutil: proxy through util (and platform) modules (API)
See the previous commit for why. Marked as API change since osutil.listdir()
seems widely used in third-party extensions.

The win32mbcs extension is updated to wrap both util. and windows. aliases.
2017-04-26 22:26:28 +09:00
Martin von Zweigbergk
da238dd9f0 dirstate: optimize walk() by using match.visitdir()
We already have the logic for restricting directory walks in
match.visitdir() that we use for treemanifests. We should take
advantage of it when walking the working copy as well.

This speeds up "hg st -I rootfilesin:." on the Firefox repo from
0.587s to 0.305s on warm disk (and much more on cold disk). More time
is spent reading the dirstate than walking the working copy after.

I tried to find scenarios where calling match.visitdir() would be a
noticeable overhead, but I couldn't find any. I encourage the reader
to try for themselves, since this is performance-critical code.
2017-05-05 08:49:46 -07:00
Ryan McElroy
b1c2e24234 dirstate: use tryunlink 2017-03-21 06:50:28 -07:00
Augie Fackler
4ee50ed840 dirstate: use future-proof next(iter) instead of iter.next
The latter has been removed in Python 3.
2017-03-19 01:08:17 -04:00
Pulkit Goyal
f9b7821158 dirstate: use list comprehension to get a list of keys
We have used dict.keys() which returns a dict_keys() object instead
of list on Python 3. So this patch replaces that with list comprehension
which works both on Python 2 and 3.
2017-03-16 09:00:27 +05:30
Durham Goode
832a191f75 dirstate: track otherparent files same as nonnormal
Calling dirstate.setparents() is expensive in a large repo because it iterates
over every file in the dirstate. It does so to undo any merge state or
otherparent state files. Merge state files are already covered by
dirstate._nonnormalset, so we just need to track otherparent files in a similar
manner to avoid the full iteration here.

Fixing this shaves 20-25% off histedit in large repos.

I tested this by adding temporary debug logic to verify that the old files
processed in the loop matched the new files processed in the loop and running
the test suite.
2017-03-08 17:35:20 -08:00
Jun Wu
3c38af4dff dirstate: avoid unnecessary load+dump during backup
Previously, dirstate.savebackup unconditionally dumps the dirstate map to
disk. It may require loading dirstate first to be able to dump it. Those
operations could be expensive if the dirstate is big, and could be avoided
if we know the dirstate file is up-to-date.

This patch avoids the read and write if the dirstate is clean. In that case,
we just do a plain copy without any serialization.

This should make commands which use transactions but do not touch dirstate
faster. For example, "hg bookmark -r REV NAME".
2017-03-01 18:21:06 -08:00
Jun Wu
0bbf2239d3 dirstate: try to use hardlink to backup dirstate
This should be more efficient once util.copyfile has real hardlink support.
2017-03-01 17:59:21 -08:00
Durham Goode
c93b79c0e6 dirstate: track updated files to improve write time
Previously, dirstate.write() would iterate over the entire dirstate to find any
entries that needed to be marked 'lookup' (i.e. if they have the same timestamp
as now). This was O(working copy) and slow in large repos. It was most visible
when rebasing or histediting multiple commits, since it gets executed once per
commit, even if the entire rebase/histedit is wrapped in a transaction.

The fix is to track which files have been editted, and only check those to see
if they need to be marked as 'lookup'. This saves 25% on histedit times in very
large repositories.

I tested this by adding temporary debug logic to verify that the old files
processed in the loop matched the new files processed in the loop and running
the test suite.
2017-03-05 16:20:07 -08:00
FUJIWARA Katsunori
c63bad51f6 txnutil: factor out the logic to read file in according to HG_PENDING
This patch adds new file txnutil.py, because:

  - transaction.py is too large to import small utility logic
  - scmutil.py or so causes cyclic importing in phases.py

mayhavepending() is defined separately for convenience in subsequent
patch.
2017-02-21 01:20:59 +09:00
Pulkit Goyal
f1c1938039 py3: replace os.environ with encoding.environ (part 1 of 5)
os.environ is a dictionary which has string elements on Python 3. We have
encoding.environ which take care of all these things. This is the first patch
of 5 patch series which tend to replace the occurences of os.environ with
encoding.environ as using os.environ will result in unusual behaviour.
2016-12-18 01:34:41 +05:30
Pulkit Goyal
a7d1fd0177 py3: replace os.sep with pycompat.ossep (part 2 of 4)
This part also replaces some chunks of os.sep with pycompat.ossep.
2016-12-17 20:02:50 +05:30
Pulkit Goyal
97f340e354 py3: use pycompat.getcwd() instead of os.getcwd()
We have pycompat.getcwd() which returns bytes path on Python 3. This patch
changes most of the occurences of the os.getcwd() with pycompat one.
2016-11-23 00:03:11 +05:30
Pulkit Goyal
af51d6f213 py3: use pycompat.ossep at certain places
Certain instances of os.sep has been converted to pycompat.ossep where it was
sure to use bytes only. There are more such instances which needs some more
attention and will get surely.
2016-11-06 04:10:33 +05:30
Mads Kiilerich
a2ea53b6ed dirstate: fix debug.dirstate.delaywrite to use the new "now" after sleeping
It seems like the a regression has sneaked into debug.dirstate.delaywrite in
14bddc099338. It would sleep until no files were modified "now" any more, but
when writing the dirstate it would use the old "now" and still mark files as
'unset' instead of recording the timestamp that would make the file show up as
clean instead of unknown.

Instead of getting a new "now" from the file system, we trust the computed end
time as the new "now" and thus cause the actual modification time to be
writiten to the dirstate.

debug.dirstate.delaywrite is undocumented and only used in
test-largefiles-update.t . All tests seems to work fine for me without
debug.dirstate.delaywrite . Perhaps because it not really worked as intended
without the fix in this patch, and code and tests thus have evolved to do fine
without it? It could thus perhaps make sense to drop usage of this setting in
the tests. That could speed the test up a bit.

This functionality (or something very similar) can however apparently be very
convenient in setups where checking dirty-ness is expensive - such as when
using large files and have slow file filesystems or are CPU constrained. Now it
works and we can try it. (But ideally, for the largefile use case, it should
probably only delay lfdirstate writes - not ordinary dirstate.)
2016-10-18 16:52:35 +02:00
Mateusz Kwapich
016e1e5ef8 dirstate: rebuild should update dirstate properly
Updating dirstate by simply adding and dropping files from self._map doesn't
keep the other maps updated (think: _dirs, _copymap, _foldmap, _nonormalset)
thus introducing cache inconsistency.

This is also affecting the debugstate tests since now we don't even try to set
correct mode and mtime for the files because they are marked dirty anyway and
will be checked during next status call.
2016-08-30 15:16:28 -07:00
Martin von Zweigbergk
2fbf01764c util: rename checkcase() to fscasesensitive() (API)
I always read the name "checkcase(path)" as "do we need to check for
case folding at this path", but it's actually (I think) meant to be
read "check if the file system cares about case at this path". I'm
clearly not the only one confused by this as the dirstate has this
property:

  def _checkcase(self):
      return not util.checkcase(self._join('.hg'))

Maybe we should even inverse the function and call it fscasefolding()
since that's what all callers care about?
2016-08-30 09:22:53 -07:00
Mateusz Kwapich
de44e608e1 dirstate: add callback to notify extensions about wd parent change
The journal extension had to touch the dirstate internals to be notified about
wd parent change. To make that detection cleaner and reusable let's move it core.
Now the extension can register to be notified about parent changes.
2016-08-11 08:00:41 -07:00
Pierre-Yves David
9652a8ad03 deprecation: enforce thew 'tr' argument of 'dirstate.write' (API)
Compatibility was meant to be drop after 3.9 is released.
2016-08-02 16:51:27 +02:00
FUJIWARA Katsunori
19907e427c dirstate: make restoring from backup avoid ambiguity of file stat
File .hg/dirstate is restored by renaming from backup in failure
inside scopes below. If renaming keeps ctime, mtime and size of a
file, restoring is overlooked, and old contents cached before
restoring isn't invalidated as expected.

  - dirstateguard scope (from '.hg/dirstate.SUFFIX')
  - transaction scope (from '.hg/journal.dirstate')

To avoid ambiguity of file stat at restoring, this patch invokes
vfs.rename() with checkambig=True.

This patch is a part of "Exact Cache Validation Plan":

    https://www.mercurial-scm.org/wiki/ExactCacheValidationPlan
2016-06-13 05:11:56 +09:00
FUJIWARA Katsunori
f90241706d dirstate: make writing branch file out avoid ambiguity of file stat
Cached attribute dirstate._branch uses stat of '.hg/branch' file to
examine validity of cached contents. If writing '.hg/branch' file out
keeps ctime, mtime and size of it, change is overlooked, and old
contents cached before change isn't invalidated as expected.

To avoid ambiguity of file stat, this patch writes '.hg/branch' file
out with checkambig=True.

This patch is a part of "Exact Cache Validation Plan":

    https://www.mercurial-scm.org/wiki/ExactCacheValidationPlan
2016-06-03 00:44:20 +09:00
FUJIWARA Katsunori
00e016ed43 dirstate: make writing dirstate file out avoid ambiguity of file stat
Cached attribute repo.dirstate uses stat of '.hg/dirstate' file to
examine validity of cached contents. If writing '.hg/dirstate' file
out keeps ctime, mtime and size of it, change is overlooked, and old
contents cached before change isn't invalidated as expected.

To avoid ambiguity of file stat, this patch writes '.hg/dirstate' file
out with checkambig=True.

The former diff hunk changes the code path for "dirstate.write()", and
the latter changes the code path for "dirstate.savebackup()".

This patch is a part of "Exact Cache Validation Plan":

    https://www.mercurial-scm.org/wiki/ExactCacheValidationPlan
2016-06-03 00:44:20 +09:00
Mateusz Kwapich
6a0946ae30 distate: add assertions to backup functions
Those assertions will prevent the backup functions from overwriting
the dirstate file in case both: suffix and prefix are empty.

(foozy suggested making that change and I agree with him)
2016-05-26 17:36:44 -07:00
Mateusz Kwapich
3f38941482 dirstate: don't use actualfilename to name the backup file
The issue with using actualfilename is that dirstate saved during transaction
with "pending" in filename will be impossible to recover from outside of the
transaction because the recover method will be looking for the name without
"pending".
2016-05-25 16:36:16 -07:00
Mateusz Kwapich
c2a06fee01 dirstate: remove file from copymap on drop
As the copymap is short-lived object regenerated from dirstate on each
read this didn't affect us in any serious way. But since I've started working
on permanent storage of copymap in my experiments with sqldirstate[1] I've seen
this bug leaving the copy information in copymap after reverting the file
moves and copies.

[1] https://www.mercurial-scm.org/wiki/SQLDirstatePlan
2016-05-25 16:09:07 -07:00
Mateusz Kwapich
2ac744860e dirstate: add prefix and suffix arguments to backup
This would allow the code explicitly copying dirstate to use this method instead.
Use of this method will increase encapsulation (the dirstate class will be sole
owner of its on-disk storage).
2016-05-13 13:28:09 -07:00
Pierre-Yves David
47ac7dc0f8 cleanup: replace False identity testing with an explicit token object
The recommended way to check default value (when None is not as option) is a
token object. Identity testing to integer is less explicit and not guaranteed to
work in all implementations.
2016-05-05 19:32:51 +02:00
Pierre-Yves David
917636e516 devel: officially deprecate dirstate.write without transaction argument
When we introduce the develwarning, we did not had an official deprecation API
and infrastructure. We can now officially deprecate the old way with a version
deadline.
2016-05-11 09:31:47 +02:00
Mateusz Kwapich
fc3f152c3e dirstate: make backup methods public
They are called from outside of dirstate anyway and I want the localrepo to
use them too.
2016-05-05 17:06:54 -07:00
Pierre-Yves David
6a42d00a81 devel: use the new 'config' argument for the dirstate develwarn 2016-05-08 10:43:41 +02:00
Laurent Charignon
59af678158 dirstate: add a way to get the ignore file/line matching an ignored file
This information will be used to improve debugignore (issue4856).
2016-01-05 07:52:04 -08:00
Laurent Charignon
64fb638545 dirstate: extract logic to compute the list of ignorefiles
We are going to reuse this logic to improve debugignore in the next patches
of the series.
2015-12-23 11:52:54 -08:00
Laurent Charignon
0657cb64cb dirstate: call the C implementation of nonnonormalentries when available
Before this patch, we were using python code for computing the nonnormal
dirstate entries. This patch makes us use the C implementation of the function
when it is available.

Using the nonnormal set in hgwatchman improves hg status performance. Below
are the numbers for mozilla-central.

with the changes:
$ hg perfstatus
    ! wall 0.010632 comb 0.000000 user 0.000000 sys 0.000000 (best of 246)

without the changes:
$ hg perfstatus
    ! wall 0.036442 comb 0.030000 user 0.030000 sys 0.000000 (best of 100)

On mozilla-central the improvement to hg status is ~20% (0.25s to 0.2s),
on our big repos at Facebook, the win is ~40% (1.2s to 0.72s).
2015-12-23 13:16:03 -08:00
Laurent Charignon
f7e5157f49 dirstate: add code to update the non-normal set
Before this patch, we were only populating the non-normal set when parsing
or packing the dirstate. This was not enough to keep the non-normal set up to
date at all time as we don't write and read the dirstate whenever a change
happens. This patch solves this issue by updating the non-normal set when it
should be updated. note: pack_dirstate changes the dmap and we have it keep
it unchanged for retrocompatibility so we are forced to recompute the
non-normal set after calling it.
2016-01-01 23:40:54 +01:00
Laurent Charignon
c8798d976e dirstate: attach the nonnormalset to a propertycache
This patch attaches the nonnormalset to a property cache so that we build it
only when needed.
2015-12-23 13:13:22 -08:00
Laurent Charignon
cca2d0e30d dirstate: add a function to compute non-normal entries from the dmap
This patch adds a new python function in the dirstate to compute the set of
non-normal files from the dmap. These files are useful to compute the repository
status.
2015-12-21 16:22:43 -08:00
Gregory Szorc
061e8691b5 dirstate: use absolute_import 2015-12-21 21:38:53 -08:00
Matt Mackall
48434b4246 dirstate: make delaywrite sleep until the next multiple of n seconds
Rather than sleep for 2 seconds, we sleep until the next even-numbered
second, which has the same effect, but makes tests faster. This
removes test-largefiles-update as the long pole of the test suite.
2015-12-16 20:58:26 -06:00
Matt Mackall
476828ae86 dirstate: only invoke delaywrite if relevant
This avoids a significant amount of sleeping in some of our longest
tests.
2015-12-16 20:49:18 -06:00
Matt Mackall
105f68a336 dirstate: move delaywrite logic from write to _write
This will allow us to be smarter in upcoming patches.
2015-12-16 20:46:53 -06:00
Christian Delahousse
2a005d816a dirstate: change debugrebuilddirstate --minimal to use dirstate.rebuild
When debugrebuilddirstate --minimal is called, rebuilding the dirstate was done
outside of the appropriate rebuild function. This patch makes
debugrebuilddirstate use dirstate.rebuild.

This was done to allow our extension to become aware debugrebuilddirstate
--minimal
2015-11-30 11:23:15 -08:00
Matt Mackall
ab46ec3b99 util: drop statmtimesec
We've globablly forced stat to return integer times which agrees with
our extension code, so this is no longer needed.

This speeds up status on mozilla-central substantially:

$ hg perfstatus
! wall 0.190179 comb 0.180000 user 0.120000 sys 0.060000 (best of 53)
$ hg perfstatus
! wall 0.275729 comb 0.270000 user 0.210000 sys 0.060000 (best of 36)
2015-11-19 13:15:17 -06:00
Bryan O'Sullivan
9d37a5f6b4 dirstate: back out dd36f84bd784
Superseded by the parent of this commit.
2015-11-17 13:47:16 -08:00
Mateusz Kwapich
266a6f869e dirstate: fix filefoldmap incosistency on file delete
The _filefoldmap is not updated in when files are deleted from dirstate. In the
case where the file with the same but differently cased name is added afterwards
it renders _filefoldmap incorrect.  Those steps must occur to for a problem to
reproduce:
 - call status (with listunknown=True),
 - update working rectory to a commit which does a casefolding change (A -> a)
 - call status again (it will show the file "a" as deleted)

Unfortunately I'm unable to write a test for it because I don't know any
core-mercurial command able to reproduce those steps.

The bug was originally spotted when hgwatchman was enabled. It caused the
changeset contents change during hg rebase (one file unrelarted to changeset
was deleted in it after rebase).

The hgwatchman is able to hit it because when hgignore changes the hgwatchmans
overridestatus is calling original status with listunknown=True.
2015-11-09 10:43:23 -08:00
James Mills
9a53147d94 dirstate: fix invalid reference to self.ui 2015-10-19 12:07:17 -07:00
Mads Kiilerich
09567db49a spelling: trivial spell checking 2015-10-17 00:58:46 +02:00
FUJIWARA Katsunori
54ce7de850 dirstate: show develwarn for write() invocation without transaction
This is used to detect 'dirstate.write()' invocation without the value
gotten by 'repo.currenttransaction()' (mainly focused on 3rd party
extensions).
2015-10-17 01:15:34 +09:00