Mercurial > hg-git
annotate hggit/__init__.py @ 344:af48a5961432
Add just enough code to handle changes to cset discovery.
author | Augie Fackler <durin42@gmail.com> |
---|---|
date | Sat, 12 Jun 2010 21:49:14 -0500 |
parents | eb345bacc1da |
children | dd90394cd13b |
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 |
334
eb345bacc1da
Cope with tags being sorted (hg cset c7dbd6c4877a) by backporting that behavior
Augie Fackler <durin42@gmail.com>
parents:
320
diff
changeset
|
20 from mercurial import commands |
eb345bacc1da
Cope with tags being sorted (hg cset c7dbd6c4877a) by backporting that behavior
Augie Fackler <durin42@gmail.com>
parents:
320
diff
changeset
|
21 from mercurial import extensions |
eb345bacc1da
Cope with tags being sorted (hg cset c7dbd6c4877a) by backporting that behavior
Augie Fackler <durin42@gmail.com>
parents:
320
diff
changeset
|
22 from mercurial import hg |
eb345bacc1da
Cope with tags being sorted (hg cset c7dbd6c4877a) by backporting that behavior
Augie Fackler <durin42@gmail.com>
parents:
320
diff
changeset
|
23 from mercurial import localrepo |
eb345bacc1da
Cope with tags being sorted (hg cset c7dbd6c4877a) by backporting that behavior
Augie Fackler <durin42@gmail.com>
parents:
320
diff
changeset
|
24 from mercurial import util as hgutil |
0
06366111af3c
initial import of the hg-git bridging extension for mercurial
Scott Chacon <schacon@gmail.com>
parents:
diff
changeset
|
25 from mercurial.i18n import _ |
220
211fa793d74f
support local git repositories (fixes issue 5 bb)
Abderrahim Kitouni <a.kitouni@gmail.com>
parents:
210
diff
changeset
|
26 |
210
9a27c618d0ed
remove broken tagging code (see issue 3 bb)
Abderrahim Kitouni <a.kitouni@gmail.com>
parents:
206
diff
changeset
|
27 import gitrepo, hgrepo |
5
d6c443a91b18
refactored the git handling stuff out into another class
Scott Chacon <schacon@gmail.com>
parents:
4
diff
changeset
|
28 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
|
29 |
60
05a96f7750ad
add support for `hg clone git://github.com/defunkt/facebox.git`
Chris Wanstrath <chris@ozmm.org>
parents:
59
diff
changeset
|
30 # 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
|
31 # 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
|
32 hg.schemes['git'] = gitrepo |
168
8bfa8aa6b68f
added empty changelog handling
Scott Chacon <schacon@gmail.com>
parents:
165
diff
changeset
|
33 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
|
34 |
256
442fe2ca104d
Simpler handling of detection of git repos
Mads Kiilerich <mads@kiilerich.com>
parents:
220
diff
changeset
|
35 # 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
|
36 _oldlocal = hg.schemes['file'] |
211fa793d74f
support local git repositories (fixes issue 5 bb)
Abderrahim Kitouni <a.kitouni@gmail.com>
parents:
210
diff
changeset
|
37 |
211fa793d74f
support local git repositories (fixes issue 5 bb)
Abderrahim Kitouni <a.kitouni@gmail.com>
parents:
210
diff
changeset
|
38 def _local(path): |
320
6eded2e4c616
Un-break hg 1.3 by adding a compat layer for progress.
Augie Fackler <durin42@gmail.com>
parents:
300
diff
changeset
|
39 p = hgutil.drop_scheme('file', path) |
280 | 40 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
|
41 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
|
42 return gitrepo |
263
9f5a7a5d52aa
Enable detection of bare repositories as a local git repo
Lincoln Stoll <lstoll@lstoll.net>
parents:
260
diff
changeset
|
43 # detect a bare repository |
280 | 44 if (os.path.exists(os.path.join(p, 'HEAD')) and |
45 os.path.exists(os.path.join(p, 'objects')) and | |
46 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
|
47 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
|
48 return gitrepo |
256
442fe2ca104d
Simpler handling of detection of git repos
Mads Kiilerich <mads@kiilerich.com>
parents:
220
diff
changeset
|
49 return _oldlocal(path) |
220
211fa793d74f
support local git repositories (fixes issue 5 bb)
Abderrahim Kitouni <a.kitouni@gmail.com>
parents:
210
diff
changeset
|
50 |
211fa793d74f
support local git repositories (fixes issue 5 bb)
Abderrahim Kitouni <a.kitouni@gmail.com>
parents:
210
diff
changeset
|
51 hg.schemes['file'] = _local |
211fa793d74f
support local git repositories (fixes issue 5 bb)
Abderrahim Kitouni <a.kitouni@gmail.com>
parents:
210
diff
changeset
|
52 |
281
a14529b7b8f2
init: strip .git for default clone destination for git sources
Augie Fackler <durin42@gmail.com>
parents:
280
diff
changeset
|
53 hgdefaultdest = hg.defaultdest |
a14529b7b8f2
init: strip .git for default clone destination for git sources
Augie Fackler <durin42@gmail.com>
parents:
280
diff
changeset
|
54 def defaultdest(source): |
a14529b7b8f2
init: strip .git for default clone destination for git sources
Augie Fackler <durin42@gmail.com>
parents:
280
diff
changeset
|
55 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
|
56 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
|
57 source = source[:-4] |
a14529b7b8f2
init: strip .git for default clone destination for git sources
Augie Fackler <durin42@gmail.com>
parents:
280
diff
changeset
|
58 break |
a14529b7b8f2
init: strip .git for default clone destination for git sources
Augie Fackler <durin42@gmail.com>
parents:
280
diff
changeset
|
59 return hgdefaultdest(source) |
a14529b7b8f2
init: strip .git for default clone destination for git sources
Augie Fackler <durin42@gmail.com>
parents:
280
diff
changeset
|
60 hg.defaultdest = defaultdest |
a14529b7b8f2
init: strip .git for default clone destination for git sources
Augie Fackler <durin42@gmail.com>
parents:
280
diff
changeset
|
61 |
297
a90fe3e8a8c3
hggit: defend against exceptions when pulling with -r
Augie Fackler <durin42@gmail.com>
parents:
296
diff
changeset
|
62 # defend against tracebacks if we specify -r in 'hg pull' |
a90fe3e8a8c3
hggit: defend against exceptions when pulling with -r
Augie Fackler <durin42@gmail.com>
parents:
296
diff
changeset
|
63 def safebranchrevs(orig, lrepo, repo, branches, revs): |
a90fe3e8a8c3
hggit: defend against exceptions when pulling with -r
Augie Fackler <durin42@gmail.com>
parents:
296
diff
changeset
|
64 revs, co = orig(lrepo, repo, branches, revs) |
a90fe3e8a8c3
hggit: defend against exceptions when pulling with -r
Augie Fackler <durin42@gmail.com>
parents:
296
diff
changeset
|
65 if getattr(lrepo, 'changelog', False) and co not in lrepo.changelog: |
a90fe3e8a8c3
hggit: defend against exceptions when pulling with -r
Augie Fackler <durin42@gmail.com>
parents:
296
diff
changeset
|
66 co = None |
a90fe3e8a8c3
hggit: defend against exceptions when pulling with -r
Augie Fackler <durin42@gmail.com>
parents:
296
diff
changeset
|
67 return revs, co |
300
eec31dee258e
Various hg 1.4 compat fixes.
Augie Fackler <durin42@gmail.com>
parents:
298
diff
changeset
|
68 if getattr(hg, 'addbranchrevs', False): |
eec31dee258e
Various hg 1.4 compat fixes.
Augie Fackler <durin42@gmail.com>
parents:
298
diff
changeset
|
69 extensions.wrapfunction(hg, 'addbranchrevs', safebranchrevs) |
297
a90fe3e8a8c3
hggit: defend against exceptions when pulling with -r
Augie Fackler <durin42@gmail.com>
parents:
296
diff
changeset
|
70 |
206
5986ac6a591e
create the repository subclass in reposetup
Abderrahim Kitouni <a.kitouni@gmail.com>
parents:
182
diff
changeset
|
71 def reposetup(ui, repo): |
296
32456f9cb7a4
hggit: don't wrap gitrepo with hgrepo
Augie Fackler <durin42@gmail.com>
parents:
281
diff
changeset
|
72 if not isinstance(repo, gitrepo.gitrepo): |
32456f9cb7a4
hggit: don't wrap gitrepo with hgrepo
Augie Fackler <durin42@gmail.com>
parents:
281
diff
changeset
|
73 klass = hgrepo.generate_repo_subclass(repo.__class__) |
32456f9cb7a4
hggit: don't wrap gitrepo with hgrepo
Augie Fackler <durin42@gmail.com>
parents:
281
diff
changeset
|
74 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
|
75 |
137
5aefcbf1e50c
add a gimport command
Sverre Rabbelier <sverre@rabbelier.nl>
parents:
136
diff
changeset
|
76 def gimport(ui, repo, remote_name=None): |
5aefcbf1e50c
add a gimport command
Sverre Rabbelier <sverre@rabbelier.nl>
parents:
136
diff
changeset
|
77 git = GitHandler(repo, ui) |
5aefcbf1e50c
add a gimport command
Sverre Rabbelier <sverre@rabbelier.nl>
parents:
136
diff
changeset
|
78 git.import_commits(remote_name) |
5aefcbf1e50c
add a gimport command
Sverre Rabbelier <sverre@rabbelier.nl>
parents:
136
diff
changeset
|
79 |
97 | 80 def gexport(ui, repo): |
81 git = GitHandler(repo, ui) | |
136
74385b613bb7
rename export to export_commits for future consitency
Sverre Rabbelier <sverre@rabbelier.nl>
parents:
134
diff
changeset
|
82 git.export_commits() |
97 | 83 |
40
f5b000ec7100
added gclear command to remove all the git data
Scott Chacon <schacon@gmail.com>
parents:
39
diff
changeset
|
84 def gclear(ui, repo): |
f5b000ec7100
added gclear command to remove all the git data
Scott Chacon <schacon@gmail.com>
parents:
39
diff
changeset
|
85 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
|
86 git = GitHandler(repo, ui) |
f5b000ec7100
added gclear command to remove all the git data
Scott Chacon <schacon@gmail.com>
parents:
39
diff
changeset
|
87 git.clear() |
59
19d714ee9941
gfetch should access repo when printing, not dest_repo
Chris Wanstrath <chris@ozmm.org>
parents:
40
diff
changeset
|
88 |
298
6ad6945b6629
pull: make it possible to un-wedge the repo after stripping git revs
Augie Fackler <durin42@gmail.com>
parents:
297
diff
changeset
|
89 def git_cleanup(ui, repo): |
6ad6945b6629
pull: make it possible to un-wedge the repo after stripping git revs
Augie Fackler <durin42@gmail.com>
parents:
297
diff
changeset
|
90 new_map = [] |
6ad6945b6629
pull: make it possible to un-wedge the repo after stripping git revs
Augie Fackler <durin42@gmail.com>
parents:
297
diff
changeset
|
91 for line in repo.opener(GitHandler.mapfile): |
6ad6945b6629
pull: make it possible to un-wedge the repo after stripping git revs
Augie Fackler <durin42@gmail.com>
parents:
297
diff
changeset
|
92 gitsha, hgsha = line.strip().split(' ', 1) |
6ad6945b6629
pull: make it possible to un-wedge the repo after stripping git revs
Augie Fackler <durin42@gmail.com>
parents:
297
diff
changeset
|
93 if hgsha in repo: |
6ad6945b6629
pull: make it possible to un-wedge the repo after stripping git revs
Augie Fackler <durin42@gmail.com>
parents:
297
diff
changeset
|
94 new_map.append('%s %s\n' % (gitsha, hgsha)) |
6ad6945b6629
pull: make it possible to un-wedge the repo after stripping git revs
Augie Fackler <durin42@gmail.com>
parents:
297
diff
changeset
|
95 f = repo.opener(GitHandler.mapfile, 'wb') |
6ad6945b6629
pull: make it possible to un-wedge the repo after stripping git revs
Augie Fackler <durin42@gmail.com>
parents:
297
diff
changeset
|
96 map(f.write, new_map) |
6ad6945b6629
pull: make it possible to un-wedge the repo after stripping git revs
Augie Fackler <durin42@gmail.com>
parents:
297
diff
changeset
|
97 ui.status(_('git commit map cleaned\n')) |
6ad6945b6629
pull: make it possible to un-wedge the repo after stripping git revs
Augie Fackler <durin42@gmail.com>
parents:
297
diff
changeset
|
98 |
334
eb345bacc1da
Cope with tags being sorted (hg cset c7dbd6c4877a) by backporting that behavior
Augie Fackler <durin42@gmail.com>
parents:
320
diff
changeset
|
99 # drop this when we're 1.6-only, this just backports new behavior |
eb345bacc1da
Cope with tags being sorted (hg cset c7dbd6c4877a) by backporting that behavior
Augie Fackler <durin42@gmail.com>
parents:
320
diff
changeset
|
100 def sortednodetags(orig, *args, **kwargs): |
eb345bacc1da
Cope with tags being sorted (hg cset c7dbd6c4877a) by backporting that behavior
Augie Fackler <durin42@gmail.com>
parents:
320
diff
changeset
|
101 ret = orig(*args, **kwargs) |
eb345bacc1da
Cope with tags being sorted (hg cset c7dbd6c4877a) by backporting that behavior
Augie Fackler <durin42@gmail.com>
parents:
320
diff
changeset
|
102 ret.sort() |
eb345bacc1da
Cope with tags being sorted (hg cset c7dbd6c4877a) by backporting that behavior
Augie Fackler <durin42@gmail.com>
parents:
320
diff
changeset
|
103 return ret |
eb345bacc1da
Cope with tags being sorted (hg cset c7dbd6c4877a) by backporting that behavior
Augie Fackler <durin42@gmail.com>
parents:
320
diff
changeset
|
104 extensions.wrapfunction(localrepo.localrepository, 'nodetags', sortednodetags) |
eb345bacc1da
Cope with tags being sorted (hg cset c7dbd6c4877a) by backporting that behavior
Augie Fackler <durin42@gmail.com>
parents:
320
diff
changeset
|
105 |
344
af48a5961432
Add just enough code to handle changes to cset discovery.
Augie Fackler <durin42@gmail.com>
parents:
334
diff
changeset
|
106 try: |
af48a5961432
Add just enough code to handle changes to cset discovery.
Augie Fackler <durin42@gmail.com>
parents:
334
diff
changeset
|
107 from mercurial import discovery |
af48a5961432
Add just enough code to handle changes to cset discovery.
Augie Fackler <durin42@gmail.com>
parents:
334
diff
changeset
|
108 def findoutgoing(orig, local, remote, base=None, heads=None, force=False): |
af48a5961432
Add just enough code to handle changes to cset discovery.
Augie Fackler <durin42@gmail.com>
parents:
334
diff
changeset
|
109 if isinstance(remote, gitrepo.gitrepo): |
af48a5961432
Add just enough code to handle changes to cset discovery.
Augie Fackler <durin42@gmail.com>
parents:
334
diff
changeset
|
110 git = GitHandler(local, local.ui) |
af48a5961432
Add just enough code to handle changes to cset discovery.
Augie Fackler <durin42@gmail.com>
parents:
334
diff
changeset
|
111 base, heads = git.get_refs(remote.path) |
af48a5961432
Add just enough code to handle changes to cset discovery.
Augie Fackler <durin42@gmail.com>
parents:
334
diff
changeset
|
112 r = orig(local, remote, base=base, heads=heads, |
af48a5961432
Add just enough code to handle changes to cset discovery.
Augie Fackler <durin42@gmail.com>
parents:
334
diff
changeset
|
113 force=force) |
af48a5961432
Add just enough code to handle changes to cset discovery.
Augie Fackler <durin42@gmail.com>
parents:
334
diff
changeset
|
114 return [x[0] for x in r] |
af48a5961432
Add just enough code to handle changes to cset discovery.
Augie Fackler <durin42@gmail.com>
parents:
334
diff
changeset
|
115 return orig(local, remote, base=base, heads=heads, force=force) |
af48a5961432
Add just enough code to handle changes to cset discovery.
Augie Fackler <durin42@gmail.com>
parents:
334
diff
changeset
|
116 extensions.wrapfunction(discovery, 'findoutgoing', findoutgoing) |
af48a5961432
Add just enough code to handle changes to cset discovery.
Augie Fackler <durin42@gmail.com>
parents:
334
diff
changeset
|
117 except ImportError: |
af48a5961432
Add just enough code to handle changes to cset discovery.
Augie Fackler <durin42@gmail.com>
parents:
334
diff
changeset
|
118 pass |
af48a5961432
Add just enough code to handle changes to cset discovery.
Augie Fackler <durin42@gmail.com>
parents:
334
diff
changeset
|
119 |
0
06366111af3c
initial import of the hg-git bridging extension for mercurial
Scott Chacon <schacon@gmail.com>
parents:
diff
changeset
|
120 cmdtable = { |
137
5aefcbf1e50c
add a gimport command
Sverre Rabbelier <sverre@rabbelier.nl>
parents:
136
diff
changeset
|
121 "gimport": |
5aefcbf1e50c
add a gimport command
Sverre Rabbelier <sverre@rabbelier.nl>
parents:
136
diff
changeset
|
122 (gimport, [], _('hg gimport')), |
97 | 123 "gexport": |
124 (gexport, [], _('hg gexport')), | |
40
f5b000ec7100
added gclear command to remove all the git data
Scott Chacon <schacon@gmail.com>
parents:
39
diff
changeset
|
125 "gclear": |
f5b000ec7100
added gclear command to remove all the git data
Scott Chacon <schacon@gmail.com>
parents:
39
diff
changeset
|
126 (gclear, [], _('Clears out the Git cached data')), |
298
6ad6945b6629
pull: make it possible to un-wedge the repo after stripping git revs
Augie Fackler <durin42@gmail.com>
parents:
297
diff
changeset
|
127 "git-cleanup": (git_cleanup, [], _( |
6ad6945b6629
pull: make it possible to un-wedge the repo after stripping git revs
Augie Fackler <durin42@gmail.com>
parents:
297
diff
changeset
|
128 "Cleans up git repository after history editing")) |
182
9bdd8e76bbab
Remove remotes support (use the paths section in hgrc instead)
Abderrahim Kitouni <a.kitouni@gmail.com>
parents:
180
diff
changeset
|
129 } |