annotate hggit/gitrepo.py @ 1052:5db8d0d0ae47

compat: update for upcoming hg 4.4 release This is a bit of a simplification of an earlier patch from Jun Wu <quark@fb.com>.
author Kevin Bullock <kbullock@ringworld.org>
date Sun, 01 Oct 2017 12:51:49 +0100
parents be627eeee5a9
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
921
0e975d03f8ca gitrepo: use isgitsshuri in islocal
Sean Farley <sean@farley.io>
parents: 891
diff changeset
1 from util import isgitsshuri
461
de618e24dcdd gitrepo: cope with module/class renames in hg 2.3
Bryan O'Sullivan <bryano@fb.com>
parents: 458
diff changeset
2 from mercurial import util
967
be627eeee5a9 gitrepo: clean up compat cruft
Siddharth Agarwal <sid0@fb.com>
parents: 921
diff changeset
3 from mercurial.error import RepoError
1052
5db8d0d0ae47 compat: update for upcoming hg 4.4 release
Kevin Bullock <kbullock@ringworld.org>
parents: 967
diff changeset
4
5db8d0d0ae47 compat: update for upcoming hg 4.4 release
Kevin Bullock <kbullock@ringworld.org>
parents: 967
diff changeset
5 peerapi = False
5db8d0d0ae47 compat: update for upcoming hg 4.4 release
Kevin Bullock <kbullock@ringworld.org>
parents: 967
diff changeset
6 try:
5db8d0d0ae47 compat: update for upcoming hg 4.4 release
Kevin Bullock <kbullock@ringworld.org>
parents: 967
diff changeset
7 from mercurial.repository import peer as peerrepository
5db8d0d0ae47 compat: update for upcoming hg 4.4 release
Kevin Bullock <kbullock@ringworld.org>
parents: 967
diff changeset
8 peerapi = True
5db8d0d0ae47 compat: update for upcoming hg 4.4 release
Kevin Bullock <kbullock@ringworld.org>
parents: 967
diff changeset
9 except ImportError:
5db8d0d0ae47 compat: update for upcoming hg 4.4 release
Kevin Bullock <kbullock@ringworld.org>
parents: 967
diff changeset
10 from mercurial.peer import peerrepository
461
de618e24dcdd gitrepo: cope with module/class renames in hg 2.3
Bryan O'Sullivan <bryano@fb.com>
parents: 458
diff changeset
11
462
406ed78809b2 gitrepo: correct capitalization of peerrepository
Augie Fackler <raf@durin42.com>
parents: 461
diff changeset
12 class gitrepo(peerrepository):
179
c5c63783ace0 Initial clone/pull/push support for git repositories
Abderrahim Kitouni <a.kitouni@gmail.com>
parents: 61
diff changeset
13 def __init__(self, ui, path, create):
891
5322f12e64ed gitrepo: flake8 cleanups
Sean Farley <sean@farley.io>
parents: 868
diff changeset
14 if create: # pragma: no cover
179
c5c63783ace0 Initial clone/pull/push support for git repositories
Abderrahim Kitouni <a.kitouni@gmail.com>
parents: 61
diff changeset
15 raise util.Abort('Cannot create a git repository.')
1052
5db8d0d0ae47 compat: update for upcoming hg 4.4 release
Kevin Bullock <kbullock@ringworld.org>
parents: 967
diff changeset
16 self._ui = ui
179
c5c63783ace0 Initial clone/pull/push support for git repositories
Abderrahim Kitouni <a.kitouni@gmail.com>
parents: 61
diff changeset
17 self.path = path
556
affd119533ae peer: pass localrepo to new gitrepo instances
David M. Carr <david@carrclan.us>
parents: 465
diff changeset
18 self.localrepo = None
347
2efbee89d3f7 gitrepo: update for pushable bookmarks
Augie Fackler <durin42@gmail.com>
parents: 344
diff changeset
19
1052
5db8d0d0ae47 compat: update for upcoming hg 4.4 release
Kevin Bullock <kbullock@ringworld.org>
parents: 967
diff changeset
20 _peercapabilities = ['lookup']
5db8d0d0ae47 compat: update for upcoming hg 4.4 release
Kevin Bullock <kbullock@ringworld.org>
parents: 967
diff changeset
21
5db8d0d0ae47 compat: update for upcoming hg 4.4 release
Kevin Bullock <kbullock@ringworld.org>
parents: 967
diff changeset
22 def _capabilities(self):
5db8d0d0ae47 compat: update for upcoming hg 4.4 release
Kevin Bullock <kbullock@ringworld.org>
parents: 967
diff changeset
23 return self._peercapabilities
5db8d0d0ae47 compat: update for upcoming hg 4.4 release
Kevin Bullock <kbullock@ringworld.org>
parents: 967
diff changeset
24
5db8d0d0ae47 compat: update for upcoming hg 4.4 release
Kevin Bullock <kbullock@ringworld.org>
parents: 967
diff changeset
25 def capabilities(self):
5db8d0d0ae47 compat: update for upcoming hg 4.4 release
Kevin Bullock <kbullock@ringworld.org>
parents: 967
diff changeset
26 return self._peercapabilities
5db8d0d0ae47 compat: update for upcoming hg 4.4 release
Kevin Bullock <kbullock@ringworld.org>
parents: 967
diff changeset
27
5db8d0d0ae47 compat: update for upcoming hg 4.4 release
Kevin Bullock <kbullock@ringworld.org>
parents: 967
diff changeset
28 @property
5db8d0d0ae47 compat: update for upcoming hg 4.4 release
Kevin Bullock <kbullock@ringworld.org>
parents: 967
diff changeset
29 def ui(self):
5db8d0d0ae47 compat: update for upcoming hg 4.4 release
Kevin Bullock <kbullock@ringworld.org>
parents: 967
diff changeset
30 return self._ui
5db8d0d0ae47 compat: update for upcoming hg 4.4 release
Kevin Bullock <kbullock@ringworld.org>
parents: 967
diff changeset
31
458
dfb2b7b5d586 gitrepo: add url() attribute to fix subrepo support
Augie Fackler <raf@durin42.com>
parents: 409
diff changeset
32 def url(self):
dfb2b7b5d586 gitrepo: add url() attribute to fix subrepo support
Augie Fackler <raf@durin42.com>
parents: 409
diff changeset
33 return self.path
dfb2b7b5d586 gitrepo: add url() attribute to fix subrepo support
Augie Fackler <raf@durin42.com>
parents: 409
diff changeset
34
232
0ba1aee0467c initial support for pull -r
Abderrahim Kitouni <a.kitouni@gmail.com>
parents: 215
diff changeset
35 def lookup(self, key):
0ba1aee0467c initial support for pull -r
Abderrahim Kitouni <a.kitouni@gmail.com>
parents: 215
diff changeset
36 if isinstance(key, str):
0ba1aee0467c initial support for pull -r
Abderrahim Kitouni <a.kitouni@gmail.com>
parents: 215
diff changeset
37 return key
347
2efbee89d3f7 gitrepo: update for pushable bookmarks
Augie Fackler <durin42@gmail.com>
parents: 344
diff changeset
38
257
75063203cfb5 Simple hack for handling wrong use of git repos (fixes issue 24 bb)
Abderrahim Kitouni <a.kitouni@gmail.com>
parents: 232
diff changeset
39 def local(self):
75063203cfb5 Simple hack for handling wrong use of git repos (fixes issue 24 bb)
Abderrahim Kitouni <a.kitouni@gmail.com>
parents: 232
diff changeset
40 if not self.path:
75063203cfb5 Simple hack for handling wrong use of git repos (fixes issue 24 bb)
Abderrahim Kitouni <a.kitouni@gmail.com>
parents: 232
diff changeset
41 raise RepoError
347
2efbee89d3f7 gitrepo: update for pushable bookmarks
Augie Fackler <durin42@gmail.com>
parents: 344
diff changeset
42
344
af48a5961432 Add just enough code to handle changes to cset discovery.
Augie Fackler <durin42@gmail.com>
parents: 260
diff changeset
43 def heads(self):
af48a5961432 Add just enough code to handle changes to cset discovery.
Augie Fackler <durin42@gmail.com>
parents: 260
diff changeset
44 return []
257
75063203cfb5 Simple hack for handling wrong use of git repos (fixes issue 24 bb)
Abderrahim Kitouni <a.kitouni@gmail.com>
parents: 232
diff changeset
45
347
2efbee89d3f7 gitrepo: update for pushable bookmarks
Augie Fackler <durin42@gmail.com>
parents: 344
diff changeset
46 def listkeys(self, namespace):
557
4f4ab2d89375 gitrepo: initial support for listkeys
David M. Carr <david@carrclan.us>
parents: 556
diff changeset
47 if namespace == 'namespaces':
891
5322f12e64ed gitrepo: flake8 cleanups
Sean Farley <sean@farley.io>
parents: 868
diff changeset
48 return {'bookmarks': ''}
557
4f4ab2d89375 gitrepo: initial support for listkeys
David M. Carr <david@carrclan.us>
parents: 556
diff changeset
49 elif namespace == 'bookmarks':
662
a0c7824d28ae gitrepo.listkeys: use githandler from localrepo
Siddharth Agarwal <sid0@fb.com>
parents: 564
diff changeset
50 if self.localrepo is not None:
a0c7824d28ae gitrepo.listkeys: use githandler from localrepo
Siddharth Agarwal <sid0@fb.com>
parents: 564
diff changeset
51 handler = self.localrepo.githandler
718
40c43c02f5b1 listkeys: while looking for bookmarks, don't fetch a pack
Siddharth Agarwal <sid0@fb.com>
parents: 679
diff changeset
52 refs = handler.fetch_pack(self.path, heads=[])
40c43c02f5b1 listkeys: while looking for bookmarks, don't fetch a pack
Siddharth Agarwal <sid0@fb.com>
parents: 679
diff changeset
53 # map any git shas that exist in hg to hg shas
557
4f4ab2d89375 gitrepo: initial support for listkeys
David M. Carr <david@carrclan.us>
parents: 556
diff changeset
54 stripped_refs = dict([
718
40c43c02f5b1 listkeys: while looking for bookmarks, don't fetch a pack
Siddharth Agarwal <sid0@fb.com>
parents: 679
diff changeset
55 (ref[11:], handler.map_hg_get(refs[ref]) or refs[ref])
891
5322f12e64ed gitrepo: flake8 cleanups
Sean Farley <sean@farley.io>
parents: 868
diff changeset
56 for ref in refs.keys() if ref.startswith('refs/heads/')
5322f12e64ed gitrepo: flake8 cleanups
Sean Farley <sean@farley.io>
parents: 868
diff changeset
57 ])
557
4f4ab2d89375 gitrepo: initial support for listkeys
David M. Carr <david@carrclan.us>
parents: 556
diff changeset
58 return stripped_refs
347
2efbee89d3f7 gitrepo: update for pushable bookmarks
Augie Fackler <durin42@gmail.com>
parents: 344
diff changeset
59 return {}
2efbee89d3f7 gitrepo: update for pushable bookmarks
Augie Fackler <durin42@gmail.com>
parents: 344
diff changeset
60
2efbee89d3f7 gitrepo: update for pushable bookmarks
Augie Fackler <durin42@gmail.com>
parents: 344
diff changeset
61 def pushkey(self, namespace, key, old, new):
2efbee89d3f7 gitrepo: update for pushable bookmarks
Augie Fackler <durin42@gmail.com>
parents: 344
diff changeset
62 return False
2efbee89d3f7 gitrepo: update for pushable bookmarks
Augie Fackler <durin42@gmail.com>
parents: 344
diff changeset
63
1052
5db8d0d0ae47 compat: update for upcoming hg 4.4 release
Kevin Bullock <kbullock@ringworld.org>
parents: 967
diff changeset
64 if peerapi:
5db8d0d0ae47 compat: update for upcoming hg 4.4 release
Kevin Bullock <kbullock@ringworld.org>
parents: 967
diff changeset
65 def branchmap(self):
5db8d0d0ae47 compat: update for upcoming hg 4.4 release
Kevin Bullock <kbullock@ringworld.org>
parents: 967
diff changeset
66 raise NotImplementedError
5db8d0d0ae47 compat: update for upcoming hg 4.4 release
Kevin Bullock <kbullock@ringworld.org>
parents: 967
diff changeset
67
5db8d0d0ae47 compat: update for upcoming hg 4.4 release
Kevin Bullock <kbullock@ringworld.org>
parents: 967
diff changeset
68 def canpush(self):
5db8d0d0ae47 compat: update for upcoming hg 4.4 release
Kevin Bullock <kbullock@ringworld.org>
parents: 967
diff changeset
69 return True
5db8d0d0ae47 compat: update for upcoming hg 4.4 release
Kevin Bullock <kbullock@ringworld.org>
parents: 967
diff changeset
70
5db8d0d0ae47 compat: update for upcoming hg 4.4 release
Kevin Bullock <kbullock@ringworld.org>
parents: 967
diff changeset
71 def close(self):
5db8d0d0ae47 compat: update for upcoming hg 4.4 release
Kevin Bullock <kbullock@ringworld.org>
parents: 967
diff changeset
72 pass
5db8d0d0ae47 compat: update for upcoming hg 4.4 release
Kevin Bullock <kbullock@ringworld.org>
parents: 967
diff changeset
73
5db8d0d0ae47 compat: update for upcoming hg 4.4 release
Kevin Bullock <kbullock@ringworld.org>
parents: 967
diff changeset
74 def debugwireargs(self):
5db8d0d0ae47 compat: update for upcoming hg 4.4 release
Kevin Bullock <kbullock@ringworld.org>
parents: 967
diff changeset
75 raise NotImplementedError
5db8d0d0ae47 compat: update for upcoming hg 4.4 release
Kevin Bullock <kbullock@ringworld.org>
parents: 967
diff changeset
76
5db8d0d0ae47 compat: update for upcoming hg 4.4 release
Kevin Bullock <kbullock@ringworld.org>
parents: 967
diff changeset
77 def getbundle(self):
5db8d0d0ae47 compat: update for upcoming hg 4.4 release
Kevin Bullock <kbullock@ringworld.org>
parents: 967
diff changeset
78 raise NotImplementedError
5db8d0d0ae47 compat: update for upcoming hg 4.4 release
Kevin Bullock <kbullock@ringworld.org>
parents: 967
diff changeset
79
5db8d0d0ae47 compat: update for upcoming hg 4.4 release
Kevin Bullock <kbullock@ringworld.org>
parents: 967
diff changeset
80 def iterbatch(self):
5db8d0d0ae47 compat: update for upcoming hg 4.4 release
Kevin Bullock <kbullock@ringworld.org>
parents: 967
diff changeset
81 raise NotImplementedError
5db8d0d0ae47 compat: update for upcoming hg 4.4 release
Kevin Bullock <kbullock@ringworld.org>
parents: 967
diff changeset
82
5db8d0d0ae47 compat: update for upcoming hg 4.4 release
Kevin Bullock <kbullock@ringworld.org>
parents: 967
diff changeset
83 def known(self):
5db8d0d0ae47 compat: update for upcoming hg 4.4 release
Kevin Bullock <kbullock@ringworld.org>
parents: 967
diff changeset
84 raise NotImplementedError
5db8d0d0ae47 compat: update for upcoming hg 4.4 release
Kevin Bullock <kbullock@ringworld.org>
parents: 967
diff changeset
85
5db8d0d0ae47 compat: update for upcoming hg 4.4 release
Kevin Bullock <kbullock@ringworld.org>
parents: 967
diff changeset
86 def peer(self):
5db8d0d0ae47 compat: update for upcoming hg 4.4 release
Kevin Bullock <kbullock@ringworld.org>
parents: 967
diff changeset
87 return self
5db8d0d0ae47 compat: update for upcoming hg 4.4 release
Kevin Bullock <kbullock@ringworld.org>
parents: 967
diff changeset
88
5db8d0d0ae47 compat: update for upcoming hg 4.4 release
Kevin Bullock <kbullock@ringworld.org>
parents: 967
diff changeset
89 def stream_out(self):
5db8d0d0ae47 compat: update for upcoming hg 4.4 release
Kevin Bullock <kbullock@ringworld.org>
parents: 967
diff changeset
90 raise NotImplementedError
5db8d0d0ae47 compat: update for upcoming hg 4.4 release
Kevin Bullock <kbullock@ringworld.org>
parents: 967
diff changeset
91
5db8d0d0ae47 compat: update for upcoming hg 4.4 release
Kevin Bullock <kbullock@ringworld.org>
parents: 967
diff changeset
92 def unbundle(self):
5db8d0d0ae47 compat: update for upcoming hg 4.4 release
Kevin Bullock <kbullock@ringworld.org>
parents: 967
diff changeset
93 raise NotImplementedError
5db8d0d0ae47 compat: update for upcoming hg 4.4 release
Kevin Bullock <kbullock@ringworld.org>
parents: 967
diff changeset
94
60
05a96f7750ad add support for `hg clone git://github.com/defunkt/facebox.git`
Chris Wanstrath <chris@ozmm.org>
parents:
diff changeset
95 instance = gitrepo
402
e3b5b23f7236 Define gitrepo.islocal
Brendan Cully <brendan@kublai.com>
parents: 347
diff changeset
96
e3b5b23f7236 Define gitrepo.islocal
Brendan Cully <brendan@kublai.com>
parents: 347
diff changeset
97 def islocal(path):
921
0e975d03f8ca gitrepo: use isgitsshuri in islocal
Sean Farley <sean@farley.io>
parents: 891
diff changeset
98 if isgitsshuri(path):
0e975d03f8ca gitrepo: use isgitsshuri in islocal
Sean Farley <sean@farley.io>
parents: 891
diff changeset
99 return True
0e975d03f8ca gitrepo: use isgitsshuri in islocal
Sean Farley <sean@farley.io>
parents: 891
diff changeset
100
402
e3b5b23f7236 Define gitrepo.islocal
Brendan Cully <brendan@kublai.com>
parents: 347
diff changeset
101 u = util.url(path)
e3b5b23f7236 Define gitrepo.islocal
Brendan Cully <brendan@kublai.com>
parents: 347
diff changeset
102 return not u.scheme or u.scheme == 'file'