I couldn't really figure out how to do this "the right way", but I
needed the feature now, so I created a small python script that
generates a unified diff directly, not using svn diff.

initial-review.py [path] [path] ...  > review.diff

Basically just like using post-review. Paths can be files or folders
and must be under version control.

For example, on the reviewboard svn:
python initial-review.py reports setup.py > review.diff
Open the reviewboard site, create a New Review Request, Base Diff
Path=/, Diff=review.diff
Result: http://demo.review-board.org/r/1733/diff/

The script below has stuff borrowed from post-review.py, and is only
tested sparsely on winxp, not tested on linux. It's basically a hack,
but it works ....

------------------------------------------

#!/usr/bin/python
import sys
import os
import os.path
import subprocess
from optparse import OptionParser

DUMMY_FILENAME = "__dummy_non_existing_file"

def get_files(paths):
    if not paths:
        paths = ["."]

    files = []
    for p in paths:
        if not os.path.exists(p):
            raise Exception("Invalid path: " + p)

        _files = execute(["svn", "list", "--recursive", p],
split_lines=True)
        if os.path.isdir(p):
            _files = [os.path.join(p, file) for file in _files]

        for f in _files:
            if os.path.isfile(f):
                files.append(f)

    return files


def create_file_diff(file):
    diff = execute(["diff", "-u", "--new-file", DUMMY_FILENAME, file],
split_lines=True, ignore_errors=True)

    if not diff:
        return ""

    info = execute(["svn", "info", file], split_lines=True)
    for l in info:
        if l.lower().startswith("url"):
            url = l.split(":",1)[1].strip()
        if l.lower().startswith("repository root"):
            repos_root = l.split(":",1)[1].strip()
        if l.lower().startswith("revision"):
            rev = l.split(":",1)[1].strip()
    if not url or not repos_root or not rev:
        raise Exception("Failed to get svn info for " + file)

    url =  url.replace(repos_root, "")

    diff.insert(0, "Index: " + url)
    diff.insert(1,
"===================================================================")
    diff[2] = "--- " + url + "\t(revision 0)"
    diff[3] = "+++ " + url + "\t(revision %s)" % (rev)

    return "\n".join(diff)


def execute(command, env=None, split_lines=False, ignore_errors=False,
            extra_ignore_errors=()):
    if env:
        env.update(os.environ)
    else:
        env = os.environ.copy()

    env['LC_ALL'] = 'en_US.UTF-8'
    env['LANGUAGE'] = 'en_US.UTF-8'

    if sys.platform.startswith('win'):
        p = subprocess.Popen(command,
                             stdin=subprocess.PIPE,
                             stdout=subprocess.PIPE,
                             stderr=subprocess.STDOUT,
                             shell=False,
                             universal_newlines=True,
                             env=env)
    else:
        p = subprocess.Popen(command,
                             stdin=subprocess.PIPE,
                             stdout=subprocess.PIPE,
                             stderr=subprocess.STDOUT,
                             shell=False,
                             close_fds=True,
                             universal_newlines=True,
                             env=env)
    if split_lines:
        data = [line.rstrip("\n") for line in p.stdout.readlines()]
    else:
        data = p.stdout.read()
    rc = p.wait()
    if rc and not ignore_errors and rc not in extra_ignore_errors:
        raise Exception('Failed to execute command: %s\n%s' %
(command, data))

    return data

def parse_options(args):
    parser = OptionParser()
    (globals()["options"], args) = parser.parse_args(args)
    return args

def main(args):
    args = parse_options(args)
    files = get_files(args)
    diff = ''.join([create_file_diff(file) for file in files])
    print diff

if __name__ == "__main__":
    main(sys.argv[1:])

------------------------------------------------------------

 -- Jeppe
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"reviewboard" group.
To post to this group, send email to reviewboard@googlegroups.com
To unsubscribe from this group, send email to 
reviewboard+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/reviewboard?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to