Mercurial > hg-git
changeset 179:c5c63783ace0
Initial clone/pull/push support for git repositories
author | Abderrahim Kitouni <a.kitouni@gmail.com> |
---|---|
date | Wed, 03 Jun 2009 21:15:43 +0100 |
parents | 53ef6f725598 |
children | 682863000e9a |
files | git_handler.py gitrepo.py hgrepo.py |
diffstat | 3 files changed, 38 insertions(+), 21 deletions(-) [+] |
line wrap: on
line diff
--- a/git_handler.py Wed Jun 03 19:29:44 2009 +0100 +++ b/git_handler.py Wed Jun 03 21:15:43 2009 +0100 @@ -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',
--- a/gitrepo.py Wed Jun 03 19:29:44 2009 +0100 +++ b/gitrepo.py Wed Jun 03 21:15:43 2009 +0100 @@ -1,26 +1,10 @@ -from mercurial import hg, repo +from mercurial import repo, util 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
--- a/hgrepo.py Wed Jun 03 19:29:44 2009 +0100 +++ b/hgrepo.py Wed Jun 03 21:15:43 2009 +0100 @@ -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