changeset 6636:7f95546f584e

evolve: remove legacy.py that provided debugconvertobsolete It's not very useful nowadays because the old obsmarkers format was before Mercurial 2.3 and it's pretty safe to say we're not going to see any repo from that era that people tried to use safe history rewriting and still didn't upgrade it. Additionally, legacy.py was excluded from packages, so it was only easy to use for evolve developers and contributors.
author Anton Shestakov <av6@dwimlabs.net>
date Thu, 04 Jan 2024 13:33:28 -0300
parents 6940272bc07d
children 8a51498b9976
files CHANGELOG MANIFEST.in debian/source/options hgext3rd/evolve/legacy.py tests/test-check-sdist.t tests/test-oldconvert.t
diffstat 6 files changed, 7 insertions(+), 315 deletions(-) [+]
line wrap: on
line diff
--- a/CHANGELOG	Wed Jan 03 13:56:27 2024 -0300
+++ b/CHANGELOG	Thu Jan 04 13:33:28 2024 -0300
@@ -1,6 +1,12 @@
 Changelog
 =========
 
+11.2.0 - in progress
+--------------------
+
+  * evolve: remove legacy.py that could be used to "detect and convert
+    prehistoric format of obsolete markers" (older than Mercurial 2.3)
+
 11.1.0 -- 2023-10-23
 --------------------
 
--- a/MANIFEST.in	Wed Jan 03 13:56:27 2024 -0300
+++ b/MANIFEST.in	Thu Jan 04 13:33:28 2024 -0300
@@ -19,11 +19,9 @@
 
 exclude docs/tutorial/.netlify
 exclude .gitlab-ci.yml
-exclude hgext3rd/evolve/legacy.py
 exclude .hg-format-source
 exclude Makefile
 exclude tests/test-drop.t
-exclude tests/test-oldconvert.t
 
 prune contrib
 prune debian
--- a/debian/source/options	Wed Jan 03 13:56:27 2024 -0300
+++ b/debian/source/options	Thu Jan 04 13:33:28 2024 -0300
@@ -1,1 +1,1 @@
-extend-diff-ignore = "^(contrib/|\.gitlab/|\.gitlab-ci.yml|\.hg-format-source|MANIFEST|Makefile|docs/tutorial/\.netlify|hgext3rd/evolve/hack/|tests/\.testtimes|tests/test-drop\.t|tests/test-oldconvert\.t)"
+extend-diff-ignore = "^(contrib/|\.gitlab/|\.gitlab-ci.yml|\.hg-format-source|MANIFEST|Makefile|docs/tutorial/\.netlify|hgext3rd/evolve/hack/|tests/\.testtimes|tests/test-drop\.t)"
--- a/hgext3rd/evolve/legacy.py	Wed Jan 03 13:56:27 2024 -0300
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,204 +0,0 @@
-# Copyright 2011 Pierre-Yves David <pierre-yves.david@ens-lyon.org>
-#                Logilab SA        <contact@logilab.fr>
-#
-# This software may be used and distributed according to the terms of the
-# GNU General Public License version 2 or any later version.
-"""Deprecated extension that formerly introduced "Changeset Obsolescence".
-
-This concept is now partially in Mercurial core (starting with Mercurial 2.3).
-The remaining logic has been grouped with the evolve extension.
-
-Some code remains 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.
-"""
-
-from mercurial import error
-
-import sys
-import json
-
-from mercurial.i18n import _
-from mercurial import lock as lockmod
-from mercurial.node import bin, nullid
-from mercurial import registrar
-from mercurial import util
-
-try:
-    from mercurial.utils.dateutil import makedate
-except ImportError:
-    # compat with hg < 4.6
-    from mercurial.util import makedate
-
-commandfunc = registrar.command
-
-#####################################################################
-### Older format management                                       ###
-#####################################################################
-
-# Code related to detection and management of older legacy format never
-# handled by core
-
-
-def reposetup(ui, repo):
-    """Detect that a repo still contains some old obsolete format
-    """
-    if not repo.local():
-        return
-    evolveopts = ui.configlist(b'experimental', b'evolution')
-    if not evolveopts:
-        evolveopts = b'all'
-        ui.setconfig(b'experimental', b'evolution', evolveopts)
-    for arg in sys.argv:
-        if r'debugc' in arg:
-            break
-    else:
-        data = repo.vfs.tryread(b'obsolete-relations')
-        if not data:
-            data = repo.svfs.tryread(b'obsoletemarkers')
-        if data:
-            raise error.Abort(b'old format of obsolete marker detected!\n'
-                              b'run `hg debugconvertobsolete` once.')
-
-def _obsdeserialize(flike):
-    """read a file like object serialized with _obsserialize
-
-    this deserialize into a {subject -> objects} mapping
-
-    this was the very first format ever."""
-    rels = {}
-    for line in flike:
-        subhex, objhex = line.split()
-        subnode = bin(subhex)
-        if subnode == nullid:
-            subnode = None
-        rels.setdefault(subnode, set()).add(bin(objhex))
-    return rels
-
-cmdtable = {}
-command = commandfunc(cmdtable)
-@command(b'debugconvertobsolete', [], b'')
-def cmddebugconvertobsolete(ui, repo):
-    """import markers from an .hg/obsolete-relations file"""
-    cnt = 0
-    err = 0
-    lock = repo.lock()
-    some = False
-    try:
-        unlink = []
-        tr = repo.transaction(b'convert-obsolete')
-        try:
-            repo._importoldobsolete = True
-            store = repo.obsstore
-            ### very first format
-            try:
-                f = repo.vfs(b'obsolete-relations')
-                try:
-                    some = True
-                    for line in f:
-                        subhex, objhex = line.split()
-                        suc = bin(subhex)
-                        prec = bin(objhex)
-                        sucs = (suc == nullid) and [] or [suc]
-                        meta = {
-                            b'date': b'%i %i' % makedate(),
-                            b'user': ui.username(),
-                            }
-                        try:
-                            store.create(tr, prec, sucs, 0, metadata=meta)
-                            cnt += 1
-                        except ValueError:
-                            repo.ui.write_err(b"invalid old marker line: %s"
-                                              % (line))
-                            err += 1
-                finally:
-                    f.close()
-                unlink.append(repo.vfs.join(b'obsolete-relations'))
-            except IOError:
-                pass
-            ### second (json) format
-            data = repo.svfs.tryread(b'obsoletemarkers')
-            if data:
-                some = True
-                for oldmark in json.loads(data):
-                    del oldmark[r'id']  # dropped for now
-                    del oldmark[r'reason']  # unused until then
-                    oldobject = str(oldmark.pop(r'object'))
-                    oldsubjects = [str(s) for s in oldmark.pop(r'subjects', [])]
-                    lookup_errors = (error.RepoLookupError, error.LookupError)
-                    if len(oldobject) != 40:
-                        try:
-                            oldobject = repo[oldobject].node()
-                        except lookup_errors:
-                            pass
-                    if any(len(s) != 40 for s in oldsubjects):
-                        try:
-                            oldsubjects = [repo[s].node() for s in oldsubjects]
-                        except lookup_errors:
-                            pass
-
-                    oldmark[r'date'] = r'%i %i' % tuple(oldmark[r'date'])
-                    meta = dict((k.encode('utf-8'), v.encode('utf-8'))
-                                for k, v in oldmark.items())
-                    try:
-                        succs = [bin(n) for n in oldsubjects]
-                        succs = [n for n in succs if n != nullid]
-                        store.create(tr, bin(oldobject), succs,
-                                     0, metadata=meta)
-                        cnt += 1
-                    except ValueError:
-                        msg = b"invalid marker %s -> %s\n"
-                        msg %= (oldobject, oldsubjects)
-                        repo.ui.write_err(msg)
-                        err += 1
-                unlink.append(repo.svfs.join(b'obsoletemarkers'))
-            tr.close()
-            for path in unlink:
-                util.unlink(path)
-        finally:
-            tr.release()
-    finally:
-        del repo._importoldobsolete
-        lock.release()
-    if not some:
-        ui.warn(_(b'nothing to do\n'))
-    ui.status(b'%i obsolete marker converted\n' % cnt)
-    if err:
-        ui.write_err(b'%i conversion failed. check you graph!\n' % err)
-
-@command(b'debugrecordpruneparents', [], b'')
-def cmddebugrecordpruneparents(ui, repo):
-    """add parent data to prune markers when possible
-
-    This command searches the repo for prune markers without parent information.
-    If the pruned node is locally known, it creates a new marker with parent
-    data.
-    """
-    pgop = b'reading markers'
-
-    # lock from the beginning to prevent race
-    wlock = lock = tr = None
-    try:
-        wlock = repo.wlock()
-        lock = repo.lock()
-        tr = repo.transaction(b'recordpruneparents')
-        unfi = repo.unfiltered()
-        nm = unfi.changelog.nodemap
-        store = repo.obsstore
-        pgtotal = len(store._all)
-        for idx, mark in enumerate(list(store._all)):
-            if not mark[1]:
-                rev = nm.get(mark[0])
-                if rev is not None:
-                    ctx = unfi[rev]
-                    parents = tuple(p.node() for p in ctx.parents())
-                    before = len(store._all)
-                    store.create(tr, prec=mark[0], succs=mark[1], flag=mark[2],
-                                 metadata=dict(mark[3]), parents=parents)
-                    if len(store._all) - before:
-                        ui.write(_(b'created new markers for %i\n') % rev)
-            ui.progress(pgop, idx, total=pgtotal)
-        tr.close()
-        ui.progress(pgop, None)
-    finally:
-        lockmod.release(tr, lock, wlock)
--- a/tests/test-check-sdist.t	Wed Jan 03 13:56:27 2024 -0300
+++ b/tests/test-check-sdist.t	Thu Jan 04 13:33:28 2024 -0300
@@ -58,7 +58,5 @@
 
   $ egrep '(gitlab|contrib|hack|format-source)' files
   [1]
-  $ fgrep legacy.py files
-  [1]
   $ fgrep netlify files
   [1]
--- a/tests/test-oldconvert.t	Wed Jan 03 13:56:27 2024 -0300
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,106 +0,0 @@
-  $ cat >> $HGRCPATH <<EOF
-  > [extensions]
-  > EOF
-  $ mkcommit() {
-  >    echo "$1" > "$1"
-  >    hg add "$1"
-  >    hg ci -m "add $1"
-  > }
-
-create commit
-
-  $ hg init repo
-  $ cd repo
-  $ mkcommit a
-  $ mkcommit b
-  $ hg up -q 0
-  $ mkcommit c
-  created new head
-
-forge old style relation files
-
-  $ hg log -r 2 --template='{node} ' > .hg/obsolete-relations
-  $ hg log -r 1 --template='{node}' >> .hg/obsolete-relations
-
-enable the extensions
-
-  $ echo "obsolete=$(echo $(dirname $TESTDIR))/hgext3rd/evolve/legacy.py" >> $HGRCPATH
-
-  $ hg log -G
-  abort: old format of obsolete marker detected!
-  run `hg debugconvertobsolete` once.
-  [255]
-  $ hg debugconvertobsolete --traceback
-  1 obsolete marker converted
-  $ hg log -G
-  @  changeset:   2:d67cd0334eee
-  |  tag:         tip
-  |  parent:      0:1f0dee641bb7
-  |  user:        test
-  |  date:        Thu Jan 01 00:00:00 1970 +0000
-  |  summary:     add c
-  |
-  o  changeset:   0:1f0dee641bb7
-     user:        test
-     date:        Thu Jan 01 00:00:00 1970 +0000
-     summary:     add a
-  
-  $ hg debugobsolete
-  7c3bad9141dcb46ff89abf5f61856facd56e476c d67cd0334eeecfded222fed9009f0db4beb57585 0 (*) {'user': 'test'} (glob)
-  $ hg debugconvertobsolete
-  nothing to do
-  0 obsolete marker converted
-
-Convert json
-
-  $ cat > .hg/store/obsoletemarkers << EOF
-  > [
-  >     {
-  >         "reason": "import from older format.", 
-  >         "subjects": [
-  >             "3218406b50ed13480765e7c260669620f37fba6e"
-  >         ], 
-  >         "user": "Pierre-Yves David <pierre-yves.david@ens-lyon.org>", 
-  >         "date": [
-  >             1336503323.9768269, 
-  >             -7200
-  >         ], 
-  >         "object": "3e03d82708d4da97a92158558dd13386d8f09ad5", 
-  >         "id": "4743f676eaf3923cb98c921ee06b2e91052c365b"
-  >     }, 
-  >     {
-  >         "reason": "import from older format.", 
-  >         "user": "Pierre-Yves David <pierre-yves.david@logilab.fr>", 
-  >         "date": [
-  >             1336557472.7875929, 
-  >             -7200
-  >         ], 
-  >         "object": "5c722672795c3a2cb94d0cc9a821c394c1475f87", 
-  >         "id": "1fd90a84b7225d2e3062b7e1b3100aa2e060fc72"
-  >     }, 
-  >     {
-  >         "reason": "import from older format.", 
-  >         "subjects": [
-  >             "0000000000000000000000000000000000000000"
-  >         ], 
-  >         "user": "Pierre-Yves David <pierre-yves.david@logilab.fr>", 
-  >         "date": [
-  >             1336557472.784307, 
-  >             -7200
-  >         ], 
-  >         "object": "2c3784e102bb34ccc93862af5bd6d609ee30c577", 
-  >         "id": "7d940c5ee1f886c8a6c0d805b43e522cb3ef7a15"
-  >     }
-  > ]
-  > EOF
-  $ hg log -G
-  abort: old format of obsolete marker detected!
-  run `hg debugconvertobsolete` once.
-  [255]
-  $ hg debugconvertobsolete --traceback
-  3 obsolete marker converted
-  $ hg debugobsolete
-  7c3bad9141dcb46ff89abf5f61856facd56e476c d67cd0334eeecfded222fed9009f0db4beb57585 0 (*) {'user': 'test'} (glob)
-  3e03d82708d4da97a92158558dd13386d8f09ad5 3218406b50ed13480765e7c260669620f37fba6e 0 (Tue May 08 20:55:23 2012 +0200) {'user': 'Pierre-Yves David <pierre-yves.david@ens-lyon.org>'}
-  5c722672795c3a2cb94d0cc9a821c394c1475f87 0 (Wed May 09 11:57:52 2012 +0200) {'user': 'Pierre-Yves David <pierre-yves.david@logilab.fr>'}
-  2c3784e102bb34ccc93862af5bd6d609ee30c577 0 (Wed May 09 11:57:52 2012 +0200) {'user': 'Pierre-Yves David <pierre-yves.david@logilab.fr>'}