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

Unified Diff: static/upload.py

Issue 14053: Bazaar Support For upload.py SVN Base: http://rietveld.googlecode.com/svn/trunk/
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:
View side by-side-diff with in-line comments
Download patch
« no previous file | no next file » | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: static/upload.py
===================================================================
--- static/upload.py (revision 403)
+++ static/upload.py (working copy)
@@ -21,6 +21,7 @@
Diff options are passed to the diff command of the underlying system.
Supported version control systems:
+ Bazaar
Git
Mercurial
Subversion
@@ -575,10 +576,11 @@
def RunShell(command, silent_ok=False, universal_newlines=True,
- print_output=False):
+ print_output=False,check_returncode=True):
data, retcode = RunShellWithReturnCode(command, print_output,
universal_newlines)
- if retcode:
+
+ if retcode and check_returncode:
ErrorExit("Got error status from %s:\n%s" % (command, data))
if not silent_ok and not data:
ErrorExit("No output from %s" % command)
@@ -641,7 +643,7 @@
def GetBaseFiles(self, diff):
"""Helper that calls GetBase file for each file in the patch.
-
+
Returns:
A dictionary that maps from filename to GetBaseFile's tuple. Filenames
are retrieved based on lines that start with "Index:" or
@@ -1115,7 +1117,7 @@
if out[0].startswith('%s: ' % relpath):
out = out[1:]
if len(out) > 1:
- # Moved/copied => considered as modified, use old filename to
+ # Moved/copied => considered as modified, use old filename to
# retrieve base contents
oldrelpath = out[1].strip()
status = "M"
@@ -1137,6 +1139,71 @@
return base_content, new_content, is_binary, status
+class BazaarVCS(VersionControlSystem):
+ """Implementation of the VersionControlSystem interface for Bazaar."""
+
+ def GenerateDiff(self, args):
+ """Return the current diff as a string.
+
+ Args:
+ args: Extra arguments to pass to the diff command.
+ """
+ if self.options.revision:
+ args = ["-r", self.options.revision] + args
+ # We need check_returncode = False because bzr diff returns 1 if changes
+ # are found.
+
+ data,retcode = RunShellWithReturnCode(["bzr", "diff"] + args, True)
+ filecount = 0
+ lines = data.splitlines()
+ for i, line in enumerate(lines):
+ match = re.match(r"^=== (added|removed|modified) file '(.*)'$", line)
+ if match:
+ # Modify line to make it look like as it comes from svn diff.
+ lines[i] = "Index: %s" % match.group(2)
+ filecount += 1
+ logging.info(line)
+ if not filecount:
+ ErrorExit("No valid patches found in output from bzr diff")
+ return "\n".join(lines)
+
+ def GetUnknownFiles(self):
+ """Return a list of files unknown to the VCS."""
+ args = ["-S"]
+ if self.options.revision:
+ args += ["-r", self.options.revision]
+ status = RunShell(["bzr", "status"] + args, silent_ok=True)
+ unknown_files = []
+ for line in status.splitlines():
+ if line and line[0] == "?":
+ unknown_files.append(line)
+ return unknown_files
+
+ def GetBaseFile(self, filename):
+ """Get the content of the upstream version of a file.
+
+ Returns:
+ A tuple (content, status) representing the file content and the status of
+ the file.
+ """
+ st_args = []
+ cat_args = []
+ new_content = None
+ if self.options.revision:
+ if '..' in self.options.revision:
+ start_rev = self.options.revision.split('..', 1)[0]
+ cat_args += ["-r", start_rev]
+ else:
+ cat_args += ["-r", self.options.revision]
+ st_args += ["-r", self.options.revision]
+ status = RunShell(["bzr", "status", "-S"] + st_args + [filename])
+ if status[1] == "N":
+ content = ""
+ else:
+ content = RunShell(["bzr", "cat"] + cat_args + [filename])
+ return content, new_content, False, status[0:4]
+
+
# NOTE: The SplitPatch function is duplicated in engine.py, keep them in sync.
def SplitPatch(data):
"""Splits a patch into separate pieces for each file.
@@ -1226,12 +1293,19 @@
except OSError, (errno, message):
if errno != 2: # ENOENT -- they don't have hg installed.
raise
-
+ try:
bialix 2009/03/24 22:49:23 I think you need either use command ["bzr", "--no-
+ out, returncode = RunShellWithReturnCode(["bzr", "root"])
+ if returncode == 0:
+ os.chdir(out.strip())
+ return BazaarVCS(options)
+ except OSError, (errno, message):
+ if errno != 2: # ENOENT -- they don't have bzr installed.
+ raise
# Subversion has a .svn in all working directories.
if os.path.isdir('.svn'):
logging.info("Guessed VCS = Subversion")
return SubversionVCS(options)
-
+
# Git has a command to test if you're in a git tree.
# Try running it, but don't die if we don't have git installed.
try:
@@ -1248,18 +1322,6 @@
def RealMain(argv, data=None):
- """The real main function.
-
- Args:
- argv: Command line arguments.
- data: Diff contents. If None (default) the diff is generated by
- the VersionControlSystem implementation returned by GuessVCS().
-
- Returns:
- A 2-tuple (issue id, patchset id).
- The patchset id is None if the base files are not uploaded by this
- script (applies only to SVN checkouts).
- """
logging.basicConfig(format=("%(asctime).19s %(levelname)s %(filename)s:"
"%(lineno)s %(message)s "))
os.environ['LC_ALL'] = 'C'
@@ -1345,7 +1407,6 @@
uploaded_diff_file = [("data", "data.diff", data)]
ctype, body = EncodeMultipartFormData(form_fields, uploaded_diff_file)
response_body = rpc_server.Send("/upload", body, content_type=ctype)
- patchset = None
if not options.download_base or not uploaded_diff_file:
lines = response_body.splitlines()
if len(lines) >= 2:
« no previous file | no next file »

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