1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18 """mercurial utilities (mercurial should be installed)"""
19
20 __docformat__ = "restructuredtext en"
21
22 import os
23 import sys
24 import os.path as osp
25
26 try:
27 from mercurial.error import RepoError
28 from mercurial.__version__ import version as hg_version
29 except ImportError:
30 from mercurial.repo import RepoError
31 from mercurial.version import get_version
32 hg_version = get_version()
33
34 from mercurial.hg import repository as Repository
35 from mercurial.ui import ui as Ui
36 from mercurial.node import short
37 try:
38
39 from mercurial.cmdutil import walkchangerevs
40 except ImportError, ex:
41 from mercurial.commands import walkchangerevs
42 try:
43
44 from mercurial.util import cachefunc
45 except ImportError, ex:
48 try:
49
50 from mercurial import encoding
51 _encoding = encoding.encoding
52 except ImportError:
53 try:
54 from mercurial.util import _encoding
55 except ImportError:
56 import locale
57
58
59 try:
60 _encoding = os.environ.get("HGENCODING")
61 if sys.platform == 'darwin' and not _encoding:
62
63
64
65 locale.setlocale(locale.LC_CTYPE, '')
66 _encoding = locale.getlocale()[1]
67 if not _encoding:
68 _encoding = locale.getpreferredencoding() or 'ascii'
69 except locale.Error:
70 _encoding = 'ascii'
71 try:
72
73
74 from mercurial import demandimport
75 demandimport.disable()
76 except:
77 pass
78
79 Ui.warn = lambda *args, **kwargs: 0
80
82 """returns <path>'s mercurial repository
83
84 None if <path> is not under hg control
85 """
86 path = osp.realpath(osp.abspath(path))
87 while not osp.isdir(osp.join(path, ".hg")):
88 oldpath = path
89 path = osp.dirname(path)
90 if path == oldpath:
91 return None
92 return path
93
94
96 """Simple function that open a hg repository"""
97 repopath = find_repository(path)
98 if repopath is None:
99 raise RuntimeError('no repository found in %s' % osp.abspath(path))
100 return Repository(Ui(), path=repopath)
101
103 try:
104 return wdrepo.findincoming(masterrepo)
105 except AttributeError:
106 from mercurial import hg, discovery
107 revs, checkout = hg.addbranchrevs(wdrepo, masterrepo, ('', []), None)
108 common, incoming, rheads = discovery.findcommonincoming(
109 wdrepo, masterrepo, heads=revs)
110 if not masterrepo.local():
111 from mercurial import bundlerepo, changegroup
112 if revs is None and masterrepo.capable('changegroupsubset'):
113 revs = rheads
114 if revs is None:
115 cg = masterrepo.changegroup(incoming, "incoming")
116 else:
117 cg = masterrepo.changegroupsubset(incoming, revs, 'incoming')
118 fname = changegroup.writebundle(cg, None, "HG10UN")
119
120 masterrepo = bundlerepo.bundlerepository(wdrepo.ui, wdrepo.root, fname)
121 return masterrepo.changelog.nodesbetween(incoming, revs)[0]
122
124 try:
125 return wdrepo.findoutgoing(masterrepo)
126 except AttributeError:
127 from mercurial import hg, discovery
128 revs, checkout = hg.addbranchrevs(wdrepo, wdrepo, ('', []), None)
129 o = discovery.findoutgoing(wdrepo, masterrepo)
130 return wdrepo.changelog.nodesbetween(o, revs)[0]
131