Commit Graph

48 Commits

Author SHA1 Message Date
Martijn Pieters
a9f4167218 sparse: add filtering on field contents
Summary: This lets you select on substrings in fields and paths.

Reviewed By: quark-zju

Differential Revision: D7788826

fbshipit-source-id: f92b8cc646fd36f4cb3b8a4dc6116576db80eb42
2018-04-30 14:16:44 -07:00
Martijn Pieters
796523487a sparse: add a hint about using --verbose on hg sparse list
Summary: Calculation on how many profiles were hidden is only done when the hint is actually shown.

Reviewed By: quark-zju

Differential Revision: D7774192

fbshipit-source-id: a7196b2cc5640d0a7cb9c4d572e1a31ebfa41598
2018-04-30 14:16:44 -07:00
Martijn Pieters
2c10ce3145 sparse: add filtering options for fields present or missing
Summary:
This lets us produce a list of profiles with the title set, or find all profiles that are missing a description.

Convert the 'hidden' filter to use this feature, rather than special-case it in `_discover()`.

Reviewed By: quark-zju

Differential Revision: D7774029

fbshipit-source-id: 3bcba75e6da97bf0e560e11ce1ae7cbcee49ee45
2018-04-30 14:16:44 -07:00
Jun Wu
e21cf00d2e sparse: move some documentation to extension-level
Summary:
check-seclevel.py complains about using section markers inside a container.
The help text about sparse file format and config options can be put at
extension-level.

Reviewed By: mjpieters

Differential Revision: D7776355

fbshipit-source-id: 0b7d813c5eee352a054b21897682f6064f384829
2018-04-27 23:40:00 -07:00
Martijn Pieters
ed857415c5 sparse: allow listing of profiles at a different revision
Summary: This is needed to be able to list profiles via SCMQuery, where there is a working copy at the null revision.

Reviewed By: quark-zju

Differential Revision: D7745434

fbshipit-source-id: b5ac236c36f9bafc9e0f305bc0892e0cd8bec628
2018-04-25 08:50:27 -07:00
Martijn Pieters
51dae5969e sparse: ignore non-existing profiles when listing
Summary: If there is a non-existing sparse profile active in .hg/sparse, skip it rather than bail out.

Reviewed By: quark-zju

Differential Revision: D7744957

fbshipit-source-id: 4e6a046c95f5fe6cf49a7093d3443340f70e8e2a
2018-04-24 10:21:22 -07:00
Adam Simpkins
05edd145db ensure that fbsparse never wraps Eden repositories
Summary:
Update `fbsparse.reposetup()` to avoid attempting to wrap the localrepo object
in Eden repositories.  The fbsparse extension is normally disabled in Eden
repositories, but this ensures the code does the correct thing even if the
fbsparse extension has been explicitly loaded.

Reviewed By: ryanmce

Differential Revision: D7642679

fbshipit-source-id: d0a229091d794fb326ab1db1c01e5a0a271092c4
2018-04-18 12:18:01 -07:00
Adam Simpkins
36de34b8f2 do not allow hg sparse to execute in non-sparse repositories
Summary:
Update the sparse command to fail early if the repository in question is not a
sparse repository.

Reviewed By: ryanmce

Differential Revision: D7642680

fbshipit-source-id: eaf765d38b45acf17d7c755f95083371f43f7259
2018-04-18 12:18:01 -07:00
Martijn Pieters
f07e9c14b6 fbsparse: add hint to sparse explain about the verbose flag
Summary:
```
$ hg sparse explain some/profile
[...]
hint[sparse-explain-verbose]: use 'hg sparse explain --verbose some/profile' to include the total file size for a give profile
hint[hint-ack]: use 'hg hint --ack sparse-explain-verbose' to silence these hints
```

Differential Revision: D7669896

fbshipit-source-id: c700fbc2f42044a9b15371278305f03e9e6c989f
2018-04-18 10:38:35 -07:00
Martijn Pieters
0b9356d3f2 sparse: update all subcommands with proper arguments / synopsis info
Summary: Tweak the help output to reflect the now-complete subcommand information.

Differential Revision: D7667900

fbshipit-source-id: a5a04e8bcbfe4a90266c30e25ffd705de0bdc8a9
2018-04-18 10:38:35 -07:00
Martijn Pieters
c05fc0e620 sparse: fix bug with prefetching
Summary: The attribute is called 'hex', not 'hash'. Oops.

Reviewed By: markbt

Differential Revision: D7600689

fbshipit-source-id: 027031000e6481f353ceaad79c7dc2c46a16a3cf
2018-04-17 08:27:00 -07:00
Martijn Pieters
b31ce422e2 sparse: provide sensible __repr__ strings for the custom matchers.
Summary: These matchers provide better values than the default now provided by mercurial.match.basematcher.

Reviewed By: quark-zju

Differential Revision: D7635868

fbshipit-source-id: c826390b3a5e3a2da897eeb54be22850e14403f6
2018-04-16 12:53:41 -07:00
Martijn Pieters
3f7758625a sparse: Add support for specifying a revision to sparse explain
Summary: We need this to support producing sparse profile stats in a null-revision working copy.

Reviewed By: quark-zju

Differential Revision: D7553022

fbshipit-source-id: b1643f443de5a748bf81ff2df16ace984d59a2c2
2018-04-13 21:51:50 -07:00
Martijn Pieters
6e097ff6cd sparse: add support for per-subcommand switches
Summary: A followup diff will add more in the way of testing; this is easier with an actual usecase.

Reviewed By: quark-zju

Differential Revision: D7553020

fbshipit-source-id: a6e8b86154d802f8cdbc846f5ea14fa809ac5264
2018-04-13 21:51:50 -07:00
Martijn Pieters
440232e553 sparse: fix the accidental recursive handling of profiles
Summary:
hg sparse explain wasn't supposed to recurse, not without additional support.

It was the process of gathering stats that overwrote shared mutable structures.
Prevent this from happening again by making these structures immutable.

Differential Revision: D7516570

fbshipit-source-id: 247c60b4bd8d2d22b42c41871e1eb15988820025
2018-04-13 21:51:50 -07:00
Martijn Pieters
62ec76397b sparse: fix broken signature calculation for sparse profiles
Summary:
We were ignoring the actual profile data, and all profiles were given the same .hg/sparse-based hash signature instead.

Error introduced in D7415720

Differential Revision: D7514087

fbshipit-source-id: 56288aaaa2065b031318e7c065ec6310f6cecd37
2018-04-13 21:51:50 -07:00
Martijn Pieters
0aa55642b8 hg: make sure len(manifest) always raises TypeError
Summary:
`len()` on a hybrid manifest wrapping a treemanifest would raise an attribute error. But if there is no treemanifest or there is *only* a treemanifest, then a TypeError is raised. Using `len()` on an object that doesn't support length should always raise `TypeError`, consistently.

Instead of looking up the `__len__` attribute, use the built-in `len()` function, which will raise `TypeError` if the wrapped manifest in a hybrid doesn't have a `__len__` method. This ensures that we get a consistent exception.

Reviewed By: farnz

Differential Revision: D7485510

fbshipit-source-id: 4132d6b383171cde8dd99dd60098716d4aedc527
2018-04-13 21:51:45 -07:00
Martijn Pieters
bf9eb9018e sparse: add the option to hide certain profiles
Summary:
Some profiles are not for general consumption; they are usually profiles aimed at CI subsystems or similar. These can be hidden from listings by default using a `hidden` key.

The value of the key doesn't matter but can be used to explain why it is hidden.

Reviewed By: quark-zju

Differential Revision: D7433781

fbshipit-source-id: 877cd8698d50dc64cec8da706ab005e1fd786de4
2018-04-13 21:51:39 -07:00
Martijn Pieters
b9cca4a62b sparse: rework help information
Summary:
The hg sparse help page was overwhelming, and out of date. With subcommands, we
can break up the information a bit more.

* Subcommand help is the place for details on that command. Reduce the main
  help info to an overview.
* Move configuration switches to a `verbose` container to hide it by default.
* Add documentation on the sparse profile format.
* Mark the command-line switches with subcommands as deprecated so they are
  hidden by default.

Reviewed By: quark-zju

Differential Revision: D7432862

fbshipit-source-id: ffddd27e0ee4216f7e743e63e8efaed4eeaac582
2018-04-13 21:51:38 -07:00
Martijn Pieters
a4952f4bfa sparse: add a hg sparse files command
Summary: This command mostly echoes how `hg files` works, albeit simplified somewhat. Given a profile and optional patterns, the files that profile matches are listed.

Reviewed By: quark-zju

Differential Revision: D7431522

fbshipit-source-id: 8e9d1f0d2aa31335f53269f3005875a0cc2e65bf
2018-04-13 21:51:38 -07:00
Martijn Pieters
4c93c15316 sparse: include sparse profile impact
Summary:
Show the 'impact' of a profile, relative to a non-sparse working copy.

By default, this is the percentage of the total file count; adding --verbose will show the file sizes too.

The defined matchers have been refactored to reuse more of mercurial.match.basematcher, making it easier to reuse these in a wider mercurial context and avoiding repetition of common methods.

Reviewed By: quark-zju

Differential Revision: D7415720

fbshipit-source-id: 4ac3492c61aa70ee71d4bdf8c201b905a345a9d1
2018-04-13 21:51:38 -07:00
Martijn Pieters
96a6a5773d sparse: make hg help sparse <subcommand> work
Summary:
This gives us access to the specifics of a subcommand, including switches
(still stubbed out). Note: `hg sparse <subcommand> -h` doesn't work yet, as the
`-h` command line switch would need intercepting as well.

Reviewed By: quark-zju

Differential Revision: D7413859

fbshipit-source-id: 02534f1255a11985ebe8636b26946fbeffc6fe09
2018-04-13 21:51:38 -07:00
Martijn Pieters
84bfcf3162 RFC: sparse: ignore case collisions outside the sparse profile
Summary:
When updating a working copy that is limited by a sparse profile, do not abort on case collisions outside of the current working copy view.

Performance-wise, this isn't a big change; previously `_checkcollision()` would convert the whole manifest to a set, now we filter first with the matcher, then convert the remainder to a set. Either the original set conversion or the filtering can take O(size-of-manifest) time.

Reviewed By: ryanmce

Differential Revision: D7350251

fbshipit-source-id: efb8e270631f0aaa75c34c7b68189c60efe45984
2018-04-13 21:51:37 -07:00
Martijn Pieters
6414c84571 sparse: show individual profile details
Summary: This shows basic details about a template, including base metadata. Once we have support for per-subcommand switches we can add further filtering.

Reviewed By: ryanmce

Differential Revision: D7365794

fbshipit-source-id: 3dd362f099e7f4d6db73c9bda7c24a9f4f2f90ee
2018-04-13 21:51:37 -07:00
Martijn Pieters
422a95de10 sparse: provide subcommands for other common tasks
Summary: Now all commands can be subcommands. The command-line switches will be hidden in a next commit (but remain available for backwards compatibility).

Reviewed By: ryanmce

Differential Revision: D7365393

fbshipit-source-id: 29b8ed2ac6bffccda41ed3f738087dde23312a8c
2018-04-13 21:51:37 -07:00
Martijn Pieters
5296ef905b sparse: make the help system print our subcommands
Summary:
This means we can

- count on the minirst module to format longer lines correctly,
- show subcommands when an error occurs (so full is false),
- add verbose help when the -v switch

Reviewed By: ryanmce

Differential Revision: D7365392

fbshipit-source-id: c8711bd19a6d992ad86f24f3c07b381f69d02121
2018-04-13 21:51:37 -07:00
Martijn Pieters
b8110f185c Allow for better help handling and multiple registrations for a single function.
Summary:
We take help info from the docstring but that'd disallow multiple registrations for a single function that can handle multiple subcommands. Refactor to let the decorator set an override.

So before you'd do this:

```
subcmd('foo')
def _foocmd(...):
    "Help for foo command"
    # implementation for foo

subcmd('bar')
def _barcmd(...):
    "Help for bar command"
    # implementation for bar
```
but you could not *combine* the implementations into one function and decorate both, because there is only the single docstring.

Now you can do:

```
subcmd('foo', help="Help for foo command")
subcmd('bar', help="Help for bar command")
def _fooandbarcmd(cmd, ...):
    "This docstring is no longer used"
    # implementation for foo and bar, combined, switching on the value of cmd
```

Reviewed By: ryanmce

Differential Revision: D7365390

fbshipit-source-id: 3d41542f1f197137ef13458e8d850cda8f53da74
2018-04-13 21:51:37 -07:00
Martijn Pieters
85eb89e007 sparse: make listing profiles a subcommand
Summary:
This is based on the hg show implementation. hg sparse --list-profiles is not yet widely known, so now is the time to move it to a subcommand.

This is the first step in untangling the mess that is the `hg sparse` forest of options.

Currently, all switches on the command are mutually exclusive, except for `—force` and `—template`, which each only apply to a subset of the actions the other switches affect.

Subcommands are the right pattern for mutually-exclusive actions that can accept their own individual switches.

Reviewed By: quark-zju

Differential Revision: D7350928

fbshipit-source-id: d03014cf7edd2f089f670d11465c70940d96c070
2018-04-13 21:51:35 -07:00
Mark Thomas
77d4bc2b83 fbsparse: use new-style progress bars
Reviewed By: mjpieters

Differential Revision: D7329504

fbshipit-source-id: 8037f704f88ea8b7d02ef323932143298fef5c66
2018-04-13 21:51:33 -07:00
Martijn Pieters
36a3e5b595 sparse: use -l as the short option for --list-profiles
Summary: There's a precedent for `-l` for listing: `hg shelve -l`, `hg undo -l`, `hg resolve -l`.

Reviewed By: ryanmce

Differential Revision: D7337527

fbshipit-source-id: 3d9c340590e9756e39cad3bfdd0b017f45fd3a6e
2018-04-13 21:51:31 -07:00
Martijn Pieters
efd45069e3 sparse: use relglob to exclude readme files
Summary: Although the old glob *should* work, in practice the treemanifest matcher seems to have issues with glob:**/ paths, where relglob: works.

Reviewed By: ryanmce

Differential Revision: D7287992

fbshipit-source-id: d3802e730d937eeca7059dac691d8dac5a5de262
2018-04-13 21:51:31 -07:00
Ryan McElroy
4380742b11 fbsparse: cache translations and properly close progress bars
Reviewed By: markbt

Differential Revision: D7211458

fbshipit-source-id: 6536a9e7060ca945a0763a4a54b075bf747d09fc
2018-04-13 21:51:29 -07:00
Ryan McElroy
94ae24f468 fbsparse: show spinner while populating the fileset
Summary:
On a large repo, this can take seconds. Let the user see progress
during this time.

Differential Revision: D7211460

fbshipit-source-id: bfa9ad658a1c190399f9e33de7ddfbe006d6cbfb
2018-04-13 21:51:28 -07:00
Ryan McElroy
07c6e90f29 fbsparse: use context manager for wlock()
Summary:
During testing, I discovered that a ctrl-c while `hg sparse --refresh`
was waitign on the wlock would cause a traceback. This fixes that.

Differential Revision: D7211459

fbshipit-source-id: dde006208f688cc7e2509e822443dececd59c08d
2018-04-13 21:51:28 -07:00
Martijn Pieters
37547cff41 sparse: list profile titles
Summary: Put titles, if present, into a second 'column' in the plain output.

Differential Revision: D7258046

fbshipit-source-id: dedbb04ecbf0b2262c4c507683262e4b7bef8d70
2018-04-13 21:51:28 -07:00
Martijn Pieters
a8786716bf sparse: load metadata from profiles
Summary:
Profiles can now have a [metadata] section, with key-value pairs defining some metadata to be associated with the profile.

This supports multiline entries by starting a continuation line with some whitespace:

```
[metadata]
title = Some cool title
description = A longer description
 will be joined with newlines
 provided you start with a space
 or a tab.
```

Differential Revision: D7257628

fbshipit-source-id: d6b09161d54cb6824f691d07caee83d0f8bd0a84
2018-04-13 21:51:28 -07:00
Martijn Pieters
8bb4e6a0ec sparse: include a filename when reporting sparse profile parsing issues
Summary: We regularly parse multiple profiles, through includes or when discovering. Be clear what profile file caused the issue.

Differential Revision: D7257636

fbshipit-source-id: 1203c13f6c6a4e4d1397ace818aee21b9db38550
2018-04-13 21:51:28 -07:00
Martijn Pieters
d02feb0eb6 sparse: refactor profile parsing
Summary:
- Include line numbers for error messages
- Handle sections via a mapping, for ease of extending
- Use identity to test for the excludes section, because even if the contents
  matched we'd want this to be an error.

Reviewed By: quark-zju

Differential Revision: D7239581

fbshipit-source-id: 36cf79102ed01758b809009bcbe470714ddd27e4
2018-04-13 21:51:27 -07:00
Martijn Pieters
0749a79a56 sparse: use a attrs class for internal sparse config passing
Summary: This makes it easier to add metadata later on, and code that needs only a single entry becomes cleaner.

Reviewed By: quark-zju

Differential Revision: D7239580

fbshipit-source-id: 8900b4fd4883e68ac599396e4a80063d11bbf07c
2018-04-13 21:51:27 -07:00
Martijn Pieters
74cb7a9391 fbsparse: use attrs to define the ProfileInfo class
Summary:
attrs is more flexible than a namedtuple, and we don't need indices on these objects.

The object is still immutable and has a low memory profile, but now we can trivially validate values. It's easier to extend the class now to add metadata.

Reviewed By: quark-zju

Differential Revision: D7239584

fbshipit-source-id: cbd0b38c54f08ed19d5a7e05811356e4694d7d19
2018-04-13 21:51:27 -07:00
Martijn Pieters
216613fa86 sparse: treat semicolons as comments too
Summary:
Sparse profile files are INI files, and semicolons are the traditional comment line starter.

There are already profiles that use the semicolon as a comment, see diffusion/FBS/browse/master/tools/scm/sparse/fbobjc/sandcastle and diffusion/FBS/browse/master/tools/scm/sparse/fbandroid/sandcastle

Reviewed By: farnz

Differential Revision: D7181613

fbshipit-source-id: a42171f6bd6213147c6363f8f359f885af38b8af
2018-04-13 21:51:23 -07:00
Martijn Pieters
15383f0bd3 sparse: use manifest matcher when discovering profiles
Summary:
This echos the change in D7056650; there is no need to special-case
treemanifests here; delegation to the manifest .match method allows the
manifest to apply optimisations when available.

Differential Revision: D7100363

fbshipit-source-id: 66a35850a132f804efb407712d2e4db737c10cff
2018-04-13 21:51:22 -07:00
Martijn Pieters
3b4b3d8cbb sparse: make use of matchers for faster path listing
Summary:
The current code iterates over all files in the manifest, filtering against a prefix.

But a manifest supports using a matcher directly, and efficient implementations like the treemanifest will prune the tree to a much smaller subset rapidly based on the path in a matcher. Switching to using a matcher dramatically improves --cwd-list performance in fbsource, when treemanifests are available.

Reviewed By: quark-zju

Differential Revision: D7056650

fbshipit-source-id: 2bf62ea93680323a49c9282266118805881d7b02
2018-04-13 21:51:21 -07:00
Martijn Pieters
42ac84e8cf sparse: clean up path handling, making it platform agnostic
Summary:
There is no need to strip path separators from the normalised path; normpath
will never leave any.

We also ensure that the path prefix we test ends in a path separator, to avoid
matching on sibling paths that happen to share a prefix.

Reviewed By: ryanmce

Differential Revision: D7056649

fbshipit-source-id: 10b78a78ba44fbc8d9c05fb7ffd0ffd1c1496a67
2018-04-13 21:51:18 -07:00
Peter Na
0911201aa9 fbsparse: add progress output for refresh
Summary: Adds output to hg sparse --refresh for long running calculations, --verbose adds more notes on progress.

Reviewed By: ryanmce

Differential Revision: D6886545

fbshipit-source-id: 9fe176724bec0cb56bc8da4939f42a6e7745cf41
2018-04-13 21:51:04 -07:00
Phil Cohen
66cb3160e1 sparse: don't materialize sparse files during IMM
There's no need to do this and not doing so speeds up IMM tremendously when the sparse profile had to be adjusted.

(This is the grafted version from the fb-hgext repo)

Test Plan:

I ran an IMM before and after this change. Both succeeded but the later version was
much faster.

Differential Revision: https://phab.mercurial-scm.org/D1805
2018-01-16 17:43:19 -08:00
Kostia Balytskyi
0e4d95b67e fb-hgext: fix gendoc-related issues
Summary:
These fixes are related to documentation-related check-style tests.

Depends on D6675344

Test Plan: - more tests pass

Reviewers: #sourcecontrol

Differential Revision: https://phabricator.intern.facebook.com/D6675351
2018-01-09 03:44:33 -08:00
Kostia Balytskyi
e75b9fc1b1 fb-hgext: move most of hgext3rd and related tests to core
Summary:
This commit moves most of the stuff in hgext3rd and related tests to
hg-crew/hgext and hg-crew/test respectively.

The things that are not moved are the ones which require some more complex
imports.


Depends on D6675309

Test Plan: - tests are failing at this commit, fixes are in the following commits

Reviewers: #sourcecontrol

Differential Revision: https://phabricator.intern.facebook.com/D6675329
2018-01-09 03:03:59 -08:00