[PATCH 2 of 8] command: creation of obsolete marker
pierre-yves.david at logilab.fr
pierre-yves.david at logilab.fr
Thu Jun 7 17:24:53 UTC 2012
# HG changeset patch
# User Pierre-Yves.David at ens-lyon.org
# Date 1339089323 -7200
# Node ID e94318746f0c2c66e379e0290ea41b475d530f7c
# Parent 83d66f9957e9f73404c2c776fc3dbe5dce1c18e8
command: creation of obsolete marker
* add metadata encoding/decoding ability
* add a method to obsstore to help creating marker
* add a debug command to create marker
diff --git a/mercurial/commands.py b/mercurial/commands.py
--- a/mercurial/commands.py
+++ b/mercurial/commands.py
@@ -2047,10 +2047,25 @@ def debugknown(ui, repopath, *ids, **opt
if not repo.capable('known'):
raise util.Abort("known() not supported by target repository")
flags = repo.known([bin(s) for s in ids])
ui.write("%s\n" % ("".join([f and "1" or "0" for f in flags])))
+ at command('debugobsolete', [] + commitopts2,
+ _('OBSOLETED [REPLACEMENT] [REPL...'))
+def debugobsolete(ui, repo, precursor, *successors, **opts):
+ """create arbitrary obsolete marker"""
+ metadata = {}
+ if 'date' in opts:
+ metadata['date'] = opts['date']
+ metadata['user'] = opts['user'] or ui.username()
+ succs = tuple(bin(succ) for succ in successors)
+ l = repo.lock()
+ try:
+ repo.obsstore.create(bin(precursor), succs, 0, metadata)
+ finally:
+ l.release()
+
@command('debugpushkey', [], _('REPO NAMESPACE [KEY OLD NEW]'))
def debugpushkey(ui, repopath, namespace, *keyinfo, **opts):
'''access the pushkey key/value protocol
With two args, list the keys in the given namespace.
diff --git a/mercurial/obsolete.py b/mercurial/obsolete.py
--- a/mercurial/obsolete.py
+++ b/mercurial/obsolete.py
@@ -133,10 +133,27 @@ class obsstore(object):
# new markers to serialize
self._new = []
self.precursors = {}
self.successors = {}
+ def create(self, prec, succs=(), flag=0, metadata=None):
+ """obsolete: add a new obsolete marker
+
+ * ensuring it is hashable
+ * check mandatory metadata
+ * encode metadata
+ """
+ if metadata is None:
+ metadata = {}
+ if len(prec) != 20:
+ raise ValueError(prec)
+ for succ in succs:
+ if len(succ) != 20:
+ raise ValueError(prec)
+ marker = (str(prec), tuple(succs), int(flag), encodemeta(metadata))
+ self.add(marker)
+
def add(self, marker):
"""Add a new marker to the store
This marker still needs to be written to disk"""
self._new.append(marker)
diff --git a/tests/test-debugcomplete.t b/tests/test-debugcomplete.t
--- a/tests/test-debugcomplete.t
+++ b/tests/test-debugcomplete.t
@@ -84,10 +84,11 @@ Show debug commands if there are no othe
debugignore
debugindex
debugindexdot
debuginstall
debugknown
+ debugobsolete
debugpushkey
debugpvec
debugrebuildstate
debugrename
debugrevlog
@@ -234,10 +235,11 @@ Show all commands + options
debugignore:
debugindex: changelog, manifest, format
debugindexdot:
debuginstall:
debugknown:
+ debugobsolete: date, user
debugpushkey:
debugpvec:
debugrebuildstate: rev
debugrename: rev
debugrevlog: changelog, manifest, dump
diff --git a/tests/test-obsolete.t b/tests/test-obsolete.t
new file mode 100644
--- /dev/null
+++ b/tests/test-obsolete.t
@@ -0,0 +1,49 @@
+
+ $ mkcommit() {
+ > echo "$1" > "$1"
+ > hg add "$1"
+ > hg ci -m "add $1"
+ > }
+ $ getid() {
+ > hg id --debug -ir "desc('$1')"
+ > }
+
+
+ $ hg init tmpa
+ $ cd tmpa
+
+Killing a single changeset without replacement
+
+ $ mkcommit kill_me
+ $ hg debugobsolete -d '0 0' `getid kill_me` -u babar
+ $ cd ..
+
+Killing a single changeset with replacement
+
+ $ hg init tmpb
+ $ cd tmpb
+ $ mkcommit a
+ $ mkcommit b
+ $ mkcommit original_c
+ $ hg up "desc('b')"
+ 0 files updated, 0 files merged, 1 files removed, 0 files unresolved
+ $ mkcommit new_c
+ created new head
+ $ hg debugobsolete `getid original_c` `getid new_c` -d '56 12'
+
+do it again (it read the obsstore before adding new changeset)
+
+ $ hg up '.^'
+ 0 files updated, 0 files merged, 1 files removed, 0 files unresolved
+ $ mkcommit new_2_c
+ created new head
+ $ hg debugobsolete -d '1337 0' `getid new_c` `getid new_2_c`
+
+Register two markers with a missing node
+
+ $ hg up '.^'
+ 0 files updated, 0 files merged, 1 files removed, 0 files unresolved
+ $ mkcommit new_3_c
+ created new head
+ $ hg debugobsolete -d '1338 0' `getid new_2_c` 1337133713371337133713371337133713371337
+ $ hg debugobsolete -d '1339 0' 1337133713371337133713371337133713371337 `getid new_3_c`
More information about the Mercurial-devel
mailing list