2009-02-21 05:27:51 +03:00
|
|
|
# git.py - git server bridge
|
|
|
|
#
|
|
|
|
# Copyright 2008 Scott Chacon <schacon at gmail dot com>
|
2009-09-26 06:09:33 +04:00
|
|
|
# also some code (and help) borrowed from durin42
|
2009-02-21 05:27:51 +03:00
|
|
|
#
|
|
|
|
# This software may be used and distributed according to the terms
|
|
|
|
# of the GNU General Public License, incorporated herein by reference.
|
|
|
|
|
|
|
|
'''push and pull from a Git server
|
|
|
|
|
|
|
|
This extension lets you communicate (push and pull) with a Git server.
|
2009-09-26 06:09:33 +04:00
|
|
|
This way you can use Git hosting for your project or collaborate with a
|
2009-02-21 05:27:51 +03:00
|
|
|
project that is in Git. A bridger of worlds, this plugin be.
|
|
|
|
|
2009-09-26 06:09:33 +04:00
|
|
|
Try hg clone git:// or hg clone git+ssh://
|
2009-02-21 05:27:51 +03:00
|
|
|
'''
|
|
|
|
|
2009-10-08 04:27:00 +04:00
|
|
|
import os
|
|
|
|
|
2009-07-23 11:38:20 +04:00
|
|
|
from mercurial import commands, extensions, hg, util
|
2009-02-21 05:27:51 +03:00
|
|
|
from mercurial.i18n import _
|
2009-07-23 11:38:20 +04:00
|
|
|
|
2009-07-05 19:39:28 +04:00
|
|
|
import gitrepo, hgrepo
|
2009-04-24 02:26:10 +04:00
|
|
|
from git_handler import GitHandler
|
2009-02-21 05:27:51 +03:00
|
|
|
|
2009-04-29 11:54:13 +04:00
|
|
|
# support for `hg clone git://github.com/defunkt/facebox.git`
|
2009-06-02 07:17:11 +04:00
|
|
|
# also hg clone git+ssh://git@github.com/schacon/simplegit.git
|
2009-04-29 11:54:13 +04:00
|
|
|
hg.schemes['git'] = gitrepo
|
2009-06-02 07:17:11 +04:00
|
|
|
hg.schemes['git+ssh'] = gitrepo
|
2009-06-04 21:07:05 +04:00
|
|
|
|
2009-10-08 04:27:00 +04:00
|
|
|
# support for `hg clone localgitrepo`
|
2009-07-23 11:38:20 +04:00
|
|
|
_oldlocal = hg.schemes['file']
|
|
|
|
|
|
|
|
def _local(path):
|
|
|
|
p = util.drop_scheme('file', path)
|
2010-01-12 05:46:52 +03:00
|
|
|
if (os.path.exists(os.path.join(p, '.git')) and
|
2009-10-08 04:27:00 +04:00
|
|
|
not os.path.exists(os.path.join(p, '.hg'))):
|
2009-07-23 11:38:20 +04:00
|
|
|
return gitrepo
|
2009-10-26 19:52:32 +03:00
|
|
|
# detect a bare repository
|
2010-01-12 05:46:52 +03:00
|
|
|
if (os.path.exists(os.path.join(p, 'HEAD')) and
|
|
|
|
os.path.exists(os.path.join(p, 'objects')) and
|
|
|
|
os.path.exists(os.path.join(p, 'refs')) and
|
2009-10-26 19:52:32 +03:00
|
|
|
not os.path.exists(os.path.join(p, '.hg'))):
|
|
|
|
return gitrepo
|
2009-10-08 04:27:00 +04:00
|
|
|
return _oldlocal(path)
|
2009-07-23 11:38:20 +04:00
|
|
|
|
|
|
|
hg.schemes['file'] = _local
|
|
|
|
|
2009-07-02 00:31:35 +04:00
|
|
|
def reposetup(ui, repo):
|
|
|
|
klass = hgrepo.generate_repo_subclass(repo.__class__)
|
|
|
|
repo.__class__ = klass
|
2009-04-29 11:54:13 +04:00
|
|
|
|
2009-05-15 02:48:24 +04:00
|
|
|
def gimport(ui, repo, remote_name=None):
|
|
|
|
git = GitHandler(repo, ui)
|
|
|
|
git.import_commits(remote_name)
|
|
|
|
|
2009-05-10 17:14:36 +04:00
|
|
|
def gexport(ui, repo):
|
|
|
|
git = GitHandler(repo, ui)
|
2009-05-15 02:43:38 +04:00
|
|
|
git.export_commits()
|
2009-05-10 17:14:36 +04:00
|
|
|
|
2009-04-29 03:56:05 +04:00
|
|
|
def gclear(ui, repo):
|
|
|
|
repo.ui.status(_("clearing out the git cache data\n"))
|
|
|
|
git = GitHandler(repo, ui)
|
|
|
|
git.clear()
|
2009-04-30 00:55:22 +04:00
|
|
|
|
2009-02-21 05:27:51 +03:00
|
|
|
cmdtable = {
|
2009-05-15 02:48:24 +04:00
|
|
|
"gimport":
|
|
|
|
(gimport, [], _('hg gimport')),
|
2009-05-10 17:14:36 +04:00
|
|
|
"gexport":
|
|
|
|
(gexport, [], _('hg gexport')),
|
2009-04-29 03:56:05 +04:00
|
|
|
"gclear":
|
|
|
|
(gclear, [], _('Clears out the Git cached data')),
|
2009-06-08 22:15:58 +04:00
|
|
|
}
|