本文整理汇总了Python中mercurial.hg.repository函数的典型用法代码示例。如果您正苦于以下问题:Python repository函数的具体用法?Python repository怎么用?Python repository使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了repository函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: overview
def overview(ui, repo, source=None, **opts):
'''provides a general overview of your repository state
This command combines the output of the hg incomng, hg outgoing,
hg status, and hg id commands into an easily human-readable explanation
of the entire state of your current working repository.
'''
if not repo:
return
originurl = ui.expandpath(source or 'default')
targeturl = ui.expandpath(source or 'default-push', source or 'default')
origin, hashbranch = parseurl(originurl)
origin = hg.repository(remoteui(repo, opts), origin)
target, hashbranch = parseurl(targeturl)
target = hg.repository(remoteui(repo, opts), target)
if originurl == targeturl:
ui.status(_('parent repository: %s\n') % url.hidepassword(originurl))
else:
ui.status(_('source repository: %s\n') % url.hidepassword(getattr(origin, 'root', origin.url())))
ui.status(_('destination repository: %s\n') % url.hidepassword(getattr(target, 'root', target.url())))
ui.pushbuffer()
out = outgoing(repo, target)
inc = incoming(repo, origin, filter(bool, [hashbranch]))
ui.popbuffer()
changed = any(repo.status())
if changed:
status = _('uncommitted changes')
else:
status = _('working copy up-to-date')
# grab heads
heads = repo.branchheads(None, closed=False)
if len(heads) > 1:
merge = 'merge required'
else:
merge = ''
ui.status(_('| Remote | << %s | Local | %s\n') % (str(len(out)).center(5), merge))
ui.status(_('| Repository | %s >> | Repository | %s\n') % (str(len(inc)).center(5), status))
if opts['detail']:
if len(out) > 0:
ui.status(_('\noutgoing changes:\n'))
for rev in out:
ui.status('%s %s\n' % (repo[rev],
repo[rev].description().strip().split('\n')[0]))
if len(inc) > 0:
ui.status(_('\nincoming changes:\n'))
for rev in inc:
ui.status('%s %s\n' % (repo[rev],
repo[rev].description().strip().split('\n')[0]))
if changed:
ui.status(_('\nlocal files:\n'))
ui.pushbuffer()
commands.status(ui, repo, '', **opts)
status = ui.popbuffer()
for l in status.splitlines():
print ' %s' % l
示例2: __init__
def __init__(self, ui, path):
common.converter_sink.__init__(self, ui, path)
self.branchnames = ui.configbool('convert', 'hg.usebranchnames', True)
self.clonebranches = ui.configbool('convert', 'hg.clonebranches', False)
self.tagsbranch = ui.config('convert', 'hg.tagsbranch', 'default')
self.lastbranch = None
if os.path.isdir(path) and len(os.listdir(path)) > 0:
try:
self.repo = hg.repository(self.ui, path)
if not self.repo.local():
raise NoRepo(_('%s is not a local Mercurial repository')
% path)
except error.RepoError as err:
ui.traceback()
raise NoRepo(err.args[0])
else:
try:
ui.status(_('initializing destination %s repository\n') % path)
self.repo = hg.repository(self.ui, path, create=True)
if not self.repo.local():
raise NoRepo(_('%s is not a local Mercurial repository')
% path)
self.created.append(path)
except error.RepoError:
ui.traceback()
raise NoRepo(_("could not create hg repository %s as sink")
% path)
self.lock = None
self.wlock = None
self.filemapmode = False
self.subrevmaps = {}
示例3: validate_hg_url
def validate_hg_url(self, url):
error = _("Invalid Hg URL: '%s'") % url
source, branches = hg.parseurl(url)
try:
hg.repository(ui.ui(), source)
except RepoError:
raise forms.ValidationError(error)
示例4: launch
def launch(root='', files=[], cwd='', main=True):
u = ui.ui()
u.updateopts(debug=False, traceback=False)
repo = hg.repository(u, path=root)
# move cwd to repo root if repo is merged, so we can show
# all the changed files
if len(repo.workingctx().parents()) > 1 and repo.root != cwd:
cwd = repo.root
repo = hg.repository(u, path=cwd)
files = [cwd]
ct = repo.ui.config('tortoisehg', 'commit', 'internal')
if ct not in ['', 'internal']:
from hglib import thgdispatch
args = ['--repository', root, ct]
try:
ret = thgdispatch(repo.ui, args=args)
except SystemExit:
pass
return None
cmdoptions = {
'user':'', 'date':'',
'modified':True, 'added':True, 'removed':True, 'deleted':True,
'unknown':False, 'ignored':False,
'exclude':[], 'include':[],
'check': False, 'git':False, 'logfile':'', 'addremove':False,
}
dialog = GCommit(u, repo, cwd, files, cmdoptions, main)
dialog.display()
return dialog
示例5: get_repo
def get_repo(url, alias):
global peer
myui = ui.ui()
myui.setconfig('ui', 'interactive', 'off')
myui.fout = sys.stderr
if get_config_bool('remote-hg.insecure'):
myui.setconfig('web', 'cacerts', '')
extensions.loadall(myui)
if hg.islocal(url) and not os.environ.get('GIT_REMOTE_HG_TEST_REMOTE'):
repo = hg.repository(myui, url)
if not os.path.exists(dirname):
os.makedirs(dirname)
else:
shared_path = os.path.join(gitdir, 'hg')
# check and upgrade old organization
hg_path = os.path.join(shared_path, '.hg')
if os.path.exists(shared_path) and not os.path.exists(hg_path):
repos = os.listdir(shared_path)
for x in repos:
local_hg = os.path.join(shared_path, x, 'clone', '.hg')
if not os.path.exists(local_hg):
continue
if not os.path.exists(hg_path):
shutil.move(local_hg, hg_path)
shutil.rmtree(os.path.join(shared_path, x, 'clone'))
# setup shared repo (if not there)
try:
hg.peer(myui, {}, shared_path, create=True)
except error.RepoError:
pass
if not os.path.exists(dirname):
os.makedirs(dirname)
local_path = os.path.join(dirname, 'clone')
if not os.path.exists(local_path):
hg.share(myui, shared_path, local_path, update=False)
else:
# make sure the shared path is always up-to-date
util.writefile(os.path.join(local_path, '.hg', 'sharedpath'), hg_path)
repo = hg.repository(myui, local_path)
try:
peer = hg.peer(myui, {}, url)
except:
die('Repository error')
repo.pull(peer, heads=None, force=True)
updatebookmarks(repo, peer)
return repo
示例6: get_repo_for_repository
def get_repo_for_repository(app, repository=None, repo_path=None):
# Import from mercurial here to let Galaxy start under Python 3
from mercurial import (
hg,
ui
)
if repository is not None:
return hg.repository(ui.ui(), repository.repo_path(app))
if repo_path is not None:
return hg.repository(ui.ui(), repo_path)
示例7: create_queue
def create_queue(repo, qname):
if not has_queue(repo, qname):
name = qname[8:] if qname != 'patches' else 'patches'
fh = repo.opener('patches.queues', 'a')
fh.write('%s\n' % (name,))
fh.close()
path = os.path.join(repo.path, qname)
if not os.path.exists(path):
hg.repository(repo.ui, path, create=True)
示例8: test_diff_base_against_clone
def test_diff_base_against_clone(self):
"""Test that the right error is raised on trying to do a diff across
a different divergant clone"""
ui = mock_ui()
orig = os.path.join(settings.REPOSITORY_BASE, "orig")
clone = os.path.join(settings.REPOSITORY_BASE, "clone")
hgcommands.init(ui, orig)
hgorig = repository(ui, orig)
(
open(hgorig.pathto("file.dtd"), "w").write(
"""
<!ENTITY old "content we will delete">
<!ENTITY mod "this has stuff to keep and delete">
"""
)
)
hgcommands.addremove(ui, hgorig)
hgcommands.commit(ui, hgorig, user="Jane Doe <[email protected]", message="initial commit")
assert len(hgorig) == 1 # 1 commit
# set up a second repo called 'clone'
hgcommands.clone(ui, orig, clone)
hgclone = repository(ui, clone)
# new commit on base
(
open(hgorig.pathto("file.dtd"), "w").write(
"""
<!ENTITY mod "this has stuff to keep and add">
<!ENTITY new "this has stuff that is new">
"""
)
)
hgcommands.commit(ui, hgorig, user="Jane Doe <[email protected]", message="second commit on base")
assert len(hgorig) == 2 # 2 commits
rev_from = hgorig[1].hex()
# different commit on clone
(
open(hgclone.pathto("file.dtd"), "w").write(
"""
<!ENTITY mod "this has stuff to keep and change">
<!ENTITY new_in_clone "this has stuff that is different from base">
"""
)
)
hgcommands.commit(ui, hgclone, user="John Doe <[email protected]", message="a different commit on clone")
rev_to = hgclone[1].hex()
Repository.objects.create(name="orig", url="http://localhost:8001/orig/")
Repository.objects.create(name="clone", url="http://localhost:8001/clone/")
url = reverse("pushes.views.diff")
# right now, we can't diff between repos, this might change!
self.assertRaises(RepoError, self.client.get, url, {"repo": "clone", "from": rev_from[:12], "to": rev_to[:12]})
示例9: _local_repo
def _local_repo(self):
if self.key not in revision._state.repositories:
if not os.path.exists(self.local):
try:
os.makedirs(self.local)
revision._state.repositories[self.key] = hg.repository(self._ui, self.local, create=True)
except error.RepoError:
pass
if self.key not in revision._state.repositories:
revision._state.repositories[self.key] = hg.repository(self._ui, self.local)
return revision._state.repositories[self.key]
示例10: init
def init(self):
dest = self.getPath()
if dest == '':
qtlib.ErrorMsgBox(_('Error executing init'),
_('Destination path is empty'),
_('Please enter the directory path'))
self.dest_edit.setFocus()
return False
dest = os.path.normpath(dest)
self.dest_edit.setText(hglib.tounicode(dest))
udest = self.dest_edit.text()
if not os.path.exists(dest):
p = dest
l = 0
while not os.path.exists(p):
l += 1
p, t = os.path.split(p)
if not t:
break # already root path
if l > 1:
res = qtlib.QuestionMsgBox(_('Init'),
_('Are you sure about adding the new repository '
'%d extra levels deep?') % l,
_('Path exists up to:\n%s\nand you asked for:\n%s')
% (p, udest),
defaultbutton=QMessageBox.No)
if not res:
self.dest_edit.setFocus()
return
try:
# create the folder, just like Hg would
os.makedirs(dest)
except:
qtlib.ErrorMsgBox(_('Error executing init'),
_('Cannot create folder %s') % udest)
return False
_ui = ui.ui()
# dotencode is the new default repo format in Mercurial 1.7
if self.make_pre_1_7_chk.isChecked():
_ui.setconfig('format', 'dotencode', 'False')
try:
# create the new repo
hg.repository(_ui, dest, create=1)
except error.RepoError, inst:
qtlib.ErrorMsgBox(_('Error executing init'),
_('Unable to create new repository'),
hglib.tounicode(str(inst)))
return False
示例11: hgproto_init
def hgproto_init(repo, proto):
"""An hg protocol command handler that creates a new repository. This gets
bound to the 'init' command."""
virtual = proto.req.env.get("PATH_INFO", "").strip("/")
paths = {}
for name, value in repo.ui.configitems("paths"):
paths[name] = value
local = local_path_for_repo(virtual, paths)
hg.repository(repo.ui, path=local, create=True)
示例12: __init__
def __init__(self, parent=None):
QtCore.QThread.__init__(self, parent)
self.logger = logging.getLogger('__main__')
self.info = lambda msg : self.logger.info(msg)
self.debug = lambda msg : self.logger.debug(msg)
self.ui = ui.ui()
self.url = 'https://open-ihm.googlecode.com/hg/'
try:
self.repo = hg.repository(self.ui, REPO_DIR)
except Exception:
self.repo = hg.repository(self.ui, REPO_DIR, create=True)
return
示例13: create
def create(self):
if(self.destinationField.stringValue() is not None):
try:
hg.repository(cmdutil.remoteui(ui.ui(), {}), self.destinationField.stringValue(), create=1)
NSAlert.alertWithMessageText_defaultButton_alternateButton_otherButton_informativeTextWithFormat_(
NSLocalizedString("ERROR", None), "Ok", None, None, NSLocalizedString("Repository created sucessfully!", None)).runModal()
except:
NSAlert.alertWithMessageText_defaultButton_alternateButton_otherButton_informativeTextWithFormat_(
NSLocalizedString("ERROR", None), "Ok", None, None, NSLocalizedString("An error occurred while creating Mercurial repository!", None)).runModal()
import traceback
traceback.print_exc()
return ERROR(u'Exception, see traceback')
示例14: handlePushes
def handlePushes(repo_id, submits, do_update=True):
if not submits:
return
repo = Repository.objects.get(id=repo_id)
revisions = reduce(lambda r,l: r+l,
[p.changesets for p in submits],
[])
ui = _ui()
repopath = os.path.join(settings.REPOSITORY_BASE,
repo.name)
configpath = os.path.join(repopath, '.hg', 'hgrc')
if not os.path.isfile(configpath):
if not os.path.isdir(os.path.dirname(repopath)):
os.makedirs(os.path.dirname(repopath))
clone(ui, str(repo.url), str(repopath),
pull=False, uncompressed=False, rev=[],
noupdate=False)
cfg = open(configpath, 'a')
cfg.write('default-push = ssh%s\n' % str(repo.url)[4:])
cfg.close()
ui.readconfig(configpath)
hgrepo = repository(ui, repopath)
else:
ui.readconfig(configpath)
hgrepo = repository(ui, repopath)
cs = submits[-1].changesets[-1]
try:
hgrepo.changectx(cs)
except RepoError:
pull(ui, hgrepo, source = str(repo.url),
force=False, update=False,
rev=[])
if do_update:
update(ui, hgrepo)
for data in submits:
changesets = []
for revision in data.changesets:
try:
cs = getChangeset(repo, hgrepo, revision)
transaction.commit()
changesets.append(cs)
except Exception, e:
transaction.rollback()
raise
print repo.name, e
p = Push.objects.create(repository = repo,
push_id = data.id, user = data.user,
push_date =
datetime.utcfromtimestamp(data.date))
p.changesets = changesets
p.save()
transaction.commit()
示例15: __init__
def __init__(self, path, username):
uio = ui.ui()
uio.quiet = True
if not os.environ.get('HGUSER') and not uio.config("ui", "username"):
os.environ['HGUSER'] = username
try:
repo = hg.repository(ui=uio, path=path)
except:
repo = hg.repository(ui=uio, path=path, create=True)
hgignore = os.path.join(path, '.hgignore')
if not os.path.exists(hgignore):
open(hgignore, 'w').write(_hgignore_content)
self.repo = repo
self.decode = None