diff --git a/git_handler.py b/git_handler.py index 53ef6f725598e1cd0793bbd087a57e97aec96c22_Z2l0X2hhbmRsZXIucHk=..c5c63783ace06b8a623f44e3fd332397395fbb10_Z2l0X2hhbmRsZXIucHk= 100644 --- a/git_handler.py +++ b/git_handler.py @@ -100,6 +100,7 @@ self.save_map() def fetch(self, remote_name): + remote_name = self.remote_name_from_url(remote_name) self.ui.status(_("fetching from : %s\n") % remote_name) self.export_git_objects() refs = self.fetch_pack(remote_name) @@ -116,6 +117,7 @@ self.save_map() def push(self, remote_name): + remote_name = self.remote_name_from_url(remote_name) self.fetch(remote_name) # get and convert objects if they already exist self.ui.status(_("pushing to : %s\n") % remote_name) self.export_commits(False) @@ -149,6 +151,13 @@ def remote_name_to_url(self, remote_name): return self._config['remote.' + remote_name + '.url'] + def remote_name_from_url(self, remote): + if 'remote.' + remote + '.url' in self._config: + return remote + if remote in self._config.values(): + return [key[7:-4] for key in self._config + if self._config[key] == remote][0] + def update_references(self): try: # We only care about bookmarks of the form 'name', diff --git a/gitrepo.py b/gitrepo.py index 53ef6f725598e1cd0793bbd087a57e97aec96c22_Z2l0cmVwby5weQ==..c5c63783ace06b8a623f44e3fd332397395fbb10_Z2l0cmVwby5weQ== 100644 --- a/gitrepo.py +++ b/gitrepo.py @@ -1,4 +1,4 @@ -from mercurial import hg, repo +from mercurial import repo, util from git_handler import GitHandler class gitrepo(repo.repository): @@ -2,25 +2,9 @@ from git_handler import GitHandler class gitrepo(repo.repository): - def __init__(self, ui, path, create=True): - dest = hg.defaultdest(path) - - if dest.endswith('.git'): - dest = dest[:-4] - - # create the local hg repo on disk - dest_repo = hg.repository(ui, dest, create=True) - - # fetch the initial git data - git = GitHandler(dest_repo, ui) - git.remote_add('origin', path) - git.fetch('origin') - - # checkout the tip - node = git.remote_head('origin') - hg.update(dest_repo, node) - - # exit to stop normal `hg clone` flow - raise SystemExit + def __init__(self, ui, path, create): + if create: + raise util.Abort('Cannot create a git repository.') + self.path = path instance = gitrepo diff --git a/hgrepo.py b/hgrepo.py index 53ef6f725598e1cd0793bbd087a57e97aec96c22_aGdyZXBvLnB5..c5c63783ace06b8a623f44e3fd332397395fbb10_aGdyZXBvLnB5 100644 --- a/hgrepo.py +++ b/hgrepo.py @@ -2,6 +2,10 @@ from mercurial import changelog, dirstate, filelog, manifest, context, weakref from mercurial.node import bin, hex, nullid, nullrev, short +from git_handler import GitHandler +from gitrepo import gitrepo + + class hgrepo(localrepo.localrepository): def commit_import_ctx(self, wctx, ancestor, force_files = None): @@ -133,5 +137,25 @@ self.dirstate.invalidate() del tr + def clone(self, remote, heads=[], stream=False): + if isinstance(remote, gitrepo): + git = GitHandler(self, self.ui) + git.remote_add('origin', remote.path) + + super(hgrepo, self).clone(remote, heads) + + def pull(self, remote, heads=None, force=False): + if isinstance(remote, gitrepo): + git = GitHandler(self, self.ui) + git.fetch(remote.path) + else: + super(hgrepo, self).pull(remote, heads, force) + + def push(self, remote, force=False, revs=None): + if isinstance(remote, gitrepo): + git = GitHandler(self, self.ui) + git.push(remote.path) + else: + super(hgrepo, self).push(remote, force, revs) instance = hgrepo