Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code | Sign in
(105)

Delta Between Two Patch Sets: static/upload.py

Issue 14053: Bazaar Support For upload.py SVN Base: http://rietveld.googlecode.com/svn/trunk/
Left Patch Set: Updated to work against latest upload.py Created 10 months ago
Right Patch Set: Utilized bzr root to detect when in subdirectory Created 8 months, 3 weeks ago
Use n/p to move between diff chunks; N/P to move between comments. Please Sign in to add in-line comments.
Jump to:
Left: Side by side diff | Download
Right: Side by side diff | Download
« no previous file | no next file » | Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
LEFTRIGHT
1 #!/usr/bin/env python 1 #!/usr/bin/env python
2 # 2 #
3 # Copyright 2007 Google Inc. 3 # Copyright 2007 Google Inc.
4 # 4 #
5 # Licensed under the Apache License, Version 2.0 (the "License"); 5 # Licensed under the Apache License, Version 2.0 (the "License");
6 # you may not use this file except in compliance with the License. 6 # you may not use this file except in compliance with the License.
7 # You may obtain a copy of the License at 7 # You may obtain a copy of the License at
8 # 8 #
9 # http://www.apache.org/licenses/LICENSE-2.0 9 # http://www.apache.org/licenses/LICENSE-2.0
10 # 10 #
(...skipping 558 matching lines...) Expand 10 before | Expand all | Expand 10 after
569 p.wait() 569 p.wait()
570 errout = p.stderr.read() 570 errout = p.stderr.read()
571 if print_output and errout: 571 if print_output and errout:
572 print >>sys.stderr, errout 572 print >>sys.stderr, errout
573 p.stdout.close() 573 p.stdout.close()
574 p.stderr.close() 574 p.stderr.close()
575 return output, p.returncode 575 return output, p.returncode
576 576
577 577
578 def RunShell(command, silent_ok=False, universal_newlines=True, 578 def RunShell(command, silent_ok=False, universal_newlines=True,
579 print_output=False,check_returncode=True): 579 print_output=False,check_returncode=True):
Andi Albrecht 2009/02/25 13:48:09 Consider RunShellWithReturnCode(). I think check_r
580 data, retcode = RunShellWithReturnCode(command, print_output, 580 data, retcode = RunShellWithReturnCode(command, print_output,
581 universal_newlines) 581 universal_newlines)
582 582
kevin.kubasik 2009/02/09 17:54:25 Added logic to handle bzr's diff return code of 1.
583 if retcode and check_returncode: 583 if retcode and check_returncode:
584 ErrorExit("Got error status from %s:\n%s" % (command, data)) 584 ErrorExit("Got error status from %s:\n%s" % (command, data))
585 if not silent_ok and not data: 585 if not silent_ok and not data:
586 ErrorExit("No output from %s" % command) 586 ErrorExit("No output from %s" % command)
587 return data 587 return data
588 588
589 589
590 class VersionControlSystem(object): 590 class VersionControlSystem(object):
591 """Abstract base class providing an interface to the VCS.""" 591 """Abstract base class providing an interface to the VCS."""
592 592
(...skipping 312 matching lines...) Expand 10 before | Expand all | Expand 10 after
905 # If a file is copied its status will be "A +", which signifies 905 # If a file is copied its status will be "A +", which signifies
906 # "addition-with-history". See "svn st" for more information. We need to 906 # "addition-with-history". See "svn st" for more information. We need to
907 # upload the original file or else diff parsing will fail if the file was 907 # upload the original file or else diff parsing will fail if the file was
908 # edited. 908 # edited.
909 if status[0] == "A" and status[3] != "+": 909 if status[0] == "A" and status[3] != "+":
910 # We'll need to upload the new content if we're adding a binary file 910 # We'll need to upload the new content if we're adding a binary file
911 # since diff's output won't contain it. 911 # since diff's output won't contain it.
912 mimetype = RunShell(["svn", "propget", "svn:mime-type", filename], 912 mimetype = RunShell(["svn", "propget", "svn:mime-type", filename],
913 silent_ok=True) 913 silent_ok=True)
914 base_content = "" 914 base_content = ""
915 is_binary = mimetype and not mimetype.startswith("text/") 915 is_binary = bool(mimetype) and not mimetype.startswith("text/")
916 if is_binary and self.IsImage(filename): 916 if is_binary and self.IsImage(filename):
917 new_content = self.ReadFile(filename) 917 new_content = self.ReadFile(filename)
918 elif (status[0] in ("M", "D", "R") or 918 elif (status[0] in ("M", "D", "R") or
919 (status[0] == "A" and status[3] == "+") or # Copied file. 919 (status[0] == "A" and status[3] == "+") or # Copied file.
920 (status[0] == " " and status[1] == "M")): # Property change. 920 (status[0] == " " and status[1] == "M")): # Property change.
921 args = [] 921 args = []
922 if self.options.revision: 922 if self.options.revision:
923 url = "%s/%s@%s" % (self.svn_base, filename, self.rev_start) 923 url = "%s/%s@%s" % (self.svn_base, filename, self.rev_start)
924 else: 924 else:
925 # Don't change filename, it's needed later. 925 # Don't change filename, it's needed later.
926 url = filename 926 url = filename
927 args += ["-r", "BASE"] 927 args += ["-r", "BASE"]
928 cmd = ["svn"] + args + ["propget", "svn:mime-type", url] 928 cmd = ["svn"] + args + ["propget", "svn:mime-type", url]
929 mimetype, returncode = RunShellWithReturnCode(cmd) 929 mimetype, returncode = RunShellWithReturnCode(cmd)
930 if returncode: 930 if returncode:
931 # File does not exist in the requested revision. 931 # File does not exist in the requested revision.
932 # Reset mimetype, it contains an error message. 932 # Reset mimetype, it contains an error message.
933 mimetype = "" 933 mimetype = ""
934 get_base = False 934 get_base = False
935 is_binary = mimetype and not mimetype.startswith("text/") 935 is_binary = bool(mimetype) and not mimetype.startswith("text/")
936 if status[0] == " ": 936 if status[0] == " ":
937 # Empty base content just to force an upload. 937 # Empty base content just to force an upload.
938 base_content = "" 938 base_content = ""
939 elif is_binary: 939 elif is_binary:
940 if self.IsImage(filename): 940 if self.IsImage(filename):
941 get_base = True 941 get_base = True
942 if status[0] == "M": 942 if status[0] == "M":
943 if not self.rev_end: 943 if not self.rev_end:
944 new_content = self.ReadFile(filename) 944 new_content = self.ReadFile(filename)
945 else: 945 else:
(...skipping 186 matching lines...) Expand 10 before | Expand all | Expand 10 after
1132 is_binary = is_binary or "\0" in new_content 1132 is_binary = is_binary or "\0" in new_content
1133 if is_binary and base_content: 1133 if is_binary and base_content:
1134 # Fetch again without converting newlines 1134 # Fetch again without converting newlines
1135 base_content = RunShell(["hg", "cat", "-r", self.base_rev, oldrelpath], 1135 base_content = RunShell(["hg", "cat", "-r", self.base_rev, oldrelpath],
1136 silent_ok=True, universal_newlines=False) 1136 silent_ok=True, universal_newlines=False)
1137 if not is_binary or not self.IsImage(relpath): 1137 if not is_binary or not self.IsImage(relpath):
1138 new_content = None 1138 new_content = None
1139 return base_content, new_content, is_binary, status 1139 return base_content, new_content, is_binary, status
1140 1140
1141 1141
1142 class BazaarVCS(VersionControlSystem): 1142 class BazaarVCS(VersionControlSystem):
kevin.kubasik 2009/02/09 17:54:25 The Bzr implementation.
1143 """Implementation of the VersionControlSystem interface for Bazaar.""" 1143 """Implementation of the VersionControlSystem interface for Bazaar."""
1144 1144
1145 def GenerateDiff(self, args): 1145 def GenerateDiff(self, args):
bialix 2009/03/07 22:19:06 You really need to consider of using bzrlib direct
bialix 2009/03/09 07:40:24 On 2009/03/07 22:19:06, bialix wrote: > You really
1146 """Return the current diff as a string. 1146 """Return the current diff as a string.
1147 1147
1148 Args: 1148 Args:
1149 args: Extra arguments to pass to the diff command. 1149 args: Extra arguments to pass to the diff command.
1150 """ 1150 """
1151 if self.options.revision: 1151 if self.options.revision:
1152 args = ["-r", self.options.revision] + args 1152 args = ["-r", self.options.revision] + args
1153 # We need check_returncode = False because bzr diff returns 1 if changes 1153 # We need check_returncode = False because bzr diff returns 1 if changes
1154 # are found. 1154 # are found.
1155 data = RunShell(["bzr", "diff"] + args, silent_ok=True, 1155
1156 check_returncode=False) 1156 data,retcode = RunShellWithReturnCode(["bzr", "diff"] + args, True)
1157 filecount = 0 1157 filecount = 0
1158 lines = data.splitlines() 1158 lines = data.splitlines()
1159 for i, line in enumerate(lines): 1159 for i, line in enumerate(lines):
1160 match = re.match(r"^=== (added|removed|modified) file '(.*)'$", line) 1160 match = re.match(r"^=== (added|removed|modified) file '(.*)'$", line)
1161 if match: 1161 if match:
1162 # Modify line to make it look like as it comes from svn diff. 1162 # Modify line to make it look like as it comes from svn diff.
1163 lines[i] = "Index: %s" % match.group(2) 1163 lines[i] = "Index: %s" % match.group(2)
1164 filecount += 1 1164 filecount += 1
1165 logging.info(line) 1165 logging.info(line)
1166 if not filecount: 1166 if not filecount:
1167 ErrorExit("No valid patches found in output from bzr diff") 1167 ErrorExit("No valid patches found in output from bzr diff")
1168 return "\n".join(lines) 1168 return "\n".join(lines)
1169 1169
1170 def GetUnknownFiles(self): 1170 def GetUnknownFiles(self):
1171 """Return a list of files unknown to the VCS.""" 1171 """Return a list of files unknown to the VCS."""
bialix 2009/03/08 12:03:34 You can use command: bzr ls --unknown --verbose an
1172 args = ["-S"] 1172 args = ["-S"]
1173 if self.options.revision: 1173 if self.options.revision:
1174 args += ["-r", self.options.revision] 1174 args += ["-r", self.options.revision]
1175 status = RunShell(["bzr", "status"] + args, silent_ok=True) 1175 status = RunShell(["bzr", "status"] + args, silent_ok=True)
1176 unknown_files = [] 1176 unknown_files = []
1177 for line in status.splitlines(): 1177 for line in status.splitlines():
1178 if line and line[0] == "?": 1178 if line and line[0] == "?":
1179 unknown_files.append(line) 1179 unknown_files.append(line)
1180 return unknown_files 1180 return unknown_files
1181 1181
(...skipping 104 matching lines...) Expand 10 before | Expand all | Expand 10 after
1286 # Mercurial has a command to get the base directory of a repository 1286 # Mercurial has a command to get the base directory of a repository
1287 # Try running it, but don't die if we don't have hg installed. 1287 # Try running it, but don't die if we don't have hg installed.
1288 # NOTE: we try Mercurial first as it can sit on top of an SVN working copy. 1288 # NOTE: we try Mercurial first as it can sit on top of an SVN working copy.
1289 try: 1289 try:
1290 out, returncode = RunShellWithReturnCode(["hg", "root"]) 1290 out, returncode = RunShellWithReturnCode(["hg", "root"])
1291 if returncode == 0: 1291 if returncode == 0:
1292 return MercurialVCS(options, out.strip()) 1292 return MercurialVCS(options, out.strip())
1293 except OSError, (errno, message): 1293 except OSError, (errno, message):
1294 if errno != 2: # ENOENT -- they don't have hg installed. 1294 if errno != 2: # ENOENT -- they don't have hg installed.
1295 raise 1295 raise
1296 1296 try:
bialix 2009/03/24 22:49:23 I think you need either use command ["bzr", "--no-
1297 out, returncode = RunShellWithReturnCode(["bzr", "root"])
1298 if returncode == 0:
1299 os.chdir(out.strip())
1300 return BazaarVCS(options)
1301 except OSError, (errno, message):
1302 if errno != 2: # ENOENT -- they don't have bzr installed.
1303 raise
1297 # Subversion has a .svn in all working directories. 1304 # Subversion has a .svn in all working directories.
1298 if os.path.isdir('.svn'): 1305 if os.path.isdir('.svn'):
1299 logging.info("Guessed VCS = Subversion") 1306 logging.info("Guessed VCS = Subversion")
1300 return SubversionVCS(options) 1307 return SubversionVCS(options)
1301 elif os.path.isdir(".bzr"): 1308
bialix 2009/03/07 22:19:06 Bazaar has root command similar to Mercurial. I th
1302 logging.info("Guessed VCS = Bazaar")
1303 return BazaarVCS(options)
1304 # Git has a command to test if you're in a git tree. 1309 # Git has a command to test if you're in a git tree.
1305 # Try running it, but don't die if we don't have git installed. 1310 # Try running it, but don't die if we don't have git installed.
1306 try: 1311 try:
1307 out, returncode = RunShellWithReturnCode(["git", "rev-parse", 1312 out, returncode = RunShellWithReturnCode(["git", "rev-parse",
1308 "--is-inside-work-tree"]) 1313 "--is-inside-work-tree"])
1309 if returncode == 0: 1314 if returncode == 0:
1310 return GitVCS(options) 1315 return GitVCS(options)
1311 except OSError, (errno, message): 1316 except OSError, (errno, message):
1312 if errno != 2: # ENOENT -- they don't have git installed. 1317 if errno != 2: # ENOENT -- they don't have git installed.
1313 raise 1318 raise
(...skipping 120 matching lines...) Expand 10 before | Expand all | Expand 10 after
1434 try: 1439 try:
1435 RealMain(sys.argv) 1440 RealMain(sys.argv)
1436 except KeyboardInterrupt: 1441 except KeyboardInterrupt:
1437 print 1442 print
1438 StatusUpdate("Interrupted.") 1443 StatusUpdate("Interrupted.")
1439 sys.exit(1) 1444 sys.exit(1)
1440 1445
1441 1446
1442 if __name__ == "__main__": 1447 if __name__ == "__main__":
1443 main() 1448 main()
LEFTRIGHT
« no previous file | no next file » | Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Toggle Comments ('s')

Powered by Google App Engine
RSS Feeds Recent Issues | This issue
This is Rietveld r497