Mercurial > hg-stable
changeset 17071:11f26e2669aa
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
author | Pierre-Yves.David@ens-lyon.org |
---|---|
date | Thu, 07 Jun 2012 19:15:23 +0200 |
parents | ad0d6c2b3279 |
children | 517af63ba382 |
files | mercurial/commands.py mercurial/obsolete.py tests/test-debugcomplete.t tests/test-obsolete.t |
diffstat | 4 files changed, 83 insertions(+), 0 deletions(-) [+] |
line wrap: on
line diff
--- a/mercurial/commands.py Thu Jun 07 19:07:39 2012 +0200 +++ b/mercurial/commands.py Thu Jun 07 19:15:23 2012 +0200 @@ -2049,6 +2049,21 @@ 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
--- a/mercurial/obsolete.py Thu Jun 07 19:07:39 2012 +0200 +++ b/mercurial/obsolete.py Thu Jun 07 19:15:23 2012 +0200 @@ -135,6 +135,23 @@ 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
--- a/tests/test-debugcomplete.t Thu Jun 07 19:07:39 2012 +0200 +++ b/tests/test-debugcomplete.t Thu Jun 07 19:15:23 2012 +0200 @@ -86,6 +86,7 @@ debugindexdot debuginstall debugknown + debugobsolete debugpushkey debugpvec debugrebuildstate @@ -236,6 +237,7 @@ debugindexdot: debuginstall: debugknown: + debugobsolete: date, user debugpushkey: debugpvec: debugrebuildstate: rev
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/tests/test-obsolete.t Thu Jun 07 19:15:23 2012 +0200 @@ -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`