Mercurial > public > mercurial-scm > hg-stable
comparison mercurial/commands.py @ 17922:7f5dab94e48c
bookmarks: introduce a bmstore to manage bookmark persistence
Bookmarks persistence still showed a fair amount of its legacy as a
monkeypatching extension. This encapsulates all bookmarks
serialization and parsing in a single class, and offers a single
location where other bookmarks storage engines can be substituted
in. As a result, many files no longer import the bookmarks module,
which strikes me as an encapsulation win.
This doesn't do anything to the current bookmark state yet, but I'm
hoping put that in the bmstore class as well.
author | Augie Fackler <raf@durin42.com> |
---|---|
date | Wed, 07 Nov 2012 16:21:39 -0600 |
parents | 7a3de6c23f6d |
children | 1e6b5faf9d4e |
comparison
equal
deleted
inserted
replaced
17921:4ac9cf3d810c | 17922:7f5dab94e48c |
---|---|
819 if mark not in marks: | 819 if mark not in marks: |
820 raise util.Abort(_("bookmark '%s' does not exist") % mark) | 820 raise util.Abort(_("bookmark '%s' does not exist") % mark) |
821 if mark == repo._bookmarkcurrent: | 821 if mark == repo._bookmarkcurrent: |
822 bookmarks.setcurrent(repo, None) | 822 bookmarks.setcurrent(repo, None) |
823 del marks[mark] | 823 del marks[mark] |
824 bookmarks.write(repo) | 824 marks.write() |
825 | 825 |
826 elif rename: | 826 elif rename: |
827 if mark is None: | 827 if mark is None: |
828 raise util.Abort(_("new bookmark name required")) | 828 raise util.Abort(_("new bookmark name required")) |
829 mark = checkformat(mark) | 829 mark = checkformat(mark) |
832 checkconflict(repo, mark, force) | 832 checkconflict(repo, mark, force) |
833 marks[mark] = marks[rename] | 833 marks[mark] = marks[rename] |
834 if repo._bookmarkcurrent == rename and not inactive: | 834 if repo._bookmarkcurrent == rename and not inactive: |
835 bookmarks.setcurrent(repo, mark) | 835 bookmarks.setcurrent(repo, mark) |
836 del marks[rename] | 836 del marks[rename] |
837 bookmarks.write(repo) | 837 marks.write() |
838 | 838 |
839 elif mark is not None: | 839 elif mark is not None: |
840 mark = checkformat(mark) | 840 mark = checkformat(mark) |
841 if inactive and mark == repo._bookmarkcurrent: | 841 if inactive and mark == repo._bookmarkcurrent: |
842 bookmarks.setcurrent(repo, None) | 842 bookmarks.setcurrent(repo, None) |
846 marks[mark] = scmutil.revsingle(repo, rev).node() | 846 marks[mark] = scmutil.revsingle(repo, rev).node() |
847 else: | 847 else: |
848 marks[mark] = cur | 848 marks[mark] = cur |
849 if not inactive and cur == marks[mark]: | 849 if not inactive and cur == marks[mark]: |
850 bookmarks.setcurrent(repo, mark) | 850 bookmarks.setcurrent(repo, mark) |
851 bookmarks.write(repo) | 851 marks.write() |
852 | 852 |
853 # Same message whether trying to deactivate the current bookmark (-i | 853 # Same message whether trying to deactivate the current bookmark (-i |
854 # with no NAME) or listing bookmarks | 854 # with no NAME) or listing bookmarks |
855 elif len(marks) == 0: | 855 elif len(marks) == 0: |
856 ui.status(_("no bookmarks set\n")) | 856 ui.status(_("no bookmarks set\n")) |
1319 ui.status(_("nothing changed\n")) | 1319 ui.status(_("nothing changed\n")) |
1320 return 1 | 1320 return 1 |
1321 elif marks: | 1321 elif marks: |
1322 ui.debug('moving bookmarks %r from %s to %s\n' % | 1322 ui.debug('moving bookmarks %r from %s to %s\n' % |
1323 (marks, old.hex(), hex(node))) | 1323 (marks, old.hex(), hex(node))) |
1324 newmarks = repo._bookmarks | |
1324 for bm in marks: | 1325 for bm in marks: |
1325 repo._bookmarks[bm] = node | 1326 newmarks[bm] = node |
1326 if bm == current: | 1327 if bm == current: |
1327 bookmarks.setcurrent(repo, bm) | 1328 bookmarks.setcurrent(repo, bm) |
1328 bookmarks.write(repo) | 1329 newmarks.write() |
1329 else: | 1330 else: |
1330 e = cmdutil.commiteditor | 1331 e = cmdutil.commiteditor |
1331 if opts.get('force_editor'): | 1332 if opts.get('force_editor'): |
1332 e = cmdutil.commitforceeditor | 1333 e = cmdutil.commitforceeditor |
1333 | 1334 |
4671 finally: | 4672 finally: |
4672 del repo._subtoppath | 4673 del repo._subtoppath |
4673 | 4674 |
4674 # update specified bookmarks | 4675 # update specified bookmarks |
4675 if opts.get('bookmark'): | 4676 if opts.get('bookmark'): |
4677 marks = repo._bookmarks | |
4676 for b in opts['bookmark']: | 4678 for b in opts['bookmark']: |
4677 # explicit pull overrides local bookmark if any | 4679 # explicit pull overrides local bookmark if any |
4678 ui.status(_("importing bookmark %s\n") % b) | 4680 ui.status(_("importing bookmark %s\n") % b) |
4679 repo._bookmarks[b] = repo[rb[b]].node() | 4681 marks[b] = repo[rb[b]].node() |
4680 bookmarks.write(repo) | 4682 marks.write() |
4681 | 4683 |
4682 return ret | 4684 return ret |
4683 | 4685 |
4684 @command('^push', | 4686 @command('^push', |
4685 [('f', 'force', None, _('force push')), | 4687 [('f', 'force', None, _('force push')), |