Warning, /sdk/kde-dev-scripts/reviewboarddiff is written in an unsupported language. File is not indexed.
0001 #!/usr/bin/env python 0002 # encoding: utf-8 0003 # 0004 # Generates reviewboard compatible diffs from git-svn repositories. 0005 # 0006 # Licence: GPL v3 0007 # Author: Aurélien Gâteau <agateau@kde.org> 0008 # 0009 # Based on a shell script by Riccardo Iaconelli <riccardo@kde.org> 0010 import sys 0011 from subprocess import * 0012 USAGE=""" 0013 Prints a reviewboard-compatible diff from a git-svn repository on stdout. 0014 0015 Usage: reviewboarddiff <git-diff-args> 0016 0017 Examples: 0018 reviewboarddiff HEAD : generates diff for uncommitted changes 0019 reviewboarddiff HEAD^ : generates diff for latest commit 0020 reviewboarddiff HEAD~3: generates diff for 3 latest commits 0021 """ 0022 0023 def run(*args): 0024 process = Popen(args, stdout=PIPE) 0025 out, err = process.communicate() 0026 if process.returncode != 0: 0027 print >>sys.stderr, "Command '%s' failed:" % " ".join(args) 0028 print >>sys.stderr, err 0029 sys.exit(1) 0030 return out.rstrip() 0031 0032 def add_suffix(line, suffix): 0033 return line.rstrip() + suffix + "\n" 0034 0035 def generate_diff(diff_args): 0036 wc_suffix = " (working copy)" 0037 new_suffix = " (revision 0)" 0038 0039 rev_list = run("git", "rev-list", "--date-order", "--max-count=1", "git-svn") 0040 rev = run("git", "svn", "find-rev", rev_list) 0041 rev_suffix = " (revision %s)" % rev 0042 0043 out = Popen(["git", "diff", "--no-prefix"] + diff_args, stdout=PIPE).stdout 0044 0045 while True: 0046 line = out.readline() 0047 if not line: 0048 break 0049 0050 """ 0051 git outputs new files as 0052 --- /dev/null 0053 +++ /new/file 0054 0055 while svn prefers: 0056 0057 --- /new/file (revision 0) 0058 +++ /new/file (working copy) 0059 0060 We skip the "--- /dev/null" line, read the next line (+++ /new/file) 0061 and recreate "--- /new/file" from it 0062 """ 0063 if line.startswith("--- /dev/null"): 0064 line = out.readline() 0065 null_line = add_suffix(line.replace("+++", "---"), new_suffix) 0066 sys.stdout.write(null_line) 0067 0068 # Add suffixes 0069 if line.startswith("---"): 0070 line = add_suffix(line, rev_suffix) 0071 elif line.startswith("+++"): 0072 line = add_suffix(line, wc_suffix) 0073 0074 sys.stdout.write(line) 0075 0076 return 0 0077 0078 def main(argv): 0079 if len(argv) == 1: 0080 print USAGE 0081 return -1 0082 return generate_diff(argv[1:]) 0083 0084 if __name__=="__main__": 0085 sys.exit(main(sys.argv)) 0086 # vi: ts=4 sw=4 et