##// END OF EJS Templates
vcs: drop the superfluous and leaky hgcompat "layer"...
Mads Kiilerich -
r7977:f713a375 default
parent child Browse files
Show More
@@ -30,6 +30,7 b' Original author and date, and relevant c'
30 import logging
30 import logging
31 import re
31 import re
32
32
33 import mercurial.unionrepo
33 from tg import request
34 from tg import request
34 from tg import tmpl_context as c
35 from tg import tmpl_context as c
35 from tg.i18n import ugettext as _
36 from tg.i18n import ugettext as _
@@ -43,7 +44,6 b' from kallithea.lib.auth import HasRepoPe'
43 from kallithea.lib.base import BaseRepoController, render
44 from kallithea.lib.base import BaseRepoController, render
44 from kallithea.lib.graphmod import graph_data
45 from kallithea.lib.graphmod import graph_data
45 from kallithea.lib.utils2 import ascii_bytes, ascii_str, safe_int, safe_str
46 from kallithea.lib.utils2 import ascii_bytes, ascii_str, safe_int, safe_str
46 from kallithea.lib.vcs.utils.hgcompat import unionrepo
47 from kallithea.model.db import Repository
47 from kallithea.model.db import Repository
48
48
49
49
@@ -97,7 +97,7 b' class CompareController(BaseRepoControll'
97 elif alias == 'hg':
97 elif alias == 'hg':
98 # case two independent repos
98 # case two independent repos
99 if org_repo != other_repo:
99 if org_repo != other_repo:
100 hgrepo = unionrepo.makeunionrepository(other_repo.baseui,
100 hgrepo = mercurial.unionrepo.makeunionrepository(other_repo.baseui,
101 other_repo.path,
101 other_repo.path,
102 org_repo.path)
102 org_repo.path)
103 # all ancestors of other_rev will be in other_repo and
103 # all ancestors of other_rev will be in other_repo and
@@ -29,6 +29,7 b' import logging'
29 import traceback
29 import traceback
30
30
31 import formencode
31 import formencode
32 import mercurial.unionrepo
32 from tg import request
33 from tg import request
33 from tg import tmpl_context as c
34 from tg import tmpl_context as c
34 from tg.i18n import ugettext as _
35 from tg.i18n import ugettext as _
@@ -44,7 +45,6 b' from kallithea.lib.graphmod import graph'
44 from kallithea.lib.page import Page
45 from kallithea.lib.page import Page
45 from kallithea.lib.utils2 import ascii_bytes, safe_bytes, safe_int, safe_str
46 from kallithea.lib.utils2 import ascii_bytes, safe_bytes, safe_int, safe_str
46 from kallithea.lib.vcs.exceptions import ChangesetDoesNotExistError, EmptyRepositoryError
47 from kallithea.lib.vcs.exceptions import ChangesetDoesNotExistError, EmptyRepositoryError
47 from kallithea.lib.vcs.utils.hgcompat import unionrepo
48 from kallithea.model.changeset_status import ChangesetStatusModel
48 from kallithea.model.changeset_status import ChangesetStatusModel
49 from kallithea.model.comment import ChangesetCommentsModel
49 from kallithea.model.comment import ChangesetCommentsModel
50 from kallithea.model.db import ChangesetStatus, PullRequest, PullRequestReviewer, Repository, User
50 from kallithea.model.db import ChangesetStatus, PullRequest, PullRequestReviewer, Repository, User
@@ -533,7 +533,7 b' class PullrequestsController(BaseRepoCon'
533 # Note: org_scm_instance.path must come first so all
533 # Note: org_scm_instance.path must come first so all
534 # valid revision numbers are 100% org_scm compatible
534 # valid revision numbers are 100% org_scm compatible
535 # - both for avail_revs and for revset results
535 # - both for avail_revs and for revset results
536 hgrepo = unionrepo.makeunionrepository(org_scm_instance.baseui,
536 hgrepo = mercurial.unionrepo.makeunionrepository(org_scm_instance.baseui,
537 org_scm_instance.path,
537 org_scm_instance.path,
538 other_scm_instance.path)
538 other_scm_instance.path)
539 else:
539 else:
@@ -28,12 +28,13 b' Original author and date, and relevant c'
28 import os
28 import os
29 import time
29 import time
30
30
31 import mercurial.scmutil
32
31 from kallithea.lib import helpers as h
33 from kallithea.lib import helpers as h
32 from kallithea.lib.exceptions import UserCreationError
34 from kallithea.lib.exceptions import UserCreationError
33 from kallithea.lib.utils import action_logger, make_ui, setup_cache_regions
35 from kallithea.lib.utils import action_logger, make_ui, setup_cache_regions
34 from kallithea.lib.utils2 import ascii_str, get_hook_environment, safe_str, safe_unicode
36 from kallithea.lib.utils2 import ascii_str, get_hook_environment, safe_str, safe_unicode
35 from kallithea.lib.vcs.backends.base import EmptyChangeset
37 from kallithea.lib.vcs.backends.base import EmptyChangeset
36 from kallithea.lib.vcs.utils.hgcompat import revrange
37 from kallithea.model.db import Repository, User
38 from kallithea.model.db import Repository, User
38
39
39
40
@@ -108,7 +109,7 b' def log_push_action(ui, repo, node, node'
108 Note: This hook is not only logging, but also the side effect invalidating
109 Note: This hook is not only logging, but also the side effect invalidating
109 cahes! The function should perhaps be renamed.
110 cahes! The function should perhaps be renamed.
110 """
111 """
111 revs = [ascii_str(repo[r].hex()) for r in revrange(repo, [b'%s:%s' % (node, node_last)])]
112 revs = [ascii_str(repo[r].hex()) for r in mercurial.scmutil.revrange(repo, [b'%s:%s' % (node, node_last)])]
112 process_pushed_raw_ids(revs)
113 process_pushed_raw_ids(revs)
113 return 0
114 return 0
114
115
@@ -32,10 +32,11 b' import logging'
32 import os
32 import os
33 import urllib
33 import urllib
34
34
35 import mercurial.hgweb
36
35 from kallithea.lib.base import BaseVCSController, get_path_info
37 from kallithea.lib.base import BaseVCSController, get_path_info
36 from kallithea.lib.utils import make_ui
38 from kallithea.lib.utils import make_ui
37 from kallithea.lib.utils2 import safe_str, safe_unicode
39 from kallithea.lib.utils2 import safe_str, safe_unicode
38 from kallithea.lib.vcs.utils.hgcompat import hgweb_mod
39
40
40
41
41 log = logging.getLogger(__name__)
42 log = logging.getLogger(__name__)
@@ -139,10 +140,10 b' class SimpleHg(BaseVCSController):'
139 str_repo_name = safe_str(parsed_request.repo_name)
140 str_repo_name = safe_str(parsed_request.repo_name)
140 repo_path = os.path.join(safe_str(self.basepath), str_repo_name)
141 repo_path = os.path.join(safe_str(self.basepath), str_repo_name)
141 baseui = make_ui(repo_path=repo_path)
142 baseui = make_ui(repo_path=repo_path)
142 hgweb_app = hgweb_mod.hgweb(repo_path, name=str_repo_name, baseui=baseui)
143 hgweb_app = mercurial.hgweb.hgweb(repo_path, name=str_repo_name, baseui=baseui)
143
144
144 def wrapper_app(environ, start_response):
145 def wrapper_app(environ, start_response):
145 environ['REPO_NAME'] = str_repo_name # used by hgweb_mod.hgweb
146 environ['REPO_NAME'] = str_repo_name # used by mercurial.hgweb.hgweb
146 return hgweb_app(environ, start_response)
147 return hgweb_app(environ, start_response)
147
148
148 return wrapper_app
149 return wrapper_app
@@ -34,6 +34,8 b' import traceback'
34 from distutils.version import StrictVersion
34 from distutils.version import StrictVersion
35
35
36 import beaker
36 import beaker
37 import mercurial.config
38 import mercurial.ui
37 from beaker.cache import _cache_decorate
39 from beaker.cache import _cache_decorate
38 from tg.i18n import ugettext as _
40 from tg.i18n import ugettext as _
39
41
@@ -46,7 +48,6 b' from kallithea.lib.vcs.conf import setti'
46 from kallithea.lib.vcs.exceptions import RepositoryError, VCSError
48 from kallithea.lib.vcs.exceptions import RepositoryError, VCSError
47 from kallithea.lib.vcs.utils.fakemod import create_module
49 from kallithea.lib.vcs.utils.fakemod import create_module
48 from kallithea.lib.vcs.utils.helpers import get_scm
50 from kallithea.lib.vcs.utils.helpers import get_scm
49 from kallithea.lib.vcs.utils.hgcompat import config, ui
50 from kallithea.model import meta
51 from kallithea.model import meta
51 from kallithea.model.db import RepoGroup, Repository, Setting, Ui, User, UserGroup, UserLog
52 from kallithea.model.db import RepoGroup, Repository, Setting, Ui, User, UserGroup, UserLog
52
53
@@ -327,12 +328,12 b' def make_ui(repo_path=None):'
327 Create an Mercurial 'ui' object based on database Ui settings, possibly
328 Create an Mercurial 'ui' object based on database Ui settings, possibly
328 augmenting with content from a hgrc file.
329 augmenting with content from a hgrc file.
329 """
330 """
330 baseui = ui.ui()
331 baseui = mercurial.ui.ui()
331
332
332 # clean the baseui object
333 # clean the baseui object
333 baseui._ocfg = config.config()
334 baseui._ocfg = mercurial.config.config()
334 baseui._ucfg = config.config()
335 baseui._ucfg = mercurial.config.config()
335 baseui._tcfg = config.config()
336 baseui._tcfg = mercurial.config.config()
336
337
337 sa = meta.Session()
338 sa = meta.Session()
338 for ui_ in sa.query(Ui).all():
339 for ui_ in sa.query(Ui).all():
@@ -356,7 +357,7 b' def make_ui(repo_path=None):'
356 hgrc_path = os.path.join(repo_path, '.hg', 'hgrc')
357 hgrc_path = os.path.join(repo_path, '.hg', 'hgrc')
357 if os.path.isfile(hgrc_path):
358 if os.path.isfile(hgrc_path):
358 log.debug('reading hgrc from %s', hgrc_path)
359 log.debug('reading hgrc from %s', hgrc_path)
359 cfg = config.config()
360 cfg = mercurial.config.config()
360 cfg.read(hgrc_path)
361 cfg.read(hgrc_path)
361 for section in ui_sections:
362 for section in ui_sections:
362 for k, v in cfg.items(section):
363 for k, v in cfg.items(section):
@@ -18,6 +18,8 b' import urllib'
18 import urllib2
18 import urllib2
19 from collections import OrderedDict
19 from collections import OrderedDict
20
20
21 import mercurial.url # import httpbasicauthhandler, httpdigestauthhandler
22 import mercurial.util # import url as hg_url
21 from dulwich.config import ConfigFile
23 from dulwich.config import ConfigFile
22 from dulwich.objects import Tag
24 from dulwich.objects import Tag
23 from dulwich.repo import NotGitRepository, Repo
25 from dulwich.repo import NotGitRepository, Repo
@@ -28,7 +30,6 b' from kallithea.lib.vcs.conf import setti'
28 from kallithea.lib.vcs.exceptions import (
30 from kallithea.lib.vcs.exceptions import (
29 BranchDoesNotExistError, ChangesetDoesNotExistError, EmptyRepositoryError, RepositoryError, TagAlreadyExistError, TagDoesNotExistError)
31 BranchDoesNotExistError, ChangesetDoesNotExistError, EmptyRepositoryError, RepositoryError, TagAlreadyExistError, TagDoesNotExistError)
30 from kallithea.lib.vcs.utils import ascii_str, date_fromtimestamp, makedate, safe_str, safe_unicode
32 from kallithea.lib.vcs.utils import ascii_str, date_fromtimestamp, makedate, safe_str, safe_unicode
31 from kallithea.lib.vcs.utils.hgcompat import hg_url, httpbasicauthhandler, httpdigestauthhandler
32 from kallithea.lib.vcs.utils.lazy import LazyProperty
33 from kallithea.lib.vcs.utils.lazy import LazyProperty
33 from kallithea.lib.vcs.utils.paths import abspath, get_user_home
34 from kallithea.lib.vcs.utils.paths import abspath, get_user_home
34
35
@@ -168,7 +169,7 b' class GitRepository(BaseRepository):'
168 url = url[url.find('+') + 1:]
169 url = url[url.find('+') + 1:]
169
170
170 handlers = []
171 handlers = []
171 url_obj = hg_url(url)
172 url_obj = mercurial.util.url(url)
172 test_uri, authinfo = url_obj.authinfo()
173 test_uri, authinfo = url_obj.authinfo()
173 if not test_uri.endswith('info/refs'):
174 if not test_uri.endswith('info/refs'):
174 test_uri = test_uri.rstrip('/') + '/info/refs'
175 test_uri = test_uri.rstrip('/') + '/info/refs'
@@ -181,8 +182,8 b' class GitRepository(BaseRepository):'
181 passmgr = urllib2.HTTPPasswordMgrWithDefaultRealm()
182 passmgr = urllib2.HTTPPasswordMgrWithDefaultRealm()
182 passmgr.add_password(*authinfo)
183 passmgr.add_password(*authinfo)
183
184
184 handlers.extend((httpbasicauthhandler(passmgr),
185 handlers.extend((mercurial.url.httpbasicauthhandler(passmgr),
185 httpdigestauthhandler(passmgr)))
186 mercurial.url.httpdigestauthhandler(passmgr)))
186
187
187 o = urllib2.build_opener(*handlers)
188 o = urllib2.build_opener(*handlers)
188 o.addheaders = [('User-Agent', 'git/1.7.8.0')] # fake some git
189 o.addheaders = [('User-Agent', 'git/1.7.8.0')] # fake some git
@@ -9,6 +9,8 b''
9 :copyright: (c) 2010-2011 by Marcin Kuzminski, Lukasz Balcerzak.
9 :copyright: (c) 2010-2011 by Marcin Kuzminski, Lukasz Balcerzak.
10 """
10 """
11
11
12 from kallithea.lib.vcs.utils import hgcompat
13
12 from .changeset import MercurialChangeset
14 from .changeset import MercurialChangeset
13 from .inmemory import MercurialInMemoryChangeset
15 from .inmemory import MercurialInMemoryChangeset
14 from .repository import MercurialRepository
16 from .repository import MercurialRepository
@@ -19,3 +21,5 b' from .workdir import MercurialWorkdir'
19 'MercurialRepository', 'MercurialChangeset',
21 'MercurialRepository', 'MercurialChangeset',
20 'MercurialInMemoryChangeset', 'MercurialWorkdir',
22 'MercurialInMemoryChangeset', 'MercurialWorkdir',
21 ]
23 ]
24
25 hgcompat.monkey_do()
@@ -1,13 +1,16 b''
1 import os
1 import os
2 import posixpath
2 import posixpath
3
3
4 import mercurial.archival
5 import mercurial.node
6 import mercurial.obsutil
7
4 from kallithea.lib.vcs.backends.base import BaseChangeset
8 from kallithea.lib.vcs.backends.base import BaseChangeset
5 from kallithea.lib.vcs.conf import settings
9 from kallithea.lib.vcs.conf import settings
6 from kallithea.lib.vcs.exceptions import ChangesetDoesNotExistError, ChangesetError, ImproperArchiveTypeError, NodeDoesNotExistError, VCSError
10 from kallithea.lib.vcs.exceptions import ChangesetDoesNotExistError, ChangesetError, ImproperArchiveTypeError, NodeDoesNotExistError, VCSError
7 from kallithea.lib.vcs.nodes import (
11 from kallithea.lib.vcs.nodes import (
8 AddedFileNodesGenerator, ChangedFileNodesGenerator, DirNode, FileNode, NodeKind, RemovedFileNodesGenerator, RootNode, SubModuleNode)
12 AddedFileNodesGenerator, ChangedFileNodesGenerator, DirNode, FileNode, NodeKind, RemovedFileNodesGenerator, RootNode, SubModuleNode)
9 from kallithea.lib.vcs.utils import ascii_bytes, ascii_str, date_fromtimestamp, safe_str, safe_unicode
13 from kallithea.lib.vcs.utils import ascii_bytes, ascii_str, date_fromtimestamp, safe_str, safe_unicode
10 from kallithea.lib.vcs.utils.hgcompat import archival, hex, obsutil
11 from kallithea.lib.vcs.utils.lazy import LazyProperty
14 from kallithea.lib.vcs.utils.lazy import LazyProperty
12 from kallithea.lib.vcs.utils.paths import get_dirs_for_path
15 from kallithea.lib.vcs.utils.paths import get_dirs_for_path
13
16
@@ -72,17 +75,17 b' class MercurialChangeset(BaseChangeset):'
72
75
73 @LazyProperty
76 @LazyProperty
74 def successors(self):
77 def successors(self):
75 successors = obsutil.successorssets(self._ctx._repo, self._ctx.node(), closest=True)
78 successors = mercurial.obsutil.successorssets(self._ctx._repo, self._ctx.node(), closest=True)
76 if successors:
79 if successors:
77 # flatten the list here handles both divergent (len > 1)
80 # flatten the list here handles both divergent (len > 1)
78 # and the usual case (len = 1)
81 # and the usual case (len = 1)
79 successors = [hex(n)[:12] for sub in successors for n in sub if n != self._ctx.node()]
82 successors = [mercurial.node.hex(n)[:12] for sub in successors for n in sub if n != self._ctx.node()]
80
83
81 return successors
84 return successors
82
85
83 @LazyProperty
86 @LazyProperty
84 def predecessors(self):
87 def predecessors(self):
85 return [hex(n)[:12] for n in obsutil.closestpredecessors(self._ctx._repo, self._ctx.node())]
88 return [mercurial.node.hex(n)[:12] for n in mercurial.obsutil.closestpredecessors(self._ctx._repo, self._ctx.node())]
86
89
87 @LazyProperty
90 @LazyProperty
88 def bookmarks(self):
91 def bookmarks(self):
@@ -271,7 +274,7 b' class MercurialChangeset(BaseChangeset):'
271 cnt = 0
274 cnt = 0
272 for cs in reversed([x for x in fctx.filelog()]):
275 for cs in reversed([x for x in fctx.filelog()]):
273 cnt += 1
276 cnt += 1
274 hist.append(hex(fctx.filectx(cs).node()))
277 hist.append(mercurial.node.hex(fctx.filectx(cs).node()))
275 if limit is not None and cnt == limit:
278 if limit is not None and cnt == limit:
276 break
279 break
277
280
@@ -320,7 +323,7 b' class MercurialChangeset(BaseChangeset):'
320 elif prefix.strip() == '':
323 elif prefix.strip() == '':
321 raise VCSError("Prefix cannot be empty")
324 raise VCSError("Prefix cannot be empty")
322
325
323 archival.archive(self.repository._repo, stream, ascii_bytes(self.raw_id),
326 mercurial.archival.archive(self.repository._repo, stream, ascii_bytes(self.raw_id),
324 kind, prefix=prefix, subrepos=subrepos)
327 kind, prefix=prefix, subrepos=subrepos)
325
328
326 def get_nodes(self, path):
329 def get_nodes(self, path):
@@ -1,9 +1,11 b''
1 import datetime
1 import datetime
2
2
3 import mercurial.context
4 import mercurial.node
5
3 from kallithea.lib.vcs.backends.base import BaseInMemoryChangeset
6 from kallithea.lib.vcs.backends.base import BaseInMemoryChangeset
4 from kallithea.lib.vcs.exceptions import RepositoryError
7 from kallithea.lib.vcs.exceptions import RepositoryError
5 from kallithea.lib.vcs.utils import ascii_str, safe_bytes
8 from kallithea.lib.vcs.utils import ascii_str, safe_bytes
6 from kallithea.lib.vcs.utils.hgcompat import hex, memctx, memfilectx
7
9
8
10
9 class MercurialInMemoryChangeset(BaseInMemoryChangeset):
11 class MercurialInMemoryChangeset(BaseInMemoryChangeset):
@@ -51,7 +53,7 b' class MercurialInMemoryChangeset(BaseInM'
51 # check if this path is added
53 # check if this path is added
52 for node in self.added:
54 for node in self.added:
53 if node.path == path:
55 if node.path == path:
54 return memfilectx(_repo, memctx, path=node.path,
56 return mercurial.context.memfilectx(_repo, memctx, path=node.path,
55 data=node.content,
57 data=node.content,
56 islink=False,
58 islink=False,
57 isexec=node.is_executable,
59 isexec=node.is_executable,
@@ -60,7 +62,7 b' class MercurialInMemoryChangeset(BaseInM'
60 # or changed
62 # or changed
61 for node in self.changed:
63 for node in self.changed:
62 if node.path == path:
64 if node.path == path:
63 return memfilectx(_repo, memctx, path=node.path,
65 return mercurial.context.memfilectx(_repo, memctx, path=node.path,
64 data=node.content,
66 data=node.content,
65 islink=False,
67 islink=False,
66 isexec=node.is_executable,
68 isexec=node.is_executable,
@@ -77,7 +79,8 b' class MercurialInMemoryChangeset(BaseInM'
77 if date and isinstance(date, datetime.datetime):
79 if date and isinstance(date, datetime.datetime):
78 date = date.strftime('%a, %d %b %Y %H:%M:%S')
80 date = date.strftime('%a, %d %b %Y %H:%M:%S')
79
81
80 commit_ctx = memctx(repo=self.repository._repo,
82 commit_ctx = mercurial.context.memctx(
83 repo=self.repository._repo,
81 parents=parents,
84 parents=parents,
82 text=b'',
85 text=b'',
83 files=self.get_paths(),
86 files=self.get_paths(),
@@ -98,7 +101,7 b' class MercurialInMemoryChangeset(BaseInM'
98 # Update vcs repository object & recreate mercurial _repo
101 # Update vcs repository object & recreate mercurial _repo
99 # new_ctx = self.repository._repo[node]
102 # new_ctx = self.repository._repo[node]
100 # new_tip = ascii_str(self.repository.get_changeset(new_ctx.hex()))
103 # new_tip = ascii_str(self.repository.get_changeset(new_ctx.hex()))
101 self.repository.revisions.append(ascii_str(hex(n)))
104 self.repository.revisions.append(ascii_str(mercurial.node.hex(n)))
102 self._repo = self.repository._get_repo(create=False)
105 self._repo = self.repository._get_repo(create=False)
103 self.repository.branches = self.repository._get_branches()
106 self.repository.branches = self.repository._get_branches()
104 tip = self.repository.get_changeset()
107 tip = self.repository.get_changeset()
@@ -17,12 +17,27 b' import urllib'
17 import urllib2
17 import urllib2
18 from collections import OrderedDict
18 from collections import OrderedDict
19
19
20 import mercurial.commands
21 import mercurial.error
22 import mercurial.exchange
23 import mercurial.hg
24 import mercurial.hgweb
25 import mercurial.httppeer
26 import mercurial.match
27 import mercurial.mdiff
28 import mercurial.node
29 import mercurial.patch
30 import mercurial.scmutil
31 import mercurial.sshpeer
32 import mercurial.tags
33 import mercurial.ui
34 import mercurial.url
35 import mercurial.util
36
20 from kallithea.lib.vcs.backends.base import BaseRepository, CollectionGenerator
37 from kallithea.lib.vcs.backends.base import BaseRepository, CollectionGenerator
21 from kallithea.lib.vcs.exceptions import (
38 from kallithea.lib.vcs.exceptions import (
22 BranchDoesNotExistError, ChangesetDoesNotExistError, EmptyRepositoryError, RepositoryError, TagAlreadyExistError, TagDoesNotExistError, VCSError)
39 BranchDoesNotExistError, ChangesetDoesNotExistError, EmptyRepositoryError, RepositoryError, TagAlreadyExistError, TagDoesNotExistError, VCSError)
23 from kallithea.lib.vcs.utils import ascii_str, author_email, author_name, date_fromtimestamp, makedate, safe_bytes, safe_str, safe_unicode
40 from kallithea.lib.vcs.utils import ascii_str, author_email, author_name, date_fromtimestamp, makedate, safe_bytes, safe_str, safe_unicode
24 from kallithea.lib.vcs.utils.hgcompat import (
25 Abort, RepoError, RepoLookupError, clone, diffopts, get_contact, hex, hg_url, httpbasicauthhandler, httpdigestauthhandler, httppeer, localrepo, match_exact, nullid, patch, peer, scmutil, sshpeer, tag, ui)
26 from kallithea.lib.vcs.utils.lazy import LazyProperty
41 from kallithea.lib.vcs.utils.lazy import LazyProperty
27 from kallithea.lib.vcs.utils.paths import abspath
42 from kallithea.lib.vcs.utils.paths import abspath
28
43
@@ -62,7 +77,7 b' class MercurialRepository(BaseRepository'
62 type(repo_path))
77 type(repo_path))
63
78
64 self.path = abspath(repo_path)
79 self.path = abspath(repo_path)
65 self.baseui = baseui or ui.ui()
80 self.baseui = baseui or mercurial.ui.ui()
66 # We've set path and ui, now we can set _repo itself
81 # We've set path and ui, now we can set _repo itself
67 self._repo = self._get_repo(create, src_url, update_after_clone)
82 self._repo = self._get_repo(create, src_url, update_after_clone)
68
83
@@ -118,10 +133,10 b' class MercurialRepository(BaseRepository'
118 for bn, _heads, node, isclosed in sorted(self._repo.branchmap().iterbranches()):
133 for bn, _heads, node, isclosed in sorted(self._repo.branchmap().iterbranches()):
119 if isclosed:
134 if isclosed:
120 if closed:
135 if closed:
121 bt[safe_unicode(bn)] = ascii_str(hex(node))
136 bt[safe_unicode(bn)] = ascii_str(mercurial.node.hex(node))
122 else:
137 else:
123 if normal:
138 if normal:
124 bt[safe_unicode(bn)] = ascii_str(hex(node))
139 bt[safe_unicode(bn)] = ascii_str(mercurial.node.hex(node))
125 return bt
140 return bt
126
141
127 @LazyProperty
142 @LazyProperty
@@ -136,7 +151,7 b' class MercurialRepository(BaseRepository'
136 return {}
151 return {}
137
152
138 return OrderedDict(sorted(
153 return OrderedDict(sorted(
139 ((safe_unicode(n), ascii_str(hex(h))) for n, h in self._repo.tags().items()),
154 ((safe_unicode(n), ascii_str(mercurial.node.hex(h))) for n, h in self._repo.tags().items()),
140 reverse=True,
155 reverse=True,
141 key=lambda x: x[0], # sort by name
156 key=lambda x: x[0], # sort by name
142 ))
157 ))
@@ -167,8 +182,8 b' class MercurialRepository(BaseRepository'
167 date = datetime.datetime.now().strftime('%a, %d %b %Y %H:%M:%S')
182 date = datetime.datetime.now().strftime('%a, %d %b %Y %H:%M:%S')
168
183
169 try:
184 try:
170 tag(self._repo, name, changeset._ctx.node(), message, local, user, date)
185 mercurial.tags.tag(self._repo, name, changeset._ctx.node(), message, local, user, date)
171 except Abort as e:
186 except mercurial.error.Abort as e:
172 raise RepositoryError(e.message)
187 raise RepositoryError(e.message)
173
188
174 # Reinitialize tags
189 # Reinitialize tags
@@ -197,9 +212,9 b' class MercurialRepository(BaseRepository'
197 local = False
212 local = False
198
213
199 try:
214 try:
200 tag(self._repo, name, nullid, message, local, user, date)
215 mercurial.tags.tag(self._repo, name, mercurial.commands.nullid, message, local, user, date)
201 self.tags = self._get_tags()
216 self.tags = self._get_tags()
202 except Abort as e:
217 except mercurial.error.Abort as e:
203 raise RepositoryError(e.message)
218 raise RepositoryError(e.message)
204
219
205 @LazyProperty
220 @LazyProperty
@@ -256,12 +271,12 b' class MercurialRepository(BaseRepository'
256 self.get_changeset(rev1)
271 self.get_changeset(rev1)
257 self.get_changeset(rev2)
272 self.get_changeset(rev2)
258 if path:
273 if path:
259 file_filter = match_exact(path)
274 file_filter = mercurial.match.exact(path)
260 else:
275 else:
261 file_filter = None
276 file_filter = None
262
277
263 return b''.join(patch.diff(self._repo, rev1, rev2, match=file_filter,
278 return b''.join(mercurial.patch.diff(self._repo, rev1, rev2, match=file_filter,
264 opts=diffopts(git=True,
279 opts=mercurial.mdiff.diffopts(git=True,
265 showfunc=True,
280 showfunc=True,
266 ignorews=ignore_whitespace,
281 ignorews=ignore_whitespace,
267 context=context)))
282 context=context)))
@@ -284,7 +299,7 b' class MercurialRepository(BaseRepository'
284 if url.startswith(b'ssh:'):
299 if url.startswith(b'ssh:'):
285 # in case of invalid uri or authentication issues, sshpeer will
300 # in case of invalid uri or authentication issues, sshpeer will
286 # throw an exception.
301 # throw an exception.
287 sshpeer.instance(repoui or ui.ui(), url, False).lookup(b'tip')
302 mercurial.sshpeer.instance(repoui or mercurial.ui.ui(), url, False).lookup(b'tip')
288 return True
303 return True
289
304
290 url_prefix = None
305 url_prefix = None
@@ -292,7 +307,7 b' class MercurialRepository(BaseRepository'
292 url_prefix, url = url.split(b'+', 1)
307 url_prefix, url = url.split(b'+', 1)
293
308
294 handlers = []
309 handlers = []
295 url_obj = hg_url(url)
310 url_obj = mercurial.util.url(url)
296 test_uri, authinfo = url_obj.authinfo()
311 test_uri, authinfo = url_obj.authinfo()
297 url_obj.passwd = b'*****'
312 url_obj.passwd = b'*****'
298 cleaned_uri = str(url_obj)
313 cleaned_uri = str(url_obj)
@@ -302,8 +317,8 b' class MercurialRepository(BaseRepository'
302 passmgr = urllib2.HTTPPasswordMgrWithDefaultRealm()
317 passmgr = urllib2.HTTPPasswordMgrWithDefaultRealm()
303 passmgr.add_password(*authinfo)
318 passmgr.add_password(*authinfo)
304
319
305 handlers.extend((httpbasicauthhandler(passmgr),
320 handlers.extend((mercurial.url.httpbasicauthhandler(passmgr),
306 httpdigestauthhandler(passmgr)))
321 mercurial.url.httpdigestauthhandler(passmgr)))
307
322
308 o = urllib2.build_opener(*handlers)
323 o = urllib2.build_opener(*handlers)
309 o.addheaders = [('Content-Type', 'application/mercurial-0.1'),
324 o.addheaders = [('Content-Type', 'application/mercurial-0.1'),
@@ -326,7 +341,7 b' class MercurialRepository(BaseRepository'
326 if not url_prefix: # skip svn+http://... (and git+... too)
341 if not url_prefix: # skip svn+http://... (and git+... too)
327 # now check if it's a proper hg repo
342 # now check if it's a proper hg repo
328 try:
343 try:
329 httppeer.instance(repoui or ui.ui(), url, False).lookup(b'tip')
344 mercurial.httppeer.instance(repoui or mercurial.ui.ui(), url, False).lookup(b'tip')
330 except Exception as e:
345 except Exception as e:
331 raise urllib2.URLError(
346 raise urllib2.URLError(
332 "url [%s] does not look like an hg repo org_exc: %s"
347 "url [%s] does not look like an hg repo org_exc: %s"
@@ -352,12 +367,12 b' class MercurialRepository(BaseRepository'
352 if not update_after_clone:
367 if not update_after_clone:
353 opts.update({'noupdate': True})
368 opts.update({'noupdate': True})
354 MercurialRepository._check_url(url, self.baseui)
369 MercurialRepository._check_url(url, self.baseui)
355 clone(self.baseui, url, self.path, **opts)
370 mercurial.commands.clone(self.baseui, url, self.path, **opts)
356
371
357 # Don't try to create if we've already cloned repo
372 # Don't try to create if we've already cloned repo
358 create = False
373 create = False
359 return localrepo.instance(self.baseui, self.path, create=create)
374 return mercurial.localrepo.instance(self.baseui, self.path, create=create)
360 except (Abort, RepoError) as err:
375 except (mercurial.error.Abort, mercurial.error.RepoError) as err:
361 if create:
376 if create:
362 msg = "Cannot create repository at %s. Original error was %s" \
377 msg = "Cannot create repository at %s. Original error was %s" \
363 % (self.path, err)
378 % (self.path, err)
@@ -377,7 +392,7 b' class MercurialRepository(BaseRepository'
377
392
378 @LazyProperty
393 @LazyProperty
379 def contact(self):
394 def contact(self):
380 return safe_unicode(get_contact(self._repo.ui.config)
395 return safe_unicode(mercurial.hgweb.common.get_contact(self._repo.ui.config)
381 or b'Unknown')
396 or b'Unknown')
382
397
383 @LazyProperty
398 @LazyProperty
@@ -416,8 +431,8 b' class MercurialRepository(BaseRepository'
416 try:
431 try:
417 if isinstance(revision, int):
432 if isinstance(revision, int):
418 return ascii_str(self._repo[revision].hex())
433 return ascii_str(self._repo[revision].hex())
419 return ascii_str(scmutil.revsymbol(self._repo, revision).hex())
434 return ascii_str(mercurial.scmutil.revsymbol(self._repo, revision).hex())
420 except (IndexError, ValueError, RepoLookupError, TypeError):
435 except (IndexError, ValueError, mercurial.error.RepoLookupError, TypeError):
421 msg = ("Revision %s does not exist for %s" % (revision, self))
436 msg = ("Revision %s does not exist for %s" % (revision, self))
422 raise ChangesetDoesNotExistError(msg)
437 raise ChangesetDoesNotExistError(msg)
423 except (LookupError, ):
438 except (LookupError, ):
@@ -445,7 +460,7 b' class MercurialRepository(BaseRepository'
445 except LookupError:
460 except LookupError:
446 msg = ("Ambiguous identifier %s:%s for %s" % (ref_type, ref_name, self.name))
461 msg = ("Ambiguous identifier %s:%s for %s" % (ref_type, ref_name, self.name))
447 raise ChangesetDoesNotExistError(msg)
462 raise ChangesetDoesNotExistError(msg)
448 except RepoLookupError:
463 except mercurial.error.RepoLookupError:
449 msg = ("Revision %s:%s does not exist for %s" % (ref_type, ref_name, self.name))
464 msg = ("Revision %s:%s does not exist for %s" % (ref_type, ref_name, self.name))
450 raise ChangesetDoesNotExistError(msg)
465 raise ChangesetDoesNotExistError(msg)
451 if revs:
466 if revs:
@@ -533,7 +548,7 b' class MercurialRepository(BaseRepository'
533 revspec = b'all()'
548 revspec = b'all()'
534 if max_revisions:
549 if max_revisions:
535 revspec = b'limit(%s, %d)' % (revspec, max_revisions)
550 revspec = b'limit(%s, %d)' % (revspec, max_revisions)
536 revisions = scmutil.revrange(self._repo, [revspec])
551 revisions = mercurial.scmutil.revrange(self._repo, [revspec])
537 else:
552 else:
538 revisions = self.revisions
553 revisions = self.revisions
539
554
@@ -550,11 +565,10 b' class MercurialRepository(BaseRepository'
550 Tries to pull changes from external location.
565 Tries to pull changes from external location.
551 """
566 """
552 url = self._get_url(url)
567 url = self._get_url(url)
553 other = peer(self._repo, {}, url)
568 other = mercurial.hg.peer(self._repo, {}, url)
554 try:
569 try:
555 from mercurial import exchange
570 mercurial.exchange.pull(self._repo, other, heads=None, force=None)
556 exchange.pull(self._repo, other, heads=None, force=None)
571 except mercurial.error.Abort as err:
557 except Abort as err:
558 # Propagate error but with vcs's type
572 # Propagate error but with vcs's type
559 raise RepositoryError(str(err))
573 raise RepositoryError(str(err))
560
574
@@ -581,7 +595,7 b' class MercurialRepository(BaseRepository'
581
595
582 config = self._repo.ui
596 config = self._repo.ui
583 if config_file:
597 if config_file:
584 config = ui.ui()
598 config = mercurial.ui.ui()
585 for path in config_file:
599 for path in config_file:
586 config.readconfig(path)
600 config.readconfig(path)
587 return config.config(section, name)
601 return config.config(section, name)
@@ -14,8 +14,8 b''
14
14
15 import logging
15 import logging
16
16
17 from mercurial import hg
17 import mercurial.hg
18 from mercurial.wireprotoserver import sshserver
18 import mercurial.wireprotoserver
19
19
20 from kallithea.lib.utils import make_ui
20 from kallithea.lib.utils import make_ui
21 from kallithea.lib.vcs.backends.ssh import BaseSshHandler
21 from kallithea.lib.vcs.backends.ssh import BaseSshHandler
@@ -61,6 +61,6 b' class MercurialSshHandler(BaseSshHandler'
61 baseui.setconfig(b'hooks', b'pretxnopen._ssh_reject', b'python:kallithea.lib.hooks.rejectpush')
61 baseui.setconfig(b'hooks', b'pretxnopen._ssh_reject', b'python:kallithea.lib.hooks.rejectpush')
62 baseui.setconfig(b'hooks', b'prepushkey._ssh_reject', b'python:kallithea.lib.hooks.rejectpush')
62 baseui.setconfig(b'hooks', b'prepushkey._ssh_reject', b'python:kallithea.lib.hooks.rejectpush')
63
63
64 repo = hg.repository(baseui, safe_bytes(self.db_repo.repo_full_path))
64 repo = mercurial.hg.repository(baseui, safe_bytes(self.db_repo.repo_full_path))
65 log.debug("Starting Mercurial sshserver for %s", self.db_repo.repo_full_path)
65 log.debug("Starting Mercurial sshserver for %s", self.db_repo.repo_full_path)
66 sshserver(baseui, repo).serve_forever()
66 mercurial.wireprotoserver.sshserver(baseui, repo).serve_forever()
@@ -1,7 +1,8 b''
1 import mercurial.merge
2
1 from kallithea.lib.vcs.backends.base import BaseWorkdir
3 from kallithea.lib.vcs.backends.base import BaseWorkdir
2 from kallithea.lib.vcs.exceptions import BranchDoesNotExistError
4 from kallithea.lib.vcs.exceptions import BranchDoesNotExistError
3 from kallithea.lib.vcs.utils import ascii_bytes, ascii_str
5 from kallithea.lib.vcs.utils import ascii_bytes, ascii_str
4 from kallithea.lib.vcs.utils.hgcompat import hg_merge
5
6
6
7
7 class MercurialWorkdir(BaseWorkdir):
8 class MercurialWorkdir(BaseWorkdir):
@@ -20,4 +21,4 b' class MercurialWorkdir(BaseWorkdir):'
20 raise BranchDoesNotExistError
21 raise BranchDoesNotExistError
21
22
22 raw_id = self.repository.branches[branch]
23 raw_id = self.repository.branches[branch]
23 hg_merge.update(self.repository._repo, ascii_bytes(raw_id), False, False, None)
24 mercurial.merge.update(self.repository._repo, ascii_bytes(raw_id), False, False, None)
@@ -2,28 +2,12 b''
2 Mercurial libs compatibility
2 Mercurial libs compatibility
3 """
3 """
4
4
5 import mercurial
5 import mercurial.localrepo
6 from mercurial import archival, config, demandimport, discovery, httppeer, localrepo
7 from mercurial import merge as hg_merge
8 from mercurial import obsutil, patch, scmutil, sshpeer, ui, unionrepo
9 from mercurial.commands import clone, nullid, pull
10 from mercurial.context import memctx, memfilectx
11 from mercurial.discovery import findcommonoutgoing
12 from mercurial.error import Abort, RepoError, RepoLookupError
13 from mercurial.hg import peer
14 from mercurial.hgweb import hgweb_mod
15 from mercurial.hgweb.common import get_contact
16 from mercurial.match import exact as match_exact
17 from mercurial.match import match
18 from mercurial.mdiff import diffopts
19 from mercurial.node import hex, nullrev
20 from mercurial.scmutil import revrange
21 from mercurial.tags import tag
22 from mercurial.url import httpbasicauthhandler, httpdigestauthhandler
23 from mercurial.util import url as hg_url
24
6
25
7
26 # workaround for 3.3 94ac64bcf6fe and not calling largefiles reposetup correctly, and test_archival failing
8 def monkey_do():
27 localrepo.localrepository._lfstatuswriters = [lambda *msg, **opts: None]
9 """Apply some Mercurial monkey patching"""
28 # 3.5 7699d3212994 added the invariant that repo.lfstatus must exist before hitting overridearchive
10 # workaround for 3.3 94ac64bcf6fe and not calling largefiles reposetup correctly, and test_archival failing
29 localrepo.localrepository.lfstatus = False
11 mercurial.localrepo.localrepository._lfstatuswriters = [lambda *msg, **opts: None]
12 # 3.5 7699d3212994 added the invariant that repo.lfstatus must exist before hitting overridearchive
13 mercurial.localrepo.localrepository.lfstatus = False
@@ -235,7 +235,7 b' TODO: To be written...'
235 assert node.kind == NodeKind.FILE
235 assert node.kind == NodeKind.FILE
236 assert node.content == readme
236 assert node.content == readme
237
237
238 @mock.patch('kallithea.lib.vcs.backends.hg.repository.diffopts')
238 @mock.patch('mercurial.mdiff.diffopts')
239 def test_get_diff_does_not_sanitize_zero_context(self, mock_diffopts):
239 def test_get_diff_does_not_sanitize_zero_context(self, mock_diffopts):
240 zero_context = 0
240 zero_context = 0
241
241
@@ -243,7 +243,7 b' TODO: To be written...'
243
243
244 mock_diffopts.assert_called_once_with(git=True, showfunc=True, ignorews=False, context=zero_context)
244 mock_diffopts.assert_called_once_with(git=True, showfunc=True, ignorews=False, context=zero_context)
245
245
246 @mock.patch('kallithea.lib.vcs.backends.hg.repository.diffopts')
246 @mock.patch('mercurial.mdiff.diffopts')
247 def test_get_diff_sanitizes_negative_context(self, mock_diffopts):
247 def test_get_diff_sanitizes_negative_context(self, mock_diffopts):
248 negative_context = -10
248 negative_context = -10
249 zero_context = 0
249 zero_context = 0
General Comments 0
You need to be logged in to leave comments. Login now