Edgewall Software

Ticket #586: repo-paths.2.diff

File repo-paths.2.diff, 10.2 KB (added by hazmat@…, 5 years ago)

fixes an issue with log and syncs

  • Browser.py

    diff -u trac-dist/Browser.py trac/Browser.py
    old new  
    4040        except core.SubversionException: 
    4141            raise TracError('Invalid revision number: %d' % revision) 
    4242 
     43        path = svn_path_join( self.repos_path, path) 
    4344        node_type = fs.check_path(root, path, self.pool) 
     45         
    4446        if not node_type in [core.svn_node_dir, core.svn_node_file]: 
    4547            raise TracError('"%s": no such file or directory in revision %d' \ 
    4648                            % (path, revision), 'Not such file or directory') 
     
    7880            else: 
    7981                date_seconds = 0 
    8082                date = '' 
     83        
     84            if self.repos_path: 
     85                url_path = fullpath[len(self.repos_path):] 
     86            else: 
     87                url_path = fullpath 
    8188 
    8289            item = { 
    8390                'name'       : name, 
    8491                'fullpath'   : fullpath, 
     92                'urlpath'    : url_path, 
    8593                'created_rev': created_rev, 
    8694                'date'       : date, 
    8795                'date_seconds' : date_seconds, 
     
    9098                'size'       : pretty_size(size), 
    9199                'size_bytes' : size } 
    92100            if rev_specified: 
    93                 item['log_href'] = self.env.href.log(fullpath, revision) 
     101                item['log_href'] = self.env.href.log(url_path, revision) 
    94102                if is_dir: 
    95                     item['browser_href'] = self.env.href.browser(fullpath, 
     103                    item['browser_href'] = self.env.href.browser(url_path, 
    96104                                                                 revision) 
    97105                else: 
    98                     item['browser_href'] = self.env.href.file(fullpath, revision) 
     106                    item['browser_href'] = self.env.href.file(url_path, revision) 
    99107            else: 
    100                 item['log_href'] = self.env.href.log(fullpath) 
     108                item['log_href'] = self.env.href.log(url_path) 
    101109                if is_dir: 
    102                     item['browser_href'] = self.env.href.browser(fullpath) 
     110                    item['browser_href'] = self.env.href.browser(url_path) 
    103111                else: 
    104                     item['browser_href'] = self.env.href.file(fullpath) 
     112                    item['browser_href'] = self.env.href.file(url_path) 
    105113 
    106114            info.append(item) 
    107115        return info 
  • File.py

    diff -u trac-dist/File.py trac/File.py
    old new  
    222222        FileCommon.render(self) 
    223223         
    224224        rev = self.args.get('rev', None) 
    225         self.path = self.args.get('path', '/') 
     225        path = self.args.get('path', '/') 
     226        self.path = util.svn_path_join(self.repos_path, path) 
     227         
    226228        if not rev: 
    227229            rev_specified = 0 
    228230            rev = svn.fs.youngest_rev(self.fs_ptr, self.pool) 
  • Log.py

    diff -u trac-dist/Log.py trac/Log.py
    old new  
    102102    def render (self): 
    103103        self.perm.assert_permission (perm.LOG_VIEW) 
    104104 
    105         self.path = self.args.get('path', '/') 
     105        self.path = svn_path_join(self.repos_path, self.args.get('path', '/')) 
    106106        if self.args.has_key('rev'): 
    107107            try: 
    108108                rev = int(self.args.get('rev')) 
  • core.py

    diff -u trac-dist/core.py trac/core.py
    old new  
    151151    if need_svn: 
    152152        import sync 
    153153        repos_dir = env.get_config('trac', 'repository_dir') 
     154        repos_path = env.get_config('trac', 'repository_path') 
    154155        pool, rep, fs_ptr = open_svn_repos(repos_dir) 
    155156        module.repos = rep 
     157        module.repos_path = repos_path         
    156158        module.fs_ptr = fs_ptr 
    157         sync.sync(module.db, rep, fs_ptr, pool) 
     159        sync.sync(module.db, rep, repos_path, fs_ptr, pool) 
    158160        module.pool = pool 
    159161    return module 
    160162 
  • sync.py

    diff -u trac-dist/sync.py trac/sync.py
    old new  
    2020# Author: Jonas Borgstr�jonas@edgewall.com> 
    2121 
    2222from util import * 
    23 from svn import fs, util, delta, repos, core 
     23from svn import fs, util, delta, core, repos 
    2424 
    25 def sync(db, repos, fs_ptr, pool): 
     25def sync(db, repo, repos_path, fs_ptr, pool): 
    2626    """ 
    2727    updates the revision and node_change tables to be in sync with 
    2828    the repository. 
     
    3636    cursor = db.cursor() 
    3737    cursor.execute('SELECT ifnull(max(rev), 0) FROM revision') 
    3838    youngest_stored =  int(cursor.fetchone()[0]) 
     39     
    3940    max_rev = fs.youngest_rev(fs_ptr, pool) 
    40     num = max_rev - youngest_stored 
    41     offset = youngest_stored + 1 
     41 
     42    revision_set = [] 
    4243     
     44    if repos_path: 
     45        revision_set = get_revision_set( 
     46            db, 
     47            repo, 
     48            repos_path, 
     49            fs_ptr, 
     50            pool, 
     51            youngest_stored, 
     52            max_rev 
     53            ) 
     54 
     55    if not revision_set and not repos_path: 
     56        revision_set = range(youngest_stored+1, max_rev) 
     57 
    4358    subpool = core.svn_pool_create(pool) 
    44     for rev in range(num): 
    45         message = fs.revision_prop(fs_ptr, rev + offset, 
     59    for rev in revision_set: 
     60        message = fs.revision_prop(fs_ptr, rev, 
    4661                                   util.SVN_PROP_REVISION_LOG, subpool) 
    47         author = fs.revision_prop(fs_ptr, rev + offset, 
     62        author = fs.revision_prop(fs_ptr, rev, 
    4863                                  util.SVN_PROP_REVISION_AUTHOR, subpool) 
    49         date = fs.revision_prop(fs_ptr, rev + offset, 
     64        date = fs.revision_prop(fs_ptr, rev, 
    5065                                util.SVN_PROP_REVISION_DATE, subpool) 
    5166 
    5267        date = util.svn_time_from_cstring(date, subpool) / 1000000 
    5368         
    5469        cursor.execute ('INSERT INTO revision (rev, time, author, message) ' 
    55                         'VALUES (%s, %s, %s, %s)', rev + offset, date, 
     70                        'VALUES (%s, %s, %s, %s)', rev, date, 
    5671                        author, message) 
    57         insert_change (subpool, fs_ptr, rev + offset, cursor) 
     72        insert_change (subpool, fs_ptr, rev, repos_path, cursor) 
    5873        core.svn_pool_clear(subpool) 
    5974 
    6075    core.svn_pool_destroy(subpool) 
    6176    db.commit() 
    6277 
    63 def insert_change (pool, fs_ptr, rev, cursor): 
     78def insert_change (pool, fs_ptr, rev, repos_path, cursor): 
    6479     
    6580    class ChangeEditor(delta.Editor): 
    66         def __init__(self, rev, old_root, new_root, cursor): 
     81        def __init__(self, rev, old_root, new_root, repos_path, cursor): 
    6782            self.rev = rev 
    6883            self.cursor = cursor 
    6984            self.old_root = old_root 
    7085            self.new_root = new_root 
     86            self.repos_path = repos_path 
    7187         
    7288        def delete_entry(self, path, revision, parent_baton, pool): 
     89            if not path.startswith( self.repos_path): 
     90                return 
    7391            self.cursor.execute('INSERT INTO node_change (rev, name, change) ' 
    7492                                'VALUES (%s, %s, \'D\')', self.rev, path) 
    7593         
    7694        def add_directory(self, path, parent_baton, 
    7795                          copyfrom_path, copyfrom_revision, dir_pool): 
     96            if not path.startswith( self.repos_path): 
     97                return 
    7898            self.cursor.execute('INSERT INTO node_change (rev, name, change) ' 
    7999                                'VALUES (%s, %s, \'A\')', self.rev, path) 
    80100 
    81101        def add_file(self, path, parent_baton, 
    82102                     copyfrom_path, copyfrom_revision, file_pool): 
     103            if not path.startswith( self.repos_path): 
     104                return 
    83105            self.cursor.execute('INSERT INTO node_change (rev, name, change) ' 
    84106                                'VALUES (%s, %s, \'A\')',self.rev, path) 
    85107             
    86108        def open_file(self, path, parent_baton, base_revision, file_pool): 
     109            if not path.startswith( self.repos_path): 
     110                return             
    87111            self.cursor.execute('INSERT INTO node_change (rev, name, change) ' 
    88112                                'VALUES (%s, %s, \'M\')',self.rev, path) 
    89113 
     
    91115    old_root = fs.revision_root(fs_ptr, rev - 1, pool) 
    92116    new_root = fs.revision_root(fs_ptr, rev, pool) 
    93117     
    94     editor = ChangeEditor(rev, old_root, new_root, cursor) 
     118    editor = ChangeEditor(rev, old_root, new_root, repos_path, cursor) 
    95119    e_ptr, e_baton = delta.make_editor(editor, pool) 
    96120 
    97121    if util.SVN_VER_MAJOR == 0 and util.SVN_VER_MINOR == 37: 
     
    104128                                  new_root, '', e_ptr, e_baton, authz_cb, 
    105129                                  0, 1, 0, 1, pool) 
    106130 
     131def get_revision_set( db, repo, repos_path, fs_ptr, pool, youngest_stored, max_rev): 
     132    revision_set = [] 
     133    root = fs.revision_root(fs_ptr, max_rev, pool) 
     134    node_type = fs.check_path(root, repos_path, pool) 
     135 
     136    if not node_type in (core.svn_node_dir, core.svn_node_file): 
     137        raise ValueError("Svn Repository Path Invalid %r"%repos_path) 
     138     
     139    revs = [] 
     140     
     141    def addLog( paths, revision, author, date, message, pool): 
     142        revs.append(revision) 
     143 
     144    repos.svn_repos_get_logs( 
     145            repo, 
     146            [repos_path], 
     147            max_rev, # start rev 
     148            0, # end rev 
     149            0, # changed paths 
     150            0, # strict history 
     151            addLog, 
     152            pool 
     153            ) 
     154 
     155    revs.sort() 
     156    for rev in revs: 
     157        if rev > youngest_stored: 
     158            revision_set.append( rev ) 
     159 
     160    return revision_set 
  • util.py

    Only in trac-dist: tests
    Common subdirectories: trac-dist/upgrades and trac/upgrades
    diff -u trac-dist/util.py trac/util.py
    old new  
    2929TRUE =  ['yes', '1', 1, 'true',  'on',  'aye'] 
    3030FALSE = ['no',  '0', 0, 'false', 'off', 'nay'] 
    3131 
     32def svn_path_join(*args): 
     33    return "/%s"%'/'.join(filter(None, '/'.join(args).split('/'))) 
     34 
    3235def svn_date_to_string(date, pool): 
    3336    from svn import util 
    3437    date_seconds = util.svn_time_from_cstring(date,