Mercurial > hg-git
annotate hggit/__init__.py @ 296:32456f9cb7a4
hggit: don't wrap gitrepo with hgrepo
author | Augie Fackler <durin42@gmail.com> |
---|---|
date | Thu, 25 Mar 2010 20:23:00 -0500 |
parents | a14529b7b8f2 |
children | a90fe3e8a8c3 |
rev | line source |
---|---|
0
06366111af3c
initial import of the hg-git bridging extension for mercurial
Scott Chacon <schacon@gmail.com>
parents:
diff
changeset
|
1 # git.py - git server bridge |
06366111af3c
initial import of the hg-git bridging extension for mercurial
Scott Chacon <schacon@gmail.com>
parents:
diff
changeset
|
2 # |
06366111af3c
initial import of the hg-git bridging extension for mercurial
Scott Chacon <schacon@gmail.com>
parents:
diff
changeset
|
3 # Copyright 2008 Scott Chacon <schacon at gmail dot com> |
250 | 4 # also some code (and help) borrowed from durin42 |
0
06366111af3c
initial import of the hg-git bridging extension for mercurial
Scott Chacon <schacon@gmail.com>
parents:
diff
changeset
|
5 # |
06366111af3c
initial import of the hg-git bridging extension for mercurial
Scott Chacon <schacon@gmail.com>
parents:
diff
changeset
|
6 # This software may be used and distributed according to the terms |
06366111af3c
initial import of the hg-git bridging extension for mercurial
Scott Chacon <schacon@gmail.com>
parents:
diff
changeset
|
7 # of the GNU General Public License, incorporated herein by reference. |
06366111af3c
initial import of the hg-git bridging extension for mercurial
Scott Chacon <schacon@gmail.com>
parents:
diff
changeset
|
8 |
06366111af3c
initial import of the hg-git bridging extension for mercurial
Scott Chacon <schacon@gmail.com>
parents:
diff
changeset
|
9 '''push and pull from a Git server |
06366111af3c
initial import of the hg-git bridging extension for mercurial
Scott Chacon <schacon@gmail.com>
parents:
diff
changeset
|
10 |
06366111af3c
initial import of the hg-git bridging extension for mercurial
Scott Chacon <schacon@gmail.com>
parents:
diff
changeset
|
11 This extension lets you communicate (push and pull) with a Git server. |
250 | 12 This way you can use Git hosting for your project or collaborate with a |
0
06366111af3c
initial import of the hg-git bridging extension for mercurial
Scott Chacon <schacon@gmail.com>
parents:
diff
changeset
|
13 project that is in Git. A bridger of worlds, this plugin be. |
06366111af3c
initial import of the hg-git bridging extension for mercurial
Scott Chacon <schacon@gmail.com>
parents:
diff
changeset
|
14 |
250 | 15 Try hg clone git:// or hg clone git+ssh:// |
0
06366111af3c
initial import of the hg-git bridging extension for mercurial
Scott Chacon <schacon@gmail.com>
parents:
diff
changeset
|
16 ''' |
06366111af3c
initial import of the hg-git bridging extension for mercurial
Scott Chacon <schacon@gmail.com>
parents:
diff
changeset
|
17 |
256
442fe2ca104d
Simpler handling of detection of git repos
Mads Kiilerich <mads@kiilerich.com>
parents:
220
diff
changeset
|
18 import os |
442fe2ca104d
Simpler handling of detection of git repos
Mads Kiilerich <mads@kiilerich.com>
parents:
220
diff
changeset
|
19 |
220
211fa793d74f
support local git repositories (fixes issue 5 bb)
Abderrahim Kitouni <a.kitouni@gmail.com>
parents:
210
diff
changeset
|
20 from mercurial import commands, extensions, hg, util |
0
06366111af3c
initial import of the hg-git bridging extension for mercurial
Scott Chacon <schacon@gmail.com>
parents:
diff
changeset
|
21 from mercurial.i18n import _ |
220
211fa793d74f
support local git repositories (fixes issue 5 bb)
Abderrahim Kitouni <a.kitouni@gmail.com>
parents:
210
diff
changeset
|
22 |
210
9a27c618d0ed
remove broken tagging code (see issue 3 bb)
Abderrahim Kitouni <a.kitouni@gmail.com>
parents:
206
diff
changeset
|
23 import gitrepo, hgrepo |
5
d6c443a91b18
refactored the git handling stuff out into another class
Scott Chacon <schacon@gmail.com>
parents:
4
diff
changeset
|
24 from git_handler import GitHandler |
0
06366111af3c
initial import of the hg-git bridging extension for mercurial
Scott Chacon <schacon@gmail.com>
parents:
diff
changeset
|
25 |
60
05a96f7750ad
add support for `hg clone git://github.com/defunkt/facebox.git`
Chris Wanstrath <chris@ozmm.org>
parents:
59
diff
changeset
|
26 # support for `hg clone git://github.com/defunkt/facebox.git` |
168
8bfa8aa6b68f
added empty changelog handling
Scott Chacon <schacon@gmail.com>
parents:
165
diff
changeset
|
27 # also hg clone git+ssh://git@github.com/schacon/simplegit.git |
60
05a96f7750ad
add support for `hg clone git://github.com/defunkt/facebox.git`
Chris Wanstrath <chris@ozmm.org>
parents:
59
diff
changeset
|
28 hg.schemes['git'] = gitrepo |
168
8bfa8aa6b68f
added empty changelog handling
Scott Chacon <schacon@gmail.com>
parents:
165
diff
changeset
|
29 hg.schemes['git+ssh'] = gitrepo |
180
682863000e9a
Make it possible to clone/pull from bundle repositories
Abderrahim Kitouni <a.kitouni@gmail.com>
parents:
175
diff
changeset
|
30 |
256
442fe2ca104d
Simpler handling of detection of git repos
Mads Kiilerich <mads@kiilerich.com>
parents:
220
diff
changeset
|
31 # support for `hg clone localgitrepo` |
220
211fa793d74f
support local git repositories (fixes issue 5 bb)
Abderrahim Kitouni <a.kitouni@gmail.com>
parents:
210
diff
changeset
|
32 _oldlocal = hg.schemes['file'] |
211fa793d74f
support local git repositories (fixes issue 5 bb)
Abderrahim Kitouni <a.kitouni@gmail.com>
parents:
210
diff
changeset
|
33 |
211fa793d74f
support local git repositories (fixes issue 5 bb)
Abderrahim Kitouni <a.kitouni@gmail.com>
parents:
210
diff
changeset
|
34 def _local(path): |
211fa793d74f
support local git repositories (fixes issue 5 bb)
Abderrahim Kitouni <a.kitouni@gmail.com>
parents:
210
diff
changeset
|
35 p = util.drop_scheme('file', path) |
280 | 36 if (os.path.exists(os.path.join(p, '.git')) and |
256
442fe2ca104d
Simpler handling of detection of git repos
Mads Kiilerich <mads@kiilerich.com>
parents:
220
diff
changeset
|
37 not os.path.exists(os.path.join(p, '.hg'))): |
220
211fa793d74f
support local git repositories (fixes issue 5 bb)
Abderrahim Kitouni <a.kitouni@gmail.com>
parents:
210
diff
changeset
|
38 return gitrepo |
263
9f5a7a5d52aa
Enable detection of bare repositories as a local git repo
Lincoln Stoll <lstoll@lstoll.net>
parents:
260
diff
changeset
|
39 # detect a bare repository |
280 | 40 if (os.path.exists(os.path.join(p, 'HEAD')) and |
41 os.path.exists(os.path.join(p, 'objects')) and | |
42 os.path.exists(os.path.join(p, 'refs')) and | |
263
9f5a7a5d52aa
Enable detection of bare repositories as a local git repo
Lincoln Stoll <lstoll@lstoll.net>
parents:
260
diff
changeset
|
43 not os.path.exists(os.path.join(p, '.hg'))): |
9f5a7a5d52aa
Enable detection of bare repositories as a local git repo
Lincoln Stoll <lstoll@lstoll.net>
parents:
260
diff
changeset
|
44 return gitrepo |
256
442fe2ca104d
Simpler handling of detection of git repos
Mads Kiilerich <mads@kiilerich.com>
parents:
220
diff
changeset
|
45 return _oldlocal(path) |
220
211fa793d74f
support local git repositories (fixes issue 5 bb)
Abderrahim Kitouni <a.kitouni@gmail.com>
parents:
210
diff
changeset
|
46 |
211fa793d74f
support local git repositories (fixes issue 5 bb)
Abderrahim Kitouni <a.kitouni@gmail.com>
parents:
210
diff
changeset
|
47 hg.schemes['file'] = _local |
211fa793d74f
support local git repositories (fixes issue 5 bb)
Abderrahim Kitouni <a.kitouni@gmail.com>
parents:
210
diff
changeset
|
48 |
281
a14529b7b8f2
init: strip .git for default clone destination for git sources
Augie Fackler <durin42@gmail.com>
parents:
280
diff
changeset
|
49 hgdefaultdest = hg.defaultdest |
a14529b7b8f2
init: strip .git for default clone destination for git sources
Augie Fackler <durin42@gmail.com>
parents:
280
diff
changeset
|
50 def defaultdest(source): |
a14529b7b8f2
init: strip .git for default clone destination for git sources
Augie Fackler <durin42@gmail.com>
parents:
280
diff
changeset
|
51 for scheme in ('git', 'git+ssh'): |
a14529b7b8f2
init: strip .git for default clone destination for git sources
Augie Fackler <durin42@gmail.com>
parents:
280
diff
changeset
|
52 if source.startswith('%s://' % scheme) and source.endswith('.git'): |
a14529b7b8f2
init: strip .git for default clone destination for git sources
Augie Fackler <durin42@gmail.com>
parents:
280
diff
changeset
|
53 source = source[:-4] |
a14529b7b8f2
init: strip .git for default clone destination for git sources
Augie Fackler <durin42@gmail.com>
parents:
280
diff
changeset
|
54 break |
a14529b7b8f2
init: strip .git for default clone destination for git sources
Augie Fackler <durin42@gmail.com>
parents:
280
diff
changeset
|
55 return hgdefaultdest(source) |
a14529b7b8f2
init: strip .git for default clone destination for git sources
Augie Fackler <durin42@gmail.com>
parents:
280
diff
changeset
|
56 hg.defaultdest = defaultdest |
a14529b7b8f2
init: strip .git for default clone destination for git sources
Augie Fackler <durin42@gmail.com>
parents:
280
diff
changeset
|
57 |
206
5986ac6a591e
create the repository subclass in reposetup
Abderrahim Kitouni <a.kitouni@gmail.com>
parents:
182
diff
changeset
|
58 def reposetup(ui, repo): |
296
32456f9cb7a4
hggit: don't wrap gitrepo with hgrepo
Augie Fackler <durin42@gmail.com>
parents:
281
diff
changeset
|
59 if not isinstance(repo, gitrepo.gitrepo): |
32456f9cb7a4
hggit: don't wrap gitrepo with hgrepo
Augie Fackler <durin42@gmail.com>
parents:
281
diff
changeset
|
60 klass = hgrepo.generate_repo_subclass(repo.__class__) |
32456f9cb7a4
hggit: don't wrap gitrepo with hgrepo
Augie Fackler <durin42@gmail.com>
parents:
281
diff
changeset
|
61 repo.__class__ = klass |
60
05a96f7750ad
add support for `hg clone git://github.com/defunkt/facebox.git`
Chris Wanstrath <chris@ozmm.org>
parents:
59
diff
changeset
|
62 |
137
5aefcbf1e50c
add a gimport command
Sverre Rabbelier <sverre@rabbelier.nl>
parents:
136
diff
changeset
|
63 def gimport(ui, repo, remote_name=None): |
5aefcbf1e50c
add a gimport command
Sverre Rabbelier <sverre@rabbelier.nl>
parents:
136
diff
changeset
|
64 git = GitHandler(repo, ui) |
5aefcbf1e50c
add a gimport command
Sverre Rabbelier <sverre@rabbelier.nl>
parents:
136
diff
changeset
|
65 git.import_commits(remote_name) |
5aefcbf1e50c
add a gimport command
Sverre Rabbelier <sverre@rabbelier.nl>
parents:
136
diff
changeset
|
66 |
97 | 67 def gexport(ui, repo): |
68 git = GitHandler(repo, ui) | |
136
74385b613bb7
rename export to export_commits for future consitency
Sverre Rabbelier <sverre@rabbelier.nl>
parents:
134
diff
changeset
|
69 git.export_commits() |
97 | 70 |
40
f5b000ec7100
added gclear command to remove all the git data
Scott Chacon <schacon@gmail.com>
parents:
39
diff
changeset
|
71 def gclear(ui, repo): |
f5b000ec7100
added gclear command to remove all the git data
Scott Chacon <schacon@gmail.com>
parents:
39
diff
changeset
|
72 repo.ui.status(_("clearing out the git cache data\n")) |
f5b000ec7100
added gclear command to remove all the git data
Scott Chacon <schacon@gmail.com>
parents:
39
diff
changeset
|
73 git = GitHandler(repo, ui) |
f5b000ec7100
added gclear command to remove all the git data
Scott Chacon <schacon@gmail.com>
parents:
39
diff
changeset
|
74 git.clear() |
59
19d714ee9941
gfetch should access repo when printing, not dest_repo
Chris Wanstrath <chris@ozmm.org>
parents:
40
diff
changeset
|
75 |
0
06366111af3c
initial import of the hg-git bridging extension for mercurial
Scott Chacon <schacon@gmail.com>
parents:
diff
changeset
|
76 cmdtable = { |
137
5aefcbf1e50c
add a gimport command
Sverre Rabbelier <sverre@rabbelier.nl>
parents:
136
diff
changeset
|
77 "gimport": |
5aefcbf1e50c
add a gimport command
Sverre Rabbelier <sverre@rabbelier.nl>
parents:
136
diff
changeset
|
78 (gimport, [], _('hg gimport')), |
97 | 79 "gexport": |
80 (gexport, [], _('hg gexport')), | |
40
f5b000ec7100
added gclear command to remove all the git data
Scott Chacon <schacon@gmail.com>
parents:
39
diff
changeset
|
81 "gclear": |
f5b000ec7100
added gclear command to remove all the git data
Scott Chacon <schacon@gmail.com>
parents:
39
diff
changeset
|
82 (gclear, [], _('Clears out the Git cached data')), |
182
9bdd8e76bbab
Remove remotes support (use the paths section in hgrc instead)
Abderrahim Kitouni <a.kitouni@gmail.com>
parents:
180
diff
changeset
|
83 } |