From d94bf72dd7269e126990bb28518c16f68cc5d6cb Mon Sep 17 00:00:00 2001 From: Tony Duckles Date: Sat, 17 Mar 2012 00:40:18 -0500 Subject: [PATCH] WIP on diff-summarize --- svn2svn/run/svn2svn.py | 3 +++ svn2svn/svnclient.py | 30 ++++++++++++++++++++++++++++++ 2 files changed, 33 insertions(+) diff --git a/svn2svn/run/svn2svn.py b/svn2svn/run/svn2svn.py index 54e7368..1c88433 100644 --- a/svn2svn/run/svn2svn.py +++ b/svn2svn/run/svn2svn.py @@ -533,6 +533,9 @@ def process_svn_log_entry(log_entry, ancestors, commit_paths, prefix = ""): source_url = log_entry['url'] source_base = source_url[len(source_repos_url):] # e.g. '/trunk' ui.status(prefix + ">> process_svn_log_entry: %s", source_url+"@"+str(source_rev), level=ui.DEBUG, color='GREEN') + diff_paths = svnclient.get_diff_summarize(source_repos_url, source_url, source_rev) + for d in diff_paths: + print "%s,%s %s" % (d['item'], d['props'], d['path']) for d in log_entry['changed_paths']: # Get the full path for this changed_path # e.g. '/branches/bug123/projectA/file1.txt' diff --git a/svn2svn/svnclient.py b/svn2svn/svnclient.py index efb3212..bc4e15a 100644 --- a/svn2svn/svnclient.py +++ b/svn2svn/svnclient.py @@ -453,3 +453,33 @@ def get_all_props(svn_url_or_wc, rev_number=None): d = get_prop_value(svn_url_or_wc, prop_name, rev_number) l[d['name']] = d['value'] return l + +def parse_diff_summarize(svn_repos_url, svn_url_or_wc, xml_string): + """ + Parse the XML output from an "svn diff -c REV --xml --summarize" command + and extract useful info as list of dicts (one per path entry). + """ + l = [] + xml_string = strip_forbidden_xml_chars(xml_string) + tree = ET.fromstring(xml_string) + paths = [] + for path in tree.findall('.//paths/path'): + paths.append({ + 'path': path.text[len(svn_repos_url):], + 'kind': path.get('kind'), + 'props': path.get('props'), + 'item': path.get('item'), + }) + # Sort paths (i.e. into hierarchical order), so that process_svn_log_entry() + # can process actions in depth-first order. + return sorted(paths, key=operator.itemgetter('path')) + +def get_diff_summarize(svn_repos_url, svn_url_or_wc, rev_number): + args = ['diff', '--xml', '--summarize', '--notice-ancestry'] + url = str(svn_url_or_wc) + args += ['-c', rev_number] + if not "@" in svn_url_or_wc: + url = "%s@%s" % (svn_url_or_wc, str(rev_number)) + args += [url] + xml_string = run_svn(args) + return parse_diff_summarize(svn_repos_url, svn_url_or_wc, xml_string) -- 2.49.0