Show More
@@ -1,74 +1,75 b'' | |||
|
1 | 1 | # RhodeCode VCSServer provides access to different vcs backends via network. |
|
2 | 2 | # Copyright (C) 2014-2019 RhodeCode GmbH |
|
3 | 3 | # |
|
4 | 4 | # This program is free software; you can redistribute it and/or modify |
|
5 | 5 | # it under the terms of the GNU General Public License as published by |
|
6 | 6 | # the Free Software Foundation; either version 3 of the License, or |
|
7 | 7 | # (at your option) any later version. |
|
8 | 8 | # |
|
9 | 9 | # This program is distributed in the hope that it will be useful, |
|
10 | 10 | # but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
11 | 11 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
12 | 12 | # GNU General Public License for more details. |
|
13 | 13 | # |
|
14 | 14 | # You should have received a copy of the GNU General Public License |
|
15 | 15 | # along with this program; if not, write to the Free Software Foundation, |
|
16 | 16 | # Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA |
|
17 | 17 | |
|
18 | 18 | """ |
|
19 | 19 | Mercurial libs compatibility |
|
20 | 20 | """ |
|
21 | 21 | |
|
22 | 22 | import mercurial |
|
23 | 23 | from mercurial import demandimport |
|
24 | 24 | # patch demandimport, due to bug in mercurial when it always triggers |
|
25 | 25 | # demandimport.enable() |
|
26 | 26 | demandimport.enable = lambda *args, **kwargs: 1 |
|
27 | 27 | |
|
28 | 28 | from mercurial import ui |
|
29 | 29 | from mercurial import patch |
|
30 | 30 | from mercurial import config |
|
31 | 31 | from mercurial import extensions |
|
32 | 32 | from mercurial import scmutil |
|
33 | 33 | from mercurial import archival |
|
34 | 34 | from mercurial import discovery |
|
35 | 35 | from mercurial import unionrepo |
|
36 | 36 | from mercurial import localrepo |
|
37 | 37 | from mercurial import merge as hg_merge |
|
38 | 38 | from mercurial import subrepo |
|
39 | from mercurial import subrepoutil | |
|
39 | 40 | from mercurial import tags as hg_tag |
|
40 | 41 | |
|
41 | 42 | from mercurial.commands import clone, nullid, pull |
|
42 | 43 | from mercurial.context import memctx, memfilectx |
|
43 | 44 | from mercurial.error import ( |
|
44 | 45 | LookupError, RepoError, RepoLookupError, Abort, InterventionRequired, |
|
45 | 46 | RequirementError, ProgrammingError) |
|
46 | 47 | from mercurial.hgweb import hgweb_mod |
|
47 | 48 | from mercurial.localrepo import instance |
|
48 | 49 | from mercurial.match import match |
|
49 | 50 | from mercurial.mdiff import diffopts |
|
50 | 51 | from mercurial.node import bin, hex |
|
51 | 52 | from mercurial.encoding import tolocal |
|
52 | 53 | from mercurial.discovery import findcommonoutgoing |
|
53 | 54 | from mercurial.hg import peer |
|
54 | 55 | from mercurial.httppeer import makepeer |
|
55 | 56 | from mercurial.util import url as hg_url |
|
56 | 57 | from mercurial.scmutil import revrange, revsymbol |
|
57 | 58 | from mercurial.node import nullrev |
|
58 | 59 | from mercurial import exchange |
|
59 | 60 | from hgext import largefiles |
|
60 | 61 | |
|
61 | 62 | # those authnadlers are patched for python 2.6.5 bug an |
|
62 | 63 | # infinit looping when given invalid resources |
|
63 | 64 | from mercurial.url import httpbasicauthhandler, httpdigestauthhandler |
|
64 | 65 | |
|
65 | 66 | |
|
66 | 67 | def get_ctx(repo, ref): |
|
67 | 68 | try: |
|
68 | 69 | ctx = repo[ref] |
|
69 | 70 | except ProgrammingError: |
|
70 | 71 | # we're unable to find the rev using a regular lookup, we fallback |
|
71 | 72 | # to slower, but backward compat revsymbol usage |
|
72 | 73 | ctx = revsymbol(repo, ref) |
|
73 | 74 | |
|
74 | 75 | return ctx |
@@ -1,134 +1,134 b'' | |||
|
1 | 1 | # RhodeCode VCSServer provides access to different vcs backends via network. |
|
2 | 2 | # Copyright (C) 2014-2019 RhodeCode GmbH |
|
3 | 3 | # |
|
4 | 4 | # This program is free software; you can redistribute it and/or modify |
|
5 | 5 | # it under the terms of the GNU General Public License as published by |
|
6 | 6 | # the Free Software Foundation; either version 3 of the License, or |
|
7 | 7 | # (at your option) any later version. |
|
8 | 8 | # |
|
9 | 9 | # This program is distributed in the hope that it will be useful, |
|
10 | 10 | # but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
11 | 11 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
12 | 12 | # GNU General Public License for more details. |
|
13 | 13 | # |
|
14 | 14 | # You should have received a copy of the GNU General Public License |
|
15 | 15 | # along with this program; if not, write to the Free Software Foundation, |
|
16 | 16 | # Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA |
|
17 | 17 | |
|
18 | 18 | """ |
|
19 | 19 | Adjustments to Mercurial |
|
20 | 20 | |
|
21 | 21 | Intentionally kept separate from `hgcompat` and `hg`, so that these patches can |
|
22 | 22 | be applied without having to import the whole Mercurial machinery. |
|
23 | 23 | |
|
24 | 24 | Imports are function local, so that just importing this module does not cause |
|
25 | 25 | side-effects other than these functions being defined. |
|
26 | 26 | """ |
|
27 | 27 | |
|
28 | 28 | import logging |
|
29 | 29 | |
|
30 | 30 | |
|
31 | 31 | def patch_largefiles_capabilities(): |
|
32 | 32 | """ |
|
33 | 33 | Patches the capabilities function in the largefiles extension. |
|
34 | 34 | """ |
|
35 | 35 | from vcsserver import hgcompat |
|
36 | 36 | lfproto = hgcompat.largefiles.proto |
|
37 | 37 | wrapper = _dynamic_capabilities_wrapper( |
|
38 | 38 | lfproto, hgcompat.extensions.extensions) |
|
39 | 39 | lfproto._capabilities = wrapper |
|
40 | 40 | |
|
41 | 41 | |
|
42 | 42 | def _dynamic_capabilities_wrapper(lfproto, extensions): |
|
43 | 43 | |
|
44 | 44 | wrapped_capabilities = lfproto._capabilities |
|
45 | 45 | logger = logging.getLogger('vcsserver.hg') |
|
46 | 46 | |
|
47 | 47 | def _dynamic_capabilities(orig, repo, proto): |
|
48 | 48 | """ |
|
49 | 49 | Adds dynamic behavior, so that the capability is only added if the |
|
50 | 50 | extension is enabled in the current ui object. |
|
51 | 51 | """ |
|
52 | 52 | if 'largefiles' in dict(extensions(repo.ui)): |
|
53 | 53 | logger.debug('Extension largefiles enabled') |
|
54 | 54 | calc_capabilities = wrapped_capabilities |
|
55 | 55 | return calc_capabilities(orig, repo, proto) |
|
56 | 56 | else: |
|
57 | 57 | logger.debug('Extension largefiles disabled') |
|
58 | 58 | return orig(repo, proto) |
|
59 | 59 | |
|
60 | 60 | return _dynamic_capabilities |
|
61 | 61 | |
|
62 | 62 | |
|
63 | 63 | def patch_subrepo_type_mapping(): |
|
64 | 64 | from collections import defaultdict |
|
65 | from hgcompat import subrepo | |
|
65 | from hgcompat import subrepo, subrepoutil | |
|
66 | 66 | from vcsserver.exceptions import SubrepoMergeException |
|
67 | 67 | |
|
68 | 68 | class NoOpSubrepo(subrepo.abstractsubrepo): |
|
69 | 69 | |
|
70 | 70 | def __init__(self, ctx, path, *args, **kwargs): |
|
71 | 71 | """Initialize abstractsubrepo part |
|
72 | 72 | |
|
73 | 73 | ``ctx`` is the context referring this subrepository in the |
|
74 | 74 | parent repository. |
|
75 | 75 | |
|
76 | 76 | ``path`` is the path to this subrepository as seen from |
|
77 | 77 | innermost repository. |
|
78 | 78 | """ |
|
79 | 79 | self.ui = ctx.repo().ui |
|
80 | 80 | self._ctx = ctx |
|
81 | 81 | self._path = path |
|
82 | 82 | |
|
83 | 83 | def storeclean(self, path): |
|
84 | 84 | """ |
|
85 | 85 | returns true if the repository has not changed since it was last |
|
86 | 86 | cloned from or pushed to a given repository. |
|
87 | 87 | """ |
|
88 | 88 | return True |
|
89 | 89 | |
|
90 | 90 | def dirty(self, ignoreupdate=False, missing=False): |
|
91 | 91 | """returns true if the dirstate of the subrepo is dirty or does not |
|
92 | 92 | match current stored state. If ignoreupdate is true, only check |
|
93 | 93 | whether the subrepo has uncommitted changes in its dirstate. |
|
94 | 94 | """ |
|
95 | 95 | return False |
|
96 | 96 | |
|
97 | 97 | def basestate(self): |
|
98 | 98 | """current working directory base state, disregarding .hgsubstate |
|
99 | 99 | state and working directory modifications""" |
|
100 | substate = subrepo.state(self._ctx, self.ui) | |
|
100 | substate = subrepoutil.state(self._ctx, self.ui) | |
|
101 | 101 | file_system_path, rev, repotype = substate.get(self._path) |
|
102 | 102 | return rev |
|
103 | 103 | |
|
104 | 104 | def remove(self): |
|
105 | 105 | """remove the subrepo |
|
106 | 106 | |
|
107 | 107 | (should verify the dirstate is not dirty first) |
|
108 | 108 | """ |
|
109 | 109 | pass |
|
110 | 110 | |
|
111 | 111 | def get(self, state, overwrite=False): |
|
112 | 112 | """run whatever commands are needed to put the subrepo into |
|
113 | 113 | this state |
|
114 | 114 | """ |
|
115 | 115 | pass |
|
116 | 116 | |
|
117 | 117 | def merge(self, state): |
|
118 | 118 | """merge currently-saved state with the new state.""" |
|
119 | 119 | raise SubrepoMergeException()() |
|
120 | 120 | |
|
121 | 121 | def push(self, opts): |
|
122 | 122 | """perform whatever action is analogous to 'hg push' |
|
123 | 123 | |
|
124 | 124 | This may be a no-op on some systems. |
|
125 | 125 | """ |
|
126 | 126 | pass |
|
127 | 127 | |
|
128 | 128 | # Patch subrepo type mapping to always return our NoOpSubrepo class |
|
129 | 129 | # whenever a subrepo class is looked up. |
|
130 | 130 | subrepo.types = { |
|
131 | 131 | 'hg': NoOpSubrepo, |
|
132 | 132 | 'git': NoOpSubrepo, |
|
133 | 133 | 'svn': NoOpSubrepo |
|
134 | 134 | } |
General Comments 0
You need to be logged in to leave comments.
Login now