| 1 | # svntrac
|
|---|
| 2 | #
|
|---|
| 3 | # Copyright (C) 2003 Xyche Software
|
|---|
| 4 | #
|
|---|
| 5 | # svntrac is free software; you can redistribute it and/or
|
|---|
| 6 | # modify it under the terms of the GNU General Public License as
|
|---|
| 7 | # published by the Free Software Foundation; either version 2 of the
|
|---|
| 8 | # License, or (at your option) any later version.
|
|---|
| 9 | #
|
|---|
| 10 | # svntrac is distributed in the hope that it will be useful,
|
|---|
| 11 | # but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|---|
| 12 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|---|
| 13 | # General Public License for more details.
|
|---|
| 14 | #
|
|---|
| 15 | # You should have received a copy of the GNU General Public License
|
|---|
| 16 | # along with this program; if not, write to the Free Software
|
|---|
| 17 | # Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
|
|---|
| 18 | #
|
|---|
| 19 | # Author: Jonas Borgström <jonas@xyche.com>
|
|---|
| 20 |
|
|---|
| 21 | import sqlite
|
|---|
| 22 |
|
|---|
| 23 | from svn import fs, util, delta, repos
|
|---|
| 24 |
|
|---|
| 25 | db_name = None
|
|---|
| 26 |
|
|---|
| 27 | class ChangeEditor (delta.Editor):
|
|---|
| 28 | def __init__(self, rev, old_root, new_root, cursor):
|
|---|
| 29 | self.rev = rev
|
|---|
| 30 | self.cursor = cursor
|
|---|
| 31 | self.old_root = old_root
|
|---|
| 32 | self.new_root = new_root
|
|---|
| 33 |
|
|---|
| 34 | def delete_entry(self, path, revision, parent_baton, pool):
|
|---|
| 35 | self.cursor.execute ('INSERT INTO node_change (rev, name, change) '
|
|---|
| 36 | 'VALUES (%s, %s, \'D\')', self.rev, path)
|
|---|
| 37 |
|
|---|
| 38 | def add_directory(self, path, parent_baton,
|
|---|
| 39 | copyfrom_path, copyfrom_revision, dir_pool):
|
|---|
| 40 | self.cursor.execute ('INSERT INTO node_change (rev, name, change) '
|
|---|
| 41 | 'VALUES (%s, %s, \'A\')', self.rev, path)
|
|---|
| 42 |
|
|---|
| 43 | def add_file(self, path, parent_baton,
|
|---|
| 44 | copyfrom_path, copyfrom_revision, file_pool):
|
|---|
| 45 | self.cursor.execute ('INSERT INTO node_change (rev, name, change) '
|
|---|
| 46 | 'VALUES (%s, %s, \'A\')',self.rev, path)
|
|---|
| 47 |
|
|---|
| 48 | def open_file(self, path, parent_baton, base_revision, file_pool):
|
|---|
| 49 | self.cursor.execute ('INSERT INTO node_change (rev, name, change) '
|
|---|
| 50 | 'VALUES (%s, %s, \'M\')',self.rev, path)
|
|---|
| 51 |
|
|---|
| 52 | def get_youngest_stored (cursor):
|
|---|
| 53 | cursor.execute ('SELECT MAX(rev) FROM (SELECT MAX(rev) as rev FROM '
|
|---|
| 54 | 'revision UNION SELECT 0 as rev)')
|
|---|
| 55 | return int(cursor.fetchone()[0])
|
|---|
| 56 |
|
|---|
| 57 | def init (conf):
|
|---|
| 58 | global db_name
|
|---|
| 59 | db_name = conf.get('general', 'database')
|
|---|
| 60 |
|
|---|
| 61 | def get_connection ():
|
|---|
| 62 | return sqlite.connect (db_name)
|
|---|
| 63 |
|
|---|
| 64 | def sync (repos, fs_ptr, pool):
|
|---|
| 65 | """
|
|---|
| 66 | updates the revision and node_change tables to be in sync with
|
|---|
| 67 | the repository.
|
|---|
| 68 | """
|
|---|
| 69 | cnx = get_connection ()
|
|---|
| 70 |
|
|---|
| 71 | cursor = cnx.cursor ()
|
|---|
| 72 | youngest_stored = get_youngest_stored (cursor)
|
|---|
| 73 | max_rev = fs.youngest_rev(fs_ptr, pool)
|
|---|
| 74 | num = max_rev - youngest_stored
|
|---|
| 75 | offset = youngest_stored + 1
|
|---|
| 76 | for rev in range (num):
|
|---|
| 77 |
|
|---|
| 78 | message = fs.revision_prop(fs_ptr, rev + offset,
|
|---|
| 79 | util.SVN_PROP_REVISION_LOG, pool)
|
|---|
| 80 | author = fs.revision_prop(fs_ptr, rev + offset,
|
|---|
| 81 | util.SVN_PROP_REVISION_AUTHOR, pool)
|
|---|
| 82 | date = fs.revision_prop(fs_ptr, rev + offset,
|
|---|
| 83 | util.SVN_PROP_REVISION_DATE, pool)
|
|---|
| 84 |
|
|---|
| 85 | date = util.svn_time_from_cstring(date, pool) / 1000000
|
|---|
| 86 |
|
|---|
| 87 | cursor.execute ('INSERT INTO revision (rev, time, author, message) '
|
|---|
| 88 | 'VALUES (%s, %s, %s, %s)', rev + offset, date,
|
|---|
| 89 | author, message)
|
|---|
| 90 | insert_change (pool, fs_ptr, rev + offset, cursor)
|
|---|
| 91 | cnx.commit()
|
|---|
| 92 |
|
|---|
| 93 | def insert_change (pool, fs_ptr, rev, cursor):
|
|---|
| 94 | old_root = fs.revision_root(fs_ptr, rev - 1, pool)
|
|---|
| 95 | new_root = fs.revision_root(fs_ptr, rev, pool)
|
|---|
| 96 |
|
|---|
| 97 | editor = ChangeEditor(rev, old_root, new_root, cursor)
|
|---|
| 98 | e_ptr, e_baton = delta.make_editor(editor, pool)
|
|---|
| 99 |
|
|---|
| 100 | repos.svn_repos_dir_delta(old_root, '', None,
|
|---|
| 101 | new_root, '', e_ptr, e_baton,
|
|---|
| 102 | 0, 1, 0, 1, pool)
|
|---|