##// END OF EJS Templates
vcs: turned some of the commands to be context_uid based. Those selected...
marcink -
r746:56295f10 default
parent child Browse files
Show More
@@ -39,7 +39,7 b' from dulwich.repo import Repo as Dulwich'
39 39 from dulwich.server import update_server_info
40 40
41 41 from vcsserver import exceptions, settings, subprocessio
42 from vcsserver.utils import safe_str
42 from vcsserver.utils import safe_str, safe_int
43 43 from vcsserver.base import RepoFactory, obfuscate_qs
44 44 from vcsserver.hgcompat import (
45 45 hg_url as url_parser, httpbasicauthhandler, httpdigestauthhandler)
@@ -128,6 +128,7 b' class GitFactory(RepoFactory):'
128 128
129 129
130 130 class GitRemote(object):
131 EMPTY_COMMIT = '0' * 40
131 132
132 133 def __init__(self, factory):
133 134 self._factory = factory
@@ -190,15 +191,6 b' class GitRemote(object):'
190 191 return True
191 192
192 193 @reraise_safe_exceptions
193 def add_object(self, wire, content):
194 repo_init = self._factory.repo_libgit2(wire)
195 with repo_init as repo:
196 blob = objects.Blob()
197 blob.set_raw_string(content)
198 repo.object_store.add_object(blob)
199 return blob.id
200
201 @reraise_safe_exceptions
202 194 def assert_correct_path(self, wire):
203 195 cache_on, context_uid, repo_id = self._cache_on(wire)
204 196 @self.region.conditional_cache_on_arguments(condition=cache_on)
@@ -234,14 +226,14 b' class GitRemote(object):'
234 226 def blob_raw_length(self, wire, sha):
235 227 cache_on, context_uid, repo_id = self._cache_on(wire)
236 228 @self.region.conditional_cache_on_arguments(condition=cache_on)
237 def _blob_raw_length(_context_uid, _repo_id, _sha):
229 def _blob_raw_length(_repo_id, _sha):
238 230
239 231 repo_init = self._factory.repo_libgit2(wire)
240 232 with repo_init as repo:
241 233 blob = repo[sha]
242 234 return blob.size
243 235
244 return _blob_raw_length(context_uid, repo_id, sha)
236 return _blob_raw_length(repo_id, sha)
245 237
246 238 def _parse_lfs_pointer(self, raw_content):
247 239
@@ -261,20 +253,20 b' class GitRemote(object):'
261 253 return {}
262 254
263 255 @reraise_safe_exceptions
264 def is_large_file(self, wire, sha):
256 def is_large_file(self, wire, commit_id):
265 257
266 258 cache_on, context_uid, repo_id = self._cache_on(wire)
267 259 @self.region.conditional_cache_on_arguments(condition=cache_on)
268 def _is_large_file(_context_uid, _repo_id, _sha):
260 def _is_large_file(_repo_id, _sha):
269 261 repo_init = self._factory.repo_libgit2(wire)
270 262 with repo_init as repo:
271 blob = repo[sha]
263 blob = repo[commit_id]
272 264 if blob.is_binary:
273 265 return {}
274 266
275 267 return self._parse_lfs_pointer(blob.data)
276 268
277 return _is_large_file(context_uid, repo_id, sha)
269 return _is_large_file(repo_id, commit_id)
278 270
279 271 @reraise_safe_exceptions
280 272 def in_largefiles_store(self, wire, oid):
@@ -310,7 +302,7 b' class GitRemote(object):'
310 302 def bulk_request(self, wire, rev, pre_load):
311 303 cache_on, context_uid, repo_id = self._cache_on(wire)
312 304 @self.region.conditional_cache_on_arguments(condition=cache_on)
313 def _bulk_request(_context_uid, _repo_id, _rev, _pre_load):
305 def _bulk_request(_repo_id, _rev, _pre_load):
314 306 result = {}
315 307 for attr in pre_load:
316 308 try:
@@ -322,7 +314,7 b' class GitRemote(object):'
322 314 "Unknown bulk attribute: %s" % attr)
323 315 return result
324 316
325 return _bulk_request(context_uid, repo_id, rev, sorted(pre_load))
317 return _bulk_request(repo_id, rev, sorted(pre_load))
326 318
327 319 def _build_opener(self, url):
328 320 handlers = []
@@ -437,6 +429,15 b' class GitRemote(object):'
437 429
438 430 return _commit_branches(context_uid, repo_id, commit_id)
439 431
432 @reraise_safe_exceptions
433 def add_object(self, wire, content):
434 repo_init = self._factory.repo_libgit2(wire)
435 with repo_init as repo:
436 blob = objects.Blob()
437 blob.set_raw_string(content)
438 repo.object_store.add_object(blob)
439 return blob.id
440
440 441 # TODO: this is quite complex, check if that can be simplified
441 442 @reraise_safe_exceptions
442 443 def commit(self, wire, commit_data, branch, commit_tree, updated, removed):
@@ -783,40 +784,70 b' class GitRemote(object):'
783 784 return _revision(context_uid, repo_id, rev)
784 785
785 786 @reraise_safe_exceptions
786 def date(self, wire, rev):
787 repo_init = self._factory.repo_libgit2(wire)
788 with repo_init as repo:
789 commit = repo[rev]
790 # TODO(marcink): check dulwich difference of offset vs timezone
791 return [commit.commit_time, commit.commit_time_offset]
787 def date(self, wire, commit_id):
788 cache_on, context_uid, repo_id = self._cache_on(wire)
789 @self.region.conditional_cache_on_arguments(condition=cache_on)
790 def _date(_repo_id, _commit_id):
791 repo_init = self._factory.repo_libgit2(wire)
792 with repo_init as repo:
793 commit = repo[commit_id]
794 # TODO(marcink): check dulwich difference of offset vs timezone
795 return [commit.commit_time, commit.commit_time_offset]
796 return _date(repo_id, commit_id)
797
798 @reraise_safe_exceptions
799 def author(self, wire, commit_id):
800 cache_on, context_uid, repo_id = self._cache_on(wire)
801 @self.region.conditional_cache_on_arguments(condition=cache_on)
802 def _author(_repo_id, _commit_id):
803 repo_init = self._factory.repo_libgit2(wire)
804 with repo_init as repo:
805 commit = repo[commit_id]
806 if commit.author.email:
807 return u"{} <{}>".format(commit.author.name, commit.author.email)
808
809 return u"{}".format(commit.author.raw_name)
810 return _author(repo_id, commit_id)
792 811
793 812 @reraise_safe_exceptions
794 def author(self, wire, rev):
795 repo_init = self._factory.repo_libgit2(wire)
796 with repo_init as repo:
797 commit = repo[rev]
798 if commit.author.email:
799 return u"{} <{}>".format(commit.author.name, commit.author.email)
800
801 return u"{}".format(commit.author.raw_name)
813 def message(self, wire, commit_id):
814 cache_on, context_uid, repo_id = self._cache_on(wire)
815 @self.region.conditional_cache_on_arguments(condition=cache_on)
816 def _message(_repo_id, _commit_id):
817 repo_init = self._factory.repo_libgit2(wire)
818 with repo_init as repo:
819 commit = repo[commit_id]
820 return commit.message
821 return _message(repo_id, commit_id)
802 822
803 823 @reraise_safe_exceptions
804 def message(self, wire, rev):
805 repo_init = self._factory.repo_libgit2(wire)
806 with repo_init as repo:
807 commit = repo[rev]
808 return commit.message
824 def parents(self, wire, commit_id):
825 cache_on, context_uid, repo_id = self._cache_on(wire)
826 @self.region.conditional_cache_on_arguments(condition=cache_on)
827 def _parents(_repo_id, _commit_id):
828 repo_init = self._factory.repo_libgit2(wire)
829 with repo_init as repo:
830 commit = repo[commit_id]
831 return [x.hex for x in commit.parent_ids]
832 return _parents(repo_id, commit_id)
809 833
810 834 @reraise_safe_exceptions
811 def parents(self, wire, rev):
835 def children(self, wire, commit_id):
812 836 cache_on, context_uid, repo_id = self._cache_on(wire)
813 837 @self.region.conditional_cache_on_arguments(condition=cache_on)
814 def _parents(_context_uid, _repo_id, _rev):
815 repo_init = self._factory.repo_libgit2(wire)
816 with repo_init as repo:
817 commit = repo[rev]
818 return [x.hex for x in commit.parent_ids]
819 return _parents(context_uid, repo_id, rev)
838 def _children(_repo_id, _commit_id):
839 output, __ = self.run_git_command(
840 wire, ['rev-list', '--all', '--children'])
841
842 child_ids = []
843 pat = re.compile(r'^%s' % commit_id)
844 for l in output.splitlines():
845 if pat.match(l):
846 found_ids = l.split(' ')[1:]
847 child_ids.extend(found_ids)
848
849 return child_ids
850 return _children(repo_id, commit_id)
820 851
821 852 @reraise_safe_exceptions
822 853 def set_refs(self, wire, key, value):
@@ -878,10 +909,9 b' class GitRemote(object):'
878 909
879 910 @reraise_safe_exceptions
880 911 def tree_items(self, wire, tree_id):
881
882 912 cache_on, context_uid, repo_id = self._cache_on(wire)
883 913 @self.region.conditional_cache_on_arguments(condition=cache_on)
884 def _tree_items(_context_uid, _repo_id, _tree_id):
914 def _tree_items(_repo_id, _tree_id):
885 915
886 916 repo_init = self._factory.repo_libgit2(wire)
887 917 with repo_init as repo:
@@ -902,7 +932,75 b' class GitRemote(object):'
902 932
903 933 result.append((item.name, item_mode, item_sha, item_type))
904 934 return result
905 return _tree_items(context_uid, repo_id, tree_id)
935 return _tree_items(repo_id, tree_id)
936
937 @reraise_safe_exceptions
938 def diff(self, wire, commit_id_1, commit_id_2, file_filter, opt_ignorews, context):
939
940 flags = [
941 '-U%s' % context, '--full-index', '--binary', '-p',
942 '-M', '--abbrev=40']
943
944 if opt_ignorews:
945 flags.append('-w')
946
947 if commit_id_1 == self.EMPTY_COMMIT:
948 cmd = ['show'] + flags + [commit_id_2]
949 else:
950 cmd = ['diff'] + flags + [commit_id_1, commit_id_2]
951
952 if file_filter:
953 cmd.extend(['--', file_filter])
954
955 diff, __ = self.run_git_command(wire, cmd)
956 # If we used 'show' command, strip first few lines (until actual diff
957 # starts)
958 if commit_id_1 == self.EMPTY_COMMIT:
959 lines = diff.splitlines()
960 x = 0
961 for line in lines:
962 if line.startswith('diff'):
963 break
964 x += 1
965 # Append new line just like 'diff' command do
966 diff = '\n'.join(lines[x:]) + '\n'
967 return diff
968
969 @reraise_safe_exceptions
970 def node_history(self, wire, commit_id, path, limit):
971 cache_on, context_uid, repo_id = self._cache_on(wire)
972 @self.region.conditional_cache_on_arguments(condition=cache_on)
973 def _node_history(_context_uid, _repo_id, _commit_id, _path, _limit):
974 # optimize for n==1, rev-list is much faster for that use-case
975 if limit == 1:
976 cmd = ['rev-list', '-1', commit_id, '--', path]
977 else:
978 cmd = ['log']
979 if limit:
980 cmd.extend(['-n', str(safe_int(limit, 0))])
981 cmd.extend(['--pretty=format: %H', '-s', commit_id, '--', path])
982
983 output, __ = self.run_git_command(wire, cmd)
984 commit_ids = re.findall(r'[0-9a-fA-F]{40}', output)
985
986 return [x for x in commit_ids]
987 return _node_history(context_uid, repo_id, commit_id, path, limit)
988
989 @reraise_safe_exceptions
990 def node_annotate(self, wire, commit_id, path):
991
992 cmd = ['blame', '-l', '--root', '-r', commit_id, '--', path]
993 # -l ==> outputs long shas (and we need all 40 characters)
994 # --root ==> doesn't put '^' character for boundaries
995 # -r commit_id ==> blames for the given commit
996 output, __ = self.run_git_command(wire, cmd)
997
998 result = []
999 for i, blame_line in enumerate(output.split('\n')[:-1]):
1000 line_no = i + 1
1001 commit_id, line = re.split(r' ', blame_line, 1)
1002 result.append((line_no, commit_id, line))
1003 return result
906 1004
907 1005 @reraise_safe_exceptions
908 1006 def update_server_info(self, wire):
@@ -241,99 +241,41 b' class HgRemote(object):'
241 241 return _branches(context_uid, repo_id, normal, closed)
242 242
243 243 @reraise_safe_exceptions
244 def bulk_request(self, wire, rev, pre_load):
244 def bulk_request(self, wire, commit_id, pre_load):
245 245 cache_on, context_uid, repo_id = self._cache_on(wire)
246 246 @self.region.conditional_cache_on_arguments(condition=cache_on)
247 def _bulk_request(_context_uid, _repo_id, _rev, _pre_load):
247 def _bulk_request(_repo_id, _commit_id, _pre_load):
248 248 result = {}
249 249 for attr in pre_load:
250 250 try:
251 251 method = self._bulk_methods[attr]
252 result[attr] = method(wire, rev)
252 result[attr] = method(wire, commit_id)
253 253 except KeyError as e:
254 254 raise exceptions.VcsException(e)(
255 255 'Unknown bulk attribute: "%s"' % attr)
256 256 return result
257 257
258 return _bulk_request(context_uid, repo_id, rev, sorted(pre_load))
259
260 @reraise_safe_exceptions
261 def clone(self, wire, source, dest, update_after_clone=False, hooks=True):
262 baseui = self._factory._create_config(wire["config"], hooks=hooks)
263 clone(baseui, source, dest, noupdate=not update_after_clone)
258 return _bulk_request(repo_id, commit_id, sorted(pre_load))
264 259
265 260 @reraise_safe_exceptions
266 def commitctx(self, wire, message, parents, commit_time, commit_timezone,
267 user, files, extra, removed, updated):
268
269 repo = self._factory.repo(wire)
270 baseui = self._factory._create_config(wire['config'])
271 publishing = baseui.configbool('phases', 'publish')
272 if publishing:
273 new_commit = 'public'
274 else:
275 new_commit = 'draft'
276
277 def _filectxfn(_repo, ctx, path):
278 """
279 Marks given path as added/changed/removed in a given _repo. This is
280 for internal mercurial commit function.
281 """
282
283 # check if this path is removed
284 if path in removed:
285 # returning None is a way to mark node for removal
286 return None
287
288 # check if this path is added
289 for node in updated:
290 if node['path'] == path:
291 return memfilectx(
292 _repo,
293 changectx=ctx,
294 path=node['path'],
295 data=node['content'],
296 islink=False,
297 isexec=bool(node['mode'] & stat.S_IXUSR),
298 copysource=False)
299
300 raise exceptions.AbortException()(
301 "Given path haven't been marked as added, "
302 "changed or removed (%s)" % path)
303
304 with repo.ui.configoverride({('phases', 'new-commit'): new_commit}):
305
306 commit_ctx = memctx(
307 repo=repo,
308 parents=parents,
309 text=message,
310 files=files,
311 filectxfn=_filectxfn,
312 user=user,
313 date=(commit_time, commit_timezone),
314 extra=extra)
315
316 n = repo.commitctx(commit_ctx)
317 new_id = hex(n)
318
319 return new_id
261 def ctx_branch(self, wire, commit_id):
262 cache_on, context_uid, repo_id = self._cache_on(wire)
263 @self.region.conditional_cache_on_arguments(condition=cache_on)
264 def _ctx_branch(_repo_id, _commit_id):
265 repo = self._factory.repo(wire)
266 ctx = self._get_ctx(repo, commit_id)
267 return ctx.branch()
268 return _ctx_branch(repo_id, commit_id)
320 269
321 270 @reraise_safe_exceptions
322 def ctx_branch(self, wire, revision):
323
271 def ctx_date(self, wire, commit_id):
324 272 cache_on, context_uid, repo_id = self._cache_on(wire)
325 273 @self.region.conditional_cache_on_arguments(condition=cache_on)
326 def _ctx_branch(_context_uid, _repo_id, _revision):
274 def _ctx_date(_repo_id, _commit_id):
327 275 repo = self._factory.repo(wire)
328 ctx = self._get_ctx(repo, revision)
329 return ctx.branch()
330 return _ctx_branch(context_uid, repo_id, revision)
331
332 @reraise_safe_exceptions
333 def ctx_date(self, wire, revision):
334 repo = self._factory.repo(wire)
335 ctx = self._get_ctx(repo, revision)
336 return ctx.date()
276 ctx = self._get_ctx(repo, commit_id)
277 return ctx.date()
278 return _ctx_date(repo_id, commit_id)
337 279
338 280 @reraise_safe_exceptions
339 281 def ctx_description(self, wire, revision):
@@ -342,16 +284,15 b' class HgRemote(object):'
342 284 return ctx.description()
343 285
344 286 @reraise_safe_exceptions
345 def ctx_files(self, wire, revision):
346
287 def ctx_files(self, wire, commit_id):
347 288 cache_on, context_uid, repo_id = self._cache_on(wire)
348 289 @self.region.conditional_cache_on_arguments(condition=cache_on)
349 def _ctx_files(_context_uid, _repo_id, _revision):
290 def _ctx_files(_repo_id, _commit_id):
350 291 repo = self._factory.repo(wire)
351 ctx = self._get_ctx(repo, revision)
292 ctx = self._get_ctx(repo, commit_id)
352 293 return ctx.files()
353 294
354 return _ctx_files(context_uid, repo_id, revision)
295 return _ctx_files(repo_id, commit_id)
355 296
356 297 @reraise_safe_exceptions
357 298 def ctx_list(self, path, revision):
@@ -360,59 +301,59 b' class HgRemote(object):'
360 301 return list(ctx)
361 302
362 303 @reraise_safe_exceptions
363 def ctx_parents(self, wire, revision):
304 def ctx_parents(self, wire, commit_id):
364 305 cache_on, context_uid, repo_id = self._cache_on(wire)
365 306 @self.region.conditional_cache_on_arguments(condition=cache_on)
366 def _ctx_parents(_context_uid, _repo_id, _revision):
307 def _ctx_parents(_repo_id, _commit_id):
367 308 repo = self._factory.repo(wire)
368 ctx = self._get_ctx(repo, revision)
309 ctx = self._get_ctx(repo, commit_id)
369 310 return [parent.rev() for parent in ctx.parents()
370 311 if not (parent.hidden() or parent.obsolete())]
371 312
372 return _ctx_parents(context_uid, repo_id, revision)
313 return _ctx_parents(repo_id, commit_id)
373 314
374 315 @reraise_safe_exceptions
375 def ctx_children(self, wire, revision):
316 def ctx_children(self, wire, commit_id):
376 317 cache_on, context_uid, repo_id = self._cache_on(wire)
377 318 @self.region.conditional_cache_on_arguments(condition=cache_on)
378 def _ctx_children(_context_uid, _repo_id, _revision):
319 def _ctx_children(_repo_id, _commit_id):
379 320 repo = self._factory.repo(wire)
380 ctx = self._get_ctx(repo, revision)
321 ctx = self._get_ctx(repo, commit_id)
381 322 return [child.rev() for child in ctx.children()
382 323 if not (child.hidden() or child.obsolete())]
383 324
384 return _ctx_children(context_uid, repo_id, revision)
325 return _ctx_children(repo_id, commit_id)
385 326
386 327 @reraise_safe_exceptions
387 def ctx_phase(self, wire, revision):
328 def ctx_phase(self, wire, commit_id):
388 329 cache_on, context_uid, repo_id = self._cache_on(wire)
389 330 @self.region.conditional_cache_on_arguments(condition=cache_on)
390 def _ctx_phase(_context_uid, _repo_path, _revision):
331 def _ctx_phase(_context_uid, _repo_id, _commit_id):
391 332 repo = self._factory.repo(wire)
392 ctx = self._get_ctx(repo, revision)
333 ctx = self._get_ctx(repo, commit_id)
393 334 # public=0, draft=1, secret=3
394 335 return ctx.phase()
395 return _ctx_phase(context_uid, repo_id, revision)
336 return _ctx_phase(context_uid, repo_id, commit_id)
396 337
397 338 @reraise_safe_exceptions
398 def ctx_obsolete(self, wire, revision):
339 def ctx_obsolete(self, wire, commit_id):
399 340 cache_on, context_uid, repo_id = self._cache_on(wire)
400 341 @self.region.conditional_cache_on_arguments(condition=cache_on)
401 def _ctx_obsolete(_context_uid, _repo_path, _revision):
342 def _ctx_obsolete(_context_uid, _repo_id, _commit_id):
402 343 repo = self._factory.repo(wire)
403 ctx = self._get_ctx(repo, revision)
344 ctx = self._get_ctx(repo, commit_id)
404 345 return ctx.obsolete()
405 return _ctx_obsolete(context_uid, repo_id, revision)
346 return _ctx_obsolete(context_uid, repo_id, commit_id)
406 347
407 348 @reraise_safe_exceptions
408 def ctx_hidden(self, wire, revision):
349 def ctx_hidden(self, wire, commit_id):
409 350 cache_on, context_uid, repo_id = self._cache_on(wire)
410 351 @self.region.conditional_cache_on_arguments(condition=cache_on)
411 def _ctx_hidden(_context_uid, _repo_path, _revision):
352 def _ctx_hidden(_context_uid, _repo_id, _commit_id):
412 353 repo = self._factory.repo(wire)
413 ctx = self._get_ctx(repo, revision)
354 ctx = self._get_ctx(repo, commit_id)
414 355 return ctx.hidden()
415 return _ctx_hidden(context_uid, repo_id, revision)
356 return _ctx_hidden(context_uid, repo_id, commit_id)
416 357
417 358 @reraise_safe_exceptions
418 359 def ctx_substate(self, wire, revision):
@@ -502,7 +443,7 b' class HgRemote(object):'
502 443 return True
503 444
504 445 @reraise_safe_exceptions
505 def diff(self, wire, rev1, rev2, file_filter, opt_git, opt_ignorews, context):
446 def diff(self, wire, commit_id_1, commit_id_2, file_filter, opt_git, opt_ignorews, context):
506 447 repo = self._factory.repo(wire)
507 448
508 449 if file_filter:
@@ -513,16 +454,15 b' class HgRemote(object):'
513 454
514 455 try:
515 456 return "".join(patch.diff(
516 repo, node1=rev1, node2=rev2, match=match_filter, opts=opts))
457 repo, node1=commit_id_1, node2=commit_id_2, match=match_filter, opts=opts))
517 458 except RepoLookupError as e:
518 459 raise exceptions.LookupException(e)()
519 460
520 461 @reraise_safe_exceptions
521 462 def node_history(self, wire, revision, path, limit):
522
523 463 cache_on, context_uid, repo_id = self._cache_on(wire)
524 464 @self.region.conditional_cache_on_arguments(condition=cache_on)
525 def _node_history(_context_uid, _repo_path, _revision, _path, _limit):
465 def _node_history(_context_uid, _repo_id, _revision, _path, _limit):
526 466 repo = self._factory.repo(wire)
527 467
528 468 ctx = self._get_ctx(repo, revision)
@@ -550,10 +490,9 b' class HgRemote(object):'
550 490
551 491 @reraise_safe_exceptions
552 492 def node_history_untill(self, wire, revision, path, limit):
553
554 493 cache_on, context_uid, repo_id = self._cache_on(wire)
555 494 @self.region.conditional_cache_on_arguments(condition=cache_on)
556 def _meth(_context_uid, _repo_path):
495 def _node_history_until(_context_uid, _repo_id):
557 496 repo = self._factory.repo(wire)
558 497 ctx = self._get_ctx(repo, revision)
559 498 fctx = ctx.filectx(path)
@@ -564,7 +503,7 b' class HgRemote(object):'
564 503 file_log = file_log[-limit:]
565 504
566 505 return [hex(fctx.filectx(cs).node()) for cs in reversed(file_log)]
567 return _meth(context_uid, repo_id, revision, path, limit)
506 return _node_history_until(context_uid, repo_id, revision, path, limit)
568 507
569 508 @reraise_safe_exceptions
570 509 def fctx_annotate(self, wire, revision, path):
@@ -588,28 +527,27 b' class HgRemote(object):'
588 527 return fctx.data()
589 528
590 529 @reraise_safe_exceptions
591 def fctx_flags(self, wire, revision, path):
530 def fctx_flags(self, wire, commit_id, path):
592 531 cache_on, context_uid, repo_id = self._cache_on(wire)
593 532 @self.region.conditional_cache_on_arguments(condition=cache_on)
594 def _fctx_flags(_context_uid, _repo_path, _revision, _path):
533 def _fctx_flags(_repo_id, _commit_id, _path):
595 534 repo = self._factory.repo(wire)
596 ctx = self._get_ctx(repo, revision)
535 ctx = self._get_ctx(repo, commit_id)
597 536 fctx = ctx.filectx(path)
598 537 return fctx.flags()
599 538
600 return _fctx_flags(context_uid, repo_id, revision, path)
539 return _fctx_flags(repo_id, commit_id, path)
601 540
602 541 @reraise_safe_exceptions
603 def fctx_size(self, wire, revision, path):
604
542 def fctx_size(self, wire, commit_id, path):
605 543 cache_on, context_uid, repo_id = self._cache_on(wire)
606 544 @self.region.conditional_cache_on_arguments(condition=cache_on)
607 def _fctx_size(_context_uid, _repo_path, _revision, _path):
545 def _fctx_size(_repo_id, _revision, _path):
608 546 repo = self._factory.repo(wire)
609 ctx = self._get_ctx(repo, revision)
547 ctx = self._get_ctx(repo, commit_id)
610 548 fctx = ctx.filectx(path)
611 549 return fctx.size()
612 return _fctx_size(context_uid, repo_id, revision, path)
550 return _fctx_size(repo_id, commit_id, path)
613 551
614 552 @reraise_safe_exceptions
615 553 def get_all_commit_ids(self, wire, name):
@@ -628,16 +566,6 b' class HgRemote(object):'
628 566 return repo.ui.config(section, name, untrusted=untrusted)
629 567
630 568 @reraise_safe_exceptions
631 def get_config_bool(self, wire, section, name, untrusted=False):
632 repo = self._factory.repo(wire)
633 return repo.ui.configbool(section, name, untrusted=untrusted)
634
635 @reraise_safe_exceptions
636 def get_config_list(self, wire, section, name, untrusted=False):
637 repo = self._factory.repo(wire)
638 return repo.ui.configlist(section, name, untrusted=untrusted)
639
640 @reraise_safe_exceptions
641 569 def is_large_file(self, wire, path):
642 570 cache_on, context_uid, repo_id = self._cache_on(wire)
643 571 @self.region.conditional_cache_on_arguments(condition=cache_on)
@@ -705,22 +633,6 b' class HgRemote(object):'
705 633 return _lookup(context_uid, repo_id, revision, both)
706 634
707 635 @reraise_safe_exceptions
708 def pull(self, wire, url, commit_ids=None):
709 repo = self._factory.repo(wire)
710 # Disable any prompts for this repo
711 repo.ui.setconfig('ui', 'interactive', 'off', '-y')
712
713 remote = peer(repo, {}, url)
714 # Disable any prompts for this remote
715 remote.ui.setconfig('ui', 'interactive', 'off', '-y')
716
717 if commit_ids:
718 commit_ids = [bin(commit_id) for commit_id in commit_ids]
719
720 return exchange.pull(
721 repo, remote, heads=commit_ids, force=None).cgresult
722
723 @reraise_safe_exceptions
724 636 def sync_push(self, wire, url):
725 637 if not self.check_url(url, wire['config']):
726 638 return
@@ -785,13 +697,6 b' class HgRemote(object):'
785 697 return list(repo.revs(rev_spec, *args))
786 698
787 699 @reraise_safe_exceptions
788 def strip(self, wire, revision, update, backup):
789 repo = self._factory.repo(wire)
790 ctx = self._get_ctx(repo, revision)
791 hgext_strip(
792 repo.baseui, repo, ctx.node(), update=update, backup=backup)
793
794 @reraise_safe_exceptions
795 700 def verify(self, wire,):
796 701 repo = self._factory.repo(wire)
797 702 baseui = self._factory._create_config(wire['config'])
@@ -807,20 +712,6 b' class HgRemote(object):'
807 712 return output.getvalue()
808 713
809 714 @reraise_safe_exceptions
810 def tag(self, wire, name, revision, message, local, user, tag_time, tag_timezone):
811 repo = self._factory.repo(wire)
812 ctx = self._get_ctx(repo, revision)
813 node = ctx.node()
814
815 date = (tag_time, tag_timezone)
816 try:
817 hg_tag.tag(repo, name, node, message, local, user, date)
818 except Abort as e:
819 log.exception("Tag operation aborted")
820 # Exception can contain unicode which we convert
821 raise exceptions.AbortException(e)(repr(e))
822
823 @reraise_safe_exceptions
824 715 def tags(self, wire):
825 716 cache_on, context_uid, repo_id = self._cache_on(wire)
826 717 @self.region.conditional_cache_on_arguments(condition=cache_on)
@@ -849,23 +740,6 b' class HgRemote(object):'
849 740 return output.getvalue()
850 741
851 742 @reraise_safe_exceptions
852 def pull_cmd(self, wire, source, bookmark=None, branch=None, revision=None, hooks=True):
853 repo = self._factory.repo(wire)
854 baseui = self._factory._create_config(wire['config'], hooks=hooks)
855
856 # Mercurial internally has a lot of logic that checks ONLY if
857 # option is defined, we just pass those if they are defined then
858 opts = {}
859 if bookmark:
860 opts['bookmark'] = bookmark
861 if branch:
862 opts['branch'] = branch
863 if revision:
864 opts['rev'] = revision
865
866 commands.pull(baseui, repo, source, **opts)
867
868 @reraise_safe_exceptions
869 743 def heads(self, wire, branch=None):
870 744 repo = self._factory.repo(wire)
871 745 baseui = self._factory._create_config(wire['config'])
@@ -892,6 +766,99 b' class HgRemote(object):'
892 766 return hex(a)
893 767
894 768 @reraise_safe_exceptions
769 def clone(self, wire, source, dest, update_after_clone=False, hooks=True):
770 baseui = self._factory._create_config(wire["config"], hooks=hooks)
771 clone(baseui, source, dest, noupdate=not update_after_clone)
772
773 @reraise_safe_exceptions
774 def commitctx(self, wire, message, parents, commit_time, commit_timezone, user, files, extra, removed, updated):
775
776 repo = self._factory.repo(wire)
777 baseui = self._factory._create_config(wire['config'])
778 publishing = baseui.configbool('phases', 'publish')
779 if publishing:
780 new_commit = 'public'
781 else:
782 new_commit = 'draft'
783
784 def _filectxfn(_repo, ctx, path):
785 """
786 Marks given path as added/changed/removed in a given _repo. This is
787 for internal mercurial commit function.
788 """
789
790 # check if this path is removed
791 if path in removed:
792 # returning None is a way to mark node for removal
793 return None
794
795 # check if this path is added
796 for node in updated:
797 if node['path'] == path:
798 return memfilectx(
799 _repo,
800 changectx=ctx,
801 path=node['path'],
802 data=node['content'],
803 islink=False,
804 isexec=bool(node['mode'] & stat.S_IXUSR),
805 copysource=False)
806
807 raise exceptions.AbortException()(
808 "Given path haven't been marked as added, "
809 "changed or removed (%s)" % path)
810
811 with repo.ui.configoverride({('phases', 'new-commit'): new_commit}):
812
813 commit_ctx = memctx(
814 repo=repo,
815 parents=parents,
816 text=message,
817 files=files,
818 filectxfn=_filectxfn,
819 user=user,
820 date=(commit_time, commit_timezone),
821 extra=extra)
822
823 n = repo.commitctx(commit_ctx)
824 new_id = hex(n)
825
826 return new_id
827
828 @reraise_safe_exceptions
829 def pull(self, wire, url, commit_ids=None):
830 repo = self._factory.repo(wire)
831 # Disable any prompts for this repo
832 repo.ui.setconfig('ui', 'interactive', 'off', '-y')
833
834 remote = peer(repo, {}, url)
835 # Disable any prompts for this remote
836 remote.ui.setconfig('ui', 'interactive', 'off', '-y')
837
838 if commit_ids:
839 commit_ids = [bin(commit_id) for commit_id in commit_ids]
840
841 return exchange.pull(
842 repo, remote, heads=commit_ids, force=None).cgresult
843
844 @reraise_safe_exceptions
845 def pull_cmd(self, wire, source, bookmark=None, branch=None, revision=None, hooks=True):
846 repo = self._factory.repo(wire)
847 baseui = self._factory._create_config(wire['config'], hooks=hooks)
848
849 # Mercurial internally has a lot of logic that checks ONLY if
850 # option is defined, we just pass those if they are defined then
851 opts = {}
852 if bookmark:
853 opts['bookmark'] = bookmark
854 if branch:
855 opts['branch'] = branch
856 if revision:
857 opts['rev'] = revision
858
859 commands.pull(baseui, repo, source, **opts)
860
861 @reraise_safe_exceptions
895 862 def push(self, wire, revisions, dest_path, hooks=True, push_branches=False):
896 863 repo = self._factory.repo(wire)
897 864 baseui = self._factory._create_config(wire['config'], hooks=hooks)
@@ -899,6 +866,13 b' class HgRemote(object):'
899 866 new_branch=push_branches)
900 867
901 868 @reraise_safe_exceptions
869 def strip(self, wire, revision, update, backup):
870 repo = self._factory.repo(wire)
871 ctx = self._get_ctx(repo, revision)
872 hgext_strip(
873 repo.baseui, repo, ctx.node(), update=update, backup=backup)
874
875 @reraise_safe_exceptions
902 876 def merge(self, wire, revision):
903 877 repo = self._factory.repo(wire)
904 878 baseui = self._factory._create_config(wire['config'])
@@ -940,6 +914,20 b' class HgRemote(object):'
940 914 baseui, repo, base=source, dest=dest, abort=abort, keep=not abort)
941 915
942 916 @reraise_safe_exceptions
917 def tag(self, wire, name, revision, message, local, user, tag_time, tag_timezone):
918 repo = self._factory.repo(wire)
919 ctx = self._get_ctx(repo, revision)
920 node = ctx.node()
921
922 date = (tag_time, tag_timezone)
923 try:
924 hg_tag.tag(repo, name, node, message, local, user, date)
925 except Abort as e:
926 log.exception("Tag operation aborted")
927 # Exception can contain unicode which we convert
928 raise exceptions.AbortException(e)(repr(e))
929
930 @reraise_safe_exceptions
943 931 def bookmark(self, wire, bookmark, revision=None):
944 932 repo = self._factory.repo(wire)
945 933 baseui = self._factory._create_config(wire['config'])
@@ -215,11 +215,11 b' class SvnRemote(object):'
215 215
216 216 cache_on, context_uid, repo_id = self._cache_on(wire)
217 217 @self.region.conditional_cache_on_arguments(condition=cache_on)
218 def _revision_properties(_context_uid, _repo_id, _revision):
218 def _revision_properties(_repo_id, _revision):
219 219 repo = self._factory.repo(wire)
220 220 fs_ptr = svn.repos.fs(repo)
221 221 return svn.fs.revision_proplist(fs_ptr, revision)
222 return _revision_properties(context_uid, repo_id, revision)
222 return _revision_properties(repo_id, revision)
223 223
224 224 def revision_changes(self, wire, revision):
225 225
@@ -288,10 +288,14 b' class SvnRemote(object):'
288 288 return _assert_correct_path(context_uid, repo_id, path, revision, limit)
289 289
290 290 def node_properties(self, wire, path, revision):
291 repo = self._factory.repo(wire)
292 fsobj = svn.repos.fs(repo)
293 rev_root = svn.fs.revision_root(fsobj, revision)
294 return svn.fs.node_proplist(rev_root, path)
291 cache_on, context_uid, repo_id = self._cache_on(wire)
292 @self.region.conditional_cache_on_arguments(condition=cache_on)
293 def _node_properties(_repo_id, _path, _revision):
294 repo = self._factory.repo(wire)
295 fsobj = svn.repos.fs(repo)
296 rev_root = svn.fs.revision_root(fsobj, revision)
297 return svn.fs.node_proplist(rev_root, path)
298 return _node_properties(repo_id, path, revision)
295 299
296 300 def file_annotate(self, wire, path, revision):
297 301 abs_path = 'file://' + urllib.pathname2url(
@@ -324,7 +328,7 b' class SvnRemote(object):'
324 328
325 329 cache_on, context_uid, repo_id = self._cache_on(wire)
326 330 @self.region.conditional_cache_on_arguments(condition=cache_on)
327 def _get_node_type(_context_uid, _repo_id, _path, _revision):
331 def _get_node_type(_repo_id, _path, _revision):
328 332 repo = self._factory.repo(wire)
329 333 fs_ptr = svn.repos.fs(repo)
330 334 if _revision is None:
@@ -332,13 +336,13 b' class SvnRemote(object):'
332 336 root = svn.fs.revision_root(fs_ptr, _revision)
333 337 node = svn.fs.check_path(root, path)
334 338 return NODE_TYPE_MAPPING.get(node, None)
335 return _get_node_type(context_uid, repo_id, path, revision)
339 return _get_node_type(repo_id, path, revision)
336 340
337 341 def get_nodes(self, wire, path, revision=None):
338 342
339 343 cache_on, context_uid, repo_id = self._cache_on(wire)
340 344 @self.region.conditional_cache_on_arguments(condition=cache_on)
341 def _get_nodes(_context_uid, _repo_id, _path, _revision):
345 def _get_nodes(_repo_id, _path, _revision):
342 346 repo = self._factory.repo(wire)
343 347 fsobj = svn.repos.fs(repo)
344 348 if _revision is None:
@@ -350,7 +354,7 b' class SvnRemote(object):'
350 354 result.append(
351 355 (entry_path, NODE_TYPE_MAPPING.get(entry_info.kind, None)))
352 356 return result
353 return _get_nodes(context_uid, repo_id, path, revision)
357 return _get_nodes(repo_id, path, revision)
354 358
355 359 def get_file_content(self, wire, path, rev=None):
356 360 repo = self._factory.repo(wire)
@@ -365,7 +369,7 b' class SvnRemote(object):'
365 369
366 370 cache_on, context_uid, repo_id = self._cache_on(wire)
367 371 @self.region.conditional_cache_on_arguments(condition=cache_on)
368 def _get_file_size(_context_uid, _repo_id, _path, _revision):
372 def _get_file_size(_repo_id, _path, _revision):
369 373 repo = self._factory.repo(wire)
370 374 fsobj = svn.repos.fs(repo)
371 375 if _revision is None:
@@ -373,7 +377,7 b' class SvnRemote(object):'
373 377 root = svn.fs.revision_root(fsobj, _revision)
374 378 size = svn.fs.file_length(root, path)
375 379 return size
376 return _get_file_size(context_uid, repo_id, path, revision)
380 return _get_file_size(repo_id, path, revision)
377 381
378 382 def create_repository(self, wire, compatible_version=None):
379 383 log.info('Creating Subversion repository in path "%s"', wire['path'])
@@ -691,7 +695,6 b' class SvnDiffer(object):'
691 695 return content.splitlines(True)
692 696
693 697
694
695 698 class DiffChangeEditor(svn.delta.Editor):
696 699 """
697 700 Records changes between two given revisions
@@ -36,7 +36,7 b' class TestDiff(object):'
36 36 'deadbeef', 'index', 'message')
37 37 with pytest.raises(Exception) as exc_info:
38 38 hg_remote.diff(
39 wire={}, rev1='deadbeef', rev2='deadbee1',
39 wire={}, commit_id_1='deadbeef', commit_id_2='deadbee1',
40 40 file_filter=None, opt_git=True, opt_ignorews=True,
41 41 context=3)
42 42 assert type(exc_info.value) == Exception
General Comments 0
You need to be logged in to leave comments. Login now