hgext/obsolete.py
author timeless@mozdev.org
Wed, 09 Sep 2015 22:13:11 -0400
changeset 1496 62aa11956a40
parent 1465 777e5c369d99
child 1550 e47dda53a5c2
permissions -rw-r--r--
evolve: _() should not contain %
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.
491
6989d8fe4ed2 merge evolve and obsolete
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 490
diff changeset
     6
"""Deprecated extension that formely introduces "Changeset Obsolescence".
69
aee53d546849 [obsolete] update doc
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 58
diff changeset
     7
491
6989d8fe4ed2 merge evolve and obsolete
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 490
diff changeset
     8
This concept is now partially in Mercurial core (starting with mercurial 2.3). The remaining logic have been grouped with the evolve extension.
69
aee53d546849 [obsolete] update doc
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 58
diff changeset
     9
491
6989d8fe4ed2 merge evolve and obsolete
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 490
diff changeset
    10
Some code cemains in this extensions to detect and convert prehistoric format of obsolete marker than early user may have create. Keep it enabled if you were such user.
69
aee53d546849 [obsolete] update doc
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 58
diff changeset
    11
"""
228
5a17c0d41a00 proof-read documentation and docstrings
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents: 226
diff changeset
    12
32
c27491be4431 obsolet: basic support (hide changeset)
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff changeset
    13
from mercurial import util
433
aa1255c2ac8f obsolete: move version checks at the start of the file
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 432
diff changeset
    14
aa1255c2ac8f obsolete: move version checks at the start of the file
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 432
diff changeset
    15
try:
aa1255c2ac8f obsolete: move version checks at the start of the file
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 432
diff changeset
    16
    from mercurial import obsolete
aa1255c2ac8f obsolete: move version checks at the start of the file
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 432
diff changeset
    17
except ImportError:
458
5d47d854716e obsolete: fix indentation in obsolete import block
Patrick Mezard <patrick@mezard.eu>
parents: 457
diff changeset
    18
    raise util.Abort('Obsolete extension requires Mercurial 2.3 (or later)')
433
aa1255c2ac8f obsolete: move version checks at the start of the file
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 432
diff changeset
    19
439
6cff54825233 obsolete: reorder import
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 438
diff changeset
    20
import sys
491
6989d8fe4ed2 merge evolve and obsolete
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 490
diff changeset
    21
import json
354
bd26eb9714fb obsolete: Detect conflicting changeset!
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 351
diff changeset
    22
491
6989d8fe4ed2 merge evolve and obsolete
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 490
diff changeset
    23
from mercurial import cmdutil
6989d8fe4ed2 merge evolve and obsolete
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 490
diff changeset
    24
from mercurial import error
6989d8fe4ed2 merge evolve and obsolete
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 490
diff changeset
    25
from mercurial.node import bin, nullid
39
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 38
diff changeset
    26
44
b243c10a5fbe Add pushkey support for pull and push
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 43
diff changeset
    27
430
07db1d511faf obsolete: move old format stuff at the end
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 429
diff changeset
    28
#####################################################################
07db1d511faf obsolete: move old format stuff at the end
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 429
diff changeset
    29
### Older format management                                       ###
07db1d511faf obsolete: move old format stuff at the end
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 429
diff changeset
    30
#####################################################################
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
    31
430
07db1d511faf obsolete: move old format stuff at the end
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 429
diff changeset
    32
# 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
    33
# 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
    34
32
c27491be4431 obsolet: basic support (hide changeset)
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff changeset
    35
491
6989d8fe4ed2 merge evolve and obsolete
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 490
diff changeset
    36
def reposetup(ui, repo):
459
3477326461e3 obsolete: more typos and cleanup
Patrick Mezard <patrick@mezard.eu>
parents: 458
diff changeset
    37
    """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
    38
    """
429
079b231b8ea4 obsolete: introduce an extension helper and use it
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 428
diff changeset
    39
    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
    40
        return
1216
a307eea46f96 oldobsolete: remove use of obsolete._enabled
Durham Goode <durham@fb.com>
parents: 1061
diff changeset
    41
    evolveopts = ui.configlist('experimental', 'evolution')
a307eea46f96 oldobsolete: remove use of obsolete._enabled
Durham Goode <durham@fb.com>
parents: 1061
diff changeset
    42
    if not evolveopts:
a307eea46f96 oldobsolete: remove use of obsolete._enabled
Durham Goode <durham@fb.com>
parents: 1061
diff changeset
    43
        evolveopts = 'all'
a307eea46f96 oldobsolete: remove use of obsolete._enabled
Durham Goode <durham@fb.com>
parents: 1061
diff changeset
    44
        ui.setconfig('experimental', 'evolution', evolveopts)
429
079b231b8ea4 obsolete: introduce an extension helper and use it
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 428
diff changeset
    45
    for arg in sys.argv:
079b231b8ea4 obsolete: introduce an extension helper and use it
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 428
diff changeset
    46
        if 'debugc' in arg:
079b231b8ea4 obsolete: introduce an extension helper and use it
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 428
diff changeset
    47
            break
079b231b8ea4 obsolete: introduce an extension helper and use it
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 428
diff changeset
    48
    else:
079b231b8ea4 obsolete: introduce an extension helper and use it
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 428
diff changeset
    49
        data = repo.opener.tryread('obsolete-relations')
079b231b8ea4 obsolete: introduce an extension helper and use it
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 428
diff changeset
    50
        if not data:
1465
777e5c369d99 compat: use svfs instead of sopener
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 1216
diff changeset
    51
            data = repo.svfs.tryread('obsoletemarkers')
429
079b231b8ea4 obsolete: introduce an extension helper and use it
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 428
diff changeset
    52
        if data:
079b231b8ea4 obsolete: introduce an extension helper and use it
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 428
diff changeset
    53
            raise util.Abort('old format of obsolete marker detected!\n'
079b231b8ea4 obsolete: introduce an extension helper and use it
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 428
diff changeset
    54
                             'run `hg debugconvertobsolete` once.')
70
af4f7ef0a3c1 [obsolete] extract serialization logic.
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 69
diff changeset
    55
af4f7ef0a3c1 [obsolete] extract serialization logic.
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 69
diff changeset
    56
def _obsdeserialise(flike):
74
c7dd26dec7fc [obsolete] update docstring
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 73
diff changeset
    57
    """read a file like object serialised with _obsserialise
c7dd26dec7fc [obsolete] update docstring
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 73
diff changeset
    58
454
4e34a723115b obsolete: more comment
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 453
diff changeset
    59
    this desierialize into a {subject -> objects} mapping
4e34a723115b obsolete: more comment
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 453
diff changeset
    60
4e34a723115b obsolete: more comment
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 453
diff changeset
    61
    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
    62
    rels = {}
af4f7ef0a3c1 [obsolete] extract serialization logic.
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 69
diff changeset
    63
    for line in flike:
af4f7ef0a3c1 [obsolete] extract serialization logic.
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 69
diff changeset
    64
        subhex, objhex = line.split()
80
5d029a358252 [obsolete] add kill support
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 79
diff changeset
    65
        subnode = bin(subhex)
5d029a358252 [obsolete] add kill support
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 79
diff changeset
    66
        if subnode == nullid:
5d029a358252 [obsolete] add kill support
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 79
diff changeset
    67
            subnode = None
5d029a358252 [obsolete] add kill support
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 79
diff changeset
    68
        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
    69
    return rels
af4f7ef0a3c1 [obsolete] extract serialization logic.
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 69
diff changeset
    70
441
d702f0d26c6a obsolete: remove debugsuccessors
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 440
diff changeset
    71
cmdtable = {}
d702f0d26c6a obsolete: remove debugsuccessors
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 440
diff changeset
    72
command = cmdutil.command(cmdtable)
276
f26e9bc5f7fc obsolete: use new-style command registration
Patrick Mezard <patrick@mezard.eu>
parents: 275
diff changeset
    73
@command('debugconvertobsolete', [], '')
224
f60555898df4 new obsolete store
Pierre-Yves.David@ens-lyon.org
parents: 218
diff changeset
    74
def cmddebugconvertobsolete(ui, repo):
278
fa0b9b8a83c0 obsolete: add or fix debug commands help
Patrick Mezard <patrick@mezard.eu>
parents: 277
diff changeset
    75
    """import markers from an .hg/obsolete-relations file"""
224
f60555898df4 new obsolete store
Pierre-Yves.David@ens-lyon.org
parents: 218
diff changeset
    76
    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
    77
    err = 0
224
f60555898df4 new obsolete store
Pierre-Yves.David@ens-lyon.org
parents: 218
diff changeset
    78
    l = repo.lock()
334
fb83210bce32 obsolete: move to official binary format
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 332
diff changeset
    79
    some = False
224
f60555898df4 new obsolete store
Pierre-Yves.David@ens-lyon.org
parents: 218
diff changeset
    80
    try:
361
ac7969043677 obsolete: adapt to core: marker are written in transaction now
Pierre-Yves.David@ens-lyon.org
parents: 360
diff changeset
    81
        unlink = []
ac7969043677 obsolete: adapt to core: marker are written in transaction now
Pierre-Yves.David@ens-lyon.org
parents: 360
diff changeset
    82
        tr = repo.transaction('convert-obsolete')
224
f60555898df4 new obsolete store
Pierre-Yves.David@ens-lyon.org
parents: 218
diff changeset
    83
        try:
361
ac7969043677 obsolete: adapt to core: marker are written in transaction now
Pierre-Yves.David@ens-lyon.org
parents: 360
diff changeset
    84
            repo._importoldobsolete = True
ac7969043677 obsolete: adapt to core: marker are written in transaction now
Pierre-Yves.David@ens-lyon.org
parents: 360
diff changeset
    85
            store = repo.obsstore
ac7969043677 obsolete: adapt to core: marker are written in transaction now
Pierre-Yves.David@ens-lyon.org
parents: 360
diff changeset
    86
            ### very first format
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
                f = repo.opener('obsolete-relations')
ac7969043677 obsolete: adapt to core: marker are written in transaction now
Pierre-Yves.David@ens-lyon.org
parents: 360
diff changeset
    89
                try:
ac7969043677 obsolete: adapt to core: marker are written in transaction now
Pierre-Yves.David@ens-lyon.org
parents: 360
diff changeset
    90
                    some = True
ac7969043677 obsolete: adapt to core: marker are written in transaction now
Pierre-Yves.David@ens-lyon.org
parents: 360
diff changeset
    91
                    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
    92
                        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
    93
                        suc = bin(subhex)
ac7969043677 obsolete: adapt to core: marker are written in transaction now
Pierre-Yves.David@ens-lyon.org
parents: 360
diff changeset
    94
                        prec = bin(objhex)
ac7969043677 obsolete: adapt to core: marker are written in transaction now
Pierre-Yves.David@ens-lyon.org
parents: 360
diff changeset
    95
                        sucs = (suc==nullid) and [] or [suc]
ac7969043677 obsolete: adapt to core: marker are written in transaction now
Pierre-Yves.David@ens-lyon.org
parents: 360
diff changeset
    96
                        meta = {
ac7969043677 obsolete: adapt to core: marker are written in transaction now
Pierre-Yves.David@ens-lyon.org
parents: 360
diff changeset
    97
                            'date':  '%i %i' % util.makedate(),
ac7969043677 obsolete: adapt to core: marker are written in transaction now
Pierre-Yves.David@ens-lyon.org
parents: 360
diff changeset
    98
                            'user': ui.username(),
ac7969043677 obsolete: adapt to core: marker are written in transaction now
Pierre-Yves.David@ens-lyon.org
parents: 360
diff changeset
    99
                            }
ac7969043677 obsolete: adapt to core: marker are written in transaction now
Pierre-Yves.David@ens-lyon.org
parents: 360
diff changeset
   100
                        try:
1061
f3867e60d072 compat: always call metadata as a keyword argument
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 519
diff changeset
   101
                            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
   102
                            cnt += 1
ac7969043677 obsolete: adapt to core: marker are written in transaction now
Pierre-Yves.David@ens-lyon.org
parents: 360
diff changeset
   103
                        except ValueError:
ac7969043677 obsolete: adapt to core: marker are written in transaction now
Pierre-Yves.David@ens-lyon.org
parents: 360
diff changeset
   104
                            repo.ui.write_err("invalid old marker line: %s"
ac7969043677 obsolete: adapt to core: marker are written in transaction now
Pierre-Yves.David@ens-lyon.org
parents: 360
diff changeset
   105
                                              % (line))
ac7969043677 obsolete: adapt to core: marker are written in transaction now
Pierre-Yves.David@ens-lyon.org
parents: 360
diff changeset
   106
                            err += 1
ac7969043677 obsolete: adapt to core: marker are written in transaction now
Pierre-Yves.David@ens-lyon.org
parents: 360
diff changeset
   107
                finally:
ac7969043677 obsolete: adapt to core: marker are written in transaction now
Pierre-Yves.David@ens-lyon.org
parents: 360
diff changeset
   108
                    f.close()
ac7969043677 obsolete: adapt to core: marker are written in transaction now
Pierre-Yves.David@ens-lyon.org
parents: 360
diff changeset
   109
                unlink.append(repo.join('obsolete-relations'))
ac7969043677 obsolete: adapt to core: marker are written in transaction now
Pierre-Yves.David@ens-lyon.org
parents: 360
diff changeset
   110
            except IOError:
ac7969043677 obsolete: adapt to core: marker are written in transaction now
Pierre-Yves.David@ens-lyon.org
parents: 360
diff changeset
   111
                pass
ac7969043677 obsolete: adapt to core: marker are written in transaction now
Pierre-Yves.David@ens-lyon.org
parents: 360
diff changeset
   112
            ### second (json) format
1465
777e5c369d99 compat: use svfs instead of sopener
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 1216
diff changeset
   113
            data = repo.svfs.tryread('obsoletemarkers')
334
fb83210bce32 obsolete: move to official binary format
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 332
diff changeset
   114
            if data:
fb83210bce32 obsolete: move to official binary format
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 332
diff changeset
   115
                some = True
361
ac7969043677 obsolete: adapt to core: marker are written in transaction now
Pierre-Yves.David@ens-lyon.org
parents: 360
diff changeset
   116
                for oldmark in json.loads(data):
ac7969043677 obsolete: adapt to core: marker are written in transaction now
Pierre-Yves.David@ens-lyon.org
parents: 360
diff changeset
   117
                    del oldmark['id']  # dropped for now
ac7969043677 obsolete: adapt to core: marker are written in transaction now
Pierre-Yves.David@ens-lyon.org
parents: 360
diff changeset
   118
                    del oldmark['reason']  # unused until then
ac7969043677 obsolete: adapt to core: marker are written in transaction now
Pierre-Yves.David@ens-lyon.org
parents: 360
diff changeset
   119
                    oldobject = str(oldmark.pop('object'))
ac7969043677 obsolete: adapt to core: marker are written in transaction now
Pierre-Yves.David@ens-lyon.org
parents: 360
diff changeset
   120
                    oldsubjects = [str(s) for s in oldmark.pop('subjects', [])]
ac7969043677 obsolete: adapt to core: marker are written in transaction now
Pierre-Yves.David@ens-lyon.org
parents: 360
diff changeset
   121
                    LOOKUP_ERRORS = (error.RepoLookupError, error.LookupError)
ac7969043677 obsolete: adapt to core: marker are written in transaction now
Pierre-Yves.David@ens-lyon.org
parents: 360
diff changeset
   122
                    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
   123
                        try:
ac7969043677 obsolete: adapt to core: marker are written in transaction now
Pierre-Yves.David@ens-lyon.org
parents: 360
diff changeset
   124
                            oldobject = repo[oldobject].node()
ac7969043677 obsolete: adapt to core: marker are written in transaction now
Pierre-Yves.David@ens-lyon.org
parents: 360
diff changeset
   125
                        except LOOKUP_ERRORS:
ac7969043677 obsolete: adapt to core: marker are written in transaction now
Pierre-Yves.David@ens-lyon.org
parents: 360
diff changeset
   126
                            pass
ac7969043677 obsolete: adapt to core: marker are written in transaction now
Pierre-Yves.David@ens-lyon.org
parents: 360
diff changeset
   127
                    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
   128
                        try:
ac7969043677 obsolete: adapt to core: marker are written in transaction now
Pierre-Yves.David@ens-lyon.org
parents: 360
diff changeset
   129
                            oldsubjects = [repo[s].node() 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
   130
                        except LOOKUP_ERRORS:
ac7969043677 obsolete: adapt to core: marker are written in transaction now
Pierre-Yves.David@ens-lyon.org
parents: 360
diff changeset
   131
                            pass
224
f60555898df4 new obsolete store
Pierre-Yves.David@ens-lyon.org
parents: 218
diff changeset
   132
361
ac7969043677 obsolete: adapt to core: marker are written in transaction now
Pierre-Yves.David@ens-lyon.org
parents: 360
diff changeset
   133
                    oldmark['date'] = '%i %i' % tuple(oldmark['date'])
ac7969043677 obsolete: adapt to core: marker are written in transaction now
Pierre-Yves.David@ens-lyon.org
parents: 360
diff changeset
   134
                    meta = dict((k.encode('utf-8'), v.encode('utf-8'))
ac7969043677 obsolete: adapt to core: marker are written in transaction now
Pierre-Yves.David@ens-lyon.org
parents: 360
diff changeset
   135
                                 for k, v in oldmark.iteritems())
341
7653f80fd7a4 obsolete: harden convertion from first format
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 340
diff changeset
   136
                    try:
361
ac7969043677 obsolete: adapt to core: marker are written in transaction now
Pierre-Yves.David@ens-lyon.org
parents: 360
diff changeset
   137
                        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
   138
                        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
   139
                        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
   140
                                     0, metadata=meta)
341
7653f80fd7a4 obsolete: harden convertion from first format
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 340
diff changeset
   141
                        cnt += 1
7653f80fd7a4 obsolete: harden convertion from first format
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 340
diff changeset
   142
                    except ValueError:
361
ac7969043677 obsolete: adapt to core: marker are written in transaction now
Pierre-Yves.David@ens-lyon.org
parents: 360
diff changeset
   143
                        repo.ui.write_err("invalid marker %s -> %s\n"
ac7969043677 obsolete: adapt to core: marker are written in transaction now
Pierre-Yves.David@ens-lyon.org
parents: 360
diff changeset
   144
                                     % (oldobject, oldsubjects))
341
7653f80fd7a4 obsolete: harden convertion from first format
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 340
diff changeset
   145
                        err += 1
361
ac7969043677 obsolete: adapt to core: marker are written in transaction now
Pierre-Yves.David@ens-lyon.org
parents: 360
diff changeset
   146
                unlink.append(repo.sjoin('obsoletemarkers'))
ac7969043677 obsolete: adapt to core: marker are written in transaction now
Pierre-Yves.David@ens-lyon.org
parents: 360
diff changeset
   147
            tr.close()
ac7969043677 obsolete: adapt to core: marker are written in transaction now
Pierre-Yves.David@ens-lyon.org
parents: 360
diff changeset
   148
            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
   149
                util.unlink(path)
ac7969043677 obsolete: adapt to core: marker are written in transaction now
Pierre-Yves.David@ens-lyon.org
parents: 360
diff changeset
   150
        finally:
ac7969043677 obsolete: adapt to core: marker are written in transaction now
Pierre-Yves.David@ens-lyon.org
parents: 360
diff changeset
   151
            tr.release()
224
f60555898df4 new obsolete store
Pierre-Yves.David@ens-lyon.org
parents: 218
diff changeset
   152
    finally:
f60555898df4 new obsolete store
Pierre-Yves.David@ens-lyon.org
parents: 218
diff changeset
   153
        del repo._importoldobsolete
f60555898df4 new obsolete store
Pierre-Yves.David@ens-lyon.org
parents: 218
diff changeset
   154
        l.release()
334
fb83210bce32 obsolete: move to official binary format
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 332
diff changeset
   155
    if not some:
fb83210bce32 obsolete: move to official binary format
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 332
diff changeset
   156
            ui.warn('nothing to do\n')
224
f60555898df4 new obsolete store
Pierre-Yves.David@ens-lyon.org
parents: 218
diff changeset
   157
    ui.status('%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
   158
    if err:
ebfd1b96a013 obsolete: convert try to guess what invalid node id are
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 336
diff changeset
   159
        ui.write_err('%i conversion failed. check you graph!\n' % err)