def load(self, repo_path): repo_path = core.svn_path_canonicalize(repo_path) repos_ptr = repos.open(repo_path) fs_ptr = repos.fs(repos_ptr) rev = fs.youngest_rev(fs_ptr) base_root = fs.revision_root(fs_ptr, 0) root = fs.revision_root(fs_ptr, rev) hist = fs.node_history(root, self.root) while hist is not None: hist = fs.history_prev(hist, 0) dummy, rev = fs.history_location(hist) d = fs.revision_prop(fs_ptr, rev, core.SVN_PROP_REVISION_DATE) author = fs.revision_prop(fs_ptr, rev, \ core.SVN_PROP_REVISION_AUTHOR) if author == 'svnadmin': continue self.last_author = author self.last_date = core.svn_time_from_cstring(d) / 1000000 self.last_rev = rev def authz_cb(root, path, pool): return 1 editor = SvnDumperEditor(self) e_ptr, e_baton = delta.make_editor(editor) repos.dir_delta(base_root, '', '', root, self.root, e_ptr, e_baton, authz_cb, 0, 1, 0, 0) break
def load(self, repo_path): repo_path = core.svn_path_canonicalize(repo_path) repos_ptr = repos.open(repo_path) fs_ptr = repos.fs(repos_ptr) rev = fs.youngest_rev(fs_ptr) base_root = fs.revision_root(fs_ptr, 0) root = fs.revision_root(fs_ptr, rev) hist = fs.node_history(root, self.root) while hist is not None: hist = fs.history_prev(hist,0) dummy,rev = fs.history_location(hist) d = fs.revision_prop(fs_ptr, rev, core.SVN_PROP_REVISION_DATE) author = fs.revision_prop(fs_ptr, rev, \ core.SVN_PROP_REVISION_AUTHOR) if author == 'svnadmin': continue self.last_author = author self.last_date = core.svn_time_from_cstring(d) / 1000000 self.last_rev = rev def authz_cb(root, path, pool): return 1 editor = SvnDumperEditor(self) e_ptr, e_baton = delta.make_editor(editor) repos.dir_delta(base_root, '', '', root, self.root, e_ptr, e_baton, authz_cb, 0, 1, 0, 0) break
def get_last_modified(self): _date = fs.revision_prop(self.fs_ptr, self.created_rev, core.SVN_PROP_REVISION_DATE, self.pool()) if not _date: return None return core.svn_time_from_cstring(_date, self.pool()) / 1000000
def __init__(self, rev, authz, scope, fs_ptr): self.rev = rev self.authz = authz self.scope = scope self.fs_ptr = fs_ptr message = self._get_prop(core.SVN_PROP_REVISION_LOG) author = self._get_prop(core.SVN_PROP_REVISION_AUTHOR) date = self._get_prop(core.SVN_PROP_REVISION_DATE) date = core.svn_time_from_cstring(date) // 1000000 Changeset.__init__(self, rev, message, author, date)
def __init__(self, rev, authz, scope, fs_ptr): self.rev = rev self.authz = authz self.scope = scope self.fs_ptr = fs_ptr message = self._get_prop(core.SVN_PROP_REVISION_LOG) author = self._get_prop(core.SVN_PROP_REVISION_AUTHOR) date = self._get_prop(core.SVN_PROP_REVISION_DATE) date = core.svn_time_from_cstring(date) / 1000000 Changeset.__init__(self, rev, message, author, date)
def cmd_date(self): if self.txn_ptr: print("") else: date = self._get_property(core.SVN_PROP_REVISION_DATE) if date: aprtime = core.svn_time_from_cstring(date) # ### convert to a time_t; this requires intimate knowledge of # ### the apr_time_t type secs = aprtime / 1000000 # aprtime is microseconds; make seconds # assume secs in local TZ, convert to tuple, and format ### we don't really know the TZ, do we? print(time.strftime('%Y-%m-%d %H:%M', time.localtime(secs))) else: print("")
def cmd_date(self): if self.txn_ptr: print else: date = self._get_property(core.SVN_PROP_REVISION_DATE) if date: aprtime = core.svn_time_from_cstring(date) # ### convert to a time_t; this requires intimate knowledge of # ### the apr_time_t type secs = aprtime / 1000000 # aprtime is microseconds; make seconds # assume secs in local TZ, convert to tuple, and format ### we don't really know the TZ, do we? print time.strftime('%Y-%m-%d %H:%M', time.localtime(secs)) else: print
def get_date(self, unixtime=False): """return commit timestamp in RFC 3339 format (2010-02-08T20:37:25.195000Z) if unixtime is True, return unix timestamp return None for a txn, or if date property is not set """ if self.txn_ptr: return None date = self._get_property(core.SVN_PROP_REVISION_DATE) if not unixtime or date == None: return date # convert to unix time aprtime = core.svn_time_from_cstring(date) # ### convert to a time_t; this requires intimate knowledge of # ### the apr_time_t type secs = aprtime / 1000000 # aprtime is microseconds; make seconds return secs
def __init__(self, rev, scope, fs_ptr, pool=None): self.rev = rev self.scope = scope self.fs_ptr = fs_ptr self.pool = Pool(pool) try: self.message = self._get_prop(core.SVN_PROP_REVISION_LOG) except: raise('No such changeset') self.author = self._get_prop(core.SVN_PROP_REVISION_AUTHOR) self.message = self.message and to_unicode(self.message, 'utf-8') self.author = self.author and to_unicode(self.author, 'utf-8') _date = self._get_prop(core.SVN_PROP_REVISION_DATE) if _date: self.date = core.svn_time_from_cstring(_date, self.pool()) / 1000000 else: self.date = None
def get_date(self, unixtime=False): """return commit timestamp in RFC 3339 format (2010-02-08T20:37:25.195000Z) if unixtime is True, return unix timestamp return None if date is not set (txn properties) """ if self.txn_ptr: return None date = self._get_property(core.SVN_PROP_REVISION_DATE) if not unixtime or date == None: return date # convert to unix time aprtime = core.svn_time_from_cstring(date) # ### convert to a time_t; this requires intimate knowledge of # ### the apr_time_t type secs = aprtime / 1000000 # aprtime is microseconds; make seconds return secs
def sync(db, repos, fs_ptr, pool): """ updates the revision and node_change tables to be in sync with the repository. """ if core.SVN_VER_MAJOR < 1: raise EnvironmentError, \ "Subversion >= 1.0 required: Found %d.%d.%d" % \ (core.SVN_VER_MAJOR, core.SVN_VER_MINOR, core.SVN_VER_MICRO) cursor = db.cursor() cursor.execute('SELECT ifnull(max(rev), 0) FROM revision') youngest_stored = int(cursor.fetchone()[0]) max_rev = fs.youngest_rev(fs_ptr, pool) num = max_rev - youngest_stored offset = youngest_stored + 1 subpool = core.svn_pool_create(pool) for rev in range(num): message = fs.revision_prop(fs_ptr, rev + offset, core.SVN_PROP_REVISION_LOG, subpool) author = fs.revision_prop(fs_ptr, rev + offset, core.SVN_PROP_REVISION_AUTHOR, subpool) date = fs.revision_prop(fs_ptr, rev + offset, core.SVN_PROP_REVISION_DATE, subpool) date = core.svn_time_from_cstring(date, subpool) / 1000000 cursor.execute( 'INSERT INTO revision (rev, time, author, message) ' 'VALUES (%s, %s, %s, %s)', rev + offset, date, author, message) insert_change(subpool, fs_ptr, rev + offset, cursor) core.svn_pool_clear(subpool) core.svn_pool_destroy(subpool) db.commit()
def test_commit(self): # Replace README.txt's contents, using binary mode so we know the # exact contents even on Windows, and therefore the MD5 checksum. readme_path = "%s/trunk/README.txt" % self.path fp = open(readme_path, "wb") fp.write("hello\n") fp.close() # Setup ra_ctx. ra.initialize() callbacks = ra.Callbacks() ra_ctx = ra.open2(REPOS_URL, callbacks, None, None) # Get commit editor. commit_info = [None] def commit_cb(_commit_info, pool): commit_info[0] = _commit_info (editor, edit_baton) = ra.get_commit_editor2(ra_ctx, "log message", commit_cb, None, False) # Drive the commit. checksum = [None] def driver_cb(parent, path, pool): baton = editor.open_file(path, parent, -1, pool) adm_access = wc.adm_probe_retrieve(self.wc, readme_path, pool) (_, checksum[0]) = wc.transmit_text_deltas2(readme_path, adm_access, False, editor, baton, pool) return baton try: delta.path_driver(editor, edit_baton, -1, ["trunk/README.txt"], driver_cb) editor.close_edit(edit_baton) except: try: editor.abort_edit(edit_baton) except: # We already have an exception in progress, not much we can do # about this. pass raise (checksum,) = checksum (commit_info,) = commit_info # Assert the commit. self.assertEquals(binascii.b2a_hex(checksum), "b1946ac92492d2347c6235b4d2611184") self.assertEquals(commit_info.revision, 13) # Bump working copy state. wc.process_committed4( readme_path, wc.adm_retrieve(self.wc, os.path.dirname(readme_path)), False, commit_info.revision, commit_info.date, commit_info.author, None, False, False, checksum, ) # Assert bumped state. entry = wc.entry(readme_path, self.wc, False) self.assertEquals(entry.revision, commit_info.revision) self.assertEquals(entry.schedule, wc.schedule_normal) self.assertEquals(entry.cmt_rev, commit_info.revision) self.assertEquals(entry.cmt_date, core.svn_time_from_cstring(commit_info.date))
def _format_date(self, date): date = core.svn_time_from_cstring(date) date = time.asctime(time.localtime(date / 1000000)) return date[4:-8]
def get_last_modified(self): date = fs.revision_prop(self.fs_ptr, self.created_rev, core.SVN_PROP_REVISION_DATE) return core.svn_time_from_cstring(date) // 1000000
def svn_date_to_string(date, pool): from svn import core date_seconds = core.svn_time_from_cstring(date, pool) / 1000000 return time.strftime('%x %X', time.localtime(date_seconds))
def _datestr_to_date(datestr): try: return core.svn_time_from_cstring(datestr) // 1000000 except Exception: return None
def _datestr_to_date(datestr, pool): if datestr is None: return None return core.svn_time_from_cstring(datestr, pool) / 1000000
if start_rev > rev and end_rev > rev: sys.exit(exit) if start_rev > rev: start_rev = rev if end_rev > rev: end_rev = rev for current_rev in range(start_rev, end_rev + 1): #get comment log log = fs.revision_prop(fs_ptr, current_rev, core.SVN_PROP_REVISION_LOG) or '' #make dir folder_num = current_rev / 1000 file_folder = changeset_folder + '\\' + str(folder_num) if not os.path.exists(file_folder): os.makedirs(file_folder) #make file filename = file_folder + '\\' + str(current_rev) + '.txt' f = open(filename, 'w') f.write(log) f.close() #file update time date = fs.revision_prop(fs_ptr, current_rev, core.SVN_PROP_REVISION_DATE) aprtime = core.svn_time_from_cstring(date) secs = aprtime / 1000000 # aprtime is microseconds; make seconds timestr = time.strftime('%Y-%m-%d-%H:%M:%S', time.localtime(secs)) atime = mtime = time.mktime(time.strptime(timestr, '%Y-%m-%d-%H:%M:%S')) os.utime(filename, (atime, mtime))
def test_commit(self): # Replace README.txt's contents, using binary mode so we know the # exact contents even on Windows, and therefore the MD5 checksum. readme_path = '%s/trunk/README.txt' % self.path fp = open(readme_path, 'wb') fp.write('hello\n') fp.close() # Setup ra_ctx. ra.initialize() callbacks = ra.Callbacks() ra_ctx = ra.open2(REPOS_URL, callbacks, None, None) # Get commit editor. commit_info = [None] def commit_cb(_commit_info, pool): commit_info[0] = _commit_info (editor, edit_baton) = ra.get_commit_editor2(ra_ctx, 'log message', commit_cb, None, False) # Drive the commit. checksum = [None] def driver_cb(parent, path, pool): baton = editor.open_file(path, parent, -1, pool) adm_access = wc.adm_probe_retrieve(self.wc, readme_path, pool) (_, checksum[0]) = wc.transmit_text_deltas2(readme_path, adm_access, False, editor, baton, pool) return baton try: delta.path_driver(editor, edit_baton, -1, ['trunk/README.txt'], driver_cb) editor.close_edit(edit_baton) except: try: editor.abort_edit(edit_baton) except: # We already have an exception in progress, not much we can do # about this. pass raise (checksum, ) = checksum (commit_info, ) = commit_info # Assert the commit. self.assertEquals(binascii.b2a_hex(checksum), 'b1946ac92492d2347c6235b4d2611184') self.assertEquals(commit_info.revision, 13) # Bump working copy state. wc.process_committed4( readme_path, wc.adm_retrieve(self.wc, os.path.dirname(readme_path)), False, commit_info.revision, commit_info.date, commit_info.author, None, False, False, checksum) # Assert bumped state. entry = wc.entry(readme_path, self.wc, False) self.assertEquals(entry.revision, commit_info.revision) self.assertEquals(entry.schedule, wc.schedule_normal) self.assertEquals(entry.cmt_rev, commit_info.revision) self.assertEquals(entry.cmt_date, core.svn_time_from_cstring(commit_info.date))
def _datestr_to_date(datestr): try: return core.svn_time_from_cstring(datestr) / 1000000 except: return None
def date(self): "comitted datetime of this revision. utc, microsecond=0" d = self._prop(core.SVN_PROP_REVISION_DATE) if not d: return None return datetime.datetime(*time.gmtime(core.svn_time_from_cstring(d) / 1000000)[:6])
def get_last_modified(self): date = fs.revision_prop(self.fs_ptr, self.created_rev, core.SVN_PROP_REVISION_DATE) return core.svn_time_from_cstring(date) / 1000000