Mercurial > hg-git
annotate hggit/__init__.py @ 668:98e118410521
revset_fromgit: use githandler from repo
author | Siddharth Agarwal <sid0@fb.com> |
---|---|
date | Wed, 19 Feb 2014 15:22:36 -0800 |
parents | b5ef3f0e0efe |
children | b8fff2f4e963 |
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:// |
481
9df1741f3977
help: add additional help topics
David M. Carr <david@carrclan.us>
parents:
442
diff
changeset
|
16 |
9df1741f3977
help: add additional help topics
David M. Carr <david@carrclan.us>
parents:
442
diff
changeset
|
17 For more information and instructions, see :hg:`help git` |
0
06366111af3c
initial import of the hg-git bridging extension for mercurial
Scott Chacon <schacon@gmail.com>
parents:
diff
changeset
|
18 ''' |
06366111af3c
initial import of the hg-git bridging extension for mercurial
Scott Chacon <schacon@gmail.com>
parents:
diff
changeset
|
19 |
481
9df1741f3977
help: add additional help topics
David M. Carr <david@carrclan.us>
parents:
442
diff
changeset
|
20 from bisect import insort |
351
dd90394cd13b
findoutgoing: update wrapper for hg change 98c874a929f1
Augie Fackler <durin42@gmail.com>
parents:
344
diff
changeset
|
21 import inspect |
256
442fe2ca104d
Simpler handling of detection of git repos
Mads Kiilerich <mads@kiilerich.com>
parents:
220
diff
changeset
|
22 import os |
442fe2ca104d
Simpler handling of detection of git repos
Mads Kiilerich <mads@kiilerich.com>
parents:
220
diff
changeset
|
23 |
408 | 24 from mercurial import bundlerepo |
334
eb345bacc1da
Cope with tags being sorted (hg cset c7dbd6c4877a) by backporting that behavior
Augie Fackler <durin42@gmail.com>
parents:
320
diff
changeset
|
25 from mercurial import commands |
362
5b6961384ee2
demandimport: defend against collections breakage in new dulwich
Augie Fackler <durin42@gmail.com>
parents:
352
diff
changeset
|
26 from mercurial import demandimport |
615
503d403fc040
Fix for #68 | Use .gitignore files (with proper semantics)
Ben Kehoe <benk@berkeley.edu>
parents:
556
diff
changeset
|
27 from mercurial import dirstate |
523
8c1f2b07c04b
outgoing: re-introduce support for outgoing
David M. Carr <david@carrclan.us>
parents:
483
diff
changeset
|
28 from mercurial import discovery |
334
eb345bacc1da
Cope with tags being sorted (hg cset c7dbd6c4877a) by backporting that behavior
Augie Fackler <durin42@gmail.com>
parents:
320
diff
changeset
|
29 from mercurial import extensions |
481
9df1741f3977
help: add additional help topics
David M. Carr <david@carrclan.us>
parents:
442
diff
changeset
|
30 from mercurial import help |
334
eb345bacc1da
Cope with tags being sorted (hg cset c7dbd6c4877a) by backporting that behavior
Augie Fackler <durin42@gmail.com>
parents:
320
diff
changeset
|
31 from mercurial import hg |
615
503d403fc040
Fix for #68 | Use .gitignore files (with proper semantics)
Ben Kehoe <benk@berkeley.edu>
parents:
556
diff
changeset
|
32 from mercurial import ignore |
334
eb345bacc1da
Cope with tags being sorted (hg cset c7dbd6c4877a) by backporting that behavior
Augie Fackler <durin42@gmail.com>
parents:
320
diff
changeset
|
33 from mercurial import localrepo |
483
d2caea269670
revsets: add fromgit and gitnode selectors
David M. Carr <david@carrclan.us>
parents:
482
diff
changeset
|
34 from mercurial import revset |
482
00d591868a2f
templatekw: add support for gitnode template keyword
David M. Carr <david@carrclan.us>
parents:
481
diff
changeset
|
35 from mercurial import templatekw |
334
eb345bacc1da
Cope with tags being sorted (hg cset c7dbd6c4877a) by backporting that behavior
Augie Fackler <durin42@gmail.com>
parents:
320
diff
changeset
|
36 from mercurial import util as hgutil |
383
61865ad88740
compatibility with new url handling in Mercurial 1.9
Mads Kiilerich <mads@kiilerich.com>
parents:
373
diff
changeset
|
37 from mercurial import url |
0
06366111af3c
initial import of the hg-git bridging extension for mercurial
Scott Chacon <schacon@gmail.com>
parents:
diff
changeset
|
38 from mercurial.i18n import _ |
220
211fa793d74f
support local git repositories (fixes issue 5 bb)
Abderrahim Kitouni <a.kitouni@gmail.com>
parents:
210
diff
changeset
|
39 |
362
5b6961384ee2
demandimport: defend against collections breakage in new dulwich
Augie Fackler <durin42@gmail.com>
parents:
352
diff
changeset
|
40 demandimport.ignore.extend([ |
5b6961384ee2
demandimport: defend against collections breakage in new dulwich
Augie Fackler <durin42@gmail.com>
parents:
352
diff
changeset
|
41 'collections', |
5b6961384ee2
demandimport: defend against collections breakage in new dulwich
Augie Fackler <durin42@gmail.com>
parents:
352
diff
changeset
|
42 ]) |
5b6961384ee2
demandimport: defend against collections breakage in new dulwich
Augie Fackler <durin42@gmail.com>
parents:
352
diff
changeset
|
43 |
622
6faa5b0f8909
gitignore: gate feature on dirstate having rootcache and ignore having readpats
Augie Fackler <raf@durin42.com>
parents:
615
diff
changeset
|
44 import gitrepo, hgrepo |
5
d6c443a91b18
refactored the git handling stuff out into another class
Scott Chacon <schacon@gmail.com>
parents:
4
diff
changeset
|
45 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
|
46 |
624
3c3d18dae4f5
testedwith: drop 2.3.1, which has at least one test failure
Augie Fackler <raf@durin42.com>
parents:
623
diff
changeset
|
47 testedwith = '1.9.3 2.0.2 2.1.2 2.2.3 2.8.1' |
545 | 48 buglink = 'https://bitbucket.org/durin42/hg-git/issues' |
49 | |
60
05a96f7750ad
add support for `hg clone git://github.com/defunkt/facebox.git`
Chris Wanstrath <chris@ozmm.org>
parents:
59
diff
changeset
|
50 # 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
|
51 # also hg clone git+ssh://git@github.com/schacon/simplegit.git |
439
3f45c88100e8
add support for the HTTP smart protocol when using Dulwich tip
Dan Villiom Podlaski Christiansen <danchr@gmail.com>
parents:
430
diff
changeset
|
52 _gitschemes = ('git', 'git+ssh', 'git+http', 'git+https') |
3f45c88100e8
add support for the HTTP smart protocol when using Dulwich tip
Dan Villiom Podlaski Christiansen <danchr@gmail.com>
parents:
430
diff
changeset
|
53 for _scheme in _gitschemes: |
3f45c88100e8
add support for the HTTP smart protocol when using Dulwich tip
Dan Villiom Podlaski Christiansen <danchr@gmail.com>
parents:
430
diff
changeset
|
54 hg.schemes[_scheme] = gitrepo |
180
682863000e9a
Make it possible to clone/pull from bundle repositories
Abderrahim Kitouni <a.kitouni@gmail.com>
parents:
175
diff
changeset
|
55 |
256
442fe2ca104d
Simpler handling of detection of git repos
Mads Kiilerich <mads@kiilerich.com>
parents:
220
diff
changeset
|
56 # 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
|
57 _oldlocal = hg.schemes['file'] |
211fa793d74f
support local git repositories (fixes issue 5 bb)
Abderrahim Kitouni <a.kitouni@gmail.com>
parents:
210
diff
changeset
|
58 |
388
bcc79fa3fe09
url wasn't ever published as url.url, and is now util.url
Augie Fackler <durin42@gmail.com>
parents:
383
diff
changeset
|
59 try: |
bcc79fa3fe09
url wasn't ever published as url.url, and is now util.url
Augie Fackler <durin42@gmail.com>
parents:
383
diff
changeset
|
60 urlcls = hgutil.url |
bcc79fa3fe09
url wasn't ever published as url.url, and is now util.url
Augie Fackler <durin42@gmail.com>
parents:
383
diff
changeset
|
61 except AttributeError: |
bcc79fa3fe09
url wasn't ever published as url.url, and is now util.url
Augie Fackler <durin42@gmail.com>
parents:
383
diff
changeset
|
62 class urlcls(object): |
bcc79fa3fe09
url wasn't ever published as url.url, and is now util.url
Augie Fackler <durin42@gmail.com>
parents:
383
diff
changeset
|
63 def __init__(self, path): |
bcc79fa3fe09
url wasn't ever published as url.url, and is now util.url
Augie Fackler <durin42@gmail.com>
parents:
383
diff
changeset
|
64 self.p = hgutil.drop_scheme('file', path) |
bcc79fa3fe09
url wasn't ever published as url.url, and is now util.url
Augie Fackler <durin42@gmail.com>
parents:
383
diff
changeset
|
65 |
bcc79fa3fe09
url wasn't ever published as url.url, and is now util.url
Augie Fackler <durin42@gmail.com>
parents:
383
diff
changeset
|
66 def localpath(self): |
bcc79fa3fe09
url wasn't ever published as url.url, and is now util.url
Augie Fackler <durin42@gmail.com>
parents:
383
diff
changeset
|
67 return self.p |
bcc79fa3fe09
url wasn't ever published as url.url, and is now util.url
Augie Fackler <durin42@gmail.com>
parents:
383
diff
changeset
|
68 |
220
211fa793d74f
support local git repositories (fixes issue 5 bb)
Abderrahim Kitouni <a.kitouni@gmail.com>
parents:
210
diff
changeset
|
69 def _local(path): |
388
bcc79fa3fe09
url wasn't ever published as url.url, and is now util.url
Augie Fackler <durin42@gmail.com>
parents:
383
diff
changeset
|
70 p = urlcls(path).localpath() |
280 | 71 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
|
72 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
|
73 return gitrepo |
263
9f5a7a5d52aa
Enable detection of bare repositories as a local git repo
Lincoln Stoll <lstoll@lstoll.net>
parents:
260
diff
changeset
|
74 # detect a bare repository |
280 | 75 if (os.path.exists(os.path.join(p, 'HEAD')) and |
76 os.path.exists(os.path.join(p, 'objects')) and | |
77 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
|
78 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
|
79 return gitrepo |
256
442fe2ca104d
Simpler handling of detection of git repos
Mads Kiilerich <mads@kiilerich.com>
parents:
220
diff
changeset
|
80 return _oldlocal(path) |
220
211fa793d74f
support local git repositories (fixes issue 5 bb)
Abderrahim Kitouni <a.kitouni@gmail.com>
parents:
210
diff
changeset
|
81 |
211fa793d74f
support local git repositories (fixes issue 5 bb)
Abderrahim Kitouni <a.kitouni@gmail.com>
parents:
210
diff
changeset
|
82 hg.schemes['file'] = _local |
211fa793d74f
support local git repositories (fixes issue 5 bb)
Abderrahim Kitouni <a.kitouni@gmail.com>
parents:
210
diff
changeset
|
83 |
281
a14529b7b8f2
init: strip .git for default clone destination for git sources
Augie Fackler <durin42@gmail.com>
parents:
280
diff
changeset
|
84 hgdefaultdest = hg.defaultdest |
a14529b7b8f2
init: strip .git for default clone destination for git sources
Augie Fackler <durin42@gmail.com>
parents:
280
diff
changeset
|
85 def defaultdest(source): |
439
3f45c88100e8
add support for the HTTP smart protocol when using Dulwich tip
Dan Villiom Podlaski Christiansen <danchr@gmail.com>
parents:
430
diff
changeset
|
86 for scheme in _gitschemes: |
281
a14529b7b8f2
init: strip .git for default clone destination for git sources
Augie Fackler <durin42@gmail.com>
parents:
280
diff
changeset
|
87 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
|
88 source = source[:-4] |
a14529b7b8f2
init: strip .git for default clone destination for git sources
Augie Fackler <durin42@gmail.com>
parents:
280
diff
changeset
|
89 break |
a14529b7b8f2
init: strip .git for default clone destination for git sources
Augie Fackler <durin42@gmail.com>
parents:
280
diff
changeset
|
90 return hgdefaultdest(source) |
a14529b7b8f2
init: strip .git for default clone destination for git sources
Augie Fackler <durin42@gmail.com>
parents:
280
diff
changeset
|
91 hg.defaultdest = defaultdest |
a14529b7b8f2
init: strip .git for default clone destination for git sources
Augie Fackler <durin42@gmail.com>
parents:
280
diff
changeset
|
92 |
297
a90fe3e8a8c3
hggit: defend against exceptions when pulling with -r
Augie Fackler <durin42@gmail.com>
parents:
296
diff
changeset
|
93 # 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
|
94 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
|
95 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
|
96 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
|
97 co = None |
a90fe3e8a8c3
hggit: defend against exceptions when pulling with -r
Augie Fackler <durin42@gmail.com>
parents:
296
diff
changeset
|
98 return revs, co |
300
eec31dee258e
Various hg 1.4 compat fixes.
Augie Fackler <durin42@gmail.com>
parents:
298
diff
changeset
|
99 if getattr(hg, 'addbranchrevs', False): |
eec31dee258e
Various hg 1.4 compat fixes.
Augie Fackler <durin42@gmail.com>
parents:
298
diff
changeset
|
100 extensions.wrapfunction(hg, 'addbranchrevs', safebranchrevs) |
297
a90fe3e8a8c3
hggit: defend against exceptions when pulling with -r
Augie Fackler <durin42@gmail.com>
parents:
296
diff
changeset
|
101 |
481
9df1741f3977
help: add additional help topics
David M. Carr <david@carrclan.us>
parents:
442
diff
changeset
|
102 def extsetup(): |
482
00d591868a2f
templatekw: add support for gitnode template keyword
David M. Carr <david@carrclan.us>
parents:
481
diff
changeset
|
103 templatekw.keywords.update({'gitnode': gitnodekw}) |
483
d2caea269670
revsets: add fromgit and gitnode selectors
David M. Carr <david@carrclan.us>
parents:
482
diff
changeset
|
104 revset.symbols.update({ |
d2caea269670
revsets: add fromgit and gitnode selectors
David M. Carr <david@carrclan.us>
parents:
482
diff
changeset
|
105 'fromgit': revset_fromgit, 'gitnode': revset_gitnode |
d2caea269670
revsets: add fromgit and gitnode selectors
David M. Carr <david@carrclan.us>
parents:
482
diff
changeset
|
106 }) |
481
9df1741f3977
help: add additional help topics
David M. Carr <david@carrclan.us>
parents:
442
diff
changeset
|
107 helpdir = os.path.join(os.path.dirname(__file__), 'help') |
9df1741f3977
help: add additional help topics
David M. Carr <david@carrclan.us>
parents:
442
diff
changeset
|
108 entry = (['git'], _("Working with Git Repositories"), |
9df1741f3977
help: add additional help topics
David M. Carr <david@carrclan.us>
parents:
442
diff
changeset
|
109 lambda: open(os.path.join(helpdir, 'git.rst')).read()) |
9df1741f3977
help: add additional help topics
David M. Carr <david@carrclan.us>
parents:
442
diff
changeset
|
110 # in 1.6 and earler the help table is a tuple |
9df1741f3977
help: add additional help topics
David M. Carr <david@carrclan.us>
parents:
442
diff
changeset
|
111 if getattr(help.helptable, 'extend', None): |
9df1741f3977
help: add additional help topics
David M. Carr <david@carrclan.us>
parents:
442
diff
changeset
|
112 insort(help.helptable, entry) |
9df1741f3977
help: add additional help topics
David M. Carr <david@carrclan.us>
parents:
442
diff
changeset
|
113 else: |
9df1741f3977
help: add additional help topics
David M. Carr <david@carrclan.us>
parents:
442
diff
changeset
|
114 help.helptable = help.helptable + (entry,) |
9df1741f3977
help: add additional help topics
David M. Carr <david@carrclan.us>
parents:
442
diff
changeset
|
115 |
206
5986ac6a591e
create the repository subclass in reposetup
Abderrahim Kitouni <a.kitouni@gmail.com>
parents:
182
diff
changeset
|
116 def reposetup(ui, repo): |
296
32456f9cb7a4
hggit: don't wrap gitrepo with hgrepo
Augie Fackler <durin42@gmail.com>
parents:
281
diff
changeset
|
117 if not isinstance(repo, gitrepo.gitrepo): |
32456f9cb7a4
hggit: don't wrap gitrepo with hgrepo
Augie Fackler <durin42@gmail.com>
parents:
281
diff
changeset
|
118 klass = hgrepo.generate_repo_subclass(repo.__class__) |
32456f9cb7a4
hggit: don't wrap gitrepo with hgrepo
Augie Fackler <durin42@gmail.com>
parents:
281
diff
changeset
|
119 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
|
120 |
137
5aefcbf1e50c
add a gimport command
Sverre Rabbelier <sverre@rabbelier.nl>
parents:
136
diff
changeset
|
121 def gimport(ui, repo, remote_name=None): |
663
ad0d90fa7a4f
gimport: use githandler from repo
Siddharth Agarwal <sid0@fb.com>
parents:
624
diff
changeset
|
122 repo.githandler.import_commits(remote_name) |
137
5aefcbf1e50c
add a gimport command
Sverre Rabbelier <sverre@rabbelier.nl>
parents:
136
diff
changeset
|
123 |
97 | 124 def gexport(ui, repo): |
664
570c3702b916
gexport: use githandler from repo
Siddharth Agarwal <sid0@fb.com>
parents:
663
diff
changeset
|
125 repo.githandler.export_commits() |
97 | 126 |
40
f5b000ec7100
added gclear command to remove all the git data
Scott Chacon <schacon@gmail.com>
parents:
39
diff
changeset
|
127 def gclear(ui, repo): |
f5b000ec7100
added gclear command to remove all the git data
Scott Chacon <schacon@gmail.com>
parents:
39
diff
changeset
|
128 repo.ui.status(_("clearing out the git cache data\n")) |
665
2659f63f0beb
gclear: use githandler from repo
Siddharth Agarwal <sid0@fb.com>
parents:
664
diff
changeset
|
129 repo.githandler.clear() |
622
6faa5b0f8909
gitignore: gate feature on dirstate having rootcache and ignore having readpats
Augie Fackler <raf@durin42.com>
parents:
615
diff
changeset
|
130 |
6faa5b0f8909
gitignore: gate feature on dirstate having rootcache and ignore having readpats
Augie Fackler <raf@durin42.com>
parents:
615
diff
changeset
|
131 from mercurial import dirstate |
6faa5b0f8909
gitignore: gate feature on dirstate having rootcache and ignore having readpats
Augie Fackler <raf@durin42.com>
parents:
615
diff
changeset
|
132 from mercurial import ignore |
6faa5b0f8909
gitignore: gate feature on dirstate having rootcache and ignore having readpats
Augie Fackler <raf@durin42.com>
parents:
615
diff
changeset
|
133 if (getattr(dirstate, 'rootcache', False) and |
6faa5b0f8909
gitignore: gate feature on dirstate having rootcache and ignore having readpats
Augie Fackler <raf@durin42.com>
parents:
615
diff
changeset
|
134 getattr(ignore, 'readpats', False)): |
6faa5b0f8909
gitignore: gate feature on dirstate having rootcache and ignore having readpats
Augie Fackler <raf@durin42.com>
parents:
615
diff
changeset
|
135 # only install our dirstate wrapper if it has a hope of working |
6faa5b0f8909
gitignore: gate feature on dirstate having rootcache and ignore having readpats
Augie Fackler <raf@durin42.com>
parents:
615
diff
changeset
|
136 import gitdirstate |
6faa5b0f8909
gitignore: gate feature on dirstate having rootcache and ignore having readpats
Augie Fackler <raf@durin42.com>
parents:
615
diff
changeset
|
137 extensions.wrapfunction(ignore, 'ignore', gitdirstate.gignore) |
6faa5b0f8909
gitignore: gate feature on dirstate having rootcache and ignore having readpats
Augie Fackler <raf@durin42.com>
parents:
615
diff
changeset
|
138 dirstate.dirstate = gitdirstate.gitdirstate |
59
19d714ee9941
gfetch should access repo when printing, not dest_repo
Chris Wanstrath <chris@ozmm.org>
parents:
40
diff
changeset
|
139 |
298
6ad6945b6629
pull: make it possible to un-wedge the repo after stripping git revs
Augie Fackler <durin42@gmail.com>
parents:
297
diff
changeset
|
140 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
|
141 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
|
142 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
|
143 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
|
144 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
|
145 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
|
146 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
|
147 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
|
148 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
|
149 |
334
eb345bacc1da
Cope with tags being sorted (hg cset c7dbd6c4877a) by backporting that behavior
Augie Fackler <durin42@gmail.com>
parents:
320
diff
changeset
|
150 # 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
|
151 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
|
152 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
|
153 ret.sort() |
eb345bacc1da
Cope with tags being sorted (hg cset c7dbd6c4877a) by backporting that behavior
Augie Fackler <durin42@gmail.com>
parents:
320
diff
changeset
|
154 return ret |
eb345bacc1da
Cope with tags being sorted (hg cset c7dbd6c4877a) by backporting that behavior
Augie Fackler <durin42@gmail.com>
parents:
320
diff
changeset
|
155 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
|
156 |
523
8c1f2b07c04b
outgoing: re-introduce support for outgoing
David M. Carr <david@carrclan.us>
parents:
483
diff
changeset
|
157 def findcommonoutgoing(orig, repo, other, *args, **kwargs): |
8c1f2b07c04b
outgoing: re-introduce support for outgoing
David M. Carr <david@carrclan.us>
parents:
483
diff
changeset
|
158 if isinstance(other, gitrepo.gitrepo): |
666
27fefb7e7cec
findcommonoutgoing: use githandler from repo
Siddharth Agarwal <sid0@fb.com>
parents:
665
diff
changeset
|
159 heads = repo.githandler.get_refs(other.path)[0] |
523
8c1f2b07c04b
outgoing: re-introduce support for outgoing
David M. Carr <david@carrclan.us>
parents:
483
diff
changeset
|
160 kw = {} |
8c1f2b07c04b
outgoing: re-introduce support for outgoing
David M. Carr <david@carrclan.us>
parents:
483
diff
changeset
|
161 kw.update(kwargs) |
8c1f2b07c04b
outgoing: re-introduce support for outgoing
David M. Carr <david@carrclan.us>
parents:
483
diff
changeset
|
162 for val, k in zip(args, |
8c1f2b07c04b
outgoing: re-introduce support for outgoing
David M. Carr <david@carrclan.us>
parents:
483
diff
changeset
|
163 ('onlyheads', 'force', 'commoninc', 'portable')): |
8c1f2b07c04b
outgoing: re-introduce support for outgoing
David M. Carr <david@carrclan.us>
parents:
483
diff
changeset
|
164 kw[k] = val |
8c1f2b07c04b
outgoing: re-introduce support for outgoing
David M. Carr <david@carrclan.us>
parents:
483
diff
changeset
|
165 force = kw.get('force', False) |
8c1f2b07c04b
outgoing: re-introduce support for outgoing
David M. Carr <david@carrclan.us>
parents:
483
diff
changeset
|
166 commoninc = kw.get('commoninc', None) |
8c1f2b07c04b
outgoing: re-introduce support for outgoing
David M. Carr <david@carrclan.us>
parents:
483
diff
changeset
|
167 if commoninc is None: |
8c1f2b07c04b
outgoing: re-introduce support for outgoing
David M. Carr <david@carrclan.us>
parents:
483
diff
changeset
|
168 commoninc = discovery.findcommonincoming(repo, other, |
8c1f2b07c04b
outgoing: re-introduce support for outgoing
David M. Carr <david@carrclan.us>
parents:
483
diff
changeset
|
169 heads=heads, force=force) |
8c1f2b07c04b
outgoing: re-introduce support for outgoing
David M. Carr <david@carrclan.us>
parents:
483
diff
changeset
|
170 kw['commoninc'] = commoninc |
8c1f2b07c04b
outgoing: re-introduce support for outgoing
David M. Carr <david@carrclan.us>
parents:
483
diff
changeset
|
171 return orig(repo, other, **kw) |
8c1f2b07c04b
outgoing: re-introduce support for outgoing
David M. Carr <david@carrclan.us>
parents:
483
diff
changeset
|
172 return orig(repo, other, *args, **kwargs) |
8c1f2b07c04b
outgoing: re-introduce support for outgoing
David M. Carr <david@carrclan.us>
parents:
483
diff
changeset
|
173 extensions.wrapfunction(discovery, 'findcommonoutgoing', findcommonoutgoing) |
344
af48a5961432
Add just enough code to handle changes to cset discovery.
Augie Fackler <durin42@gmail.com>
parents:
334
diff
changeset
|
174 |
412 | 175 def getremotechanges(orig, ui, repo, other, *args, **opts): |
408 | 176 if isinstance(other, gitrepo.gitrepo): |
424
d2c4333e5f14
getremotechanges: fix incoming support
Augie Fackler <durin42@gmail.com>
parents:
412
diff
changeset
|
177 if args: |
d2c4333e5f14
getremotechanges: fix incoming support
Augie Fackler <durin42@gmail.com>
parents:
412
diff
changeset
|
178 revs = args[0] |
d2c4333e5f14
getremotechanges: fix incoming support
Augie Fackler <durin42@gmail.com>
parents:
412
diff
changeset
|
179 else: |
d2c4333e5f14
getremotechanges: fix incoming support
Augie Fackler <durin42@gmail.com>
parents:
412
diff
changeset
|
180 revs = opts.get('onlyheads', opts.get('revs')) |
667
b5ef3f0e0efe
getremotechanges: use githandler from repo
Siddharth Agarwal <sid0@fb.com>
parents:
666
diff
changeset
|
181 r, c, cleanup = repo.githandler.getremotechanges(other, revs) |
408 | 182 # ugh. This is ugly even by mercurial API compatibility standards |
183 if 'onlyheads' not in orig.func_code.co_varnames: | |
184 cleanup = None | |
185 return r, c, cleanup | |
412 | 186 return orig(ui, repo, other, *args, **opts) |
408 | 187 try: |
188 extensions.wrapfunction(bundlerepo, 'getremotechanges', getremotechanges) | |
189 except AttributeError: | |
190 # 1.7+ | |
191 pass | |
192 | |
556
affd119533ae
peer: pass localrepo to new gitrepo instances
David M. Carr <david@carrclan.us>
parents:
546
diff
changeset
|
193 def peer(orig, uiorrepo, *args, **opts): |
affd119533ae
peer: pass localrepo to new gitrepo instances
David M. Carr <david@carrclan.us>
parents:
546
diff
changeset
|
194 newpeer = orig(uiorrepo, *args, **opts) |
affd119533ae
peer: pass localrepo to new gitrepo instances
David M. Carr <david@carrclan.us>
parents:
546
diff
changeset
|
195 if isinstance(newpeer, gitrepo.gitrepo): |
affd119533ae
peer: pass localrepo to new gitrepo instances
David M. Carr <david@carrclan.us>
parents:
546
diff
changeset
|
196 if isinstance(uiorrepo, localrepo.localrepository): |
affd119533ae
peer: pass localrepo to new gitrepo instances
David M. Carr <david@carrclan.us>
parents:
546
diff
changeset
|
197 newpeer.localrepo = uiorrepo |
affd119533ae
peer: pass localrepo to new gitrepo instances
David M. Carr <david@carrclan.us>
parents:
546
diff
changeset
|
198 return newpeer |
affd119533ae
peer: pass localrepo to new gitrepo instances
David M. Carr <david@carrclan.us>
parents:
546
diff
changeset
|
199 extensions.wrapfunction(hg, 'peer', peer) |
affd119533ae
peer: pass localrepo to new gitrepo instances
David M. Carr <david@carrclan.us>
parents:
546
diff
changeset
|
200 |
483
d2caea269670
revsets: add fromgit and gitnode selectors
David M. Carr <david@carrclan.us>
parents:
482
diff
changeset
|
201 def revset_fromgit(repo, subset, x): |
d2caea269670
revsets: add fromgit and gitnode selectors
David M. Carr <david@carrclan.us>
parents:
482
diff
changeset
|
202 '''``fromgit()`` |
d2caea269670
revsets: add fromgit and gitnode selectors
David M. Carr <david@carrclan.us>
parents:
482
diff
changeset
|
203 Select changesets that originate from Git. |
d2caea269670
revsets: add fromgit and gitnode selectors
David M. Carr <david@carrclan.us>
parents:
482
diff
changeset
|
204 ''' |
d2caea269670
revsets: add fromgit and gitnode selectors
David M. Carr <david@carrclan.us>
parents:
482
diff
changeset
|
205 args = revset.getargs(x, 0, 0, "fromgit takes no arguments") |
668
98e118410521
revset_fromgit: use githandler from repo
Siddharth Agarwal <sid0@fb.com>
parents:
667
diff
changeset
|
206 git = repo.githandler |
483
d2caea269670
revsets: add fromgit and gitnode selectors
David M. Carr <david@carrclan.us>
parents:
482
diff
changeset
|
207 return [r for r in subset if git.map_git_get(repo[r].hex()) is not None] |
d2caea269670
revsets: add fromgit and gitnode selectors
David M. Carr <david@carrclan.us>
parents:
482
diff
changeset
|
208 |
d2caea269670
revsets: add fromgit and gitnode selectors
David M. Carr <david@carrclan.us>
parents:
482
diff
changeset
|
209 def revset_gitnode(repo, subset, x): |
d2caea269670
revsets: add fromgit and gitnode selectors
David M. Carr <david@carrclan.us>
parents:
482
diff
changeset
|
210 '''``gitnode(hash)`` |
d2caea269670
revsets: add fromgit and gitnode selectors
David M. Carr <david@carrclan.us>
parents:
482
diff
changeset
|
211 Select changesets that originate in the given Git revision. |
d2caea269670
revsets: add fromgit and gitnode selectors
David M. Carr <david@carrclan.us>
parents:
482
diff
changeset
|
212 ''' |
d2caea269670
revsets: add fromgit and gitnode selectors
David M. Carr <david@carrclan.us>
parents:
482
diff
changeset
|
213 args = revset.getargs(x, 1, 1, "gitnode takes one argument") |
d2caea269670
revsets: add fromgit and gitnode selectors
David M. Carr <david@carrclan.us>
parents:
482
diff
changeset
|
214 rev = revset.getstring(args[0], |
d2caea269670
revsets: add fromgit and gitnode selectors
David M. Carr <david@carrclan.us>
parents:
482
diff
changeset
|
215 "the argument to gitnode() must be a hash") |
d2caea269670
revsets: add fromgit and gitnode selectors
David M. Carr <david@carrclan.us>
parents:
482
diff
changeset
|
216 git = GitHandler(repo, repo.ui) |
d2caea269670
revsets: add fromgit and gitnode selectors
David M. Carr <david@carrclan.us>
parents:
482
diff
changeset
|
217 def matches(r): |
d2caea269670
revsets: add fromgit and gitnode selectors
David M. Carr <david@carrclan.us>
parents:
482
diff
changeset
|
218 gitnode = git.map_git_get(repo[r].hex()) |
d2caea269670
revsets: add fromgit and gitnode selectors
David M. Carr <david@carrclan.us>
parents:
482
diff
changeset
|
219 if gitnode is None: |
d2caea269670
revsets: add fromgit and gitnode selectors
David M. Carr <david@carrclan.us>
parents:
482
diff
changeset
|
220 return False |
d2caea269670
revsets: add fromgit and gitnode selectors
David M. Carr <david@carrclan.us>
parents:
482
diff
changeset
|
221 return rev in [gitnode, gitnode[:12]] |
d2caea269670
revsets: add fromgit and gitnode selectors
David M. Carr <david@carrclan.us>
parents:
482
diff
changeset
|
222 return [r for r in subset if matches(r)] |
d2caea269670
revsets: add fromgit and gitnode selectors
David M. Carr <david@carrclan.us>
parents:
482
diff
changeset
|
223 |
482
00d591868a2f
templatekw: add support for gitnode template keyword
David M. Carr <david@carrclan.us>
parents:
481
diff
changeset
|
224 def gitnodekw(**args): |
00d591868a2f
templatekw: add support for gitnode template keyword
David M. Carr <david@carrclan.us>
parents:
481
diff
changeset
|
225 """:gitnode: String. The Git changeset identification hash, as a 40 hexadecimal digit string.""" |
00d591868a2f
templatekw: add support for gitnode template keyword
David M. Carr <david@carrclan.us>
parents:
481
diff
changeset
|
226 node = args['ctx'] |
00d591868a2f
templatekw: add support for gitnode template keyword
David M. Carr <david@carrclan.us>
parents:
481
diff
changeset
|
227 repo = args['repo'] |
00d591868a2f
templatekw: add support for gitnode template keyword
David M. Carr <david@carrclan.us>
parents:
481
diff
changeset
|
228 git = GitHandler(repo, repo.ui) |
00d591868a2f
templatekw: add support for gitnode template keyword
David M. Carr <david@carrclan.us>
parents:
481
diff
changeset
|
229 gitnode = git.map_git_get(node.hex()) |
00d591868a2f
templatekw: add support for gitnode template keyword
David M. Carr <david@carrclan.us>
parents:
481
diff
changeset
|
230 if gitnode is None: |
00d591868a2f
templatekw: add support for gitnode template keyword
David M. Carr <david@carrclan.us>
parents:
481
diff
changeset
|
231 gitnode = '' |
00d591868a2f
templatekw: add support for gitnode template keyword
David M. Carr <david@carrclan.us>
parents:
481
diff
changeset
|
232 return gitnode |
00d591868a2f
templatekw: add support for gitnode template keyword
David M. Carr <david@carrclan.us>
parents:
481
diff
changeset
|
233 |
0
06366111af3c
initial import of the hg-git bridging extension for mercurial
Scott Chacon <schacon@gmail.com>
parents:
diff
changeset
|
234 cmdtable = { |
137
5aefcbf1e50c
add a gimport command
Sverre Rabbelier <sverre@rabbelier.nl>
parents:
136
diff
changeset
|
235 "gimport": |
5aefcbf1e50c
add a gimport command
Sverre Rabbelier <sverre@rabbelier.nl>
parents:
136
diff
changeset
|
236 (gimport, [], _('hg gimport')), |
97 | 237 "gexport": |
238 (gexport, [], _('hg gexport')), | |
40
f5b000ec7100
added gclear command to remove all the git data
Scott Chacon <schacon@gmail.com>
parents:
39
diff
changeset
|
239 "gclear": |
f5b000ec7100
added gclear command to remove all the git data
Scott Chacon <schacon@gmail.com>
parents:
39
diff
changeset
|
240 (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
|
241 "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
|
242 "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
|
243 } |