Commits

Jason S committed ab87377

init checkin

  • Participants

Comments (0)

Files changed (3)

+syntax: glob
+**.pyc
+test/**
+test-repos/**
+.DS_Store
+**/.DS_Store

src/svnfingerprint.py

+import sys
+import io
+import gzip
+import re
+import StringIO
+
+class StreamWrapper(object):
+    def __init__(self, s):
+        self.stream = s
+        self.readstream = s
+        sig = s.read(2)
+        s.seek(0)
+        if sig == '\x1f\x8b':
+            self.readstream = gzip.GzipFile(None, None, None, s)
+    def read(self, n):
+        return self.readstream.read(n)
+    def readline(self):
+        return self.readstream.readline()
+    def close(self):
+        self.stream.close()
+    def __enter__(self):
+        return self
+    def __exit__(self, ty, value, traceback):
+        self.close()
+        
+class UnexpectedInputError(Exception):
+    def __init__(self, value):
+        self.value = value
+    def __str__(self):
+        return repr(self.value)
+
+
+def expectNewline(f):
+    line = f.readline().rstrip('\n')
+    if len(line) != 0:
+        raise UnexpectedInputError('newline expected') 
+
+parampattern = re.compile(r"^([A-Za-z0-9-]+): (.*)")
+
+def readParameters(f):
+    result = {}
+    while True:
+        line = f.readline().rstrip('\n')
+        if len(line) == 0:
+            break
+        m = parampattern.match(line)
+        result[m.group(1)] = m.group(2)
+    return result
+
+kpattern = re.compile(r"^K ([0-9]+)")
+vpattern = re.compile(r"^V ([0-9]+)")
+
+def readKeyValue(f, line, pattern):
+    m = pattern.match(line)
+    resultlen = int(m.group(1))
+    result = f.read(resultlen)
+    expectNewline(f)
+    return result    
+    
+def readRevProps(f):
+    result = {}
+    while True:
+        line = f.readline().rstrip('\n')
+        if (line == 'PROPS-END'):
+            break
+        key = readKeyValue(f, line, kpattern)
+        line = f.readline().rstrip('\n')
+        value = readKeyValue(f, line, vpattern)
+        result[key]=value
+    return result
+
+
+class SvndumpParser(object):
+    def __init__(self, f):
+        self.f = f
+        self.peek()
+        self.formatversion = self.expectParam('SVN-fs-dump-format-version')
+        self.skipBlanks()
+        self.uuid = self.expectParam('UUID')
+    def peek(self):
+        self.line = self.f.readline().rstrip()
+    def expectParam(self,k):
+        m = parampattern.match(self.line)
+        if m is None:
+            raise UnexpectedInputError("parameter expected: " +self.line) 
+        if m.group(1) != k:
+            raise UnexpectedInputError("parameter '%s' expected, got '%s'" % (k, m.group(1)))
+        self.peek()
+        return m.group(2)        
+    def readParameters(self):
+        result = {}
+        while self.line != '':
+            m = parampattern.match(self.line)
+            result[m.group(1)] = m.group(2)
+            self.peek()
+        return result
+    def readProps(self, h):
+        proplen = int(h['Prop-content-length'])
+        return readRevProps(StringIO.StringIO(self.f.read(proplen)))
+    def skipBlanks(self):
+        while (self.line == ''):
+            self.peek()
+    def readNode(self):
+        self.skipBlanks()
+        header = self.readParameters()
+        print 'header:' + str(header)
+        props = self.readProps(header)
+        print 'props:' + str(props)
+        if 'Text-content-length' in header:
+            l = int(header['Text-content-length'])
+            text = self.f.read(l)
+        self.peek()
+    def parseRevision(self):
+        self.skipBlanks()
+        header = self.readParameters()
+        print 'header:' + str(header)
+        revprops = self.readProps(header)
+        self.peek()
+
+        print 'revprops:' + str(revprops)
+        self.skipBlanks()
+        nodes = []
+        while not self.line.startswith('Revision-number'):
+            nodes.append(self.readNode())
+
+def digest(f0):
+    with StreamWrapper(f0) as f:
+        parser = SvndumpParser(f)
+        parser.parseRevision()
+        parser.parseRevision()
+        parser.parseRevision()
+
+print "hi:" + sys.argv[1]
+srcfile = sys.argv[1]
+digest(open(srcfile, 'rb'))
+#!/bin/sh
+export HERE=`pwd`
+export LOCAL=$1
+export REMOTE=$2
+export LOCALURL=file:///$HERE/$LOCAL
+
+svnadmin create $LOCAL
+echo '#!/bin/sh' > $LOCAL/hooks/pre-revprop-change
+chmod +x $LOCAL/hooks/pre-revprop-change
+
+svnsync init $LOCALURL $REMOTE
+svnsync sync $LOCALURL
+
+# see http://www.thoughtspark.org/node/10
+# and http://pogopixels.com/blog/dumping-a-svn-repository-from-a-remote-url/