--- versioncontrol.py.orig 2007-03-02 21:32:04.000000000 +0100 +++ versioncontrol.py 2007-03-03 13:43:13.000000000 +0100 @@ -133,6 +133,14 @@ raise IOError("Subversion error running '%s': %s" % (command, error)) return output +def darcsreadfile(path): + """Get a clean version of a file from the darcs repository""" + command = "cat _darcs/pristine/%s" % shellescape(path) + output, error = pipe(command) + if error: + raise IOError("darcs error running '%s': %s" % (command, error)) + return output + def svnupdatefile(path, revision=None): """Does a clean update of the given path""" path = shellescape(path) @@ -146,6 +154,14 @@ raise IOError("Subversion error running '%s': %s" % (command, error)) return output +def darcsupdatefile(path): + """Does a clean update of the given path""" + command = "darcs revert -a %s ; darcs pull -a" % shellescape(path) + output, error = pipe(command) + if error: + raise IOError("darcs error running '%s': %s" % (command, error)) + return output + def svncommitfile(path, message=None): """Commits the file and supplies the given commit message if present""" dirname = shellescape(os.path.dirname(path)) @@ -162,6 +178,16 @@ if error: raise IOError("Error running SVN command '%s': %s" % (command, error)) +def darcscommitfile(path, message=None): + """Commits the file and supplies the given commit message if present""" + file = shellescape(path) + if message is None: + message = "" + command = "darcs record -a --skip-long-comment -m '%s' %s; darcs push -a" % (message, file) + output, error = pipe(command) + if error: + raise IOError("Error running darcs command '%s': %s" % (command, error)) + def hascvs(parentdir): cvsdir = os.path.join(parentdir, "CVS") return os.path.isdir(cvsdir) @@ -170,8 +196,12 @@ svndir = os.path.join(parentdir, ".svn") return os.path.isdir(svndir) +def hasdarcs(parentdir): + darcsdir = os.path.join(parentdir, "../../../_darcs") + return os.path.isdir(darcsdir) + def hasversioning(parentdir): - return hascvs(parentdir) or hassvn(parentdir) + return hascvs(parentdir) or hassvn(parentdir) or hasdarcs(parentdir) def getcleanfile(filename, revision=None): parentdir = os.path.dirname(filename) @@ -190,6 +220,8 @@ return cvsreadfile(cvsroot, cvsfilename, revision) if hassvn(parentdir): return svnreadfile(filename, revision) + if hasdarcs(parentdir): + return darcsreadfile(filename) raise IOError("Could not find version control information") def updatefile(filename, revision=None): @@ -198,6 +230,8 @@ return cvsupdatefile(filename, revision) if hassvn(parentdir): return svnupdatefile(filename, revision) + if hasdarcs(parentdir): + return darcsupdatefile(filename) raise IOError("Could not find version control information") def commitfile(filename, message=None): @@ -206,6 +240,8 @@ return cvscommitfile(filename, message) if hassvn(parentdir): return svncommitfile(filename, message) + if hasdarcs(parentdir): + return darcscommitfile(filename, message) raise IOError("Could not find version control information") if __name__ == "__main__":