comparison hgext/sqlitestore.py @ 40390:7e3b6c4f01a2

localrepo: support marking repos as having shallow file storage Various operations against repositories need to know if repository storage is full or partial. For example, a checkout (including possibly a widening of a sparse checkout), needs to know if it can assume all file revisions are available or whether to look for missing revisions first. This commit lays the plumbing for doing that. We define a repo creation option that indicates that shallow file storage is desired. The SQLite store uses this creation option to add an extra repo requirement indicating file storage is shallow. A new repository feature has been added to indicate that file storage is shallow. The SQLite store adds this feature when the shallow file store requirement is present. Code can now look at repo.features to determine if repo file storage may be shallow and take additional actions if so. While we're here, we also teach the SQLite store to handle the narrow repo requirement, which gets added when making narrow clones. Differential Revision: https://phab.mercurial-scm.org/D5166
author Gregory Szorc <gregory.szorc@gmail.com>
date Fri, 19 Oct 2018 14:59:03 +0200
parents 1b183edbb68e
children 595641bd8404
comparison
equal deleted inserted replaced
40389:1b183edbb68e 40390:7e3b6c4f01a2
99 99
100 REQUIREMENT = b'exp-sqlite-001' 100 REQUIREMENT = b'exp-sqlite-001'
101 REQUIREMENT_ZSTD = b'exp-sqlite-comp-001=zstd' 101 REQUIREMENT_ZSTD = b'exp-sqlite-comp-001=zstd'
102 REQUIREMENT_ZLIB = b'exp-sqlite-comp-001=zlib' 102 REQUIREMENT_ZLIB = b'exp-sqlite-comp-001=zlib'
103 REQUIREMENT_NONE = b'exp-sqlite-comp-001=none' 103 REQUIREMENT_NONE = b'exp-sqlite-comp-001=none'
104 REQUIREMENT_SHALLOW_FILES = b'exp-sqlite-shallow-files'
104 105
105 CURRENT_SCHEMA_VERSION = 1 106 CURRENT_SCHEMA_VERSION = 1
106 107
107 COMPRESSION_NONE = 1 108 COMPRESSION_NONE = 1
108 COMPRESSION_ZSTD = 2 109 COMPRESSION_ZSTD = 2
1012 if zstd: 1013 if zstd:
1013 supported.add(REQUIREMENT_ZSTD) 1014 supported.add(REQUIREMENT_ZSTD)
1014 1015
1015 supported.add(REQUIREMENT_ZLIB) 1016 supported.add(REQUIREMENT_ZLIB)
1016 supported.add(REQUIREMENT_NONE) 1017 supported.add(REQUIREMENT_NONE)
1018 supported.add(REQUIREMENT_SHALLOW_FILES)
1019 supported.add(repository.NARROW_REQUIREMENT)
1017 1020
1018 def newreporequirements(orig, ui, createopts): 1021 def newreporequirements(orig, ui, createopts):
1019 if createopts['backend'] != 'sqlite': 1022 if createopts['backend'] != 'sqlite':
1020 return orig(ui, createopts) 1023 return orig(ui, createopts)
1021 1024
1028 # we honor creation options and we do that by annotating exactly the 1031 # we honor creation options and we do that by annotating exactly the
1029 # creation options we recognize. 1032 # creation options we recognize.
1030 known = { 1033 known = {
1031 'narrowfiles', 1034 'narrowfiles',
1032 'backend', 1035 'backend',
1036 'shallowfilestore',
1033 } 1037 }
1034 1038
1035 unsupported = set(createopts) - known 1039 unsupported = set(createopts) - known
1036 if unsupported: 1040 if unsupported:
1037 raise error.Abort(_('SQLite store does not support repo creation ' 1041 raise error.Abort(_('SQLite store does not support repo creation '
1059 requirements.add(REQUIREMENT_NONE) 1063 requirements.add(REQUIREMENT_NONE)
1060 else: 1064 else:
1061 raise error.Abort(_('unknown compression engine defined in ' 1065 raise error.Abort(_('unknown compression engine defined in '
1062 'storage.sqlite.compression: %s') % compression) 1066 'storage.sqlite.compression: %s') % compression)
1063 1067
1068 if createopts.get('shallowfilestore'):
1069 requirements.add(REQUIREMENT_SHALLOW_FILES)
1070
1064 return requirements 1071 return requirements
1065 1072
1066 @interfaceutil.implementer(repository.ilocalrepositoryfilestorage) 1073 @interfaceutil.implementer(repository.ilocalrepositoryfilestorage)
1067 class sqlitefilestorage(object): 1074 class sqlitefilestorage(object):
1068 """Repository file storage backed by SQLite.""" 1075 """Repository file storage backed by SQLite."""
1080 raise error.Abort(_('unable to determine what compression engine ' 1087 raise error.Abort(_('unable to determine what compression engine '
1081 'to use for SQLite storage')) 1088 'to use for SQLite storage'))
1082 1089
1083 return sqlitefilestore(self._dbconn, path, compression) 1090 return sqlitefilestore(self._dbconn, path, compression)
1084 1091
1085 def makefilestorage(orig, requirements, **kwargs): 1092 def makefilestorage(orig, requirements, features, **kwargs):
1086 """Produce a type conforming to ``ilocalrepositoryfilestorage``.""" 1093 """Produce a type conforming to ``ilocalrepositoryfilestorage``."""
1087 if REQUIREMENT in requirements: 1094 if REQUIREMENT in requirements:
1095 if REQUIREMENT_SHALLOW_FILES in requirements:
1096 features.add(repository.REPO_FEATURE_SHALLOW_FILE_STORAGE)
1097
1088 return sqlitefilestorage 1098 return sqlitefilestorage
1089 else: 1099 else:
1090 return orig(requirements=requirements, **kwargs) 1100 return orig(requirements=requirements, features=features, **kwargs)
1091 1101
1092 def makemain(orig, ui, requirements, **kwargs): 1102 def makemain(orig, ui, requirements, **kwargs):
1093 if REQUIREMENT in requirements: 1103 if REQUIREMENT in requirements:
1094 if REQUIREMENT_ZSTD in requirements and not zstd: 1104 if REQUIREMENT_ZSTD in requirements and not zstd:
1095 raise error.Abort(_('repository uses zstandard compression, which ' 1105 raise error.Abort(_('repository uses zstandard compression, which '