def log_receiver (self, changed_paths, rev, author, date, log, pool): if not changed_paths: return # Store the copyfrom-information so we can follow the file/dir # through tags/banches/copy/renames. for newpath in changed_paths.keys(): change = changed_paths[newpath] if change.copyfrom_path: self.branch_info.setdefault(rev, []).append((change.copyfrom_path, newpath)) shortlog = util.shorten_line(util.wiki_escape_newline(log)) t = svn.core.svn_time_from_cstring(date, pool) / 1000000 gmt = time.gmtime(t) item = { 'rev' : rev, 'author' : author and util.escape(author) or 'None', 'date' : util.svn_date_to_string (date, pool), 'gmt' : time.strftime('%a, %d %b %Y %H:%M:%S GMT', gmt), 'log.raw' : util.escape(log), 'log' : wiki_to_oneliner(util.shorten_line(util.wiki_escape_newline(log)), self.req.hdf, self.env,self.db), 'shortlog' : util.escape(shortlog), 'file_href': self.env.href.browser(self.path, rev), 'changeset_href': self.env.href.changeset(rev) } self.log_info.insert (0, item)
def render(self): self.perm.assert_permission(perm.CHANGESET_VIEW) self.add_link('alternate', '?format=diff', 'Unified Diff', 'text/plain', 'diff') youngest_rev = svn.fs.youngest_rev(self.fs_ptr, self.pool) if self.args.has_key('rev'): self.rev = int(self.args.get('rev')) else: self.rev = youngest_rev Diff.get_options(self.env, self.req, self.args, 1) if self.args.has_key('update'): self.req.redirect(self.env.href.changeset(self.rev)) change_info = self.get_change_info(self.rev) changeset_info = self.get_changeset_info(self.rev) self.req.hdf.setValue('title', '[%d] (changeset)' % self.rev) self.req.hdf.setValue( 'changeset.time', time.asctime(time.localtime(int(changeset_info['time'])))) author = changeset_info['author'] or 'anonymous' self.req.hdf.setValue('changeset.author', util.escape(author)) message = changeset_info['message'] or '--' self.req.hdf.setValue( 'changeset.message', wiki_to_html(util.wiki_escape_newline(message), self.req.hdf, self.env, self.db)) self.req.hdf.setValue('changeset.revision', str(self.rev)) util.add_dictlist_to_hdf(change_info, self.req.hdf, 'changeset.changes') self.req.hdf.setValue('changeset.href', self.env.href.changeset(self.rev)) if self.rev > 1: self.add_link('first', self.env.href.changeset(1), 'Changeset 1') self.add_link('prev', self.env.href.changeset(self.rev - 1), 'Changeset %d' % (self.rev - 1)) if self.rev < youngest_rev: self.add_link('next', self.env.href.changeset(self.rev + 1), 'Changeset %d' % (self.rev + 1)) self.add_link('last', self.env.href.changeset(youngest_rev), 'Changeset %d' % youngest_rev)
def get_info(self, path, revision, rev_specified): """ Extracts information for a given path and revision """ # We need to really make sure it's an ordinary string. The FieldStorage # class provided by modpython might give us some strange string-like object # that svn doesn't like. path = str(path) try: root = svn.fs.revision_root(self.fs_ptr, revision, self.pool) except svn.core.SubversionException: raise util.TracError('Invalid revision number: %d' % revision) node_type = svn.fs.check_path(root, path, self.pool) if not node_type in [svn.core.svn_node_dir, svn.core.svn_node_file]: raise util.TracError('"%s": no such file or directory in revision %d' \ % (path, revision), 'No such file or directory') # Redirect to the file module if the requested path happens # to point to a regular file if svn.fs.is_file(root, path, self.pool): if rev_specified: self.req.redirect(self.env.href.file(path, revision)) else: self.req.redirect(self.env.href.log(path)) entries = svn.fs.dir_entries(root, path, self.pool) info = [] for item in entries.keys(): fullpath = posixpath.join(path, item) is_dir = svn.fs.is_dir(root, fullpath, self.pool) if is_dir: name = item + '/' fullpath = fullpath + '/' else: name = item created_rev = svn.fs.node_created_rev(root, fullpath, self.pool) date = svn.fs.revision_prop(self.fs_ptr, created_rev, svn.core.SVN_PROP_REVISION_DATE, self.pool) if date: date_seconds = svn.core.svn_time_from_cstring(date, self.pool) / 1000000 date = time.strftime('%x %X', time.localtime(date_seconds)) else: date_seconds = 0 date = '' author = svn.fs.revision_prop(self.fs_ptr, created_rev, svn.core.SVN_PROP_REVISION_AUTHOR, self.pool) change = svn.fs.revision_prop(self.fs_ptr, created_rev, svn.core.SVN_PROP_REVISION_LOG, self.pool) item = { 'name' : name, 'fullpath' : fullpath, 'created_rev' : created_rev, 'date' : date, 'date_seconds' : date_seconds, 'age' : util.pretty_age(date_seconds), 'is_dir' : is_dir, 'author' : author, 'change' : wiki_to_oneliner(util.shorten_line(util.wiki_escape_newline(change)), self.req.hdf, self.env,self.db), 'permission' : self.authzperm.has_permission(fullpath) } if rev_specified: item['log_href'] = self.env.href.log(fullpath, revision) if is_dir: item['browser_href'] = self.env.href.browser(fullpath, revision) else: item['browser_href'] = self.env.href.file(fullpath, revision) else: item['log_href'] = self.env.href.log(fullpath) if is_dir: item['browser_href'] = self.env.href.browser(fullpath) else: item['browser_href'] = self.env.href.file(fullpath) info.append(item) return info
def render(self): FileCommon.render(self) self.rev = self.args.get('rev', None) self.path = self.args.get('path', '/') if not self.rev: rev_specified = 0 self.rev = svn.fs.youngest_rev(self.fs_ptr, self.pool) else: rev_specified = 1 try: self.rev = int(self.rev) except ValueError: rev_specified = 0 self.rev = svn.fs.youngest_rev(self.fs_ptr, self.pool) self.generate_path_links(self.rev, rev_specified) try: root = svn.fs.revision_root(self.fs_ptr, self.rev, self.pool) except svn.core.SubversionException: self.rev = svn.fs.youngest_rev(self.fs_ptr, self.pool) root = svn.fs.revision_root(self.fs_ptr, self.rev, self.pool) node_type = svn.fs.check_path(root, self.path, self.pool) if not node_type in [svn.core.svn_node_dir, svn.core.svn_node_file]: self.rev = svn.fs.youngest_rev(self.fs_ptr, self.pool) root = svn.fs.revision_root(self.fs_ptr, self.rev, self.pool) oh = svn.fs.node_history(root, self.path, self.pool) while oh: h = oh oh = svn.fs.history_prev(h, 0, self.pool) history = h else: history = svn.fs.node_history(root, self.path, self.pool) history = svn.fs.history_prev(history, 0, self.pool) history_path, history_rev = svn.fs.history_location(history, self.pool); if self.rev != history_rev: self.rev = history_rev author = svn.fs.revision_prop(self.fs_ptr, self.rev, svn.core.SVN_PROP_REVISION_AUTHOR, self.pool) msg = svn.fs.revision_prop(self.fs_ptr, self.rev, svn.core.SVN_PROP_REVISION_LOG, self.pool) msg_html = wiki_to_html(util.wiki_escape_newline(msg), self.req.hdf, self.env, self.db) date = svn.fs.revision_prop(self.fs_ptr, self.rev, svn.core.SVN_PROP_REVISION_DATE, self.pool) sdate = util.svn_date_to_string(date, self.pool) self.req.hdf.setValue('file.chgset_href', self.env.href.changeset(self.rev)) self.req.hdf.setValue('file.rev', str(self.rev)) self.req.hdf.setValue('file.rev_author', str(author)) self.req.hdf.setValue('file.rev_date', sdate) self.req.hdf.setValue('file.rev_msg', msg_html) self.req.hdf.setValue('file.path', self.path) self.req.hdf.setValue('file.logurl', saxutils.escape(self.env.href.log(self.path, self.rev))) # Try to do an educated guess about the mime-type self.mime_type = svn.fs.node_prop (root, self.path, svn.util.SVN_PROP_MIME_TYPE, self.pool) if not self.mime_type: self.mime_type = self.env.mimeview.get_mimetype(filename=self.path) or \ 'text/plain' elif self.mime_type == 'application/octet-stream': self.mime_type = self.env.mimeview.get_mimetype(filename=self.path) or \ 'application/octet-stream' self.add_link('alternate', self.env.href.file(self.path, self.rev, 'raw'), 'Original Format', self.mime_type) self.add_link('alternate', self.env.href.file(self.path, self.rev, 'txt'), 'Plain Text', 'text/plain') self.length = svn.fs.file_length(root, self.path, self.pool) date = svn.fs.revision_prop(self.fs_ptr, self.rev, svn.util.SVN_PROP_REVISION_DATE, self.pool) date_seconds = svn.util.svn_time_from_cstring(date, self.pool) / 1000000 self.last_modified = time.strftime("%a, %d %b %Y %H:%M:%S GMT", time.gmtime(date_seconds)) fd = svn.fs.file_contents(root, self.path, self.pool) self.read_func = lambda x, f=fd: svn.util.svn_stream_read(f, x)