# HG changeset patch # User Pierre-Yves.David@ens-lyon.org # Date 2012-06-07 17:15:23 # Node ID 11f26e2669aa416e85de9e785c3f55c79a75372b # Parent ad0d6c2b32798267b38c89d5fc858b9a42491176 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 @@ -2049,6 +2049,21 @@ def debugknown(ui, repopath, *ids, **opt flags = repo.known([bin(s) for s in ids]) ui.write("%s\n" % ("".join([f and "1" or "0" for f in flags]))) +@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 diff --git a/mercurial/obsolete.py b/mercurial/obsolete.py --- a/mercurial/obsolete.py +++ b/mercurial/obsolete.py @@ -135,6 +135,23 @@ class obsstore(object): 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 diff --git a/tests/test-debugcomplete.t b/tests/test-debugcomplete.t --- a/tests/test-debugcomplete.t +++ b/tests/test-debugcomplete.t @@ -86,6 +86,7 @@ Show debug commands if there are no othe debugindexdot debuginstall debugknown + debugobsolete debugpushkey debugpvec debugrebuildstate @@ -236,6 +237,7 @@ Show all commands + options debugindexdot: debuginstall: debugknown: + debugobsolete: date, user debugpushkey: debugpvec: debugrebuildstate: rev 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`