-
Notifications
You must be signed in to change notification settings - Fork 1
/
repository.py
1424 lines (1255 loc) · 55.1 KB
/
repository.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
# Copyright (C) 2006-2011 Jelmer Vernooij <jelmer@samba.org>
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
"""Subversion repository access."""
from __future__ import absolute_import
from itertools import chain
import subvertpy
from breezy import (
branch,
errors as bzr_errors,
graph,
transactions,
ui,
urlutils,
)
from breezy.decorators import only_raises
from breezy.foreign import (
ForeignRepository,
)
from breezy.lock import (
LogicalLockResult,
)
from breezy.bzr.inventory import (
Inventory,
)
from breezy.repository import (
Repository,
RepositoryFormat,
RepositoryWriteLockResult,
)
from six import (
text_type,
)
from breezy.bzr.inventorytree import InventoryRevisionTree
from breezy.revision import (
NULL_REVISION,
ensure_null,
)
from breezy.trace import (
note,
)
from breezy.transport import (
Transport,
)
from . import (
cache,
changes,
errors,
layout,
logwalker,
revmeta as _mod_revmeta,
)
from .branchprops import (
PathPropertyProvider,
)
from .config import SvnRepositoryStack
from .fileids import (
CachingFileIdMapStore,
FileIdMapStore,
simple_apply_changes,
)
from .graph import (
SubversionGraph,
)
from .layout.standard import (
WildcardLayout,
)
from .layout.guess import (
repository_guess_layout,
)
from .mapping import (
SVN_REVPROP_BZR_SIGNATURE,
SVN_REVPROP_BZR_TIMESTAMP,
BzrSvnMapping,
foreign_vcs_svn,
find_mappings_fileprops,
find_mapping_revprops,
is_bzr_revision_revprops,
mapping_registry,
parse_svn_dateprop,
unpack_highres_date,
)
from .parents import (
DiskCachingParentsProvider,
)
from .revids import (
DiskCachingRevidMap,
MemoryCachingRevidMap,
RevidMap,
)
from .tree import (
SvnRevisionTree,
)
from .filegraph import (
PerFileParentProvider,
)
LAYOUT_SOURCE_GUESSED = 'guess'
LAYOUT_SOURCE_CONFIG = 'config'
LAYOUT_SOURCE_OVERRIDDEN = 'overridden'
LAYOUT_SOURCE_MAPPING_MANDATED = 'mapping-mandated'
class DummyLockableFiles(object):
def __init__(self, transport):
self._transport = transport
class SvnRepositoryFormat(RepositoryFormat):
"""Repository format for Subversion repositories (accessed using svn_ra).
"""
rich_root_data = True
supports_tree_reference = False
_serializer = None
supports_leaving_lock = False
fast_deltas = True
supports_full_versioned_files = False
supports_funky_characters = True
supports_external_lookups = False
revision_graph_can_have_wrong_parents = False
supports_versioned_directories = True
supports_nesting_repositories = False
supports_unreferenced_revisions = False
supports_overriding_transport = False
@property
def _matchingcontroldir(self):
from .remote import SvnRemoteFormat
return SvnRemoteFormat()
def __init__(self):
super(SvnRepositoryFormat, self).__init__()
def get_format_description(self):
return "Subversion Repository"
def network_name(self):
return "subversion"
def initialize(self, controldir, shared=False, _internal=False):
from .remote import SvnRemoteAccess
if not isinstance(controldir, SvnRemoteAccess):
raise bzr_errors.UninitializableFormat(self)
return controldir.open_repository()
def get_foreign_tests_repository_factory(self):
from .tests.test_repository import (
ForeignTestsRepositoryFactory,
)
return ForeignTestsRepositoryFactory()
def check_conversion_target(self, target_repo_format):
if not target_repo_format.rich_root_data:
raise bzr_errors.BadConversionTarget(
'Does not support rich root data.', target_repo_format)
class SubversionRepositoryCheckResult(branch.BranchCheckResult):
"""Results of checking a Subversion repository."""
def __init__(self, repository):
self.repository = repository
self.checked_rev_cnt = 0
self.checked_roundtripped_cnt = 0
self.hidden_rev_cnt = 0
self.inconsistent_stored_lhs_parent = 0
self.invalid_fileprop_cnt = 0
self.text_revision_in_parents_cnt = 0
self.paths_not_under_branch_root = 0
self.different_uuid_cnt = 0
self.multiple_mappings_cnt = 0
self.inconsistent_fileprop_revprop_cnt = 0
self.newer_mapping_parents = 0
self.ghost_revisions = set()
self.invalid_text_parents_len = 0
self.invalid_text_revisions = 0
def report_results(self, verbose):
note('checked repository %s format %s',
self.repository.controldir.root_transport,
self.repository._format)
note('%6d revisions', self.checked_rev_cnt)
if self.checked_roundtripped_cnt > 0:
note('%6d revisions originating in bzr',
self.checked_roundtripped_cnt)
if self.hidden_rev_cnt > 0:
note('%6d hidden bzr-created revisions', self.hidden_rev_cnt)
if self.inconsistent_stored_lhs_parent > 0:
note('%6d inconsistent stored left-hand side parent revision ids',
self.inconsistent_stored_lhs_parent)
if self.invalid_fileprop_cnt > 0:
note('%6d invalid bzr-related file properties',
self.invalid_fileprop_cnt)
if self.paths_not_under_branch_root > 0:
note('%6d files were modified that were not under the branch root',
self.paths_not_under_branch_root)
if self.different_uuid_cnt > 0:
note('%6d revisions originating in a different repository',
self.different_uuid_cnt)
if self.multiple_mappings_cnt > 0:
note('%6d revisions with multiple mappings',
self.multiple_mappings_cnt)
if self.inconsistent_fileprop_revprop_cnt > 0:
note('%6d revisions with file and revision properties that are inconsistent',
self.inconsistent_fileprop_revprop_cnt)
if self.newer_mapping_parents > 0:
note('%6d revisions with newer mappings than their children',
self.newer_mapping_parents)
if len(self.ghost_revisions) > 0:
note('%6d ghost revisions', len(self.ghost_revisions))
if self.invalid_text_parents_len > 0:
note('%6d text parents with invalid number',
self.invalid_text_parents_len)
if self.invalid_text_revisions > 0:
note('%6d invalid text revisions', self.invalid_text_revisions)
def check_revmeta(self, revmeta):
self.checked_rev_cnt += 1
found_fileprops = 0
# Check for multiple mappings
try:
fileprop_mappings = find_mappings_fileprops(
revmeta.get_changed_fileprops())
except subvertpy.SubversionException as e:
msg, num = e.args
if num == subvertpy.ERR_FS_NOT_DIRECTORY:
return
raise
if len(fileprop_mappings) > 1:
self.multiple_mappings_cnt += 1
mapping = revmeta.get_original_mapping()
if mapping is None:
return
if (len(fileprop_mappings) > 0 and
find_mapping_revprops(revmeta.revprops) not in
(None, fileprop_mappings[0])):
self.inconsistent_fileprop_revprop_cnt += 1
self.checked_roundtripped_cnt += 1
if revmeta.is_hidden(mapping):
self.hidden_rev_cnt += 1
mapping.check_fileprops(revmeta.get_changed_fileprops(), self)
mapping.check_revprops(revmeta.metarev.revprops, self)
lhs_parent_revmeta = revmeta.get_lhs_parent_revmeta(mapping)
for parent_revid in revmeta.get_rhs_parents(mapping, lhs_parent_revmeta):
if not self.repository.has_revision(parent_revid):
self.ghost_revisions.add(parent_revid)
# TODO: Check that stored revno matches actual revision number
# Check all paths are under branch root
branch_root = mapping.get_branch_root(revmeta.metarev.revprops)
if branch_root is not None:
for p in revmeta.metarev.paths:
if not changes.path_is_child(branch_root, p):
self.paths_not_under_branch_root += 1
original_uuid = mapping.get_repository_uuid(revmeta.metarev.revprops)
if (original_uuid is not None and
original_uuid != self.repository.uuid):
self.different_uuid_cnt += 1
if lhs_parent_revmeta is not None:
lhs_parent_mapping = lhs_parent_revmeta.get_original_mapping()
if lhs_parent_mapping is None:
lhs_parent_mapping = mapping
elif lhs_parent_mapping.newer_than(mapping):
self.newer_mapping_parents += 1
lhs_parent_mapping = mapping
expected_lhs_parent_revid = lhs_parent_revmeta.get_revision_id(
lhs_parent_mapping)
if revmeta.get_stored_lhs_parent_revid(mapping) not in (
None, expected_lhs_parent_revid):
self.inconsistent_stored_lhs_parent += 1
self.check_texts(revmeta, mapping, lhs_parent_revmeta)
def check_texts(self, revmeta, mapping, lhs_parent_revmeta):
# Check for inconsistencies in text file ids/revisions
text_revisions = revmeta.get_text_revisions(mapping)
text_ids = revmeta.get_fileid_overrides(mapping)
fileid_map = self.repository.get_fileid_map(revmeta, mapping)
path_changes = revmeta.metarev.paths
for path in set(text_ids.keys() + text_revisions.keys()):
full_path = urlutils.join(revmeta.metarev.branch_path, path)
# TODO Check consistency against parent data
ghost_parents = False
parent_revmetas = []
parent_mappings = []
parent_fileid_maps = []
for revid in revmeta.get_parent_ids(mapping, lhs_parent_revmeta):
try:
parent_revmeta, parent_mapping = self.repository._get_revmeta(
revid)
except bzr_errors.NoSuchRevision:
ghost_parents = True
else:
parent_revmetas.append(parent_revmeta)
parent_mappings.append(parent_mapping)
parent_fileid_map = self.repository.get_fileid_map(
parent_revmeta, parent_mapping)
parent_fileid_maps.append(parent_fileid_map)
for path, text_revision in text_revisions.items():
# Every text revision either has to match the actual revision's
# revision id (if it was last changed there) or the text revisions
# in one of the parents.
fileid = fileid_map.lookup(mapping, path)[0]
parent_text_revisions = []
for parent_fileid_map, parent_mapping in zip(
parent_fileid_maps, parent_mappings):
try:
parent_text_revisions.append(
parent_fileid_map.reverse_lookup(
parent_mapping, fileid))
except KeyError:
pass
if (text_revision != revmeta.get_revision_id(mapping) and
not ghost_parents and
text_revision not in parent_text_revisions):
self.invalid_text_revisions += 1
_optimizers_registered = False
def lazy_register_optimizers():
"""Register optimizers for fetching between svn and bzr repositories.
"""
global _optimizers_registered
if _optimizers_registered:
return
from breezy.repository import InterRepository
from . import push, fetch
_optimizers_registered = True
InterRepository.register_optimiser(fetch.InterFromSvnToInventoryRepository)
InterRepository.register_optimiser(push.InterToSvnRepository)
class SvnRepository(ForeignRepository):
"""
Provides a simplified interface to a Subversion repository
by using the RA (remote access) API from subversion
"""
chk_bytes = None
def __init__(self, some_dir, transport, svn_transport, branch_path=None):
lazy_register_optimizers()
self.vcs = foreign_vcs_svn
assert isinstance(transport, Transport)
control_files = DummyLockableFiles(transport)
Repository.__init__(
self, SvnRepositoryFormat(), some_dir, control_files)
self._transport = transport
self.svn_transport = svn_transport
self._cached_revnum = None
self._lock_mode = None
self._lock_count = 0
self._layout = None
self._layout_source = None
self._guessed_layout = None
self._guessed_appropriate_layout = None
self.transport = transport
self.uuid = svn_transport.get_uuid()
assert self.uuid is not None
self.base = transport.base
assert self.base is not None
self._serializer = None
self.get_config().add_location(self.base)
self._log = logwalker.LogWalker(transport=svn_transport)
self.fileid_map = FileIdMapStore(simple_apply_changes, self)
self.revmap = RevidMap(self)
self._default_mapping = None
self._hinted_branch_path = branch_path
self._real_parents_provider = self
self._cached_tags = {}
self._cache_obj = None
use_cache = self.get_config().get_use_cache()
if use_cache is None:
# TODO: Don't enable log cache in some situations, e.g.
# for large repositories ?
if self.base.startswith("file://"):
# Default to no log caching for local connections
use_cache = set(["fileids", "revids"])
else:
use_cache = set(["fileids", "revids", "revinfo", "log"])
if use_cache:
self._cache_obj = cache.get_cache(self.uuid)
if "log" in use_cache:
log_cache = self._cache_obj.open_logwalker()
if log_cache.max_revnum() > self.get_latest_revnum():
errors.warn_uuid_reuse(self.uuid, self.base)
self._log = logwalker.CachingLogWalker(self._log, log_cache)
if "fileids" in use_cache:
self.fileid_map = CachingFileIdMapStore(
self._cache_obj.open_fileid_map(), self.fileid_map)
if "revids" in use_cache:
self.revmap = DiskCachingRevidMap(
self.revmap, self._cache_obj.open_revid_map())
self._real_parents_provider = DiskCachingParentsProvider(
self._real_parents_provider, self._cache_obj.open_parents())
else:
self.revmap = MemoryCachingRevidMap(self.revmap)
if "revinfo" in use_cache:
self.revinfo_cache = self._cache_obj.open_revision_cache()
else:
self.revinfo_cache = None
self._parents_provider = graph.CachingParentsProvider(
self._real_parents_provider)
self._parents_provider.disable_cache()
self.texts = None
self.revisions = None
self.inventories = None
self.signatures = None
self.branchprop_list = PathPropertyProvider(self._log)
self._revmeta_provider = _mod_revmeta.RevisionMetadataProvider(
self, self.revinfo_cache is not None)
def _get_controldir(self):
# This is done lazily since the actual repository root may not be
# accessible, and we don't really need it.
if self._some_controldir.svn_root_url == self._some_controldir.svn_url:
return self._some_controldir
from .remote import SvnRemoteAccess
self._some_controldir = SvnRemoteAccess(
self._some_controldir.svn_transport.clone_root())
return self._some_controldir
def _set_controldir(self, value):
self._some_controldir = value
controldir = property(_get_controldir, _set_controldir)
def break_lock(self):
raise NotImplementedError(self.break_lock)
def dont_leave_lock_in_place(self):
raise NotImplementedError(self.dont_leave_lock_in_place)
def leave_lock_in_place(self):
raise NotImplementedError(self.leave_lock_in_place)
def get_file_graph(self):
"""Return the graph walker for text revisions."""
with self.lock_read():
return graph.Graph(graph.CachingParentsProvider(
PerFileParentProvider(self)))
def get_graph(self, other_repository=None):
"""Return the graph walker for this repository format"""
parents_provider = self._make_parents_provider()
if (other_repository is not None and
not self.has_same_location(other_repository)):
parents_provider = graph.StackedParentsProvider(
[parents_provider, other_repository._make_parents_provider()])
return SubversionGraph(self, parents_provider)
def add_fallback_repository(self, basis_url):
raise bzr_errors.UnstackableRepositoryFormat(self._format, self.base)
def pack(self, hint=None, clean_obsolete_packs=False):
try:
local_path = self.transport.local_abspath(".")
except bzr_errors.NotLocalUrl:
pass
else:
from subvertpy import repos
repo = repos.Repository(local_path)
pack_fs = getattr(repo, "pack_fs", None)
if pack_fs is not None:
try:
pack_fs()
except NotImplementedError:
pass
def get_transaction(self):
"""See Repository.get_transaction()."""
if self._write_group is None:
return transactions.PassThroughTransaction()
else:
return self._write_group
def lock_read(self):
if self._lock_mode:
assert self._lock_mode in ('r', 'w')
self._lock_count += 1
else:
self._lock_mode = 'r'
self._lock_count = 1
self._parents_provider.enable_cache()
return LogicalLockResult(self.unlock)
@only_raises(bzr_errors.LockNotHeld, bzr_errors.LockBroken)
def unlock(self):
if self._lock_count == 0:
raise bzr_errors.LockNotHeld(self)
if self._lock_count == 1 and self._lock_mode == 'w':
if self._write_group is not None:
self.abort_write_group()
self._lock_count -= 1
self._lock_mode = None
raise bzr_errors.BzrError(
'Must end write groups before releasing write locks.')
self._lock_count -= 1
if self._lock_count == 0:
self._lock_mode = None
self._clear_cached_state()
self._parents_provider.disable_cache()
def reconcile(self, other=None, thorough=False):
"""Reconcile this repository."""
from .reconcile import RepoReconciler
reconciler = RepoReconciler(self, thorough=thorough)
reconciler.reconcile()
return reconciler
def _cache_add_new_revision(self, revnum, revid, parents):
assert self.is_locked()
assert type(parents) == tuple or parents is None
if self._cached_revnum is None:
self._cached_revnum = revnum
else:
self._cached_revnum = max(revnum, self._cached_revnum)
if parents == () and revid != NULL_REVISION:
parents = (NULL_REVISION,)
parents_cache = self._parents_provider._cache
if parents is None:
if revid in parents_cache and parents_cache[revid] is None:
del parents_cache[revid]
else:
parents_cache[revid] = parents
def _clear_cached_state(self):
self._cached_tags = {}
self._cached_revnum = None
self._layout = None
self._layout_source = None
if self._cache_obj is not None:
self._cache_obj.commit()
def lock_write(self):
"""See Branch.lock_write()."""
if self._lock_mode:
assert self._lock_mode == 'w'
self._lock_count += 1
else:
self._lock_mode = 'w'
self._lock_count = 1
self._parents_provider.enable_cache()
return RepositoryWriteLockResult(self.unlock, None)
def is_write_locked(self):
return (self._lock_mode == 'w')
def is_locked(self):
return (self._lock_mode is not None)
@errors.convert_svn_error
def get_latest_revnum(self):
"""Return the youngest revnum in the Subversion repository.
Will be cached when there is a read lock open.
"""
if self._cached_revnum is not None:
return self._cached_revnum
revnum = self.svn_transport.get_latest_revnum()
if self.is_locked():
self._cached_revnum = revnum
return revnum
def gather_stats(self, revid=None, committers=None):
"""See Repository.gather_stats()."""
result = {}
def check_timestamp(timestamp):
if 'latestrev' not in result:
result['latestrev'] = timestamp
result['firstrev'] = timestamp
with self.lock_read():
count = 0
if committers is not None and revid is not None:
all_committers = set()
graph = self.get_graph()
revids = [r for (r, ps) in graph.iter_ancestry([revid])
if r != NULL_REVISION and ps is not None]
for rev in self.get_revisions(revids):
if rev.committer != '':
all_committers.add(rev.committer)
check_timestamp((rev.timestamp, rev.timezone))
result['committers'] = len(all_committers)
count = len(list(self.all_revision_ids()))
else:
mapping = self.get_mapping()
for revmeta in self._revmeta_provider.iter_all_revisions(
self.get_layout(), mapping.is_branch_or_tag,
self.get_latest_revnum()):
if revmeta.is_hidden(mapping):
continue
try:
timestamp = unpack_highres_date(
revmeta.metarev.revprops[SVN_REVPROP_BZR_TIMESTAMP])
except KeyError:
timestamp = parse_svn_dateprop(
revmeta.metarev.revprops[
subvertpy.properties.PROP_REVISION_DATE])
check_timestamp(timestamp)
count += 1
# Approximate number of revisions
result['revisions'] = count
result['svn-uuid'] = self.uuid
result['svn-last-revnum'] = self.get_latest_revnum()
return result
def _properties_to_set(self, mapping, target_config):
"""Determine what sort of custom properties to set when
committing a new round-tripped revision.
:return: tuple with two booleans: whether to use revision properties
and whether to use file properties.
"""
supports_custom_revprops = self.svn_transport.has_capability(
"commit-revprops")
if supports_custom_revprops and mapping.can_use_revprops:
use_revprops = True
use_fileprops = mapping.must_use_fileprops
else:
use_revprops = False
use_fileprops = mapping.can_use_fileprops
if (use_fileprops and
not target_config.get('allow_metadata_in_file_properties')):
raise errors.RequiresMetadataInFileProps()
return (use_revprops, use_fileprops)
def get_mapping_class(self):
config_mapping_name = self.get_config().get_default_mapping()
if config_mapping_name is not None:
return mapping_registry.get(config_mapping_name)
return mapping_registry.get_default()
def get_mapping(self):
"""Get the default mapping that is used for this repository."""
if self._default_mapping is None:
mappingcls = self.get_mapping_class()
self._default_mapping = mappingcls.from_repository(
self, self._hinted_branch_path)
return self._default_mapping
def _make_parents_provider(self):
"""See Repository._make_parents_provider()."""
return self._parents_provider
def get_deltas_for_revisions(self, revisions):
"""See Repository.get_deltas_for_revisions()."""
for revision in revisions:
yield self.get_delta_for_revision(revision)
def get_revision_delta(self, revid, specific_fileids=None):
return self.get_delta_for_revision(
self.get_revision(revid),
specific_fileids=specific_fileids)
def get_delta_for_revision(self, revision, specific_fileids=None):
"""See Repository.get_delta_for_revision()."""
parentrevmeta = revision.svn_meta.get_lhs_parent_revmeta(
revision.mapping)
from .fetch import TreeDeltaBuildEditor
if parentrevmeta is None:
parentfileidmap = {}
parent_branch_path = revision.svn_meta.metarev.branch_path
parentrevnum = revision.svn_meta.metarev.revnum
start_empty = True
else:
parentfileidmap = self.get_fileid_map(parentrevmeta,
revision.mapping)
parent_branch_path = parentrevmeta.metarev.branch_path
parentrevnum = parentrevmeta.metarev.revnum
start_empty = False
editor = TreeDeltaBuildEditor(revision.svn_meta, revision.mapping,
self.get_fileid_map(revision.svn_meta, revision.mapping),
parentfileidmap, specific_fileids=specific_fileids)
conn = self.svn_transport.get_connection(parent_branch_path)
try:
reporter = conn.do_diff(revision.svn_meta.metarev.revnum, "",
urlutils.join(self.svn_transport.get_svn_repos_root(),
revision.svn_meta.metarev.branch_path).rstrip("/"), editor,
True, True, False)
try:
reporter.set_path("", parentrevnum, start_empty)
reporter.finish()
except:
reporter.abort()
raise
finally:
self.svn_transport.add_connection(conn)
editor.sort()
return editor.delta
def set_layout(self, layout):
"""Set the layout that should be used by default by this instance."""
self.get_mapping().check_layout(self, layout)
self._layout = layout
self._layout_source = LAYOUT_SOURCE_OVERRIDDEN
def store_layout(self, layout):
"""Permanantly store the layout for this repository."""
self.set_layout(layout)
self.get_config_stack().set('layout', str(layout))
self._layout_source = LAYOUT_SOURCE_CONFIG
def get_layout(self):
"""Determine layout to use for this repository.
This will use whatever layout the user has specified, or
otherwise the layout that was guessed by bzr-svn.
"""
return self.get_layout_source()[0]
def get_layout_source(self):
if self._layout is None:
self._layout_source = LAYOUT_SOURCE_MAPPING_MANDATED
self._layout = self.get_mapping().get_mandated_layout(self)
if self._layout is None:
config_stack = self.get_config_stack()
layoutname = config_stack.get('layout')
if layoutname is not None:
self._layout_source = LAYOUT_SOURCE_CONFIG
self._layout = layout.layout_registry.get(layoutname)()
if self._layout is None:
config_stack = self.get_config_stack()
branches = config_stack.get('branches')
tags = config_stack.get('tags')
if branches is not None:
self._layout_source = LAYOUT_SOURCE_CONFIG
self._layout = WildcardLayout(branches, tags or [])
if self._layout is None:
if self._guessed_appropriate_layout is None:
self._find_guessed_layout(self.get_config_stack())
self._layout_source = LAYOUT_SOURCE_GUESSED
self._layout = self._guessed_appropriate_layout
return self._layout, self._layout_source
def _find_guessed_layout(self, config_stack):
# Retrieve guessed-layout from config and see if it accepts
# self._hinted_branch_path
layoutname = config_stack.get('guessed-layout')
# Cope with 'None' being saved as layout name
if layoutname == 'None':
layoutname = None
if layoutname is not None:
config_guessed_layout = layout.layout_registry.get(layoutname)()
if (self._hinted_branch_path is None or
config_guessed_layout.is_branch(self._hinted_branch_path)):
self._guessed_layout = config_guessed_layout
self._guessed_appropriate_layout = config_guessed_layout
return
else:
config_guessed_layout = None
# No guessed layout stored yet or it doesn't accept
# self._hinted_branch_path
revnum = self.get_latest_revnum()
(self._guessed_layout,
self._guessed_appropriate_layout) = repository_guess_layout(self,
revnum, self._hinted_branch_path)
if (self._guessed_layout != config_guessed_layout and
revnum > 200 and
self._guessed_layout is not None):
config_stack.set('guessed-layout', self._guessed_layout)
def get_guessed_layout(self):
"""Retrieve the layout bzr-svn deems most appropriate for this repo.
"""
if self._guessed_layout is None:
# Assume whatever is registered is appropriate
self._guessed_layout = layout.repository_registry.get(self.uuid)
if self._guessed_layout is None:
self._guessed_layout = self.get_mapping().get_guessed_layout(self)
if self._guessed_layout is None:
self._find_guessed_layout(self.get_config_stack())
return self._guessed_layout
def __repr__(self):
return '%s(%r)' % (self.__class__.__name__, self.base)
def _check(self, revision_ids=None, callback_refs=None, check_repo=True):
ret = SubversionRepositoryCheckResult(self)
# FIXME: If this is a local repository, call out to subvertpy.repos.verify_fs.
# bug=843944
with ui.ui_factory.nested_progress_bar() as pb:
if revision_ids is not None:
for i, (revid, revmeta, mapping) in enumerate(
self._iter_revmetas(revision_ids)):
if revmeta is None:
continue
if revid == NULL_REVISION:
continue
pb.update("checking revisions", i, len(revision_ids))
ret.check_revmeta(revmeta)
else:
last_revnum = self.get_latest_revnum()
for revmeta in self._revmeta_provider.iter_all_revisions(
self.get_layout(), self.get_mapping().is_branch_or_tag,
last_revnum):
pb.update(
"checking revisions",
last_revnum-revmeta.metarev.revnum, last_revnum)
ret.check_revmeta(revmeta)
return ret
def get_inventory(self, revision_id):
"""See Repository.get_inventory()."""
raise NotImplementedError(self.get_inventory)
def _iter_inventories(self, revision_ids, ordering):
raise NotImplementedError(self._iter_inventories)
def get_fileid_map(self, revmeta, mapping):
return self.fileid_map.get_map(revmeta.metarev.get_foreign_revid(), mapping)
def all_revision_ids(self, layout=None, mapping=None):
"""Find all revision ids in this repository, using the specified or
default mapping.
:note: This will use the standard layout to find the revisions,
any revisions using non-standard branch locations (even
if part of the ancestry of valid revisions) won't be
returned.
"""
ret = set()
if mapping is None:
mapping = self.get_mapping()
if layout is None:
layout = self.get_layout()
for revmeta in self._revmeta_provider.iter_all_revisions(layout,
mapping.is_branch_or_tag, self.get_latest_revnum()):
if revmeta.is_hidden(mapping):
continue
ret.add(revmeta.get_revision_id(mapping))
return ret
def set_make_working_trees(self, new_value):
"""See Repository.set_make_working_trees()."""
raise bzr_errors.UnsupportedOperation(self.set_make_working_trees, self)
def make_working_trees(self):
"""See Repository.make_working_trees().
Always returns False, as working trees are never created inside
Subversion repositories.
"""
return False
def get_known_graph_ancestry(self, keys):
"""Get a KnownGraph instance with the ancestry of keys."""
# most basic implementation is a loop around get_parent_map
pending = set(keys)
parent_map = {}
while pending:
this_parent_map = {}
for revid in pending:
if revid == NULL_REVISION:
continue
parents = self._get_parents(revid)
if parents is not None:
if tuple(parents) == (NULL_REVISION,):
parents = ()
this_parent_map[revid] = parents
parent_map.update(this_parent_map)
pending = set()
map(pending.update, this_parent_map.values())
pending = pending.difference(parent_map)
kg = graph.KnownGraph(parent_map)
return kg
def has_revisions(self, revision_ids):
ret = set()
for revision_id in revision_ids:
if self.has_revision(revision_id):
ret.add(revision_id)
return ret
def has_revision(self, revision_id, project=None):
"""See Repository.has_revision()."""
if revision_id in (None, NULL_REVISION):
return True
try:
foreign_revid, _ = self.lookup_bzr_revision_id(revision_id,
project=project)
except bzr_errors.NoSuchRevision:
return False
return self.has_foreign_revision(foreign_revid)
def has_foreign_revision(self, foreign_revid):
(uuid, path, revnum) = foreign_revid
if uuid != self.uuid:
return False
try:
kind = self.svn_transport.check_path(path, revnum)
except subvertpy.SubversionException as e:
msg, num = e.args
if num == subvertpy.ERR_FS_NO_SUCH_REVISION:
return False
raise
else:
return (kind == subvertpy.NODE_DIR)
def iter_files_bytes(self, desired_files):
per_revision = {}
for (file_id, revision_id, identifier) in desired_files:
per_revision.setdefault(revision_id, []).append(
(file_id, identifier))
for revid, files in per_revision.items():
try:
tree = self.revision_tree(revid)
except bzr_errors.NoSuchRevision:
raise bzr_errors.RevisionNotPresent(revid, self)
for identifier, curfile in tree.iter_files_bytes(
[(tree.id2path(file_id), identifier)
for (file_id, identifier) in files]):
yield identifier, curfile
def revision_trees(self, revids):
"""See Repository.revision_trees()."""
# TODO: Use diffs
for revid in revids:
yield self.revision_tree(revid)
def revision_tree(self, revision_id):
"""See Repository.revision_tree()."""
if ensure_null(revision_id) == NULL_REVISION:
inventory = Inventory(root_id=None)
inventory.revision_id = revision_id
return InventoryRevisionTree(self, inventory, revision_id)
return SvnRevisionTree(self, revision_id)
def _get_parents(self, revid):
try:
revmeta, mapping = self._get_revmeta(ensure_null(revid))
except bzr_errors.NoSuchRevision:
return None
else:
parentrevmeta = revmeta.get_lhs_parent_revmeta(mapping)
return revmeta.get_parent_ids(mapping, parentrevmeta)
def get_parent_map(self, revids):
"""See Repository.get_parent_map()."""
parent_map = {}
for revision_id in revids:
if type(revision_id) != bytes:
raise ValueError("expected sequence of revision ids")
if revision_id == NULL_REVISION:
parent_map[revision_id] = ()
continue
parents = self._get_parents(revision_id)
if parents is None:
continue
if len(parents) == 0:
parents = [NULL_REVISION]
parent_map[revision_id] = tuple(parents)
return parent_map
def _iter_revmetas(self, revision_ids):
for revid in revision_ids:
if revid == NULL_REVISION:
yield (NULL_REVISION, None, None)
else:
try: