Add some basic init functionality.
author |
Steve Losh <steve@stevelosh.com> |
date |
Sun, 04 Oct 2009 13:23:09 -0400 |
parents |
caef886ce739 |
children |
c68fc0a81e6e |
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
'''
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', 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')
}