annotate hggit/__init__.py @ 1135:c4703246f350

compat: mark all compat-checking locations outside hggit.compat with "COMPAT:" The format is: # COMPAT: hg X.Y - description of change that affects this block
author Kevin Bullock <kbullock@ringworld.org>
date Fri, 02 Feb 2018 13:41:42 -0600
parents d75d704772d1
children 633796ad1684
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
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
b9c94c21777e Add some better help.
Augie Fackler <durin42@gmail.com>
parents: 220
diff changeset
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
b9c94c21777e Add some better help.
Augie Fackler <durin42@gmail.com>
parents: 220
diff changeset
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
b9c94c21777e Add some better help.
Augie Fackler <durin42@gmail.com>
parents: 220
diff changeset
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
918
f5dc1730e4d3 init: sort imports and clean up pep warnings
Sean Farley <sean@farley.io>
parents: 913
diff changeset
20 # global modules
f5dc1730e4d3 init: sort imports and clean up pep warnings
Sean Farley <sean@farley.io>
parents: 913
diff changeset
21 import os
912
5cc9594cc811 Add version info to hggit for "hg --version -v"
anatoly techtonik <techtonik@gmail.com>
parents: 909
diff changeset
22
918
f5dc1730e4d3 init: sort imports and clean up pep warnings
Sean Farley <sean@farley.io>
parents: 913
diff changeset
23 # local modules
1062
c249de74742b compat: use config registrar if available
Kevin Bullock <kbullock@ringworld.org>
parents: 1047
diff changeset
24 import compat
918
f5dc1730e4d3 init: sort imports and clean up pep warnings
Sean Farley <sean@farley.io>
parents: 913
diff changeset
25 import gitrepo
f5dc1730e4d3 init: sort imports and clean up pep warnings
Sean Farley <sean@farley.io>
parents: 913
diff changeset
26 import hgrepo
f5dc1730e4d3 init: sort imports and clean up pep warnings
Sean Farley <sean@farley.io>
parents: 913
diff changeset
27 import overlay
f5dc1730e4d3 init: sort imports and clean up pep warnings
Sean Farley <sean@farley.io>
parents: 913
diff changeset
28 import verify
f5dc1730e4d3 init: sort imports and clean up pep warnings
Sean Farley <sean@farley.io>
parents: 913
diff changeset
29 import util
912
5cc9594cc811 Add version info to hggit for "hg --version -v"
anatoly techtonik <techtonik@gmail.com>
parents: 909
diff changeset
30
481
9df1741f3977 help: add additional help topics
David M. Carr <david@carrclan.us>
parents: 442
diff changeset
31 from bisect import insort
918
f5dc1730e4d3 init: sort imports and clean up pep warnings
Sean Farley <sean@farley.io>
parents: 913
diff changeset
32 from git_handler import GitHandler
f5dc1730e4d3 init: sort imports and clean up pep warnings
Sean Farley <sean@farley.io>
parents: 913
diff changeset
33 from mercurial.node import hex
999
a128b9a53b5a revset_gitnode: allow abbreviated hashes
Sietse Brouwer <sbbrouwer@gmail.com>
parents: 994
diff changeset
34 from mercurial.error import LookupError
918
f5dc1730e4d3 init: sort imports and clean up pep warnings
Sean Farley <sean@farley.io>
parents: 913
diff changeset
35 from mercurial.i18n import _
959
db270ed5df13 init: regularize mercurial imports
Siddharth Agarwal <sid0@fb.com>
parents: 953
diff changeset
36 from mercurial import (
db270ed5df13 init: regularize mercurial imports
Siddharth Agarwal <sid0@fb.com>
parents: 953
diff changeset
37 bundlerepo,
db270ed5df13 init: regularize mercurial imports
Siddharth Agarwal <sid0@fb.com>
parents: 953
diff changeset
38 cmdutil,
db270ed5df13 init: regularize mercurial imports
Siddharth Agarwal <sid0@fb.com>
parents: 953
diff changeset
39 demandimport,
db270ed5df13 init: regularize mercurial imports
Siddharth Agarwal <sid0@fb.com>
parents: 953
diff changeset
40 dirstate,
db270ed5df13 init: regularize mercurial imports
Siddharth Agarwal <sid0@fb.com>
parents: 953
diff changeset
41 discovery,
db270ed5df13 init: regularize mercurial imports
Siddharth Agarwal <sid0@fb.com>
parents: 953
diff changeset
42 extensions,
db270ed5df13 init: regularize mercurial imports
Siddharth Agarwal <sid0@fb.com>
parents: 953
diff changeset
43 help,
db270ed5df13 init: regularize mercurial imports
Siddharth Agarwal <sid0@fb.com>
parents: 953
diff changeset
44 hg,
db270ed5df13 init: regularize mercurial imports
Siddharth Agarwal <sid0@fb.com>
parents: 953
diff changeset
45 ui as hgui,
db270ed5df13 init: regularize mercurial imports
Siddharth Agarwal <sid0@fb.com>
parents: 953
diff changeset
46 util as hgutil,
db270ed5df13 init: regularize mercurial imports
Siddharth Agarwal <sid0@fb.com>
parents: 953
diff changeset
47 localrepo,
db270ed5df13 init: regularize mercurial imports
Siddharth Agarwal <sid0@fb.com>
parents: 953
diff changeset
48 manifest,
db270ed5df13 init: regularize mercurial imports
Siddharth Agarwal <sid0@fb.com>
parents: 953
diff changeset
49 revset,
db270ed5df13 init: regularize mercurial imports
Siddharth Agarwal <sid0@fb.com>
parents: 953
diff changeset
50 scmutil,
db270ed5df13 init: regularize mercurial imports
Siddharth Agarwal <sid0@fb.com>
parents: 953
diff changeset
51 templatekw,
db270ed5df13 init: regularize mercurial imports
Siddharth Agarwal <sid0@fb.com>
parents: 953
diff changeset
52 )
918
f5dc1730e4d3 init: sort imports and clean up pep warnings
Sean Farley <sean@farley.io>
parents: 913
diff changeset
53
1135
c4703246f350 compat: mark all compat-checking locations outside hggit.compat with "COMPAT:"
Kevin Bullock <kbullock@ringworld.org>
parents: 1134
diff changeset
54 # COMPAT: hg 3.2 - exchange module was introduced
782
e5450a81676e __init__: work around exchange not yet existing in hg 2.8.x
Augie Fackler <raf@durin42.com>
parents: 781
diff changeset
55 try:
e5450a81676e __init__: work around exchange not yet existing in hg 2.8.x
Augie Fackler <raf@durin42.com>
parents: 781
diff changeset
56 from mercurial import exchange
887
8f9d52f7942e init: whitespace and formating cleanup
Sean Farley <sean@farley.io>
parents: 857
diff changeset
57 exchange.push # existed in first iteration of this file
956
06385a2b30f3 init: handle AttributeError in addition to ImportError
timeless@gmail.com
parents: 953
diff changeset
58 except (AttributeError, ImportError):
782
e5450a81676e __init__: work around exchange not yet existing in hg 2.8.x
Augie Fackler <raf@durin42.com>
parents: 781
diff changeset
59 # We only *use* the exchange module in hg 3.2+, so this is safe
e5450a81676e __init__: work around exchange not yet existing in hg 2.8.x
Augie Fackler <raf@durin42.com>
parents: 781
diff changeset
60 pass
918
f5dc1730e4d3 init: sort imports and clean up pep warnings
Sean Farley <sean@farley.io>
parents: 913
diff changeset
61
1135
c4703246f350 compat: mark all compat-checking locations outside hggit.compat with "COMPAT:"
Kevin Bullock <kbullock@ringworld.org>
parents: 1134
diff changeset
62 # COMPAT: hg 3.5 - ignore module was removed
907
e5b10a710036 ignore: update ignore logic to match upstream
Durham Goode <durham@fb.com>
parents: 901
diff changeset
63 try:
e5b10a710036 ignore: update ignore logic to match upstream
Durham Goode <durham@fb.com>
parents: 901
diff changeset
64 from mercurial import ignore
909
67b27ec080ae ignore: evaluate ignore.readpats to see if ignore module really exists
Yuya Nishihara <yuya@tcha.org>
parents: 907
diff changeset
65 ignore.readpats
907
e5b10a710036 ignore: update ignore logic to match upstream
Durham Goode <durham@fb.com>
parents: 901
diff changeset
66 ignoremod = True
956
06385a2b30f3 init: handle AttributeError in addition to ImportError
timeless@gmail.com
parents: 953
diff changeset
67 except (AttributeError, ImportError):
907
e5b10a710036 ignore: update ignore logic to match upstream
Durham Goode <durham@fb.com>
parents: 901
diff changeset
68 ignoremod = False
887
8f9d52f7942e init: whitespace and formating cleanup
Sean Farley <sean@farley.io>
parents: 857
diff changeset
69
1135
c4703246f350 compat: mark all compat-checking locations outside hggit.compat with "COMPAT:"
Kevin Bullock <kbullock@ringworld.org>
parents: 1134
diff changeset
70 # COMPAT: hg 3.0 - revset.baseset was added
937
d46938925708 revsets: use baseset instead of raw list
Sean Farley <sean@farley.io>
parents: 936
diff changeset
71 baseset = set
d46938925708 revsets: use baseset instead of raw list
Sean Farley <sean@farley.io>
parents: 936
diff changeset
72 try:
d46938925708 revsets: use baseset instead of raw list
Sean Farley <sean@farley.io>
parents: 936
diff changeset
73 baseset = revset.baseset
d46938925708 revsets: use baseset instead of raw list
Sean Farley <sean@farley.io>
parents: 936
diff changeset
74 except AttributeError:
d46938925708 revsets: use baseset instead of raw list
Sean Farley <sean@farley.io>
parents: 936
diff changeset
75 pass
d46938925708 revsets: use baseset instead of raw list
Sean Farley <sean@farley.io>
parents: 936
diff changeset
76
1134
d75d704772d1 compat: support hg 4.7 demandimport.IGNORES API with fallback to 4.6 API
Arne Babenhauserheide <bab@draketo.de>
parents: 1123
diff changeset
77 try:
d75d704772d1 compat: support hg 4.7 demandimport.IGNORES API with fallback to 4.6 API
Arne Babenhauserheide <bab@draketo.de>
parents: 1123
diff changeset
78 demandimport.IGNORES.add('collections')
d75d704772d1 compat: support hg 4.7 demandimport.IGNORES API with fallback to 4.6 API
Arne Babenhauserheide <bab@draketo.de>
parents: 1123
diff changeset
79 except AttributeError as e: # pre 4.7 API
d75d704772d1 compat: support hg 4.7 demandimport.IGNORES API with fallback to 4.6 API
Arne Babenhauserheide <bab@draketo.de>
parents: 1123
diff changeset
80 demandimport.ignore.extend([
d75d704772d1 compat: support hg 4.7 demandimport.IGNORES API with fallback to 4.6 API
Arne Babenhauserheide <bab@draketo.de>
parents: 1123
diff changeset
81 'collections',
d75d704772d1 compat: support hg 4.7 demandimport.IGNORES API with fallback to 4.6 API
Arne Babenhauserheide <bab@draketo.de>
parents: 1123
diff changeset
82 ])
0
06366111af3c initial import of the hg-git bridging extension for mercurial
Scott Chacon <schacon@gmail.com>
parents:
diff changeset
83
1120
b90c69681d2d version: bump version number to 0.8.11
Kevin Bullock <kbullock@ringworld.org>
parents: 1105
diff changeset
84 __version__ = '0.8.11'
918
f5dc1730e4d3 init: sort imports and clean up pep warnings
Sean Farley <sean@farley.io>
parents: 913
diff changeset
85
993
1fec6463922b tests: update list of hg versions we've tested with
Kevin Bullock <kbullock@ringworld.org>
parents: 985
diff changeset
86 testedwith = ('2.8.2 2.9.2 3.0.2 3.1.2 3.2.4 3.3.3 3.4.2 3.5.2 3.6.3 3.7.3'
1105
bb255eaf3d14 compat: update testedwith for hg 4.5 release
Kevin Bullock <kbullock@ringworld.org>
parents: 1088
diff changeset
87 '3.8.4 3.9.2 4.0.2 4.1.3 4.2.3 4.3.3 4.4.2 4.5')
545
22b8df4c54c5 docs: include buglink
David M. Carr <david@carrclan.us>
parents: 523
diff changeset
88 buglink = 'https://bitbucket.org/durin42/hg-git/issues'
22b8df4c54c5 docs: include buglink
David M. Carr <david@carrclan.us>
parents: 523
diff changeset
89
732
a67fecf02adb commands: switch to new-style declaration via decorators
Siddharth Agarwal <sid0@fb.com>
parents: 731
diff changeset
90 cmdtable = {}
1062
c249de74742b compat: use config registrar if available
Kevin Bullock <kbullock@ringworld.org>
parents: 1047
diff changeset
91 configtable = {}
1020
f2118a7dd764 commands: update to use registrar
Durham Goode <durham@fb.com>
parents: 1018
diff changeset
92 try:
f2118a7dd764 commands: update to use registrar
Durham Goode <durham@fb.com>
parents: 1018
diff changeset
93 from mercurial import registrar
f2118a7dd764 commands: update to use registrar
Durham Goode <durham@fb.com>
parents: 1018
diff changeset
94 command = registrar.command(cmdtable)
1062
c249de74742b compat: use config registrar if available
Kevin Bullock <kbullock@ringworld.org>
parents: 1047
diff changeset
95 configitem = registrar.configitem(configtable)
c249de74742b compat: use config registrar if available
Kevin Bullock <kbullock@ringworld.org>
parents: 1047
diff changeset
96 compat.registerconfigs(configitem)
c249de74742b compat: use config registrar if available
Kevin Bullock <kbullock@ringworld.org>
parents: 1047
diff changeset
97
1020
f2118a7dd764 commands: update to use registrar
Durham Goode <durham@fb.com>
parents: 1018
diff changeset
98 except (ImportError, AttributeError):
f2118a7dd764 commands: update to use registrar
Durham Goode <durham@fb.com>
parents: 1018
diff changeset
99 command = cmdutil.command(cmdtable)
732
a67fecf02adb commands: switch to new-style declaration via decorators
Siddharth Agarwal <sid0@fb.com>
parents: 731
diff changeset
100
60
05a96f7750ad add support for `hg clone git://github.com/defunkt/facebox.git`
Chris Wanstrath <chris@ozmm.org>
parents: 59
diff changeset
101 # 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
102 # also hg clone git+ssh://git@github.com/schacon/simplegit.git
919
6507d2a6be0a util: add heuristic method to determine if a uri is git
Sean Farley <sean@farley.io>
parents: 918
diff changeset
103 for _scheme in util.gitschemes:
439
3f45c88100e8 add support for the HTTP smart protocol when using Dulwich tip
Dan Villiom Podlaski Christiansen <danchr@gmail.com>
parents: 430
diff changeset
104 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
105
256
442fe2ca104d Simpler handling of detection of git repos
Mads Kiilerich <mads@kiilerich.com>
parents: 220
diff changeset
106 # 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
107 _oldlocal = hg.schemes['file']
211fa793d74f support local git repositories (fixes issue 5 bb)
Abderrahim Kitouni <a.kitouni@gmail.com>
parents: 210
diff changeset
108
1135
c4703246f350 compat: mark all compat-checking locations outside hggit.compat with "COMPAT:"
Kevin Bullock <kbullock@ringworld.org>
parents: 1134
diff changeset
109 # COMPAT: hg 1.9 - url.url class moved into util module
388
bcc79fa3fe09 url wasn't ever published as url.url, and is now util.url
Augie Fackler <durin42@gmail.com>
parents: 383
diff changeset
110 try:
bcc79fa3fe09 url wasn't ever published as url.url, and is now util.url
Augie Fackler <durin42@gmail.com>
parents: 383
diff changeset
111 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
112 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
113 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
114 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
115 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
116
bcc79fa3fe09 url wasn't ever published as url.url, and is now util.url
Augie Fackler <durin42@gmail.com>
parents: 383
diff changeset
117 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
118 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
119
1115
8ed6c0cae9b8 cleanup: add some blank lines
Sean Farley <sean@farley.io>
parents: 1105
diff changeset
120
935
f7d0175264ce paths: refactor gitdir detection to a function
Durham Goode <durham@fb.com>
parents: 928
diff changeset
121 def _isgitdir(path):
f7d0175264ce paths: refactor gitdir detection to a function
Durham Goode <durham@fb.com>
parents: 928
diff changeset
122 """True if the given file path is a git repo."""
f7d0175264ce paths: refactor gitdir detection to a function
Durham Goode <durham@fb.com>
parents: 928
diff changeset
123 if os.path.exists(os.path.join(path, '.hg')):
f7d0175264ce paths: refactor gitdir detection to a function
Durham Goode <durham@fb.com>
parents: 928
diff changeset
124 return False
f7d0175264ce paths: refactor gitdir detection to a function
Durham Goode <durham@fb.com>
parents: 928
diff changeset
125
f7d0175264ce paths: refactor gitdir detection to a function
Durham Goode <durham@fb.com>
parents: 928
diff changeset
126 if os.path.exists(os.path.join(path, '.git')):
f7d0175264ce paths: refactor gitdir detection to a function
Durham Goode <durham@fb.com>
parents: 928
diff changeset
127 # is full git repo
f7d0175264ce paths: refactor gitdir detection to a function
Durham Goode <durham@fb.com>
parents: 928
diff changeset
128 return True
f7d0175264ce paths: refactor gitdir detection to a function
Durham Goode <durham@fb.com>
parents: 928
diff changeset
129
f7d0175264ce paths: refactor gitdir detection to a function
Durham Goode <durham@fb.com>
parents: 928
diff changeset
130 if (os.path.exists(os.path.join(path, 'HEAD')) and
f7d0175264ce paths: refactor gitdir detection to a function
Durham Goode <durham@fb.com>
parents: 928
diff changeset
131 os.path.exists(os.path.join(path, 'objects')) and
f7d0175264ce paths: refactor gitdir detection to a function
Durham Goode <durham@fb.com>
parents: 928
diff changeset
132 os.path.exists(os.path.join(path, 'refs'))):
f7d0175264ce paths: refactor gitdir detection to a function
Durham Goode <durham@fb.com>
parents: 928
diff changeset
133 # is bare git repo
f7d0175264ce paths: refactor gitdir detection to a function
Durham Goode <durham@fb.com>
parents: 928
diff changeset
134 return True
f7d0175264ce paths: refactor gitdir detection to a function
Durham Goode <durham@fb.com>
parents: 928
diff changeset
135
f7d0175264ce paths: refactor gitdir detection to a function
Durham Goode <durham@fb.com>
parents: 928
diff changeset
136 return False
f7d0175264ce paths: refactor gitdir detection to a function
Durham Goode <durham@fb.com>
parents: 928
diff changeset
137
1115
8ed6c0cae9b8 cleanup: add some blank lines
Sean Farley <sean@farley.io>
parents: 1105
diff changeset
138
220
211fa793d74f support local git repositories (fixes issue 5 bb)
Abderrahim Kitouni <a.kitouni@gmail.com>
parents: 210
diff changeset
139 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
140 p = urlcls(path).localpath()
935
f7d0175264ce paths: refactor gitdir detection to a function
Durham Goode <durham@fb.com>
parents: 928
diff changeset
141 if _isgitdir(p):
263
9f5a7a5d52aa Enable detection of bare repositories as a local git repo
Lincoln Stoll <lstoll@lstoll.net>
parents: 260
diff changeset
142 return gitrepo
922
ee9017a3c269 init: test for raw git ssh paths
Sean Farley <sean@farley.io>
parents: 919
diff changeset
143 # detect git ssh urls (which mercurial thinks is a file-like path)
ee9017a3c269 init: test for raw git ssh paths
Sean Farley <sean@farley.io>
parents: 919
diff changeset
144 if util.isgitsshuri(p):
ee9017a3c269 init: test for raw git ssh paths
Sean Farley <sean@farley.io>
parents: 919
diff changeset
145 return gitrepo
256
442fe2ca104d Simpler handling of detection of git repos
Mads Kiilerich <mads@kiilerich.com>
parents: 220
diff changeset
146 return _oldlocal(path)
220
211fa793d74f support local git repositories (fixes issue 5 bb)
Abderrahim Kitouni <a.kitouni@gmail.com>
parents: 210
diff changeset
147
1115
8ed6c0cae9b8 cleanup: add some blank lines
Sean Farley <sean@farley.io>
parents: 1105
diff changeset
148
220
211fa793d74f support local git repositories (fixes issue 5 bb)
Abderrahim Kitouni <a.kitouni@gmail.com>
parents: 210
diff changeset
149 hg.schemes['file'] = _local
211fa793d74f support local git repositories (fixes issue 5 bb)
Abderrahim Kitouni <a.kitouni@gmail.com>
parents: 210
diff changeset
150
1115
8ed6c0cae9b8 cleanup: add some blank lines
Sean Farley <sean@farley.io>
parents: 1105
diff changeset
151
938
e1117014036c init: wrap hgutil.url so that we can use isgitsshuri
Sean Farley <sean@farley.io>
parents: 937
diff changeset
152 # we need to wrap this so that git-like ssh paths are not prepended with a
e1117014036c init: wrap hgutil.url so that we can use isgitsshuri
Sean Farley <sean@farley.io>
parents: 937
diff changeset
153 # local filesystem path. ugh.
e1117014036c init: wrap hgutil.url so that we can use isgitsshuri
Sean Farley <sean@farley.io>
parents: 937
diff changeset
154 def _url(orig, path, **kwargs):
e1117014036c init: wrap hgutil.url so that we can use isgitsshuri
Sean Farley <sean@farley.io>
parents: 937
diff changeset
155 # we'll test for 'git@' then use our heuristic method to determine if it's
e1117014036c init: wrap hgutil.url so that we can use isgitsshuri
Sean Farley <sean@farley.io>
parents: 937
diff changeset
156 # a git uri
e1117014036c init: wrap hgutil.url so that we can use isgitsshuri
Sean Farley <sean@farley.io>
parents: 937
diff changeset
157 if not (path.startswith(os.sep) and ':' in path):
e1117014036c init: wrap hgutil.url so that we can use isgitsshuri
Sean Farley <sean@farley.io>
parents: 937
diff changeset
158 return orig(path, **kwargs)
e1117014036c init: wrap hgutil.url so that we can use isgitsshuri
Sean Farley <sean@farley.io>
parents: 937
diff changeset
159
e1117014036c init: wrap hgutil.url so that we can use isgitsshuri
Sean Farley <sean@farley.io>
parents: 937
diff changeset
160 # the file path will be everything up until the last slash right before the
e1117014036c init: wrap hgutil.url so that we can use isgitsshuri
Sean Farley <sean@farley.io>
parents: 937
diff changeset
161 # ':'
e1117014036c init: wrap hgutil.url so that we can use isgitsshuri
Sean Farley <sean@farley.io>
parents: 937
diff changeset
162 lastsep = path.rindex(os.sep, None, path.index(':')) + 1
e1117014036c init: wrap hgutil.url so that we can use isgitsshuri
Sean Farley <sean@farley.io>
parents: 937
diff changeset
163 gituri = path[lastsep:]
e1117014036c init: wrap hgutil.url so that we can use isgitsshuri
Sean Farley <sean@farley.io>
parents: 937
diff changeset
164
e1117014036c init: wrap hgutil.url so that we can use isgitsshuri
Sean Farley <sean@farley.io>
parents: 937
diff changeset
165 if util.isgitsshuri(gituri):
e1117014036c init: wrap hgutil.url so that we can use isgitsshuri
Sean Farley <sean@farley.io>
parents: 937
diff changeset
166 return orig(gituri, **kwargs)
e1117014036c init: wrap hgutil.url so that we can use isgitsshuri
Sean Farley <sean@farley.io>
parents: 937
diff changeset
167 return orig(path, **kwargs)
e1117014036c init: wrap hgutil.url so that we can use isgitsshuri
Sean Farley <sean@farley.io>
parents: 937
diff changeset
168
1115
8ed6c0cae9b8 cleanup: add some blank lines
Sean Farley <sean@farley.io>
parents: 1105
diff changeset
169
938
e1117014036c init: wrap hgutil.url so that we can use isgitsshuri
Sean Farley <sean@farley.io>
parents: 937
diff changeset
170 extensions.wrapfunction(hgutil, 'url', _url)
e1117014036c init: wrap hgutil.url so that we can use isgitsshuri
Sean Farley <sean@farley.io>
parents: 937
diff changeset
171
e1117014036c init: wrap hgutil.url so that we can use isgitsshuri
Sean Farley <sean@farley.io>
parents: 937
diff changeset
172
923
e28affca64de init: test for git http(s) paths
Sean Farley <sean@farley.io>
parents: 922
diff changeset
173 def _httpgitwrapper(orig):
e28affca64de init: test for git http(s) paths
Sean Farley <sean@farley.io>
parents: 922
diff changeset
174 # we should probably test the connection but for now, we just keep it
e28affca64de init: test for git http(s) paths
Sean Farley <sean@farley.io>
parents: 922
diff changeset
175 # simple and check for a url ending in '.git'
e28affca64de init: test for git http(s) paths
Sean Farley <sean@farley.io>
parents: 922
diff changeset
176 def httpgitscheme(uri):
e28affca64de init: test for git http(s) paths
Sean Farley <sean@farley.io>
parents: 922
diff changeset
177 if uri.endswith('.git'):
e28affca64de init: test for git http(s) paths
Sean Farley <sean@farley.io>
parents: 922
diff changeset
178 return gitrepo
e28affca64de init: test for git http(s) paths
Sean Farley <sean@farley.io>
parents: 922
diff changeset
179
924
7c80e9f8131f init: fix default hg breakage by returning the right type
Sean Farley <sean@farley.io>
parents: 923
diff changeset
180 # the http(s) scheme just returns the _peerlookup
7c80e9f8131f init: fix default hg breakage by returning the right type
Sean Farley <sean@farley.io>
parents: 923
diff changeset
181 return orig
923
e28affca64de init: test for git http(s) paths
Sean Farley <sean@farley.io>
parents: 922
diff changeset
182
e28affca64de init: test for git http(s) paths
Sean Farley <sean@farley.io>
parents: 922
diff changeset
183 return httpgitscheme
e28affca64de init: test for git http(s) paths
Sean Farley <sean@farley.io>
parents: 922
diff changeset
184
1115
8ed6c0cae9b8 cleanup: add some blank lines
Sean Farley <sean@farley.io>
parents: 1105
diff changeset
185
923
e28affca64de init: test for git http(s) paths
Sean Farley <sean@farley.io>
parents: 922
diff changeset
186 hg.schemes['https'] = _httpgitwrapper(hg.schemes['https'])
e28affca64de init: test for git http(s) paths
Sean Farley <sean@farley.io>
parents: 922
diff changeset
187 hg.schemes['http'] = _httpgitwrapper(hg.schemes['http'])
1115
8ed6c0cae9b8 cleanup: add some blank lines
Sean Farley <sean@farley.io>
parents: 1105
diff changeset
188 hgdefaultdest = hg.defaultdest
923
e28affca64de init: test for git http(s) paths
Sean Farley <sean@farley.io>
parents: 922
diff changeset
189
1115
8ed6c0cae9b8 cleanup: add some blank lines
Sean Farley <sean@farley.io>
parents: 1105
diff changeset
190
281
a14529b7b8f2 init: strip .git for default clone destination for git sources
Augie Fackler <durin42@gmail.com>
parents: 280
diff changeset
191 def defaultdest(source):
919
6507d2a6be0a util: add heuristic method to determine if a uri is git
Sean Farley <sean@farley.io>
parents: 918
diff changeset
192 for scheme in util.gitschemes:
281
a14529b7b8f2 init: strip .git for default clone destination for git sources
Augie Fackler <durin42@gmail.com>
parents: 280
diff changeset
193 if source.startswith('%s://' % scheme) and source.endswith('.git'):
919
6507d2a6be0a util: add heuristic method to determine if a uri is git
Sean Farley <sean@farley.io>
parents: 918
diff changeset
194 return hgdefaultdest(source[:-4])
6507d2a6be0a util: add heuristic method to determine if a uri is git
Sean Farley <sean@farley.io>
parents: 918
diff changeset
195
6507d2a6be0a util: add heuristic method to determine if a uri is git
Sean Farley <sean@farley.io>
parents: 918
diff changeset
196 if source.endswith('.git'):
6507d2a6be0a util: add heuristic method to determine if a uri is git
Sean Farley <sean@farley.io>
parents: 918
diff changeset
197 return hgdefaultdest(source[:-4])
6507d2a6be0a util: add heuristic method to determine if a uri is git
Sean Farley <sean@farley.io>
parents: 918
diff changeset
198
281
a14529b7b8f2 init: strip .git for default clone destination for git sources
Augie Fackler <durin42@gmail.com>
parents: 280
diff changeset
199 return hgdefaultdest(source)
1115
8ed6c0cae9b8 cleanup: add some blank lines
Sean Farley <sean@farley.io>
parents: 1105
diff changeset
200
8ed6c0cae9b8 cleanup: add some blank lines
Sean Farley <sean@farley.io>
parents: 1105
diff changeset
201
281
a14529b7b8f2 init: strip .git for default clone destination for git sources
Augie Fackler <durin42@gmail.com>
parents: 280
diff changeset
202 hg.defaultdest = defaultdest
a14529b7b8f2 init: strip .git for default clone destination for git sources
Augie Fackler <durin42@gmail.com>
parents: 280
diff changeset
203
1115
8ed6c0cae9b8 cleanup: add some blank lines
Sean Farley <sean@farley.io>
parents: 1105
diff changeset
204
918
f5dc1730e4d3 init: sort imports and clean up pep warnings
Sean Farley <sean@farley.io>
parents: 913
diff changeset
205 def getversion():
f5dc1730e4d3 init: sort imports and clean up pep warnings
Sean Farley <sean@farley.io>
parents: 913
diff changeset
206 """return version with dependencies for hg --version -v"""
f5dc1730e4d3 init: sort imports and clean up pep warnings
Sean Farley <sean@farley.io>
parents: 913
diff changeset
207 import dulwich
f5dc1730e4d3 init: sort imports and clean up pep warnings
Sean Farley <sean@farley.io>
parents: 913
diff changeset
208 dulver = '.'.join(str(i) for i in dulwich.__version__)
f5dc1730e4d3 init: sort imports and clean up pep warnings
Sean Farley <sean@farley.io>
parents: 913
diff changeset
209 return __version__ + (" (dulwich %s)" % dulver)
f5dc1730e4d3 init: sort imports and clean up pep warnings
Sean Farley <sean@farley.io>
parents: 913
diff changeset
210
1115
8ed6c0cae9b8 cleanup: add some blank lines
Sean Farley <sean@farley.io>
parents: 1105
diff changeset
211
297
a90fe3e8a8c3 hggit: defend against exceptions when pulling with -r
Augie Fackler <durin42@gmail.com>
parents: 296
diff changeset
212 # 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
213 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
214 revs, co = orig(lrepo, repo, branches, revs)
706
5e74edb7a62d safebranchrevs: handle changelog having no commits
Siddharth Agarwal <sid0@fb.com>
parents: 695
diff changeset
215 if hgutil.safehasattr(lrepo, 'changelog') and co not in lrepo.changelog:
297
a90fe3e8a8c3 hggit: defend against exceptions when pulling with -r
Augie Fackler <durin42@gmail.com>
parents: 296
diff changeset
216 co = None
a90fe3e8a8c3 hggit: defend against exceptions when pulling with -r
Augie Fackler <durin42@gmail.com>
parents: 296
diff changeset
217 return revs, co
1115
8ed6c0cae9b8 cleanup: add some blank lines
Sean Farley <sean@farley.io>
parents: 1105
diff changeset
218
8ed6c0cae9b8 cleanup: add some blank lines
Sean Farley <sean@farley.io>
parents: 1105
diff changeset
219
1135
c4703246f350 compat: mark all compat-checking locations outside hggit.compat with "COMPAT:"
Kevin Bullock <kbullock@ringworld.org>
parents: 1134
diff changeset
220 # COMPAT: hg 1.4 - this is no longer needed
300
eec31dee258e Various hg 1.4 compat fixes.
Augie Fackler <durin42@gmail.com>
parents: 298
diff changeset
221 if getattr(hg, 'addbranchrevs', False):
eec31dee258e Various hg 1.4 compat fixes.
Augie Fackler <durin42@gmail.com>
parents: 298
diff changeset
222 extensions.wrapfunction(hg, 'addbranchrevs', safebranchrevs)
297
a90fe3e8a8c3 hggit: defend against exceptions when pulling with -r
Augie Fackler <durin42@gmail.com>
parents: 296
diff changeset
223
1115
8ed6c0cae9b8 cleanup: add some blank lines
Sean Farley <sean@farley.io>
parents: 1105
diff changeset
224
695
2c67099875cd extsetup: use new-style extsetup with ui parameter
Siddharth Agarwal <sid0@fb.com>
parents: 693
diff changeset
225 def extsetup(ui):
482
00d591868a2f templatekw: add support for gitnode template keyword
David M. Carr <david@carrclan.us>
parents: 481
diff changeset
226 templatekw.keywords.update({'gitnode': gitnodekw})
483
d2caea269670 revsets: add fromgit and gitnode selectors
David M. Carr <david@carrclan.us>
parents: 482
diff changeset
227 revset.symbols.update({
d2caea269670 revsets: add fromgit and gitnode selectors
David M. Carr <david@carrclan.us>
parents: 482
diff changeset
228 'fromgit': revset_fromgit, 'gitnode': revset_gitnode
d2caea269670 revsets: add fromgit and gitnode selectors
David M. Carr <david@carrclan.us>
parents: 482
diff changeset
229 })
481
9df1741f3977 help: add additional help topics
David M. Carr <david@carrclan.us>
parents: 442
diff changeset
230 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
231 entry = (['git'], _("Working with Git Repositories"),
1135
c4703246f350 compat: mark all compat-checking locations outside hggit.compat with "COMPAT:"
Kevin Bullock <kbullock@ringworld.org>
parents: 1134
diff changeset
232 # COMPAT: hg 3.6 - help table expects a delayed loader (see
c4703246f350 compat: mark all compat-checking locations outside hggit.compat with "COMPAT:"
Kevin Bullock <kbullock@ringworld.org>
parents: 1134
diff changeset
233 # help.loaddoc())
928
983126c08bad help: ignore argument passed to doc loader
Yuya Nishihara <yuya@tcha.org>
parents: 926
diff changeset
234 lambda *args: open(os.path.join(helpdir, 'git.rst')).read())
675
4cb3515cefb0 extsetup: drop support for Mercurial < 1.7
Siddharth Agarwal <sid0@fb.com>
parents: 674
diff changeset
235 insort(help.helptable, entry)
481
9df1741f3977 help: add additional help topics
David M. Carr <david@carrclan.us>
parents: 442
diff changeset
236
1115
8ed6c0cae9b8 cleanup: add some blank lines
Sean Farley <sean@farley.io>
parents: 1105
diff changeset
237
206
5986ac6a591e create the repository subclass in reposetup
Abderrahim Kitouni <a.kitouni@gmail.com>
parents: 182
diff changeset
238 def reposetup(ui, repo):
296
32456f9cb7a4 hggit: don't wrap gitrepo with hgrepo
Augie Fackler <durin42@gmail.com>
parents: 281
diff changeset
239 if not isinstance(repo, gitrepo.gitrepo):
953
393bde462133 init: only activate git ignore logic in reposetup
Sean Farley <sean@farley.io>
parents: 946
diff changeset
240
393bde462133 init: only activate git ignore logic in reposetup
Sean Farley <sean@farley.io>
parents: 946
diff changeset
241 if (getattr(dirstate, 'rootcache', False) and
994
9c15c89088fd gitdirstate: only wrap for hg-git repos
Sean Farley <sean@farley.io>
parents: 993
diff changeset
242 (not ignoremod or getattr(ignore, 'readpats', False)) and
1018
715cbf3fa24c vfs: stop using repo.join/wjoin
Durham Goode <durham@fb.com>
parents: 1015
diff changeset
243 hgutil.safehasattr(repo, 'vfs') and
1088
c06d4656b77b shared: fix compatibility with hg < 4.2
Kevin Bullock <kbullock@ringworld.org>
parents: 1085
diff changeset
244 os.path.exists(compat.gitvfs(repo).join('git'))):
953
393bde462133 init: only activate git ignore logic in reposetup
Sean Farley <sean@farley.io>
parents: 946
diff changeset
245 # only install our dirstate wrapper if it has a hope of working
393bde462133 init: only activate git ignore logic in reposetup
Sean Farley <sean@farley.io>
parents: 946
diff changeset
246 import gitdirstate
393bde462133 init: only activate git ignore logic in reposetup
Sean Farley <sean@farley.io>
parents: 946
diff changeset
247 if ignoremod:
393bde462133 init: only activate git ignore logic in reposetup
Sean Farley <sean@farley.io>
parents: 946
diff changeset
248 def ignorewrap(orig, *args, **kwargs):
393bde462133 init: only activate git ignore logic in reposetup
Sean Farley <sean@farley.io>
parents: 946
diff changeset
249 return gitdirstate.gignore(*args, **kwargs)
393bde462133 init: only activate git ignore logic in reposetup
Sean Farley <sean@farley.io>
parents: 946
diff changeset
250 extensions.wrapfunction(ignore, 'ignore', ignorewrap)
393bde462133 init: only activate git ignore logic in reposetup
Sean Farley <sean@farley.io>
parents: 946
diff changeset
251 dirstate.dirstate = gitdirstate.gitdirstate
393bde462133 init: only activate git ignore logic in reposetup
Sean Farley <sean@farley.io>
parents: 946
diff changeset
252
296
32456f9cb7a4 hggit: don't wrap gitrepo with hgrepo
Augie Fackler <durin42@gmail.com>
parents: 281
diff changeset
253 klass = hgrepo.generate_repo_subclass(repo.__class__)
32456f9cb7a4 hggit: don't wrap gitrepo with hgrepo
Augie Fackler <durin42@gmail.com>
parents: 281
diff changeset
254 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
255
1115
8ed6c0cae9b8 cleanup: add some blank lines
Sean Farley <sean@farley.io>
parents: 1105
diff changeset
256
899
11ca21820a95 overlay: adapt diff to work with lazymanifests
Siddharth Agarwal <sid0@fb.com>
parents: 897
diff changeset
257 if hgutil.safehasattr(manifest, '_lazymanifest'):
11ca21820a95 overlay: adapt diff to work with lazymanifests
Siddharth Agarwal <sid0@fb.com>
parents: 897
diff changeset
258 # Mercurial >= 3.4
11ca21820a95 overlay: adapt diff to work with lazymanifests
Siddharth Agarwal <sid0@fb.com>
parents: 897
diff changeset
259 extensions.wrapfunction(manifest.manifestdict, 'diff',
11ca21820a95 overlay: adapt diff to work with lazymanifests
Siddharth Agarwal <sid0@fb.com>
parents: 897
diff changeset
260 overlay.wrapmanifestdictdiff)
11ca21820a95 overlay: adapt diff to work with lazymanifests
Siddharth Agarwal <sid0@fb.com>
parents: 897
diff changeset
261
1115
8ed6c0cae9b8 cleanup: add some blank lines
Sean Farley <sean@farley.io>
parents: 1105
diff changeset
262
733
5e53342c846b gimport: drop empty options and redundant synopsis, and add help text
Siddharth Agarwal <sid0@fb.com>
parents: 732
diff changeset
263 @command('gimport')
137
5aefcbf1e50c add a gimport command
Sverre Rabbelier <sverre@rabbelier.nl>
parents: 136
diff changeset
264 def gimport(ui, repo, remote_name=None):
733
5e53342c846b gimport: drop empty options and redundant synopsis, and add help text
Siddharth Agarwal <sid0@fb.com>
parents: 732
diff changeset
265 '''import commits from Git to Mercurial'''
663
ad0d90fa7a4f gimport: use githandler from repo
Siddharth Agarwal <sid0@fb.com>
parents: 624
diff changeset
266 repo.githandler.import_commits(remote_name)
137
5aefcbf1e50c add a gimport command
Sverre Rabbelier <sverre@rabbelier.nl>
parents: 136
diff changeset
267
1115
8ed6c0cae9b8 cleanup: add some blank lines
Sean Farley <sean@farley.io>
parents: 1105
diff changeset
268
734
351213785c4a gexport: drop empty options and redundant synopsis, and add help text
Siddharth Agarwal <sid0@fb.com>
parents: 733
diff changeset
269 @command('gexport')
97
f0628f5270b6 add gexport command
Sverre Rabbelier <sverre@rabbelier.nl>
parents: 63
diff changeset
270 def gexport(ui, repo):
734
351213785c4a gexport: drop empty options and redundant synopsis, and add help text
Siddharth Agarwal <sid0@fb.com>
parents: 733
diff changeset
271 '''export commits from Mercurial to Git'''
664
570c3702b916 gexport: use githandler from repo
Siddharth Agarwal <sid0@fb.com>
parents: 663
diff changeset
272 repo.githandler.export_commits()
97
f0628f5270b6 add gexport command
Sverre Rabbelier <sverre@rabbelier.nl>
parents: 63
diff changeset
273
1115
8ed6c0cae9b8 cleanup: add some blank lines
Sean Farley <sean@farley.io>
parents: 1105
diff changeset
274
735
b48be97bd6fd gclear: drop empty options and move help text to docstring
Siddharth Agarwal <sid0@fb.com>
parents: 734
diff changeset
275 @command('gclear')
40
f5b000ec7100 added gclear command to remove all the git data
Scott Chacon <schacon@gmail.com>
parents: 39
diff changeset
276 def gclear(ui, repo):
1082
b6cdf7be4059 doc: explain gclear more clearly (and warningly)
Kevin Bullock <kbullock@ringworld.org>
parents: 1075
diff changeset
277 '''clear out the Git cached data
b6cdf7be4059 doc: explain gclear more clearly (and warningly)
Kevin Bullock <kbullock@ringworld.org>
parents: 1075
diff changeset
278
b6cdf7be4059 doc: explain gclear more clearly (and warningly)
Kevin Bullock <kbullock@ringworld.org>
parents: 1075
diff changeset
279 Strips all Git-related metadata from the repo, including the mapping
b6cdf7be4059 doc: explain gclear more clearly (and warningly)
Kevin Bullock <kbullock@ringworld.org>
parents: 1075
diff changeset
280 between Git and Mercurial changesets. This is an irreversible
b6cdf7be4059 doc: explain gclear more clearly (and warningly)
Kevin Bullock <kbullock@ringworld.org>
parents: 1075
diff changeset
281 destructive operation that may prevent further interaction with
b6cdf7be4059 doc: explain gclear more clearly (and warningly)
Kevin Bullock <kbullock@ringworld.org>
parents: 1075
diff changeset
282 other clones.
b6cdf7be4059 doc: explain gclear more clearly (and warningly)
Kevin Bullock <kbullock@ringworld.org>
parents: 1075
diff changeset
283 '''
40
f5b000ec7100 added gclear command to remove all the git data
Scott Chacon <schacon@gmail.com>
parents: 39
diff changeset
284 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
285 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
286
1115
8ed6c0cae9b8 cleanup: add some blank lines
Sean Farley <sean@farley.io>
parents: 1105
diff changeset
287
732
a67fecf02adb commands: switch to new-style declaration via decorators
Siddharth Agarwal <sid0@fb.com>
parents: 731
diff changeset
288 @command('gverify',
a67fecf02adb commands: switch to new-style declaration via decorators
Siddharth Agarwal <sid0@fb.com>
parents: 731
diff changeset
289 [('r', 'rev', '', _('revision to verify'), _('REV'))],
a67fecf02adb commands: switch to new-style declaration via decorators
Siddharth Agarwal <sid0@fb.com>
parents: 731
diff changeset
290 _('[-r REV]'))
731
705f0a2a7c18 verify: add a wrapper function in __init__.py
Siddharth Agarwal <sid0@fb.com>
parents: 730
diff changeset
291 def gverify(ui, repo, **opts):
705f0a2a7c18 verify: add a wrapper function in __init__.py
Siddharth Agarwal <sid0@fb.com>
parents: 730
diff changeset
292 '''verify that a Mercurial rev matches the corresponding Git rev
705f0a2a7c18 verify: add a wrapper function in __init__.py
Siddharth Agarwal <sid0@fb.com>
parents: 730
diff changeset
293
1116
bd1a01f98154 cleanup: wrap to 80 chars
Sean Farley <sean@farley.io>
parents: 1115
diff changeset
294 Given a Mercurial revision that has a corresponding Git revision in the
bd1a01f98154 cleanup: wrap to 80 chars
Sean Farley <sean@farley.io>
parents: 1115
diff changeset
295 map, this attempts to answer whether that revision has the same contents as
bd1a01f98154 cleanup: wrap to 80 chars
Sean Farley <sean@farley.io>
parents: 1115
diff changeset
296 the corresponding Git revision.
731
705f0a2a7c18 verify: add a wrapper function in __init__.py
Siddharth Agarwal <sid0@fb.com>
parents: 730
diff changeset
297
705f0a2a7c18 verify: add a wrapper function in __init__.py
Siddharth Agarwal <sid0@fb.com>
parents: 730
diff changeset
298 '''
705f0a2a7c18 verify: add a wrapper function in __init__.py
Siddharth Agarwal <sid0@fb.com>
parents: 730
diff changeset
299 ctx = scmutil.revsingle(repo, opts.get('rev'), '.')
705f0a2a7c18 verify: add a wrapper function in __init__.py
Siddharth Agarwal <sid0@fb.com>
parents: 730
diff changeset
300 return verify.verify(ui, repo, ctx)
705f0a2a7c18 verify: add a wrapper function in __init__.py
Siddharth Agarwal <sid0@fb.com>
parents: 730
diff changeset
301
1115
8ed6c0cae9b8 cleanup: add some blank lines
Sean Farley <sean@farley.io>
parents: 1105
diff changeset
302
736
5d35a5c12b02 git-cleanup: drop empty options and move help text to docstring
Siddharth Agarwal <sid0@fb.com>
parents: 735
diff changeset
303 @command('git-cleanup')
298
6ad6945b6629 pull: make it possible to un-wedge the repo after stripping git revs
Augie Fackler <durin42@gmail.com>
parents: 297
diff changeset
304 def git_cleanup(ui, repo):
736
5d35a5c12b02 git-cleanup: drop empty options and move help text to docstring
Siddharth Agarwal <sid0@fb.com>
parents: 735
diff changeset
305 '''clean up Git commit map after history editing'''
298
6ad6945b6629 pull: make it possible to un-wedge the repo after stripping git revs
Augie Fackler <durin42@gmail.com>
parents: 297
diff changeset
306 new_map = []
1088
c06d4656b77b shared: fix compatibility with hg < 4.2
Kevin Bullock <kbullock@ringworld.org>
parents: 1085
diff changeset
307 vfs = compat.gitvfs(repo)
1085
1003994dd497 share: host the git repository alongside the store
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 1082
diff changeset
308 for line in vfs(GitHandler.map_file):
298
6ad6945b6629 pull: make it possible to un-wedge the repo after stripping git revs
Augie Fackler <durin42@gmail.com>
parents: 297
diff changeset
309 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
310 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
311 new_map.append('%s %s\n' % (gitsha, hgsha))
1025
e7a8a5710257 wlock: use non-context-manager form to restore older hg support
Kevin Bullock <kbullock@ringworld.org>
parents: 1023
diff changeset
312 wlock = repo.wlock()
e7a8a5710257 wlock: use non-context-manager form to restore older hg support
Kevin Bullock <kbullock@ringworld.org>
parents: 1023
diff changeset
313 try:
1085
1003994dd497 share: host the git repository alongside the store
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 1082
diff changeset
314 f = vfs(GitHandler.map_file, 'wb')
1023
78959c8e5e60 wlock: take wlock when writing map file
Durham Goode <durham@fb.com>
parents: 1020
diff changeset
315 map(f.write, new_map)
1025
e7a8a5710257 wlock: use non-context-manager form to restore older hg support
Kevin Bullock <kbullock@ringworld.org>
parents: 1023
diff changeset
316 finally:
e7a8a5710257 wlock: use non-context-manager form to restore older hg support
Kevin Bullock <kbullock@ringworld.org>
parents: 1023
diff changeset
317 wlock.release()
298
6ad6945b6629 pull: make it possible to un-wedge the repo after stripping git revs
Augie Fackler <durin42@gmail.com>
parents: 297
diff changeset
318 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
319
1115
8ed6c0cae9b8 cleanup: add some blank lines
Sean Farley <sean@farley.io>
parents: 1105
diff changeset
320
523
8c1f2b07c04b outgoing: re-introduce support for outgoing
David M. Carr <david@carrclan.us>
parents: 483
diff changeset
321 def findcommonoutgoing(orig, repo, other, *args, **kwargs):
8c1f2b07c04b outgoing: re-introduce support for outgoing
David M. Carr <david@carrclan.us>
parents: 483
diff changeset
322 if isinstance(other, gitrepo.gitrepo):
666
27fefb7e7cec findcommonoutgoing: use githandler from repo
Siddharth Agarwal <sid0@fb.com>
parents: 665
diff changeset
323 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
324 kw = {}
8c1f2b07c04b outgoing: re-introduce support for outgoing
David M. Carr <david@carrclan.us>
parents: 483
diff changeset
325 kw.update(kwargs)
8c1f2b07c04b outgoing: re-introduce support for outgoing
David M. Carr <david@carrclan.us>
parents: 483
diff changeset
326 for val, k in zip(args,
887
8f9d52f7942e init: whitespace and formating cleanup
Sean Farley <sean@farley.io>
parents: 857
diff changeset
327 ('onlyheads', 'force', 'commoninc', 'portable')):
523
8c1f2b07c04b outgoing: re-introduce support for outgoing
David M. Carr <david@carrclan.us>
parents: 483
diff changeset
328 kw[k] = val
8c1f2b07c04b outgoing: re-introduce support for outgoing
David M. Carr <david@carrclan.us>
parents: 483
diff changeset
329 force = kw.get('force', False)
8c1f2b07c04b outgoing: re-introduce support for outgoing
David M. Carr <david@carrclan.us>
parents: 483
diff changeset
330 commoninc = kw.get('commoninc', None)
8c1f2b07c04b outgoing: re-introduce support for outgoing
David M. Carr <david@carrclan.us>
parents: 483
diff changeset
331 if commoninc is None:
887
8f9d52f7942e init: whitespace and formating cleanup
Sean Farley <sean@farley.io>
parents: 857
diff changeset
332 commoninc = discovery.findcommonincoming(repo, other, heads=heads,
8f9d52f7942e init: whitespace and formating cleanup
Sean Farley <sean@farley.io>
parents: 857
diff changeset
333 force=force)
523
8c1f2b07c04b outgoing: re-introduce support for outgoing
David M. Carr <david@carrclan.us>
parents: 483
diff changeset
334 kw['commoninc'] = commoninc
8c1f2b07c04b outgoing: re-introduce support for outgoing
David M. Carr <david@carrclan.us>
parents: 483
diff changeset
335 return orig(repo, other, **kw)
8c1f2b07c04b outgoing: re-introduce support for outgoing
David M. Carr <david@carrclan.us>
parents: 483
diff changeset
336 return orig(repo, other, *args, **kwargs)
1115
8ed6c0cae9b8 cleanup: add some blank lines
Sean Farley <sean@farley.io>
parents: 1105
diff changeset
337
8ed6c0cae9b8 cleanup: add some blank lines
Sean Farley <sean@farley.io>
parents: 1105
diff changeset
338
523
8c1f2b07c04b outgoing: re-introduce support for outgoing
David M. Carr <david@carrclan.us>
parents: 483
diff changeset
339 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
340
1115
8ed6c0cae9b8 cleanup: add some blank lines
Sean Farley <sean@farley.io>
parents: 1105
diff changeset
341
412
5932586e6d43 Fix mercurial issue2855
Brendan Cully <brendan@kublai.com>
parents: 408
diff changeset
342 def getremotechanges(orig, ui, repo, other, *args, **opts):
408
2dcfd4bbfc1a Support for hg incoming
Brendan Cully <brendan@kublai.com>
parents: 389
diff changeset
343 if isinstance(other, gitrepo.gitrepo):
424
d2c4333e5f14 getremotechanges: fix incoming support
Augie Fackler <durin42@gmail.com>
parents: 412
diff changeset
344 if args:
d2c4333e5f14 getremotechanges: fix incoming support
Augie Fackler <durin42@gmail.com>
parents: 412
diff changeset
345 revs = args[0]
d2c4333e5f14 getremotechanges: fix incoming support
Augie Fackler <durin42@gmail.com>
parents: 412
diff changeset
346 else:
d2c4333e5f14 getremotechanges: fix incoming support
Augie Fackler <durin42@gmail.com>
parents: 412
diff changeset
347 revs = opts.get('onlyheads', opts.get('revs'))
667
b5ef3f0e0efe getremotechanges: use githandler from repo
Siddharth Agarwal <sid0@fb.com>
parents: 666
diff changeset
348 r, c, cleanup = repo.githandler.getremotechanges(other, revs)
408
2dcfd4bbfc1a Support for hg incoming
Brendan Cully <brendan@kublai.com>
parents: 389
diff changeset
349 # ugh. This is ugly even by mercurial API compatibility standards
2dcfd4bbfc1a Support for hg incoming
Brendan Cully <brendan@kublai.com>
parents: 389
diff changeset
350 if 'onlyheads' not in orig.func_code.co_varnames:
2dcfd4bbfc1a Support for hg incoming
Brendan Cully <brendan@kublai.com>
parents: 389
diff changeset
351 cleanup = None
2dcfd4bbfc1a Support for hg incoming
Brendan Cully <brendan@kublai.com>
parents: 389
diff changeset
352 return r, c, cleanup
412
5932586e6d43 Fix mercurial issue2855
Brendan Cully <brendan@kublai.com>
parents: 408
diff changeset
353 return orig(ui, repo, other, *args, **opts)
1115
8ed6c0cae9b8 cleanup: add some blank lines
Sean Farley <sean@farley.io>
parents: 1105
diff changeset
354
8ed6c0cae9b8 cleanup: add some blank lines
Sean Farley <sean@farley.io>
parents: 1105
diff changeset
355
677
73cf8d292dcb getremotechanges: drop support for Mercurial < 1.7
Siddharth Agarwal <sid0@fb.com>
parents: 676
diff changeset
356 extensions.wrapfunction(bundlerepo, 'getremotechanges', getremotechanges)
408
2dcfd4bbfc1a Support for hg incoming
Brendan Cully <brendan@kublai.com>
parents: 389
diff changeset
357
1115
8ed6c0cae9b8 cleanup: add some blank lines
Sean Farley <sean@farley.io>
parents: 1105
diff changeset
358
556
affd119533ae peer: pass localrepo to new gitrepo instances
David M. Carr <david@carrclan.us>
parents: 546
diff changeset
359 def peer(orig, uiorrepo, *args, **opts):
affd119533ae peer: pass localrepo to new gitrepo instances
David M. Carr <david@carrclan.us>
parents: 546
diff changeset
360 newpeer = orig(uiorrepo, *args, **opts)
affd119533ae peer: pass localrepo to new gitrepo instances
David M. Carr <david@carrclan.us>
parents: 546
diff changeset
361 if isinstance(newpeer, gitrepo.gitrepo):
affd119533ae peer: pass localrepo to new gitrepo instances
David M. Carr <david@carrclan.us>
parents: 546
diff changeset
362 if isinstance(uiorrepo, localrepo.localrepository):
affd119533ae peer: pass localrepo to new gitrepo instances
David M. Carr <david@carrclan.us>
parents: 546
diff changeset
363 newpeer.localrepo = uiorrepo
affd119533ae peer: pass localrepo to new gitrepo instances
David M. Carr <david@carrclan.us>
parents: 546
diff changeset
364 return newpeer
1115
8ed6c0cae9b8 cleanup: add some blank lines
Sean Farley <sean@farley.io>
parents: 1105
diff changeset
365
8ed6c0cae9b8 cleanup: add some blank lines
Sean Farley <sean@farley.io>
parents: 1105
diff changeset
366
556
affd119533ae peer: pass localrepo to new gitrepo instances
David M. Carr <david@carrclan.us>
parents: 546
diff changeset
367 extensions.wrapfunction(hg, 'peer', peer)
affd119533ae peer: pass localrepo to new gitrepo instances
David M. Carr <david@carrclan.us>
parents: 546
diff changeset
368
1115
8ed6c0cae9b8 cleanup: add some blank lines
Sean Farley <sean@farley.io>
parents: 1105
diff changeset
369
936
f05962b0e78a paths: mark git repos as valid paths
Durham Goode <durham@fb.com>
parents: 935
diff changeset
370 def isvalidlocalpath(orig, self, path):
f05962b0e78a paths: mark git repos as valid paths
Durham Goode <durham@fb.com>
parents: 935
diff changeset
371 return orig(self, path) or _isgitdir(path)
1115
8ed6c0cae9b8 cleanup: add some blank lines
Sean Farley <sean@farley.io>
parents: 1105
diff changeset
372
8ed6c0cae9b8 cleanup: add some blank lines
Sean Farley <sean@farley.io>
parents: 1105
diff changeset
373
936
f05962b0e78a paths: mark git repos as valid paths
Durham Goode <durham@fb.com>
parents: 935
diff changeset
374 if (hgutil.safehasattr(hgui, 'path') and
f05962b0e78a paths: mark git repos as valid paths
Durham Goode <durham@fb.com>
parents: 935
diff changeset
375 hgutil.safehasattr(hgui.path, '_isvalidlocalpath')):
f05962b0e78a paths: mark git repos as valid paths
Durham Goode <durham@fb.com>
parents: 935
diff changeset
376 extensions.wrapfunction(hgui.path, '_isvalidlocalpath', isvalidlocalpath)
f05962b0e78a paths: mark git repos as valid paths
Durham Goode <durham@fb.com>
parents: 935
diff changeset
377
1115
8ed6c0cae9b8 cleanup: add some blank lines
Sean Farley <sean@farley.io>
parents: 1105
diff changeset
378
780
db10082cf043 exchange: wrap pull if localrepository.pull isn't available
Siddharth Agarwal <sid0@fb.com>
parents: 768
diff changeset
379 @util.transform_notgit
913
b1b03873c9ad hggit: adapt pull wrapper function for recent hg
Augie Fackler <augie@google.com>
parents: 912
diff changeset
380 def exchangepull(orig, repo, remote, heads=None, force=False, bookmarks=(),
b1b03873c9ad hggit: adapt pull wrapper function for recent hg
Augie Fackler <augie@google.com>
parents: 912
diff changeset
381 **kwargs):
780
db10082cf043 exchange: wrap pull if localrepository.pull isn't available
Siddharth Agarwal <sid0@fb.com>
parents: 768
diff changeset
382 if isinstance(remote, gitrepo.gitrepo):
841
ef904bd8d3fb exchangepull: fixup for introduction of transaction manager upstream
Siddharth Agarwal <sid0@fb.com>
parents: 782
diff changeset
383 # transaction manager is present in Mercurial >= 3.3
847
05eb0874fa30 init: add a try/except to retain compatibility with Mercurial 3.2
Siddharth Agarwal <sid0@fb.com>
parents: 841
diff changeset
384 try:
05eb0874fa30 init: add a try/except to retain compatibility with Mercurial 3.2
Siddharth Agarwal <sid0@fb.com>
parents: 841
diff changeset
385 trmanager = getattr(exchange, 'transactionmanager')
05eb0874fa30 init: add a try/except to retain compatibility with Mercurial 3.2
Siddharth Agarwal <sid0@fb.com>
parents: 841
diff changeset
386 except AttributeError:
05eb0874fa30 init: add a try/except to retain compatibility with Mercurial 3.2
Siddharth Agarwal <sid0@fb.com>
parents: 841
diff changeset
387 trmanager = None
780
db10082cf043 exchange: wrap pull if localrepository.pull isn't available
Siddharth Agarwal <sid0@fb.com>
parents: 768
diff changeset
388 pullop = exchange.pulloperation(repo, remote, heads, force,
db10082cf043 exchange: wrap pull if localrepository.pull isn't available
Siddharth Agarwal <sid0@fb.com>
parents: 768
diff changeset
389 bookmarks=bookmarks)
841
ef904bd8d3fb exchangepull: fixup for introduction of transaction manager upstream
Siddharth Agarwal <sid0@fb.com>
parents: 782
diff changeset
390 if trmanager:
ef904bd8d3fb exchangepull: fixup for introduction of transaction manager upstream
Siddharth Agarwal <sid0@fb.com>
parents: 782
diff changeset
391 pullop.trmanager = trmanager(repo, 'pull', remote.url())
897
8026c094173a pull: acquire wlock before lock to fix lock-checker warnings
Augie Fackler <raf@durin42.com>
parents: 887
diff changeset
392 wlock = repo.wlock()
780
db10082cf043 exchange: wrap pull if localrepository.pull isn't available
Siddharth Agarwal <sid0@fb.com>
parents: 768
diff changeset
393 lock = repo.lock()
db10082cf043 exchange: wrap pull if localrepository.pull isn't available
Siddharth Agarwal <sid0@fb.com>
parents: 768
diff changeset
394 try:
db10082cf043 exchange: wrap pull if localrepository.pull isn't available
Siddharth Agarwal <sid0@fb.com>
parents: 768
diff changeset
395 pullop.cgresult = repo.githandler.fetch(remote.path, heads)
841
ef904bd8d3fb exchangepull: fixup for introduction of transaction manager upstream
Siddharth Agarwal <sid0@fb.com>
parents: 782
diff changeset
396 if trmanager:
ef904bd8d3fb exchangepull: fixup for introduction of transaction manager upstream
Siddharth Agarwal <sid0@fb.com>
parents: 782
diff changeset
397 pullop.trmanager.close()
ef904bd8d3fb exchangepull: fixup for introduction of transaction manager upstream
Siddharth Agarwal <sid0@fb.com>
parents: 782
diff changeset
398 else:
ef904bd8d3fb exchangepull: fixup for introduction of transaction manager upstream
Siddharth Agarwal <sid0@fb.com>
parents: 782
diff changeset
399 pullop.closetransaction()
780
db10082cf043 exchange: wrap pull if localrepository.pull isn't available
Siddharth Agarwal <sid0@fb.com>
parents: 768
diff changeset
400 return pullop
db10082cf043 exchange: wrap pull if localrepository.pull isn't available
Siddharth Agarwal <sid0@fb.com>
parents: 768
diff changeset
401 finally:
841
ef904bd8d3fb exchangepull: fixup for introduction of transaction manager upstream
Siddharth Agarwal <sid0@fb.com>
parents: 782
diff changeset
402 if trmanager:
ef904bd8d3fb exchangepull: fixup for introduction of transaction manager upstream
Siddharth Agarwal <sid0@fb.com>
parents: 782
diff changeset
403 pullop.trmanager.release()
ef904bd8d3fb exchangepull: fixup for introduction of transaction manager upstream
Siddharth Agarwal <sid0@fb.com>
parents: 782
diff changeset
404 else:
ef904bd8d3fb exchangepull: fixup for introduction of transaction manager upstream
Siddharth Agarwal <sid0@fb.com>
parents: 782
diff changeset
405 pullop.releasetransaction()
780
db10082cf043 exchange: wrap pull if localrepository.pull isn't available
Siddharth Agarwal <sid0@fb.com>
parents: 768
diff changeset
406 lock.release()
897
8026c094173a pull: acquire wlock before lock to fix lock-checker warnings
Augie Fackler <raf@durin42.com>
parents: 887
diff changeset
407 wlock.release()
780
db10082cf043 exchange: wrap pull if localrepository.pull isn't available
Siddharth Agarwal <sid0@fb.com>
parents: 768
diff changeset
408 else:
913
b1b03873c9ad hggit: adapt pull wrapper function for recent hg
Augie Fackler <augie@google.com>
parents: 912
diff changeset
409 return orig(repo, remote, heads, force, bookmarks=bookmarks, **kwargs)
1115
8ed6c0cae9b8 cleanup: add some blank lines
Sean Farley <sean@farley.io>
parents: 1105
diff changeset
410
8ed6c0cae9b8 cleanup: add some blank lines
Sean Farley <sean@farley.io>
parents: 1105
diff changeset
411
780
db10082cf043 exchange: wrap pull if localrepository.pull isn't available
Siddharth Agarwal <sid0@fb.com>
parents: 768
diff changeset
412 if not hgutil.safehasattr(localrepo.localrepository, 'pull'):
db10082cf043 exchange: wrap pull if localrepository.pull isn't available
Siddharth Agarwal <sid0@fb.com>
parents: 768
diff changeset
413 # Mercurial >= 3.2
db10082cf043 exchange: wrap pull if localrepository.pull isn't available
Siddharth Agarwal <sid0@fb.com>
parents: 768
diff changeset
414 extensions.wrapfunction(exchange, 'pull', exchangepull)
db10082cf043 exchange: wrap pull if localrepository.pull isn't available
Siddharth Agarwal <sid0@fb.com>
parents: 768
diff changeset
415
1115
8ed6c0cae9b8 cleanup: add some blank lines
Sean Farley <sean@farley.io>
parents: 1105
diff changeset
416
781
8bfb1d72b49c exchange: wrap push if localrepository.push isn't available
Siddharth Agarwal <sid0@fb.com>
parents: 780
diff changeset
417 # TODO figure out something useful to do with the newbranch param
8bfb1d72b49c exchange: wrap push if localrepository.push isn't available
Siddharth Agarwal <sid0@fb.com>
parents: 780
diff changeset
418 @util.transform_notgit
8bfb1d72b49c exchange: wrap push if localrepository.push isn't available
Siddharth Agarwal <sid0@fb.com>
parents: 780
diff changeset
419 def exchangepush(orig, repo, remote, force=False, revs=None, newbranch=False,
943
e1d343fdeba4 push: fix exchangepush for Mercurial 3.2
Siddharth Agarwal <sid0@fb.com>
parents: 942
diff changeset
420 bookmarks=(), **kwargs):
781
8bfb1d72b49c exchange: wrap push if localrepository.push isn't available
Siddharth Agarwal <sid0@fb.com>
parents: 780
diff changeset
421 if isinstance(remote, gitrepo.gitrepo):
943
e1d343fdeba4 push: fix exchangepush for Mercurial 3.2
Siddharth Agarwal <sid0@fb.com>
parents: 942
diff changeset
422 # opargs is in Mercurial >= 3.6
e1d343fdeba4 push: fix exchangepush for Mercurial 3.2
Siddharth Agarwal <sid0@fb.com>
parents: 942
diff changeset
423 opargs = kwargs.get('opargs')
942
d278f6d82a06 push: fix exchangepush wrapping
Durham Goode <durham@fb.com>
parents: 939
diff changeset
424 if opargs is None:
d278f6d82a06 push: fix exchangepush wrapping
Durham Goode <durham@fb.com>
parents: 939
diff changeset
425 opargs = {}
781
8bfb1d72b49c exchange: wrap push if localrepository.push isn't available
Siddharth Agarwal <sid0@fb.com>
parents: 780
diff changeset
426 pushop = exchange.pushoperation(repo, remote, force, revs, newbranch,
942
d278f6d82a06 push: fix exchangepush wrapping
Durham Goode <durham@fb.com>
parents: 939
diff changeset
427 bookmarks, **opargs)
781
8bfb1d72b49c exchange: wrap push if localrepository.push isn't available
Siddharth Agarwal <sid0@fb.com>
parents: 780
diff changeset
428 pushop.cgresult = repo.githandler.push(remote.path, revs, force)
8bfb1d72b49c exchange: wrap push if localrepository.push isn't available
Siddharth Agarwal <sid0@fb.com>
parents: 780
diff changeset
429 return pushop
8bfb1d72b49c exchange: wrap push if localrepository.push isn't available
Siddharth Agarwal <sid0@fb.com>
parents: 780
diff changeset
430 else:
939
c85c28fbc8a5 hggit: adapt push wrapper function for recent hg
Sean Farley <sean@farley.io>
parents: 938
diff changeset
431 return orig(repo, remote, force, revs, newbranch, bookmarks=bookmarks,
943
e1d343fdeba4 push: fix exchangepush for Mercurial 3.2
Siddharth Agarwal <sid0@fb.com>
parents: 942
diff changeset
432 **kwargs)
1115
8ed6c0cae9b8 cleanup: add some blank lines
Sean Farley <sean@farley.io>
parents: 1105
diff changeset
433
8ed6c0cae9b8 cleanup: add some blank lines
Sean Farley <sean@farley.io>
parents: 1105
diff changeset
434
781
8bfb1d72b49c exchange: wrap push if localrepository.push isn't available
Siddharth Agarwal <sid0@fb.com>
parents: 780
diff changeset
435 if not hgutil.safehasattr(localrepo.localrepository, 'push'):
8bfb1d72b49c exchange: wrap push if localrepository.push isn't available
Siddharth Agarwal <sid0@fb.com>
parents: 780
diff changeset
436 # Mercurial >= 3.2
8bfb1d72b49c exchange: wrap push if localrepository.push isn't available
Siddharth Agarwal <sid0@fb.com>
parents: 780
diff changeset
437 extensions.wrapfunction(exchange, 'push', exchangepush)
8bfb1d72b49c exchange: wrap push if localrepository.push isn't available
Siddharth Agarwal <sid0@fb.com>
parents: 780
diff changeset
438
1115
8ed6c0cae9b8 cleanup: add some blank lines
Sean Farley <sean@farley.io>
parents: 1105
diff changeset
439
483
d2caea269670 revsets: add fromgit and gitnode selectors
David M. Carr <david@carrclan.us>
parents: 482
diff changeset
440 def revset_fromgit(repo, subset, x):
d2caea269670 revsets: add fromgit and gitnode selectors
David M. Carr <david@carrclan.us>
parents: 482
diff changeset
441 '''``fromgit()``
d2caea269670 revsets: add fromgit and gitnode selectors
David M. Carr <david@carrclan.us>
parents: 482
diff changeset
442 Select changesets that originate from Git.
d2caea269670 revsets: add fromgit and gitnode selectors
David M. Carr <david@carrclan.us>
parents: 482
diff changeset
443 '''
887
8f9d52f7942e init: whitespace and formating cleanup
Sean Farley <sean@farley.io>
parents: 857
diff changeset
444 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
445 git = repo.githandler
714
5770a5a8bc00 revset_fromgit: use repo.changelog.node instead of contexts
Siddharth Agarwal <sid0@fb.com>
parents: 713
diff changeset
446 node = repo.changelog.node
937
d46938925708 revsets: use baseset instead of raw list
Sean Farley <sean@farley.io>
parents: 936
diff changeset
447 return baseset(r for r in subset
d46938925708 revsets: use baseset instead of raw list
Sean Farley <sean@farley.io>
parents: 936
diff changeset
448 if git.map_git_get(hex(node(r))) is not None)
483
d2caea269670 revsets: add fromgit and gitnode selectors
David M. Carr <david@carrclan.us>
parents: 482
diff changeset
449
1115
8ed6c0cae9b8 cleanup: add some blank lines
Sean Farley <sean@farley.io>
parents: 1105
diff changeset
450
483
d2caea269670 revsets: add fromgit and gitnode selectors
David M. Carr <david@carrclan.us>
parents: 482
diff changeset
451 def revset_gitnode(repo, subset, x):
d2caea269670 revsets: add fromgit and gitnode selectors
David M. Carr <david@carrclan.us>
parents: 482
diff changeset
452 '''``gitnode(hash)``
999
a128b9a53b5a revset_gitnode: allow abbreviated hashes
Sietse Brouwer <sbbrouwer@gmail.com>
parents: 994
diff changeset
453 Select the changeset that originates in the given Git revision. The hash
a128b9a53b5a revset_gitnode: allow abbreviated hashes
Sietse Brouwer <sbbrouwer@gmail.com>
parents: 994
diff changeset
454 may be abbreviated: `gitnode(a5b)` selects the revision whose Git hash
a128b9a53b5a revset_gitnode: allow abbreviated hashes
Sietse Brouwer <sbbrouwer@gmail.com>
parents: 994
diff changeset
455 starts with `a5b`. Aborts if multiple changesets match the abbreviation.
483
d2caea269670 revsets: add fromgit and gitnode selectors
David M. Carr <david@carrclan.us>
parents: 482
diff changeset
456 '''
d2caea269670 revsets: add fromgit and gitnode selectors
David M. Carr <david@carrclan.us>
parents: 482
diff changeset
457 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
458 rev = revset.getstring(args[0],
d2caea269670 revsets: add fromgit and gitnode selectors
David M. Carr <david@carrclan.us>
parents: 482
diff changeset
459 "the argument to gitnode() must be a hash")
669
b8fff2f4e963 revset_gitnode: use githandler from repo
Siddharth Agarwal <sid0@fb.com>
parents: 668
diff changeset
460 git = repo.githandler
713
96f0463a4e54 revset_gitnode: use repo.changelog.node instead of contexts
Siddharth Agarwal <sid0@fb.com>
parents: 706
diff changeset
461 node = repo.changelog.node
887
8f9d52f7942e init: whitespace and formating cleanup
Sean Farley <sean@farley.io>
parents: 857
diff changeset
462
483
d2caea269670 revsets: add fromgit and gitnode selectors
David M. Carr <david@carrclan.us>
parents: 482
diff changeset
463 def matches(r):
713
96f0463a4e54 revset_gitnode: use repo.changelog.node instead of contexts
Siddharth Agarwal <sid0@fb.com>
parents: 706
diff changeset
464 gitnode = git.map_git_get(hex(node(r)))
483
d2caea269670 revsets: add fromgit and gitnode selectors
David M. Carr <david@carrclan.us>
parents: 482
diff changeset
465 if gitnode is None:
d2caea269670 revsets: add fromgit and gitnode selectors
David M. Carr <david@carrclan.us>
parents: 482
diff changeset
466 return False
999
a128b9a53b5a revset_gitnode: allow abbreviated hashes
Sietse Brouwer <sbbrouwer@gmail.com>
parents: 994
diff changeset
467 return gitnode.startswith(rev)
a128b9a53b5a revset_gitnode: allow abbreviated hashes
Sietse Brouwer <sbbrouwer@gmail.com>
parents: 994
diff changeset
468 result = baseset(r for r in subset if matches(r))
a128b9a53b5a revset_gitnode: allow abbreviated hashes
Sietse Brouwer <sbbrouwer@gmail.com>
parents: 994
diff changeset
469 if 0 <= len(result) < 2:
a128b9a53b5a revset_gitnode: allow abbreviated hashes
Sietse Brouwer <sbbrouwer@gmail.com>
parents: 994
diff changeset
470 return result
a128b9a53b5a revset_gitnode: allow abbreviated hashes
Sietse Brouwer <sbbrouwer@gmail.com>
parents: 994
diff changeset
471 raise LookupError(rev, git.map_file, _('ambiguous identifier'))
483
d2caea269670 revsets: add fromgit and gitnode selectors
David M. Carr <david@carrclan.us>
parents: 482
diff changeset
472
1115
8ed6c0cae9b8 cleanup: add some blank lines
Sean Farley <sean@farley.io>
parents: 1105
diff changeset
473
482
00d591868a2f templatekw: add support for gitnode template keyword
David M. Carr <david@carrclan.us>
parents: 481
diff changeset
474 def gitnodekw(**args):
1116
bd1a01f98154 cleanup: wrap to 80 chars
Sean Farley <sean@farley.io>
parents: 1115
diff changeset
475 """:gitnode: String. The Git changeset identification hash, as a 40 hexadecimal
bd1a01f98154 cleanup: wrap to 80 chars
Sean Farley <sean@farley.io>
parents: 1115
diff changeset
476 digit string."""
482
00d591868a2f templatekw: add support for gitnode template keyword
David M. Carr <david@carrclan.us>
parents: 481
diff changeset
477 node = args['ctx']
00d591868a2f templatekw: add support for gitnode template keyword
David M. Carr <david@carrclan.us>
parents: 481
diff changeset
478 repo = args['repo']
670
ab3c64db47d8 gitnodekw: use githandler from repo
Siddharth Agarwal <sid0@fb.com>
parents: 669
diff changeset
479 gitnode = repo.githandler.map_git_get(node.hex())
482
00d591868a2f templatekw: add support for gitnode template keyword
David M. Carr <david@carrclan.us>
parents: 481
diff changeset
480 if gitnode is None:
00d591868a2f templatekw: add support for gitnode template keyword
David M. Carr <david@carrclan.us>
parents: 481
diff changeset
481 gitnode = ''
00d591868a2f templatekw: add support for gitnode template keyword
David M. Carr <david@carrclan.us>
parents: 481
diff changeset
482 return gitnode