hgext3rd/evolve/legacy.py
author Rodrigo Damazio Bovendorp <rdamazio@google.com>
Thu, 07 May 2020 19:47:59 -0700
changeset 5352 10368b3427b1
parent 4814 48b30ff742cb
permissions -rw-r--r--
utility: deal with having multiple When a revision has multiple prune obsolescence markers, it's thought to be a split, and the way we try to deal with splits currently crashes.
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
32
c27491be4431 obsolet: basic support (hide changeset)
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff changeset
     1
# Copyright 2011 Pierre-Yves David <pierre-yves.david@ens-lyon.org>
c27491be4431 obsolet: basic support (hide changeset)
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff changeset
     2
#                Logilab SA        <contact@logilab.fr>
c27491be4431 obsolet: basic support (hide changeset)
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff changeset
     3
#
c27491be4431 obsolet: basic support (hide changeset)
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff changeset
     4
# This software may be used and distributed according to the terms of the
c27491be4431 obsolet: basic support (hide changeset)
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff changeset
     5
# GNU General Public License version 2 or any later version.
1665
559d04a5c856 Grammar: introduced
timeless@gmail.com
parents: 1664
diff changeset
     6
"""Deprecated extension that formerly introduced "Changeset Obsolescence".
69
aee53d546849 [obsolete] update doc
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 58
diff changeset
     7
1669
11d72083883a Brand: Mercurial
timeless@gmail.com
parents: 1665
diff changeset
     8
This concept is now partially in Mercurial core (starting with Mercurial 2.3).
1664
1c9aef9497c4 Grammar: has
timeless@gmail.com
parents: 1657
diff changeset
     9
The remaining logic has been grouped with the evolve extension.
69
aee53d546849 [obsolete] update doc
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 58
diff changeset
    10
1657
103cb0d44cd8 Spelling: remains
timeless@gmail.com
parents: 1652
diff changeset
    11
Some code remains in this extensions to detect and convert prehistoric format
1550
e47dda53a5c2 check-code: make obsolete.py comply with check-code
Laurent Charignon <lcharignon@fb.com>
parents: 1465
diff changeset
    12
of obsolete marker than early user may have create. Keep it enabled if you
e47dda53a5c2 check-code: make obsolete.py comply with check-code
Laurent Charignon <lcharignon@fb.com>
parents: 1465
diff changeset
    13
were such user.
69
aee53d546849 [obsolete] update doc
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 58
diff changeset
    14
"""
228
5a17c0d41a00 proof-read documentation and docstrings
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents: 226
diff changeset
    15
1757
86e71a0b3319 errors: add missing imports of mercurial.error
Martin von Zweigbergk <martinvonz@google.com>
parents: 1669
diff changeset
    16
from mercurial import error
433
aa1255c2ac8f obsolete: move version checks at the start of the file
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 432
diff changeset
    17
439
6cff54825233 obsolete: reorder import
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 438
diff changeset
    18
import sys
491
6989d8fe4ed2 merge evolve and obsolete
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 490
diff changeset
    19
import json
354
bd26eb9714fb obsolete: Detect conflicting changeset!
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 351
diff changeset
    20
1550
e47dda53a5c2 check-code: make obsolete.py comply with check-code
Laurent Charignon <lcharignon@fb.com>
parents: 1465
diff changeset
    21
from mercurial.i18n import _
2122
efc6633e78e1 legacy: move 'debugrecordpruneparents' in the extensions
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 2070
diff changeset
    22
from mercurial import lock as lockmod
491
6989d8fe4ed2 merge evolve and obsolete
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 490
diff changeset
    23
from mercurial.node import bin, nullid
2464
2b53a2a21bbb deprecation: fix cmdutil.command deprecation warning
Boris Feld <boris.feld@octobus.net>
parents: 2273
diff changeset
    24
from mercurial import registrar
1757
86e71a0b3319 errors: add missing imports of mercurial.error
Martin von Zweigbergk <martinvonz@google.com>
parents: 1669
diff changeset
    25
from mercurial import util
39
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 38
diff changeset
    26
3514
498f782ccb4b compat: add compat layer for date related functions
Boris Feld <boris.feld@octobus.net>
parents: 3124
diff changeset
    27
try:
498f782ccb4b compat: add compat layer for date related functions
Boris Feld <boris.feld@octobus.net>
parents: 3124
diff changeset
    28
    from mercurial.utils.dateutil import makedate
4266
a4a35fb44af3 style: remove unused variables
Martijn Pieters <mj@octobus.net>
parents: 3970
diff changeset
    29
except ImportError:
3514
498f782ccb4b compat: add compat layer for date related functions
Boris Feld <boris.feld@octobus.net>
parents: 3124
diff changeset
    30
    # compat with hg < 4.6
498f782ccb4b compat: add compat layer for date related functions
Boris Feld <boris.feld@octobus.net>
parents: 3124
diff changeset
    31
    from mercurial.util import makedate
498f782ccb4b compat: add compat layer for date related functions
Boris Feld <boris.feld@octobus.net>
parents: 3124
diff changeset
    32
3970
005a10537627 legacy: drop compat layer for "command"
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 3514
diff changeset
    33
commandfunc = registrar.command
44
b243c10a5fbe Add pushkey support for pull and push
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 43
diff changeset
    34
430
07db1d511faf obsolete: move old format stuff at the end
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 429
diff changeset
    35
#####################################################################
07db1d511faf obsolete: move old format stuff at the end
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 429
diff changeset
    36
### Older format management                                       ###
07db1d511faf obsolete: move old format stuff at the end
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 429
diff changeset
    37
#####################################################################
218
ace5608350b6 obsolete: do no complain when push create a new head but obsolete an old one.
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 217
diff changeset
    38
430
07db1d511faf obsolete: move old format stuff at the end
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 429
diff changeset
    39
# Code related to detection and management of older legacy format never
07db1d511faf obsolete: move old format stuff at the end
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 429
diff changeset
    40
# handled by core
218
ace5608350b6 obsolete: do no complain when push create a new head but obsolete an old one.
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 217
diff changeset
    41
32
c27491be4431 obsolet: basic support (hide changeset)
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff changeset
    42
491
6989d8fe4ed2 merge evolve and obsolete
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 490
diff changeset
    43
def reposetup(ui, repo):
459
3477326461e3 obsolete: more typos and cleanup
Patrick Mezard <patrick@mezard.eu>
parents: 458
diff changeset
    44
    """Detect that a repo still contains some old obsolete format
273
87e4d1eec5e8 obsolete: add debugsuccessors command
Patrick Mezard <patrick@mezard.eu>
parents: 254
diff changeset
    45
    """
429
079b231b8ea4 obsolete: introduce an extension helper and use it
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 428
diff changeset
    46
    if not repo.local():
079b231b8ea4 obsolete: introduce an extension helper and use it
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 428
diff changeset
    47
        return
4814
48b30ff742cb python3: use format-source to run byteify-strings in .py files
Raphaël Gomès <rgomes@octobus.net>
parents: 4808
diff changeset
    48
    evolveopts = ui.configlist(b'experimental', b'evolution')
1216
a307eea46f96 oldobsolete: remove use of obsolete._enabled
Durham Goode <durham@fb.com>
parents: 1061
diff changeset
    49
    if not evolveopts:
4814
48b30ff742cb python3: use format-source to run byteify-strings in .py files
Raphaël Gomès <rgomes@octobus.net>
parents: 4808
diff changeset
    50
        evolveopts = b'all'
48b30ff742cb python3: use format-source to run byteify-strings in .py files
Raphaël Gomès <rgomes@octobus.net>
parents: 4808
diff changeset
    51
        ui.setconfig(b'experimental', b'evolution', evolveopts)
429
079b231b8ea4 obsolete: introduce an extension helper and use it
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 428
diff changeset
    52
    for arg in sys.argv:
4804
079dbf36e884 python3: add raw prefix in cases harder to analyze at the token level
Raphaël Gomès <rgomes@octobus.net>
parents: 4714
diff changeset
    53
        if r'debugc' in arg:
429
079b231b8ea4 obsolete: introduce an extension helper and use it
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 428
diff changeset
    54
            break
079b231b8ea4 obsolete: introduce an extension helper and use it
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 428
diff changeset
    55
    else:
4814
48b30ff742cb python3: use format-source to run byteify-strings in .py files
Raphaël Gomès <rgomes@octobus.net>
parents: 4808
diff changeset
    56
        data = repo.vfs.tryread(b'obsolete-relations')
429
079b231b8ea4 obsolete: introduce an extension helper and use it
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 428
diff changeset
    57
        if not data:
4814
48b30ff742cb python3: use format-source to run byteify-strings in .py files
Raphaël Gomès <rgomes@octobus.net>
parents: 4808
diff changeset
    58
            data = repo.svfs.tryread(b'obsoletemarkers')
429
079b231b8ea4 obsolete: introduce an extension helper and use it
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 428
diff changeset
    59
        if data:
4814
48b30ff742cb python3: use format-source to run byteify-strings in .py files
Raphaël Gomès <rgomes@octobus.net>
parents: 4808
diff changeset
    60
            raise error.Abort(b'old format of obsolete marker detected!\n'
48b30ff742cb python3: use format-source to run byteify-strings in .py files
Raphaël Gomès <rgomes@octobus.net>
parents: 4808
diff changeset
    61
                              b'run `hg debugconvertobsolete` once.')
70
af4f7ef0a3c1 [obsolete] extract serialization logic.
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 69
diff changeset
    62
1647
23521789ded0 Spelling (en-us): -ize
timeless@gmail.com
parents: 1550
diff changeset
    63
def _obsdeserialize(flike):
1648
96331d6f9940 Spelling: accessing
timeless@gmail.com
parents: 1647
diff changeset
    64
    """read a file like object serialized with _obsserialize
74
c7dd26dec7fc [obsolete] update docstring
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 73
diff changeset
    65
1649
0b8a1e58dcf7 Spelling: deserialize
timeless@gmail.com
parents: 1648
diff changeset
    66
    this deserialize into a {subject -> objects} mapping
454
4e34a723115b obsolete: more comment
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 453
diff changeset
    67
4e34a723115b obsolete: more comment
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 453
diff changeset
    68
    this was the very first format ever."""
70
af4f7ef0a3c1 [obsolete] extract serialization logic.
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 69
diff changeset
    69
    rels = {}
af4f7ef0a3c1 [obsolete] extract serialization logic.
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 69
diff changeset
    70
    for line in flike:
af4f7ef0a3c1 [obsolete] extract serialization logic.
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 69
diff changeset
    71
        subhex, objhex = line.split()
80
5d029a358252 [obsolete] add kill support
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 79
diff changeset
    72
        subnode = bin(subhex)
5d029a358252 [obsolete] add kill support
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 79
diff changeset
    73
        if subnode == nullid:
5d029a358252 [obsolete] add kill support
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 79
diff changeset
    74
            subnode = None
1550
e47dda53a5c2 check-code: make obsolete.py comply with check-code
Laurent Charignon <lcharignon@fb.com>
parents: 1465
diff changeset
    75
        rels.setdefault(subnode, set()).add(bin(objhex))
70
af4f7ef0a3c1 [obsolete] extract serialization logic.
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 69
diff changeset
    76
    return rels
af4f7ef0a3c1 [obsolete] extract serialization logic.
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 69
diff changeset
    77
441
d702f0d26c6a obsolete: remove debugsuccessors
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 440
diff changeset
    78
cmdtable = {}
2464
2b53a2a21bbb deprecation: fix cmdutil.command deprecation warning
Boris Feld <boris.feld@octobus.net>
parents: 2273
diff changeset
    79
command = commandfunc(cmdtable)
4814
48b30ff742cb python3: use format-source to run byteify-strings in .py files
Raphaël Gomès <rgomes@octobus.net>
parents: 4808
diff changeset
    80
@command(b'debugconvertobsolete', [], b'')
224
f60555898df4 new obsolete store
Pierre-Yves.David@ens-lyon.org
parents: 218
diff changeset
    81
def cmddebugconvertobsolete(ui, repo):
278
fa0b9b8a83c0 obsolete: add or fix debug commands help
Patrick Mezard <patrick@mezard.eu>
parents: 277
diff changeset
    82
    """import markers from an .hg/obsolete-relations file"""
224
f60555898df4 new obsolete store
Pierre-Yves.David@ens-lyon.org
parents: 218
diff changeset
    83
    cnt = 0
337
ebfd1b96a013 obsolete: convert try to guess what invalid node id are
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 336
diff changeset
    84
    err = 0
3124
6ef274e01f64 flake8: rename some ambiguous identifier
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 3035
diff changeset
    85
    lock = repo.lock()
334
fb83210bce32 obsolete: move to official binary format
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 332
diff changeset
    86
    some = False
224
f60555898df4 new obsolete store
Pierre-Yves.David@ens-lyon.org
parents: 218
diff changeset
    87
    try:
361
ac7969043677 obsolete: adapt to core: marker are written in transaction now
Pierre-Yves.David@ens-lyon.org
parents: 360
diff changeset
    88
        unlink = []
4814
48b30ff742cb python3: use format-source to run byteify-strings in .py files
Raphaël Gomès <rgomes@octobus.net>
parents: 4808
diff changeset
    89
        tr = repo.transaction(b'convert-obsolete')
224
f60555898df4 new obsolete store
Pierre-Yves.David@ens-lyon.org
parents: 218
diff changeset
    90
        try:
361
ac7969043677 obsolete: adapt to core: marker are written in transaction now
Pierre-Yves.David@ens-lyon.org
parents: 360
diff changeset
    91
            repo._importoldobsolete = True
ac7969043677 obsolete: adapt to core: marker are written in transaction now
Pierre-Yves.David@ens-lyon.org
parents: 360
diff changeset
    92
            store = repo.obsstore
ac7969043677 obsolete: adapt to core: marker are written in transaction now
Pierre-Yves.David@ens-lyon.org
parents: 360
diff changeset
    93
            ### very first format
224
f60555898df4 new obsolete store
Pierre-Yves.David@ens-lyon.org
parents: 218
diff changeset
    94
            try:
4814
48b30ff742cb python3: use format-source to run byteify-strings in .py files
Raphaël Gomès <rgomes@octobus.net>
parents: 4808
diff changeset
    95
                f = repo.vfs(b'obsolete-relations')
361
ac7969043677 obsolete: adapt to core: marker are written in transaction now
Pierre-Yves.David@ens-lyon.org
parents: 360
diff changeset
    96
                try:
ac7969043677 obsolete: adapt to core: marker are written in transaction now
Pierre-Yves.David@ens-lyon.org
parents: 360
diff changeset
    97
                    some = True
ac7969043677 obsolete: adapt to core: marker are written in transaction now
Pierre-Yves.David@ens-lyon.org
parents: 360
diff changeset
    98
                    for line in f:
ac7969043677 obsolete: adapt to core: marker are written in transaction now
Pierre-Yves.David@ens-lyon.org
parents: 360
diff changeset
    99
                        subhex, objhex = line.split()
ac7969043677 obsolete: adapt to core: marker are written in transaction now
Pierre-Yves.David@ens-lyon.org
parents: 360
diff changeset
   100
                        suc = bin(subhex)
ac7969043677 obsolete: adapt to core: marker are written in transaction now
Pierre-Yves.David@ens-lyon.org
parents: 360
diff changeset
   101
                        prec = bin(objhex)
2032
dd7e092a854a flake8: update the code sources to fixes a horde of pyflake warnings
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 2025
diff changeset
   102
                        sucs = (suc == nullid) and [] or [suc]
361
ac7969043677 obsolete: adapt to core: marker are written in transaction now
Pierre-Yves.David@ens-lyon.org
parents: 360
diff changeset
   103
                        meta = {
4814
48b30ff742cb python3: use format-source to run byteify-strings in .py files
Raphaël Gomès <rgomes@octobus.net>
parents: 4808
diff changeset
   104
                            b'date': b'%i %i' % makedate(),
48b30ff742cb python3: use format-source to run byteify-strings in .py files
Raphaël Gomès <rgomes@octobus.net>
parents: 4808
diff changeset
   105
                            b'user': ui.username(),
361
ac7969043677 obsolete: adapt to core: marker are written in transaction now
Pierre-Yves.David@ens-lyon.org
parents: 360
diff changeset
   106
                            }
ac7969043677 obsolete: adapt to core: marker are written in transaction now
Pierre-Yves.David@ens-lyon.org
parents: 360
diff changeset
   107
                        try:
1061
f3867e60d072 compat: always call metadata as a keyword argument
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 519
diff changeset
   108
                            store.create(tr, prec, sucs, 0, metadata=meta)
361
ac7969043677 obsolete: adapt to core: marker are written in transaction now
Pierre-Yves.David@ens-lyon.org
parents: 360
diff changeset
   109
                            cnt += 1
ac7969043677 obsolete: adapt to core: marker are written in transaction now
Pierre-Yves.David@ens-lyon.org
parents: 360
diff changeset
   110
                        except ValueError:
4814
48b30ff742cb python3: use format-source to run byteify-strings in .py files
Raphaël Gomès <rgomes@octobus.net>
parents: 4808
diff changeset
   111
                            repo.ui.write_err(b"invalid old marker line: %s"
361
ac7969043677 obsolete: adapt to core: marker are written in transaction now
Pierre-Yves.David@ens-lyon.org
parents: 360
diff changeset
   112
                                              % (line))
ac7969043677 obsolete: adapt to core: marker are written in transaction now
Pierre-Yves.David@ens-lyon.org
parents: 360
diff changeset
   113
                            err += 1
ac7969043677 obsolete: adapt to core: marker are written in transaction now
Pierre-Yves.David@ens-lyon.org
parents: 360
diff changeset
   114
                finally:
ac7969043677 obsolete: adapt to core: marker are written in transaction now
Pierre-Yves.David@ens-lyon.org
parents: 360
diff changeset
   115
                    f.close()
4814
48b30ff742cb python3: use format-source to run byteify-strings in .py files
Raphaël Gomès <rgomes@octobus.net>
parents: 4808
diff changeset
   116
                unlink.append(repo.vfs.join(b'obsolete-relations'))
361
ac7969043677 obsolete: adapt to core: marker are written in transaction now
Pierre-Yves.David@ens-lyon.org
parents: 360
diff changeset
   117
            except IOError:
ac7969043677 obsolete: adapt to core: marker are written in transaction now
Pierre-Yves.David@ens-lyon.org
parents: 360
diff changeset
   118
                pass
ac7969043677 obsolete: adapt to core: marker are written in transaction now
Pierre-Yves.David@ens-lyon.org
parents: 360
diff changeset
   119
            ### second (json) format
4814
48b30ff742cb python3: use format-source to run byteify-strings in .py files
Raphaël Gomès <rgomes@octobus.net>
parents: 4808
diff changeset
   120
            data = repo.svfs.tryread(b'obsoletemarkers')
334
fb83210bce32 obsolete: move to official binary format
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 332
diff changeset
   121
            if data:
fb83210bce32 obsolete: move to official binary format
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 332
diff changeset
   122
                some = True
361
ac7969043677 obsolete: adapt to core: marker are written in transaction now
Pierre-Yves.David@ens-lyon.org
parents: 360
diff changeset
   123
                for oldmark in json.loads(data):
4808
14c12df16ab5 python3: add raw prefix to edge-cases kwargs-like objects
Raphaël Gomès <rgomes@octobus.net>
parents: 4804
diff changeset
   124
                    del oldmark[r'id']  # dropped for now
14c12df16ab5 python3: add raw prefix to edge-cases kwargs-like objects
Raphaël Gomès <rgomes@octobus.net>
parents: 4804
diff changeset
   125
                    del oldmark[r'reason']  # unused until then
14c12df16ab5 python3: add raw prefix to edge-cases kwargs-like objects
Raphaël Gomès <rgomes@octobus.net>
parents: 4804
diff changeset
   126
                    oldobject = str(oldmark.pop(r'object'))
14c12df16ab5 python3: add raw prefix to edge-cases kwargs-like objects
Raphaël Gomès <rgomes@octobus.net>
parents: 4804
diff changeset
   127
                    oldsubjects = [str(s) for s in oldmark.pop(r'subjects', [])]
3035
a3a154e49bba legacy: rename lookup_errors to not be in all caps (flake8 warning)
Anton Shestakov <av6@dwimlabs.net>
parents: 2464
diff changeset
   128
                    lookup_errors = (error.RepoLookupError, error.LookupError)
361
ac7969043677 obsolete: adapt to core: marker are written in transaction now
Pierre-Yves.David@ens-lyon.org
parents: 360
diff changeset
   129
                    if len(oldobject) != 40:
ac7969043677 obsolete: adapt to core: marker are written in transaction now
Pierre-Yves.David@ens-lyon.org
parents: 360
diff changeset
   130
                        try:
ac7969043677 obsolete: adapt to core: marker are written in transaction now
Pierre-Yves.David@ens-lyon.org
parents: 360
diff changeset
   131
                            oldobject = repo[oldobject].node()
3035
a3a154e49bba legacy: rename lookup_errors to not be in all caps (flake8 warning)
Anton Shestakov <av6@dwimlabs.net>
parents: 2464
diff changeset
   132
                        except lookup_errors:
361
ac7969043677 obsolete: adapt to core: marker are written in transaction now
Pierre-Yves.David@ens-lyon.org
parents: 360
diff changeset
   133
                            pass
ac7969043677 obsolete: adapt to core: marker are written in transaction now
Pierre-Yves.David@ens-lyon.org
parents: 360
diff changeset
   134
                    if any(len(s) != 40 for s in oldsubjects):
ac7969043677 obsolete: adapt to core: marker are written in transaction now
Pierre-Yves.David@ens-lyon.org
parents: 360
diff changeset
   135
                        try:
ac7969043677 obsolete: adapt to core: marker are written in transaction now
Pierre-Yves.David@ens-lyon.org
parents: 360
diff changeset
   136
                            oldsubjects = [repo[s].node() for s in oldsubjects]
3035
a3a154e49bba legacy: rename lookup_errors to not be in all caps (flake8 warning)
Anton Shestakov <av6@dwimlabs.net>
parents: 2464
diff changeset
   137
                        except lookup_errors:
361
ac7969043677 obsolete: adapt to core: marker are written in transaction now
Pierre-Yves.David@ens-lyon.org
parents: 360
diff changeset
   138
                            pass
224
f60555898df4 new obsolete store
Pierre-Yves.David@ens-lyon.org
parents: 218
diff changeset
   139
4808
14c12df16ab5 python3: add raw prefix to edge-cases kwargs-like objects
Raphaël Gomès <rgomes@octobus.net>
parents: 4804
diff changeset
   140
                    oldmark[r'date'] = r'%i %i' % tuple(oldmark[r'date'])
361
ac7969043677 obsolete: adapt to core: marker are written in transaction now
Pierre-Yves.David@ens-lyon.org
parents: 360
diff changeset
   141
                    meta = dict((k.encode('utf-8'), v.encode('utf-8'))
4714
c51fc0ae7a7e py3: switch from iteritems() to items()
Martin von Zweigbergk <martinvonz@google.com>
parents: 4627
diff changeset
   142
                                for k, v in oldmark.items())
341
7653f80fd7a4 obsolete: harden convertion from first format
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 340
diff changeset
   143
                    try:
361
ac7969043677 obsolete: adapt to core: marker are written in transaction now
Pierre-Yves.David@ens-lyon.org
parents: 360
diff changeset
   144
                        succs = [bin(n) for n in oldsubjects]
ac7969043677 obsolete: adapt to core: marker are written in transaction now
Pierre-Yves.David@ens-lyon.org
parents: 360
diff changeset
   145
                        succs = [n for n in succs if n != nullid]
ac7969043677 obsolete: adapt to core: marker are written in transaction now
Pierre-Yves.David@ens-lyon.org
parents: 360
diff changeset
   146
                        store.create(tr, bin(oldobject), succs,
1061
f3867e60d072 compat: always call metadata as a keyword argument
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 519
diff changeset
   147
                                     0, metadata=meta)
341
7653f80fd7a4 obsolete: harden convertion from first format
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 340
diff changeset
   148
                        cnt += 1
7653f80fd7a4 obsolete: harden convertion from first format
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 340
diff changeset
   149
                    except ValueError:
4814
48b30ff742cb python3: use format-source to run byteify-strings in .py files
Raphaël Gomès <rgomes@octobus.net>
parents: 4808
diff changeset
   150
                        msg = b"invalid marker %s -> %s\n"
2032
dd7e092a854a flake8: update the code sources to fixes a horde of pyflake warnings
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 2025
diff changeset
   151
                        msg %= (oldobject, oldsubjects)
dd7e092a854a flake8: update the code sources to fixes a horde of pyflake warnings
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 2025
diff changeset
   152
                        repo.ui.write_err(msg)
341
7653f80fd7a4 obsolete: harden convertion from first format
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 340
diff changeset
   153
                        err += 1
4814
48b30ff742cb python3: use format-source to run byteify-strings in .py files
Raphaël Gomès <rgomes@octobus.net>
parents: 4808
diff changeset
   154
                unlink.append(repo.svfs.join(b'obsoletemarkers'))
361
ac7969043677 obsolete: adapt to core: marker are written in transaction now
Pierre-Yves.David@ens-lyon.org
parents: 360
diff changeset
   155
            tr.close()
ac7969043677 obsolete: adapt to core: marker are written in transaction now
Pierre-Yves.David@ens-lyon.org
parents: 360
diff changeset
   156
            for path in unlink:
ac7969043677 obsolete: adapt to core: marker are written in transaction now
Pierre-Yves.David@ens-lyon.org
parents: 360
diff changeset
   157
                util.unlink(path)
ac7969043677 obsolete: adapt to core: marker are written in transaction now
Pierre-Yves.David@ens-lyon.org
parents: 360
diff changeset
   158
        finally:
ac7969043677 obsolete: adapt to core: marker are written in transaction now
Pierre-Yves.David@ens-lyon.org
parents: 360
diff changeset
   159
            tr.release()
224
f60555898df4 new obsolete store
Pierre-Yves.David@ens-lyon.org
parents: 218
diff changeset
   160
    finally:
f60555898df4 new obsolete store
Pierre-Yves.David@ens-lyon.org
parents: 218
diff changeset
   161
        del repo._importoldobsolete
3124
6ef274e01f64 flake8: rename some ambiguous identifier
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 3035
diff changeset
   162
        lock.release()
334
fb83210bce32 obsolete: move to official binary format
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 332
diff changeset
   163
    if not some:
4814
48b30ff742cb python3: use format-source to run byteify-strings in .py files
Raphaël Gomès <rgomes@octobus.net>
parents: 4808
diff changeset
   164
        ui.warn(_(b'nothing to do\n'))
48b30ff742cb python3: use format-source to run byteify-strings in .py files
Raphaël Gomès <rgomes@octobus.net>
parents: 4808
diff changeset
   165
    ui.status(b'%i obsolete marker converted\n' % cnt)
337
ebfd1b96a013 obsolete: convert try to guess what invalid node id are
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 336
diff changeset
   166
    if err:
4814
48b30ff742cb python3: use format-source to run byteify-strings in .py files
Raphaël Gomès <rgomes@octobus.net>
parents: 4808
diff changeset
   167
        ui.write_err(b'%i conversion failed. check you graph!\n' % err)
2122
efc6633e78e1 legacy: move 'debugrecordpruneparents' in the extensions
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 2070
diff changeset
   168
4814
48b30ff742cb python3: use format-source to run byteify-strings in .py files
Raphaël Gomès <rgomes@octobus.net>
parents: 4808
diff changeset
   169
@command(b'debugrecordpruneparents', [], b'')
2122
efc6633e78e1 legacy: move 'debugrecordpruneparents' in the extensions
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 2070
diff changeset
   170
def cmddebugrecordpruneparents(ui, repo):
efc6633e78e1 legacy: move 'debugrecordpruneparents' in the extensions
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 2070
diff changeset
   171
    """add parent data to prune markers when possible
efc6633e78e1 legacy: move 'debugrecordpruneparents' in the extensions
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 2070
diff changeset
   172
efc6633e78e1 legacy: move 'debugrecordpruneparents' in the extensions
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 2070
diff changeset
   173
    This command searches the repo for prune markers without parent information.
efc6633e78e1 legacy: move 'debugrecordpruneparents' in the extensions
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 2070
diff changeset
   174
    If the pruned node is locally known, it creates a new marker with parent
efc6633e78e1 legacy: move 'debugrecordpruneparents' in the extensions
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 2070
diff changeset
   175
    data.
efc6633e78e1 legacy: move 'debugrecordpruneparents' in the extensions
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 2070
diff changeset
   176
    """
4814
48b30ff742cb python3: use format-source to run byteify-strings in .py files
Raphaël Gomès <rgomes@octobus.net>
parents: 4808
diff changeset
   177
    pgop = b'reading markers'
2122
efc6633e78e1 legacy: move 'debugrecordpruneparents' in the extensions
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 2070
diff changeset
   178
efc6633e78e1 legacy: move 'debugrecordpruneparents' in the extensions
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 2070
diff changeset
   179
    # lock from the beginning to prevent race
efc6633e78e1 legacy: move 'debugrecordpruneparents' in the extensions
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 2070
diff changeset
   180
    wlock = lock = tr = None
efc6633e78e1 legacy: move 'debugrecordpruneparents' in the extensions
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 2070
diff changeset
   181
    try:
efc6633e78e1 legacy: move 'debugrecordpruneparents' in the extensions
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 2070
diff changeset
   182
        wlock = repo.wlock()
efc6633e78e1 legacy: move 'debugrecordpruneparents' in the extensions
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 2070
diff changeset
   183
        lock = repo.lock()
4814
48b30ff742cb python3: use format-source to run byteify-strings in .py files
Raphaël Gomès <rgomes@octobus.net>
parents: 4808
diff changeset
   184
        tr = repo.transaction(b'recordpruneparents')
2122
efc6633e78e1 legacy: move 'debugrecordpruneparents' in the extensions
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 2070
diff changeset
   185
        unfi = repo.unfiltered()
efc6633e78e1 legacy: move 'debugrecordpruneparents' in the extensions
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 2070
diff changeset
   186
        nm = unfi.changelog.nodemap
efc6633e78e1 legacy: move 'debugrecordpruneparents' in the extensions
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 2070
diff changeset
   187
        store = repo.obsstore
efc6633e78e1 legacy: move 'debugrecordpruneparents' in the extensions
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 2070
diff changeset
   188
        pgtotal = len(store._all)
efc6633e78e1 legacy: move 'debugrecordpruneparents' in the extensions
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 2070
diff changeset
   189
        for idx, mark in enumerate(list(store._all)):
efc6633e78e1 legacy: move 'debugrecordpruneparents' in the extensions
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 2070
diff changeset
   190
            if not mark[1]:
efc6633e78e1 legacy: move 'debugrecordpruneparents' in the extensions
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 2070
diff changeset
   191
                rev = nm.get(mark[0])
efc6633e78e1 legacy: move 'debugrecordpruneparents' in the extensions
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 2070
diff changeset
   192
                if rev is not None:
efc6633e78e1 legacy: move 'debugrecordpruneparents' in the extensions
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 2070
diff changeset
   193
                    ctx = unfi[rev]
efc6633e78e1 legacy: move 'debugrecordpruneparents' in the extensions
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 2070
diff changeset
   194
                    parents = tuple(p.node() for p in ctx.parents())
efc6633e78e1 legacy: move 'debugrecordpruneparents' in the extensions
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 2070
diff changeset
   195
                    before = len(store._all)
2273
228111491788 legacy: fix debugrecordpruneparents to call obsstore.create() with keywords
Yuya Nishihara <yuya@tcha.org>
parents: 2122
diff changeset
   196
                    store.create(tr, prec=mark[0], succs=mark[1], flag=mark[2],
228111491788 legacy: fix debugrecordpruneparents to call obsstore.create() with keywords
Yuya Nishihara <yuya@tcha.org>
parents: 2122
diff changeset
   197
                                 metadata=dict(mark[3]), parents=parents)
2122
efc6633e78e1 legacy: move 'debugrecordpruneparents' in the extensions
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 2070
diff changeset
   198
                    if len(store._all) - before:
4814
48b30ff742cb python3: use format-source to run byteify-strings in .py files
Raphaël Gomès <rgomes@octobus.net>
parents: 4808
diff changeset
   199
                        ui.write(_(b'created new markers for %i\n') % rev)
2122
efc6633e78e1 legacy: move 'debugrecordpruneparents' in the extensions
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 2070
diff changeset
   200
            ui.progress(pgop, idx, total=pgtotal)
efc6633e78e1 legacy: move 'debugrecordpruneparents' in the extensions
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 2070
diff changeset
   201
        tr.close()
efc6633e78e1 legacy: move 'debugrecordpruneparents' in the extensions
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 2070
diff changeset
   202
        ui.progress(pgop, None)
efc6633e78e1 legacy: move 'debugrecordpruneparents' in the extensions
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 2070
diff changeset
   203
    finally:
efc6633e78e1 legacy: move 'debugrecordpruneparents' in the extensions
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 2070
diff changeset
   204
        lockmod.release(tr, lock, wlock)