--- a/review.py Sun Oct 04 14:21:54 2009 -0400
+++ /dev/null Thu Jan 01 00:00:00 1970 +0000
@@ -1,90 +0,0 @@
-from __future__ import with_statement
-
-'''A Mercurial extension for code reviewing changesets.
-'''
-
-import os
-from mercurial import cmdutil, hg, util
-
-
-class PreexistingDatastore(Exception):
- """Raised when trying to initialize a datastore when one seems to exist."""
- def __init__(self, committed):
- super(PreexistingDatastore, self).__init__()
- self.committed = committed
-
-
-
-def _parse_hgrf(repo):
- """Parse the .hgreview file and return the data inside."""
-
- data = {}
- lines = [line for line in repo['tip']['.hgreview'] if line.strip()]
- for line in lines:
- label, _, path = [i.strip() for i in line.partition('=')]
- if label == 'local':
- data['lpath'] = path
- elif label == 'remote':
- data['rpath'] = path
-
- return data
-
-
-class ReviewDatastore(dict):
- '''The data store for all the reviews so far.'''
-
- def __init__(self, ui, repo, lpath=None, rpath=None, create=False):
- if not create:
- data = _parse_hgrf(repo)
- self.lpath = data['lpath']
- self.rpath = data['rpath']
- else:
- if '.hgreview' in repo['tip']:
- raise PreexistingDatastore(True)
- if os.path.exists(os.path.join(repo.root, '.hgreview')):
- raise PreexistingDatastore(False)
- self.lpath = lpath or '.review'
- self.rpath = rpath or ('../%s-review' % os.path.basename(repo.root))
-
- root = os.path.join(repo.root, self.lpath)
- self.repo = hg.repository(ui, root, create)
-
- if create:
- hgrpath = os.path.join(repo.root, '.hgreview')
- with open(hgrpath, 'w') as hgrf:
- hgrf.write('local = %s\n' % self.lpath)
- hgrf.write('remote = %s\n' % self.rpath)
- repo.add(['.hgreview'])
-
-
-def review(ui, repo, *fnames, **opts):
- '''code review a changeset in the current repository
- '''
- if opts.pop('init'):
- ui.note('initializing the code review data store and config\n')
- try:
- datastore = ReviewDatastore(ui, repo, lpath=opts.pop('local_path'),
- rpath=opts.pop('remote_path'), create=True)
- ui.status('the review data has been initialized\n'
- 'run "hg commit .hgreview -m\'initialized code review\'" '
- 'to record it permanently\n')
- return
- except PreexistingDatastore, e:
- if e.committed:
- ui.note('already initialized by someone else\n')
- else:
- raise util.Abort(
- 'the review data has already been initialized, but '
- 'is not recorded!\n'
- 'run "hg commit .hgreview -m\'initialized code review\'" '
- 'to record it permanently\n')
-
-
-cmdtable = {
- 'review': (review, [
- ('i', 'init', False, 'start code reviewing this repository'),
- ('', 'local-path', '', 'the local path to the code review data'),
- ('', 'remote-path', '', 'the remote path to code review data'),
- ],
- 'hg review')
-}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/review/__init__.py Sun Oct 04 14:43:37 2009 -0400
@@ -0,0 +1,4 @@
+'''A Mercurial extension for code reviewing changesets.
+'''
+
+from extension_ui import *
\ No newline at end of file
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/review/data.py Sun Oct 04 14:43:37 2009 -0400
@@ -0,0 +1,60 @@
+from __future__ import with_statement
+
+'''The review data structures.
+'''
+
+import os
+from mercurial import hg
+
+
+class PreexistingDatastore(Exception):
+ """Raised when trying to initialize a datastore when one seems to exist."""
+ def __init__(self, committed):
+ super(PreexistingDatastore, self).__init__()
+ self.committed = committed
+
+
+
+def _parse_hgrf(repo):
+ """Parse the .hgreview file and return the data inside."""
+
+ data = {}
+ lines = [line for line in repo['tip']['.hgreview'] if line.strip()]
+ for line in lines:
+ label, _, path = [i.strip() for i in line.partition('=')]
+ if label == 'local':
+ data['lpath'] = path
+ elif label == 'remote':
+ data['rpath'] = path
+
+ return data
+
+
+class ReviewDatastore(dict):
+ '''The data store for all the reviews so far.'''
+
+ def __init__(self, ui, repo, lpath=None, rpath=None, create=False):
+ if not create:
+ data = _parse_hgrf(repo)
+ self.lpath = data['lpath']
+ self.rpath = data['rpath']
+ else:
+ if '.hgreview' in repo['tip']:
+ raise PreexistingDatastore(True)
+ if os.path.exists(os.path.join(repo.root, '.hgreview')):
+ raise PreexistingDatastore(False)
+ self.lpath = lpath or '.review'
+ self.rpath = rpath or ('../%s-review' % os.path.basename(repo.root))
+
+ root = os.path.join(repo.root, self.lpath)
+ self.repo = hg.repository(ui, root, create)
+
+ if create:
+ hgrpath = os.path.join(repo.root, '.hgreview')
+ with open(hgrpath, 'w') as hgrf:
+ hgrf.write('local = %s\n' % self.lpath)
+ hgrf.write('remote = %s\n' % self.rpath)
+ repo.add(['.hgreview'])
+
+
+
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/review/extension_ui.py Sun Oct 04 14:43:37 2009 -0400
@@ -0,0 +1,31 @@
+'''The review extension's UI.'''
+
+import messages
+from data import *
+from mercurial import util
+
+def review(ui, repo, *fnames, **opts):
+ '''code review a changeset in the current repository
+ '''
+ if opts.pop('init'):
+ ui.note(messages.INIT_START)
+ try:
+ datastore = ReviewDatastore(ui, repo, lpath=opts.pop('local_path'),
+ rpath=opts.pop('remote_path'), create=True)
+ ui.status(messages.INIT_SUCCESS)
+ return
+ except PreexistingDatastore, e:
+ if e.committed:
+ ui.note(messages.INIT_EXISTS_COMMITTED)
+ else:
+ raise util.Abort(messages.INIT_EXISTS_UNCOMMITTED)
+
+
+cmdtable = {
+ 'review': (review, [
+ ('i', 'init', False, 'start code reviewing this repository'),
+ ('', 'local-path', '', 'the local path to the code review data'),
+ ('', 'remote-path', '', 'the remote path to code review data'),
+ ],
+ 'hg review')
+}
\ No newline at end of file
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/review/messages.py Sun Oct 04 14:43:37 2009 -0400
@@ -0,0 +1,16 @@
+#!/usr/bin/env python
+
+INIT_START = '''initializing the code review data store and config
+'''
+
+INIT_SUCCESS = '''the review data has been initialized
+run "hg commit .hgreview -m'initialized code review'" to record it permanently
+'''
+
+INIT_EXISTS_COMMITTED = '''the review data was already initialized by someone else
+'''
+
+INIT_EXISTS_UNCOMMITTED = '''
+the review data has already been initialized, but is not recorded!
+run "hg commit .hgreview -m'initialized code review'" to record it permanently
+'''
\ No newline at end of file