Commit a9371767 authored by maruel@chromium.org's avatar maruel@chromium.org

Add full_move flag to GIT.GenerateDiff and Factor out FindGclientRootDir into gclient_utils.

BUG=none
TEST=none

Review URL: http://codereview.chromium.org/501171

git-svn-id: svn://svn.chromium.org/chrome/trunk/tools/depot_tools@35154 0039d316-1c4b-4281-b951-d872f2087c98
parent 650bb1f9
......@@ -831,16 +831,6 @@ def TryChange(change_info, args, swallow_exception):
root = os.path.join(root, '')
return subpath[len(root):]
# Try to find the gclient root.
def FindGclientRootDir(from_dir):
path = os.path.realpath(from_dir)
while not os.path.exists(os.path.join(path, '.gclient')):
next = os.path.split(path)
if not next[1]:
return None
path = next[0]
return path
trychange_args = []
settings = {
'port': GetCodeReviewSetting('TRYSERVER_HTTP_PORT'),
......@@ -854,7 +844,7 @@ def TryChange(change_info, args, swallow_exception):
if v:
trychange_args.extend(['--' + k, v])
gclient_root = FindGclientRootDir(GetRepositoryRoot())
gclient_root = gclient_utils.FindGclientRoot(GetRepositoryRoot())
if gclient_root:
trychange_args.extend(['--root', PathDifference(gclient_root,
GetRepositoryRoot())])
......
......@@ -307,3 +307,13 @@ def IsUsingGit(root, paths):
if os.path.exists(os.path.join(root, path, '.git')):
return True
return False
def FindGclientRoot(from_dir):
"""Tries to find the gclient root."""
path = os.path.realpath(from_dir)
while not os.path.exists(os.path.join(path, '.gclient')):
next = os.path.split(path)
if not next[1]:
return None
path = next[0]
return path
......@@ -177,12 +177,17 @@ class GIT(object):
return upstream_branch
@staticmethod
def GenerateDiff(cwd, branch=None):
"""Diffs against the upstream branch or optionally another branch."""
def GenerateDiff(cwd, branch=None, full_move=False):
"""Diffs against the upstream branch or optionally another branch.
full_move means that move or copy operations should completely recreate the
files, usually in the prospect to apply the patch for a try job."""
if not branch:
branch = GIT.GetUpstream(cwd)
diff = GIT.Capture(['diff-tree', '-p', '--no-prefix', branch, 'HEAD'],
cwd).splitlines(True)
command = ['diff-tree', '-p', '--no-prefix', branch, 'HEAD']
if not full_move:
command.append('-C')
diff = GIT.Capture(command, cwd).splitlines(True)
for i in range(len(diff)):
# In the case of added files, replace /dev/null with the path to the
# file being added.
......@@ -524,7 +529,9 @@ class SVN(object):
"""Diffs a single file.
Be sure to be in the appropriate directory before calling to have the
expected relative path."""
expected relative path.
full_move means that move or copy operations should completely recreate the
files, usually in the prospect to apply the patch for a try job."""
# Use svn info output instead of os.path.isdir because the latter fails
# when the file is deleted.
if SVN.CaptureInfo(filename).get("Node Kind") == "directory":
......
......@@ -15,6 +15,7 @@ class GclientUtilsUnittest(SuperMoxTestBase):
def testMembersChanged(self):
members = [
'CheckCall', 'CheckCallError', 'Error', 'FileRead', 'FileWrite',
'FindGclientRoot',
'FullUrlFromRelative', 'FullUrlFromRelative2', 'GetNamedNodeText',
'GetNodeNamedAttributeText', 'IsUsingGit', 'ParseXML',
'PrintableObject', 'RemoveDirectory', 'SplitUrlRevision',
......
......@@ -83,7 +83,8 @@ class GITUnittest(TryChangeTestsBase):
def testBasic(self):
trychange.os.getcwd().AndReturn(self.fake_root)
trychange.scm.GIT.GetCheckoutRoot(self.fake_root).AndReturn(self.fake_root)
trychange.scm.GIT.GenerateDiff(self.fake_root).AndReturn('a diff')
trychange.scm.GIT.GenerateDiff(self.fake_root,
full_move=True).AndReturn('a diff')
trychange.scm.GIT.GetPatchName(self.fake_root).AndReturn('bleh-1233')
trychange.scm.GIT.GetEmail(self.fake_root).AndReturn('georges@example.com')
self.mox.ReplayAll()
......
......@@ -132,7 +132,8 @@ class GIT(SCM):
SCM.__init__(self, *args, **kwargs)
self.checkout_root = scm.GIT.GetCheckoutRoot(os.getcwd())
if not self.options.diff:
self.options.diff = scm.GIT.GenerateDiff(self.checkout_root)
self.options.diff = scm.GIT.GenerateDiff(self.checkout_root,
full_move=True)
if not self.options.name:
self.options.name = scm.GIT.GetPatchName(self.checkout_root)
if not self.options.email:
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment