Index: gclient_scm.py |
diff --git a/gclient_scm.py b/gclient_scm.py |
index e2a0017ca6433c13759e2b3299005ad7c979ecae..a9c537b9c2baf0b283f230815cfdeb1d5282cb54 100644 |
--- a/gclient_scm.py |
+++ b/gclient_scm.py |
@@ -1,6 +1,16 @@ |
-# Copyright (c) 2009 The Chromium Authors. All rights reserved. |
-# Use of this source code is governed by a BSD-style license that can be |
-# found in the LICENSE file. |
+# Copyright 2009 Google Inc. All Rights Reserved. |
+# |
+# Licensed under the Apache License, Version 2.0 (the "License"); |
+# you may not use this file except in compliance with the License. |
+# You may obtain a copy of the License at |
+# |
+# http://www.apache.org/licenses/LICENSE-2.0 |
+# |
+# Unless required by applicable law or agreed to in writing, software |
+# distributed under the License is distributed on an "AS IS" BASIS, |
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
+# See the License for the specific language governing permissions and |
+# limitations under the License. |
"""Gclient-specific SCM-specific operations.""" |
@@ -8,13 +18,19 @@ import logging |
import os |
import re |
import subprocess |
+import sys |
+import xml.dom.minidom |
-import scm |
import gclient_utils |
+# TODO(maruel): Temporary. |
+from scm import CaptureGit, CaptureGitStatus, CaptureSVN |
+from scm import CaptureSVNHeadRevision, CaptureSVNInfo, CaptureSVNStatus |
+from scm import RunSVN, RunSVNAndFilterOutput, RunSVNAndGetFileList |
### SCM abstraction layer |
+ |
# Factory Method for SCM wrapper creation |
def CreateSCM(url=None, root_dir=None, relpath=None, scm_name='svn'): |
@@ -77,20 +93,20 @@ class SCMWrapper(object): |
return getattr(self, command)(options, args, file_list) |
-class GitWrapper(SCMWrapper, scm.GIT): |
+class GitWrapper(SCMWrapper): |
"""Wrapper for Git""" |
def cleanup(self, options, args, file_list): |
"""Cleanup working copy.""" |
__pychecker__ = 'unusednames=args,file_list,options' |
- self._Run(['prune'], redirect_stdout=False) |
- self._Run(['fsck'], redirect_stdout=False) |
- self._Run(['gc'], redirect_stdout=False) |
+ self._RunGit(['prune'], redirect_stdout=False) |
+ self._RunGit(['fsck'], redirect_stdout=False) |
+ self._RunGit(['gc'], redirect_stdout=False) |
def diff(self, options, args, file_list): |
__pychecker__ = 'unusednames=args,file_list,options' |
- merge_base = self._Run(['merge-base', 'HEAD', 'origin']) |
- self._Run(['diff', merge_base], redirect_stdout=False) |
+ merge_base = self._RunGit(['merge-base', 'HEAD', 'origin']) |
+ self._RunGit(['diff', merge_base], redirect_stdout=False) |
def export(self, options, args, file_list): |
__pychecker__ = 'unusednames=file_list,options' |
@@ -98,8 +114,8 @@ class GitWrapper(SCMWrapper, scm.GIT): |
export_path = os.path.abspath(os.path.join(args[0], self.relpath)) |
if not os.path.exists(export_path): |
os.makedirs(export_path) |
- self._Run(['checkout-index', '-a', '--prefix=%s/' % export_path], |
- redirect_stdout=False) |
+ self._RunGit(['checkout-index', '-a', '--prefix=%s/' % export_path], |
+ redirect_stdout=False) |
def update(self, options, args, file_list): |
"""Runs git to update or transparently checkout the working copy. |
@@ -126,21 +142,21 @@ class GitWrapper(SCMWrapper, scm.GIT): |
print("\n_____ %s%s" % (self.relpath, rev_str)) |
if not os.path.exists(self.checkout_path): |
- self._Run(['clone', url, self.checkout_path], |
- cwd=self._root_dir, redirect_stdout=False) |
+ self._RunGit(['clone', url, self.checkout_path], |
+ cwd=self._root_dir, redirect_stdout=False) |
if revision: |
- self._Run(['reset', '--hard', revision], redirect_stdout=False) |
- files = self._Run(['ls-files']).split() |
+ self._RunGit(['reset', '--hard', revision], redirect_stdout=False) |
+ files = self._RunGit(['ls-files']).split() |
file_list.extend([os.path.join(self.checkout_path, f) for f in files]) |
return |
- self._Run(['remote', 'update'], redirect_stdout=False) |
+ self._RunGit(['remote', 'update'], redirect_stdout=False) |
new_base = 'origin' |
if revision: |
new_base = revision |
- files = self._Run(['diff', new_base, '--name-only']).split() |
+ files = self._RunGit(['diff', new_base, '--name-only']).split() |
file_list.extend([os.path.join(self.checkout_path, f) for f in files]) |
- self._Run(['rebase', '-v', new_base], redirect_stdout=False) |
+ self._RunGit(['rebase', '-v', new_base], redirect_stdout=False) |
print "Checked out revision %s." % self.revinfo(options, (), None) |
def revert(self, options, args, file_list): |
@@ -156,15 +172,15 @@ class GitWrapper(SCMWrapper, scm.GIT): |
print("\n_____ %s is missing, synching instead" % self.relpath) |
# Don't reuse the args. |
return self.update(options, [], file_list) |
- merge_base = self._Run(['merge-base', 'HEAD', 'origin']) |
- files = self._Run(['diff', merge_base, '--name-only']).split() |
- self._Run(['reset', '--hard', merge_base], redirect_stdout=False) |
+ merge_base = self._RunGit(['merge-base', 'HEAD', 'origin']) |
+ files = self._RunGit(['diff', merge_base, '--name-only']).split() |
+ self._RunGit(['reset', '--hard', merge_base], redirect_stdout=False) |
file_list.extend([os.path.join(self.checkout_path, f) for f in files]) |
def revinfo(self, options, args, file_list): |
"""Display revision""" |
__pychecker__ = 'unusednames=args,file_list,options' |
- return self._Run(['rev-parse', 'HEAD']) |
+ return self._RunGit(['rev-parse', 'HEAD']) |
def runhooks(self, options, args, file_list): |
self.status(options, args, file_list) |
@@ -176,30 +192,29 @@ class GitWrapper(SCMWrapper, scm.GIT): |
print('\n________ couldn\'t run status in %s:\nThe directory ' |
'does not exist.' % self.checkout_path) |
else: |
- merge_base = self._Run(['merge-base', 'HEAD', 'origin']) |
- self._Run(['diff', '--name-status', merge_base], redirect_stdout=False) |
- files = self._Run(['diff', '--name-only', merge_base]).split() |
+ merge_base = self._RunGit(['merge-base', 'HEAD', 'origin']) |
+ self._RunGit(['diff', '--name-status', merge_base], redirect_stdout=False) |
+ files = self._RunGit(['diff', '--name-only', merge_base]).split() |
file_list.extend([os.path.join(self.checkout_path, f) for f in files]) |
- def _Run(self, args, cwd=None, checkrc=True, redirect_stdout=True): |
- # TODO(maruel): Merge with Capture? |
+ def _RunGit(self, args, cwd=None, checkrc=True, redirect_stdout=True): |
stdout=None |
if redirect_stdout: |
stdout=subprocess.PIPE |
if cwd == None: |
cwd = self.checkout_path |
- cmd = [self.COMMAND] |
+ cmd = ['git'] |
cmd.extend(args) |
sp = subprocess.Popen(cmd, cwd=cwd, stdout=stdout) |
if checkrc and sp.returncode: |
raise gclient_utils.Error('git command %s returned %d' % |
(args[0], sp.returncode)) |
output = sp.communicate()[0] |
- if output is not None: |
+ if output != None: |
return output.strip() |
-class SVNWrapper(SCMWrapper, scm.SVN): |
+class SVNWrapper(SCMWrapper): |
""" Wrapper for SVN """ |
def cleanup(self, options, args, file_list): |
@@ -207,14 +222,14 @@ class SVNWrapper(SCMWrapper, scm.SVN): |
__pychecker__ = 'unusednames=file_list,options' |
command = ['cleanup'] |
command.extend(args) |
- self.Run(command, os.path.join(self._root_dir, self.relpath)) |
+ RunSVN(command, os.path.join(self._root_dir, self.relpath)) |
def diff(self, options, args, file_list): |
# NOTE: This function does not currently modify file_list. |
__pychecker__ = 'unusednames=file_list,options' |
command = ['diff'] |
command.extend(args) |
- self.Run(command, os.path.join(self._root_dir, self.relpath)) |
+ RunSVN(command, os.path.join(self._root_dir, self.relpath)) |
def export(self, options, args, file_list): |
__pychecker__ = 'unusednames=file_list,options' |
@@ -227,7 +242,7 @@ class SVNWrapper(SCMWrapper, scm.SVN): |
assert os.path.exists(export_path) |
command = ['export', '--force', '.'] |
command.append(export_path) |
- self.Run(command, os.path.join(self._root_dir, self.relpath)) |
+ RunSVN(command, os.path.join(self._root_dir, self.relpath)) |
def update(self, options, args, file_list): |
"""Runs SCM to update or transparently checkout the working copy. |
@@ -264,11 +279,11 @@ class SVNWrapper(SCMWrapper, scm.SVN): |
command = ['checkout', url, checkout_path] |
if revision: |
command.extend(['--revision', str(revision)]) |
- self.RunAndGetFileList(options, command, self._root_dir, file_list) |
+ RunSVNAndGetFileList(options, command, self._root_dir, file_list) |
return |
# Get the existing scm url and the revision number of the current checkout. |
- from_info = self.CaptureInfo(os.path.join(checkout_path, '.'), '.') |
+ from_info = CaptureSVNInfo(os.path.join(checkout_path, '.'), '.') |
if not from_info: |
raise gclient_utils.Error("Can't update/checkout %r if an unversioned " |
"directory is present. Delete the directory " |
@@ -278,12 +293,12 @@ class SVNWrapper(SCMWrapper, scm.SVN): |
if options.manually_grab_svn_rev: |
# Retrieve the current HEAD version because svn is slow at null updates. |
if not revision: |
- from_info_live = self.CaptureInfo(from_info['URL'], '.') |
+ from_info_live = CaptureSVNInfo(from_info['URL'], '.') |
revision = str(from_info_live['Revision']) |
rev_str = ' at %s' % revision |
if from_info['URL'] != base_url: |
- to_info = self.CaptureInfo(url, '.') |
+ to_info = CaptureSVNInfo(url, '.') |
if not to_info.get('Repository Root') or not to_info.get('UUID'): |
# The url is invalid or the server is not accessible, it's safer to bail |
# out right now. |
@@ -305,12 +320,12 @@ class SVNWrapper(SCMWrapper, scm.SVN): |
from_info['Repository Root'], |
to_info['Repository Root'], |
self.relpath] |
- self.Run(command, self._root_dir) |
+ RunSVN(command, self._root_dir) |
from_info['URL'] = from_info['URL'].replace( |
from_info['Repository Root'], |
to_info['Repository Root']) |
else: |
- if self.CaptureStatus(checkout_path): |
+ if CaptureSVNStatus(checkout_path): |
raise gclient_utils.Error("Can't switch the checkout to %s; UUID " |
"don't match and there is local changes " |
"in %s. Delete the directory and " |
@@ -322,7 +337,7 @@ class SVNWrapper(SCMWrapper, scm.SVN): |
command = ['checkout', url, checkout_path] |
if revision: |
command.extend(['--revision', str(revision)]) |
- self.RunAndGetFileList(options, command, self._root_dir, file_list) |
+ RunSVNAndGetFileList(options, command, self._root_dir, file_list) |
return |
@@ -336,7 +351,7 @@ class SVNWrapper(SCMWrapper, scm.SVN): |
command = ["update", checkout_path] |
if revision: |
command.extend(['--revision', str(revision)]) |
- self.RunAndGetFileList(options, command, self._root_dir, file_list) |
+ RunSVNAndGetFileList(options, command, self._root_dir, file_list) |
def revert(self, options, args, file_list): |
"""Reverts local modifications. Subversion specific. |
@@ -353,7 +368,7 @@ class SVNWrapper(SCMWrapper, scm.SVN): |
# Don't reuse the args. |
return self.update(options, [], file_list) |
- for file_status in self.CaptureStatus(path): |
+ for file_status in CaptureSVNStatus(path): |
file_path = os.path.join(path, file_status[1]) |
if file_status[0][0] == 'X': |
# Ignore externals. |
@@ -388,7 +403,7 @@ class SVNWrapper(SCMWrapper, scm.SVN): |
try: |
# svn revert is so broken we don't even use it. Using |
# "svn up --revision BASE" achieve the same effect. |
- self.RunAndGetFileList(options, ['update', '--revision', 'BASE'], path, |
+ RunSVNAndGetFileList(options, ['update', '--revision', 'BASE'], path, |
file_list) |
except OSError, e: |
# Maybe the directory disapeared meanwhile. We don't want it to throw an |
@@ -398,7 +413,7 @@ class SVNWrapper(SCMWrapper, scm.SVN): |
def revinfo(self, options, args, file_list): |
"""Display revision""" |
__pychecker__ = 'unusednames=args,file_list,options' |
- return self.CaptureHeadRevision(self.url) |
+ return CaptureSVNHeadRevision(self.url) |
def runhooks(self, options, args, file_list): |
self.status(options, args, file_list) |
@@ -415,7 +430,7 @@ class SVNWrapper(SCMWrapper, scm.SVN): |
% (' '.join(command), path)) |
# There's no file list to retrieve. |
else: |
- self.RunAndGetFileList(options, command, path, file_list) |
+ RunSVNAndGetFileList(options, command, path, file_list) |
def pack(self, options, args, file_list): |
"""Generates a patch file which can be applied to the root of the |
@@ -460,4 +475,4 @@ class SVNWrapper(SCMWrapper, scm.SVN): |
print line |
filterer = DiffFilterer(self.relpath) |
- self.RunAndFilterOutput(command, path, False, False, filterer.Filter) |
+ RunSVNAndFilterOutput(command, path, False, False, filterer.Filter) |