From 9f263aa1278ef5c0a5660b4a8a94c1d59eda1edb Mon Sep 17 00:00:00 2001 From: Tony Duckles Date: Wed, 8 Feb 2012 21:25:24 -0600 Subject: [PATCH] Update process_svn_log_entry() to calculate d['kind'] if missing. Back-out changes from parse_svn_log_xml() to auto-calculate d['kind'] if not returned by "svn log --xml", since not all callers need d['kind']; just calculate on-demand where needed. --- svn2svn/run/svn2svn.py | 3 +++ svn2svn/svnclient.py | 21 +++++---------------- 2 files changed, 8 insertions(+), 16 deletions(-) diff --git a/svn2svn/run/svn2svn.py b/svn2svn/run/svn2svn.py index 90be23d..0a7d85f 100644 --- a/svn2svn/run/svn2svn.py +++ b/svn2svn/run/svn2svn.py @@ -468,6 +468,9 @@ def process_svn_log_entry(log_entry, options, commit_paths, prefix = ""): ui.status(prefix + ">> process_svn_log_entry: Unrelated path: %s (base: %s)", path, source_base, level=ui.DEBUG, color='GREEN') continue # Note: d['kind']="" for action="M" paths which only have property changes. + if d['kind'] == "": + d['kind'] = svnclient.get_kind(source_repos_url, path, source_rev, d['action'], log_entry['changed_paths']) + assert (d['kind'] == 'file') or (d['kind'] == 'dir') path_is_dir = True if d['kind'] == 'dir' else False path_is_file = True if d['kind'] == 'file' else False # Calculate the offset (based on source_base) for this changed_path diff --git a/svn2svn/svnclient.py b/svn2svn/svnclient.py index 02490b3..7f2a398 100644 --- a/svn2svn/svnclient.py +++ b/svn2svn/svnclient.py @@ -66,7 +66,7 @@ def parse_svn_info_xml(xml_string): d['last_changed_date'] = svn_date_to_timestamp(tree.find('.//commit/date').text) return d -def _get_kind(svn_repos_url, svn_path, svn_rev, action, paths): +def get_kind(svn_repos_url, svn_path, svn_rev, action, paths): """ Calculate the "kind"-type of a given URL in the SVN repo. """ @@ -96,22 +96,17 @@ def _get_kind(svn_repos_url, svn_path, svn_rev, action, paths): info = get_svn_info(svn_repos_url+info_path, info_rev) return info['kind'] -def parse_svn_log_xml(xml_string, svn_url_or_wc): +def parse_svn_log_xml(xml_string): """ Parse the XML output from an "svn log" command and extract useful information as a list of dicts (one per log changeset). """ l = [] - info = {} - svn_repos_url = "" xml_string = strip_forbidden_xml_chars(xml_string) tree = ET.fromstring(xml_string) for entry in tree.findall('logentry'): d = {} d['revision'] = int(entry.get('revision')) - if not info: - info = get_svn_info(svn_url_or_wc, d['revision']) - svn_repos_url = info['repos_url'] # Some revisions don't have authors, most notably the first revision # in a repository. # logentry nodes targeting directories protected by path-based @@ -132,16 +127,10 @@ def parse_svn_log_xml(xml_string, svn_url_or_wc): copyfrom_rev = path.get('copyfrom-rev') if copyfrom_rev: copyfrom_rev = int(copyfrom_rev) - cur_path = path.text - kind = path.get('kind') - action = path.get('action') - if kind == "": - kind = _get_kind(svn_repos_url, cur_path, d['revision'], action, paths) - assert (kind == 'file') or (kind == 'dir') paths.append({ 'path': path.text, - 'kind': kind, - 'action': action, + 'kind': path.get('kind'), + 'action': path.get('action'), 'copyfrom_path': path.get('copyfrom-path'), 'copyfrom_revision': copyfrom_rev, }) @@ -240,7 +229,7 @@ def run_svn_log(svn_url_or_wc, rev_start, rev_end, limit, stop_on_copy=False, ge url = "%s@%s" % (svn_url_or_wc, str(max(rev_start, rev_end))) args += ['--limit', str(limit), url] xml_string = run_svn(args) - return parse_svn_log_xml(xml_string, svn_url_or_wc) + return parse_svn_log_xml(xml_string) def get_svn_status(svn_wc, quiet=False, no_recursive=False): """ -- 2.43.0