Author: brane
Date: Sun Mar 11 15:10:29 2012
New Revision: 1299374
URL: http://svn.apache.org/viewvc?rev=1299374&view=rev
Log:
This script parses the complete verbose XML log of a repository and
imports the results into a directory index.
Requires the changelist ordering fix from r1299323.
* notes/directory-index/logimport.py: New.
Added:
subversion/trunk/notes/directory-index/logimport.py (with props)
Added: subversion/trunk/notes/directory-index/logimport.py
URL:
http://svn.apache.org/viewvc/subversion/trunk/notes/directory-index/logimport.py?rev=1299374&view=auto
==============================================================================
--- subversion/trunk/notes/directory-index/logimport.py (added)
+++ subversion/trunk/notes/directory-index/logimport.py Sun Mar 11 15:10:29 2012
@@ -0,0 +1,110 @@
+#!/usr/bin/env python
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements. See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership. The ASF licenses this file
+# to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance
+# with the License. You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing,
+# software distributed under the License is distributed on an
+# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+# KIND, either express or implied. See the License for the
+# specific language governing permissions and limitations
+# under the License.
+
+# Usage: logimport <database-name> <repoa-url> [path-to-svn]
+#
+# Converts the history of the repository at <repos-url> into a
+# single-tree directory index.
+
+
+import logging
+import subprocess
+import sys
+from xml.etree import ElementTree
+from dirindex import Index, Revision
+
+
+def parse(index, stream):
+ kindmap = {"dir": 0, "file": 1}
+
+ for event, logentry in ElementTree.iterparse(stream):
+ if logentry.tag != "logentry":
+ continue
+
+ version = int(logentry.get("revision"))
+ if version == 1 or not version % 1000:
+ logging.info("r%d", version)
+ else:
+ logging.debug("r%d", version)
+
+ created = logentry.find("date")
+ if created is not None:
+ created = created.text
+ else:
+ created = ""
+
+ author = logentry.find("author")
+ if author is not None:
+ author = author.text
+
+ log = logentry.find("msg")
+ if log is not None:
+ log = log.text
+
+ with Revision(index, version, created, author, log) as rev:
+ actionmap = dict(A = (rev.add, True),
+ R = (rev.replace, True),
+ M = (rev.modify, False),
+ D = (rev.delete, False))
+
+ for path in logentry.findall("paths/path"):
+ abspath = path.text
+ action = path.get("action")
+ handler, newnode = actionmap[action]
+ if not newnode:
+ logging.debug(" %-s %s", action, abspath)
+ handler(abspath)
+ continue
+
+ kindstr = path.get("kind")
+ kind = kindmap[kindstr]
+ frompath = path.get("copyfrom-path")
+ if frompath is not None:
+ fromrev = int(path.get("copyfrom-rev"))
+ logging.debug(" %s %-4s %s <- %s@%d",
+ action, kindstr, abspath,
+ frompath, fromrev)
+ handler(abspath, kind, frompath, fromrev)
+ else:
+ logging.debug(" %s %-4s %s", action, kindstr, abspath)
+ handler(abspath, kind)
+ pass
+
+
+def logimport(database, url, svn):
+ index = Index(database)
+ index.initialize()
+ index.cursor.execute("PRAGMA journal_mode = MEMORY")
+ index.cursor.execute("PRAGMA locking_mode = EXCLUSIVE")
+ index.cursor.execute("PRAGMA synchronous = OFF")
+ svnlog = subprocess.Popen(
+ [svn, "log", "-v", "--xml", "-r1:HEAD", url],
+ stdout = subprocess.PIPE)
+ parse(index, svnlog.stdout)
+ sys.exit(svnlog.wait())
+
+
+if __name__ == "__main__":
+ database = sys.argv[1]
+ url = sys.argv[2]
+ if len(sys.argv) > 3:
+ svn = sys.argv[3]
+ else:
+ svn = "svn"
+ logging.basicConfig(level=logging.INFO, stream=sys.stderr)
+ logimport(database, url, svn)
Propchange: subversion/trunk/notes/directory-index/logimport.py
------------------------------------------------------------------------------
svn:executable = *