# HG changeset patch # User Steve Losh # Date 1254676989 14400 # Node ID 475c9de60d4f905a828e65d2eb80db8569b3be42 # Parent caef886ce73946be5561c81f3df750df0afdbff4 Add some basic init functionality. diff -r caef886ce739 -r 475c9de60d4f review.py --- a/review.py Sun Oct 04 12:38:50 2009 -0400 +++ b/review.py Sun Oct 04 13:23:09 2009 -0400 @@ -1,15 +1,52 @@ +from __future__ import with_statement + '''A Mercurial extension for code reviewing changesets. ''' +import os +from mercurial import cmdutil, hg + def review(ui, repo, *fnames, **opts): '''code review a changeset in the current repository ''' - pass + if opts.pop('init'): + if '.hgreview' in repo['tip']: + ui.note('already initialized by someone else\n') + review_config = repo['tip']['.hgreview'] + elif os.path.exists(os.path.join(repo.root, '.hgreview')): + ui.warn('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') + else: + ui.note('initializing the code review data store and config\n') + + lpath = opts.pop('local_path') or '.review' + dspath = os.path.join(repo.root, lpath) + rpath = opts.pop('remote_path') + if not rpath: + rpath = '../%s-review' % os.path.basename(repo.root) + + ui.note('creating the datastore\n') + hg.repository(cmdutil.remoteui(ui, opts), dspath, create=1) + + ui.note('creating the .hgreview file\n') + hgrpath = os.path.join(repo.root, '.hgreview') + with open(hgrpath, 'w') as hgrf: + hgrf.write('local = %s\n' % lpath) + hgrf.write('remote = %s\n' % rpath) + repo.add([hgrpath]) + + ui.status('the review data has been initialized\n' + 'run "hg commit .hgreview -m\'initialized code review\'" ' + 'to record it permanently\n') cmdtable = { 'review': (review, [ - ('i', '--init', [], 'start code reviewing this repository'), + ('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') }