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
experimental/szager/collated-output
maruel@chromium.org 16 years ago
parent 650bb1f97d
commit a93717670e

@ -831,16 +831,6 @@ def TryChange(change_info, args, swallow_exception):
root = os.path.join(root, '') root = os.path.join(root, '')
return subpath[len(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 = [] trychange_args = []
settings = { settings = {
'port': GetCodeReviewSetting('TRYSERVER_HTTP_PORT'), 'port': GetCodeReviewSetting('TRYSERVER_HTTP_PORT'),
@ -854,7 +844,7 @@ def TryChange(change_info, args, swallow_exception):
if v: if v:
trychange_args.extend(['--' + k, v]) trychange_args.extend(['--' + k, v])
gclient_root = FindGclientRootDir(GetRepositoryRoot()) gclient_root = gclient_utils.FindGclientRoot(GetRepositoryRoot())
if gclient_root: if gclient_root:
trychange_args.extend(['--root', PathDifference(gclient_root, trychange_args.extend(['--root', PathDifference(gclient_root,
GetRepositoryRoot())]) GetRepositoryRoot())])

@ -307,3 +307,13 @@ def IsUsingGit(root, paths):
if os.path.exists(os.path.join(root, path, '.git')): if os.path.exists(os.path.join(root, path, '.git')):
return True return True
return False 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 return upstream_branch
@staticmethod @staticmethod
def GenerateDiff(cwd, branch=None): def GenerateDiff(cwd, branch=None, full_move=False):
"""Diffs against the upstream branch or optionally another branch.""" """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: if not branch:
branch = GIT.GetUpstream(cwd) branch = GIT.GetUpstream(cwd)
diff = GIT.Capture(['diff-tree', '-p', '--no-prefix', branch, 'HEAD'], command = ['diff-tree', '-p', '--no-prefix', branch, 'HEAD']
cwd).splitlines(True) if not full_move:
command.append('-C')
diff = GIT.Capture(command, cwd).splitlines(True)
for i in range(len(diff)): for i in range(len(diff)):
# In the case of added files, replace /dev/null with the path to the # In the case of added files, replace /dev/null with the path to the
# file being added. # file being added.
@ -524,7 +529,9 @@ class SVN(object):
"""Diffs a single file. """Diffs a single file.
Be sure to be in the appropriate directory before calling to have the 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 # Use svn info output instead of os.path.isdir because the latter fails
# when the file is deleted. # when the file is deleted.
if SVN.CaptureInfo(filename).get("Node Kind") == "directory": if SVN.CaptureInfo(filename).get("Node Kind") == "directory":

@ -15,6 +15,7 @@ class GclientUtilsUnittest(SuperMoxTestBase):
def testMembersChanged(self): def testMembersChanged(self):
members = [ members = [
'CheckCall', 'CheckCallError', 'Error', 'FileRead', 'FileWrite', 'CheckCall', 'CheckCallError', 'Error', 'FileRead', 'FileWrite',
'FindGclientRoot',
'FullUrlFromRelative', 'FullUrlFromRelative2', 'GetNamedNodeText', 'FullUrlFromRelative', 'FullUrlFromRelative2', 'GetNamedNodeText',
'GetNodeNamedAttributeText', 'IsUsingGit', 'ParseXML', 'GetNodeNamedAttributeText', 'IsUsingGit', 'ParseXML',
'PrintableObject', 'RemoveDirectory', 'SplitUrlRevision', 'PrintableObject', 'RemoveDirectory', 'SplitUrlRevision',

@ -83,7 +83,8 @@ class GITUnittest(TryChangeTestsBase):
def testBasic(self): def testBasic(self):
trychange.os.getcwd().AndReturn(self.fake_root) trychange.os.getcwd().AndReturn(self.fake_root)
trychange.scm.GIT.GetCheckoutRoot(self.fake_root).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.GetPatchName(self.fake_root).AndReturn('bleh-1233')
trychange.scm.GIT.GetEmail(self.fake_root).AndReturn('georges@example.com') trychange.scm.GIT.GetEmail(self.fake_root).AndReturn('georges@example.com')
self.mox.ReplayAll() self.mox.ReplayAll()

@ -132,7 +132,8 @@ class GIT(SCM):
SCM.__init__(self, *args, **kwargs) SCM.__init__(self, *args, **kwargs)
self.checkout_root = scm.GIT.GetCheckoutRoot(os.getcwd()) self.checkout_root = scm.GIT.GetCheckoutRoot(os.getcwd())
if not self.options.diff: 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: if not self.options.name:
self.options.name = scm.GIT.GetPatchName(self.checkout_root) self.options.name = scm.GIT.GetPatchName(self.checkout_root)
if not self.options.email: if not self.options.email:

Loading…
Cancel
Save