Mercurial > hg-stable
annotate mercurial/rewriteutil.py @ 43075:57875cf423c9
style: run a patched black on a subset of mercurial
This applied black to the 20 smallest files in mercurial/:
ls -S1 mercurial/*.py | tail -n20 | xargs black --skip-string-normalization
Note that a few files failed to format, presumably due to a bug in my
patch. The intent is to be able to compare results to D5064 with
https://github.com/python/black/pull/826 applied to black.
I skipped string normalization on this patch for clarity - in reality
I think we'd want one pass without string normalization, followed by
another to normalize strings (which is basically replacing ' with "
globally.)
# skip-blame mass-reformatting only
Differential Revision: https://phab.mercurial-scm.org/D6342
author | Augie Fackler <augie@google.com> |
---|---|
date | Sat, 05 Oct 2019 10:29:34 -0400 |
parents | 8c6329fa6038 |
children | 687b865b95ad |
rev | line source |
---|---|
35251
27d5c2d2db2b
rewriteutil: add utility function to check if we can create new unstable cset
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff
changeset
|
1 # rewriteutil.py - utility functions for rewriting changesets |
27d5c2d2db2b
rewriteutil: add utility function to check if we can create new unstable cset
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff
changeset
|
2 # |
27d5c2d2db2b
rewriteutil: add utility function to check if we can create new unstable cset
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff
changeset
|
3 # Copyright 2017 Octobus <contact@octobus.net> |
27d5c2d2db2b
rewriteutil: add utility function to check if we can create new unstable cset
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff
changeset
|
4 # |
27d5c2d2db2b
rewriteutil: add utility function to check if we can create new unstable cset
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff
changeset
|
5 # This software may be used and distributed according to the terms of the |
27d5c2d2db2b
rewriteutil: add utility function to check if we can create new unstable cset
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff
changeset
|
6 # GNU General Public License version 2 or any later version. |
27d5c2d2db2b
rewriteutil: add utility function to check if we can create new unstable cset
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff
changeset
|
7 |
27d5c2d2db2b
rewriteutil: add utility function to check if we can create new unstable cset
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff
changeset
|
8 from __future__ import absolute_import |
27d5c2d2db2b
rewriteutil: add utility function to check if we can create new unstable cset
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff
changeset
|
9 |
35252
490df753894d
rewriteutil: add a precheck function to check if revs can be rewritten
Pulkit Goyal <7895pulkit@gmail.com>
parents:
35251
diff
changeset
|
10 from .i18n import _ |
490df753894d
rewriteutil: add a precheck function to check if revs can be rewritten
Pulkit Goyal <7895pulkit@gmail.com>
parents:
35251
diff
changeset
|
11 |
35251
27d5c2d2db2b
rewriteutil: add utility function to check if we can create new unstable cset
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff
changeset
|
12 from . import ( |
35252
490df753894d
rewriteutil: add a precheck function to check if revs can be rewritten
Pulkit Goyal <7895pulkit@gmail.com>
parents:
35251
diff
changeset
|
13 error, |
490df753894d
rewriteutil: add a precheck function to check if revs can be rewritten
Pulkit Goyal <7895pulkit@gmail.com>
parents:
35251
diff
changeset
|
14 node, |
35251
27d5c2d2db2b
rewriteutil: add utility function to check if we can create new unstable cset
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff
changeset
|
15 obsolete, |
27d5c2d2db2b
rewriteutil: add utility function to check if we can create new unstable cset
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff
changeset
|
16 revset, |
27d5c2d2db2b
rewriteutil: add utility function to check if we can create new unstable cset
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff
changeset
|
17 ) |
27d5c2d2db2b
rewriteutil: add utility function to check if we can create new unstable cset
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff
changeset
|
18 |
43075
57875cf423c9
style: run a patched black on a subset of mercurial
Augie Fackler <augie@google.com>
parents:
40680
diff
changeset
|
19 |
35252
490df753894d
rewriteutil: add a precheck function to check if revs can be rewritten
Pulkit Goyal <7895pulkit@gmail.com>
parents:
35251
diff
changeset
|
20 def precheck(repo, revs, action='rewrite'): |
490df753894d
rewriteutil: add a precheck function to check if revs can be rewritten
Pulkit Goyal <7895pulkit@gmail.com>
parents:
35251
diff
changeset
|
21 """check if revs can be rewritten |
490df753894d
rewriteutil: add a precheck function to check if revs can be rewritten
Pulkit Goyal <7895pulkit@gmail.com>
parents:
35251
diff
changeset
|
22 action is used to control the error message. |
490df753894d
rewriteutil: add a precheck function to check if revs can be rewritten
Pulkit Goyal <7895pulkit@gmail.com>
parents:
35251
diff
changeset
|
23 |
490df753894d
rewriteutil: add a precheck function to check if revs can be rewritten
Pulkit Goyal <7895pulkit@gmail.com>
parents:
35251
diff
changeset
|
24 Make sure this function is called after taking the lock. |
490df753894d
rewriteutil: add a precheck function to check if revs can be rewritten
Pulkit Goyal <7895pulkit@gmail.com>
parents:
35251
diff
changeset
|
25 """ |
490df753894d
rewriteutil: add a precheck function to check if revs can be rewritten
Pulkit Goyal <7895pulkit@gmail.com>
parents:
35251
diff
changeset
|
26 if node.nullrev in revs: |
43075
57875cf423c9
style: run a patched black on a subset of mercurial
Augie Fackler <augie@google.com>
parents:
40680
diff
changeset
|
27 msg = _("cannot %s null changeset") % action |
35252
490df753894d
rewriteutil: add a precheck function to check if revs can be rewritten
Pulkit Goyal <7895pulkit@gmail.com>
parents:
35251
diff
changeset
|
28 hint = _("no changeset checked out") |
490df753894d
rewriteutil: add a precheck function to check if revs can be rewritten
Pulkit Goyal <7895pulkit@gmail.com>
parents:
35251
diff
changeset
|
29 raise error.Abort(msg, hint=hint) |
490df753894d
rewriteutil: add a precheck function to check if revs can be rewritten
Pulkit Goyal <7895pulkit@gmail.com>
parents:
35251
diff
changeset
|
30 |
490df753894d
rewriteutil: add a precheck function to check if revs can be rewritten
Pulkit Goyal <7895pulkit@gmail.com>
parents:
35251
diff
changeset
|
31 if len(repo[None].parents()) > 1: |
490df753894d
rewriteutil: add a precheck function to check if revs can be rewritten
Pulkit Goyal <7895pulkit@gmail.com>
parents:
35251
diff
changeset
|
32 raise error.Abort(_("cannot %s while merging") % action) |
490df753894d
rewriteutil: add a precheck function to check if revs can be rewritten
Pulkit Goyal <7895pulkit@gmail.com>
parents:
35251
diff
changeset
|
33 |
40680
8c6329fa6038
rewriteutil: move publicrevs closer to where it's used
Anton Shestakov <av6@dwimlabs.net>
parents:
35252
diff
changeset
|
34 publicrevs = repo.revs('%ld and public()', revs) |
35252
490df753894d
rewriteutil: add a precheck function to check if revs can be rewritten
Pulkit Goyal <7895pulkit@gmail.com>
parents:
35251
diff
changeset
|
35 if publicrevs: |
43075
57875cf423c9
style: run a patched black on a subset of mercurial
Augie Fackler <augie@google.com>
parents:
40680
diff
changeset
|
36 msg = _("cannot %s public changesets") % action |
35252
490df753894d
rewriteutil: add a precheck function to check if revs can be rewritten
Pulkit Goyal <7895pulkit@gmail.com>
parents:
35251
diff
changeset
|
37 hint = _("see 'hg help phases' for details") |
490df753894d
rewriteutil: add a precheck function to check if revs can be rewritten
Pulkit Goyal <7895pulkit@gmail.com>
parents:
35251
diff
changeset
|
38 raise error.Abort(msg, hint=hint) |
490df753894d
rewriteutil: add a precheck function to check if revs can be rewritten
Pulkit Goyal <7895pulkit@gmail.com>
parents:
35251
diff
changeset
|
39 |
490df753894d
rewriteutil: add a precheck function to check if revs can be rewritten
Pulkit Goyal <7895pulkit@gmail.com>
parents:
35251
diff
changeset
|
40 newunstable = disallowednewunstable(repo, revs) |
490df753894d
rewriteutil: add a precheck function to check if revs can be rewritten
Pulkit Goyal <7895pulkit@gmail.com>
parents:
35251
diff
changeset
|
41 if newunstable: |
490df753894d
rewriteutil: add a precheck function to check if revs can be rewritten
Pulkit Goyal <7895pulkit@gmail.com>
parents:
35251
diff
changeset
|
42 raise error.Abort(_("cannot %s changeset with children") % action) |
490df753894d
rewriteutil: add a precheck function to check if revs can be rewritten
Pulkit Goyal <7895pulkit@gmail.com>
parents:
35251
diff
changeset
|
43 |
43075
57875cf423c9
style: run a patched black on a subset of mercurial
Augie Fackler <augie@google.com>
parents:
40680
diff
changeset
|
44 |
35251
27d5c2d2db2b
rewriteutil: add utility function to check if we can create new unstable cset
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff
changeset
|
45 def disallowednewunstable(repo, revs): |
27d5c2d2db2b
rewriteutil: add utility function to check if we can create new unstable cset
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff
changeset
|
46 """Checks whether editing the revs will create new unstable changesets and |
27d5c2d2db2b
rewriteutil: add utility function to check if we can create new unstable cset
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff
changeset
|
47 are we allowed to create them. |
27d5c2d2db2b
rewriteutil: add utility function to check if we can create new unstable cset
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff
changeset
|
48 |
27d5c2d2db2b
rewriteutil: add utility function to check if we can create new unstable cset
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff
changeset
|
49 To allow new unstable changesets, set the config: |
27d5c2d2db2b
rewriteutil: add utility function to check if we can create new unstable cset
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff
changeset
|
50 `experimental.evolution.allowunstable=True` |
27d5c2d2db2b
rewriteutil: add utility function to check if we can create new unstable cset
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff
changeset
|
51 """ |
27d5c2d2db2b
rewriteutil: add utility function to check if we can create new unstable cset
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff
changeset
|
52 allowunstable = obsolete.isenabled(repo, obsolete.allowunstableopt) |
27d5c2d2db2b
rewriteutil: add utility function to check if we can create new unstable cset
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff
changeset
|
53 if allowunstable: |
27d5c2d2db2b
rewriteutil: add utility function to check if we can create new unstable cset
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff
changeset
|
54 return revset.baseset() |
27d5c2d2db2b
rewriteutil: add utility function to check if we can create new unstable cset
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff
changeset
|
55 return repo.revs("(%ld::) - %ld", revs, revs) |