3
# Licensed to the Apache Software Foundation (ASF) under one
4
# or more contributor license agreements. See the NOTICE file
5
# distributed with this work for additional information
6
# regarding copyright ownership. The ASF licenses this file
7
# to you under the Apache License, Version 2.0 (the
8
# "License"); you may not use this file except in compliance
9
# with the License. You may obtain a copy of the License at
11
# http://www.apache.org/licenses/LICENSE-2.0
13
# Unless required by applicable law or agreed to in writing,
14
# software distributed under the License is distributed on an
15
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16
# KIND, either express or implied. See the License for the
17
# specific language governing permissions and limitations
21
A script that takes a .svn/pristine/ hierarchy, with its existing
22
.svn/wc.db database, and populates the database's PRISTINE table
23
accordingly. (Use 'svn cleanup' to remove unreferenced pristines.)
30
# TODO: resolve the NotImplemented() in __main__
32
# TODO: increment refcount upon collision
33
# TODO: add <given file>, not just argv[1]/.svn/pristine/??/*
41
# ### This could require any other format that has the same PRISTINE schema
44
BUFFER_SIZE = 4 * 1024
46
class UnknownFormat(Exception):
47
def __init__(self, formatno):
48
self.formatno = formatno
51
wc_db = os.path.join(wc_path, '.svn', 'wc.db')
52
conn = sqlite3.connect(wc_db)
54
curs.execute('pragma user_version;')
55
formatno = int(curs.fetchone()[0])
57
raise UnknownFormat(formatno)
60
_sha1_re = re.compile(r'^[0-9a-f]{40}$')
63
fd = os.open(path, os.O_RDONLY)
66
s = os.read(fd, BUFFER_SIZE)
71
return ctx.hexdigest()
75
INTO pristine(checksum,compression,size,refcount,md5_checksum)
79
def populate(wc_path):
80
conn = open_db(wc_path)
81
sys.stdout.write("Updating '%s': " % wc_path)
82
for dirname, dirs, files in os.walk(os.path.join(wc_path, '.svn/pristine/')):
83
# skip everything but .svn/pristine/xx/
84
if os.path.basename(os.path.dirname(dirname)) == 'pristine':
85
sys.stdout.write("'%s', " % os.path.basename(dirname))
86
for f in filter(lambda x: _sha1_re.match(x), files):
87
fullpath = os.path.join(dirname, f)
88
conn.execute(INSERT_QUERY,
89
('$sha1$'+f, None, os.stat(fullpath).st_size, 1,
90
'$md5 $'+md5_of(fullpath)))
91
# periodic transaction commits, for efficiency
94
sys.stdout.write(".\n")
96
if __name__ == '__main__':
97
raise NotImplemented("""Subversion does not know yet to avoid fetching
98
a file when a file with matching sha1 appears in the PRISTINE table.""")
103
for wc_path in paths:
106
except UnknownFormat, e:
107
sys.stderr.write("Don't know how to handle '%s' (format %d)'\n"
108
% (wc_path, e.formatno))