Commit 178d06c7 authored by maruel@chromium.org's avatar maruel@chromium.org

Sync git-cl and git-try to the master branch.

Remove import readline since it is not used and not available on win32
Fix the tempfile.NamedTemporaryFile() handling on win32.

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

git-svn-id: svn://svn.chromium.org/chrome/trunk/tools/depot_tools@16220 0039d316-1c4b-4281-b951-d872f2087c98
parent 3d23524c
......@@ -6,7 +6,6 @@ import getpass
import optparse
import os
import re
import readline
import subprocess
import sys
import tempfile
......@@ -14,6 +13,11 @@ import textwrap
import upload
import urllib2
try:
import readline
except ImportError:
pass
DEFAULT_SERVER = 'codereview.appspot.com'
def DieWithError(message):
......@@ -21,11 +25,16 @@ def DieWithError(message):
sys.exit(1)
def RunGit(args, error_ok=False, error_message=None, exit_code=False):
def RunGit(args, error_ok=False, error_message=None, exit_code=False,
redirect_stdout=True):
cmd = ['git'] + args
# Useful for debugging:
# print >>sys.stderr, ' '.join(cmd)
proc = subprocess.Popen(cmd, stdout=subprocess.PIPE)
if redirect_stdout:
stdout = subprocess.PIPE
else:
stdout = None
proc = subprocess.Popen(cmd, stdout=stdout)
output = proc.communicate()[0]
if exit_code:
return proc.returncode
......@@ -86,10 +95,6 @@ class Settings:
'refs/remotes']).splitlines()
svn_refs = {}
for ref in remotes:
# git-svn remote refs are generally directly in the refs/remotes/dir,
# not a subdirectory (like refs/remotes/origin/master).
if '/' in ref[len('refs/remotes/'):]:
continue
match = git_svn_re.search(RunGit(['cat-file', '-p', ref]))
if match:
svn_refs[match.group(1)] = ref
......@@ -377,7 +382,9 @@ def UserEditedLog(starting_text):
if ret != 0:
return
text = open(filename).read()
file.flush()
file.seek(0)
text = file.read()
file.close()
stripcomment_re = re.compile(r'^#.*$', re.MULTILINE)
return stripcomment_re.sub('', text).strip()
......@@ -521,6 +528,14 @@ def CmdDCommit(args):
if RunGit(['show-ref', '--quiet', '--verify', 'refs/heads/' + MERGE_BRANCH],
exit_code=True) == 0:
RunGit(['branch', '-D', MERGE_BRANCH])
# We might be in a directory that's present in this branch but not in the
# trunk. Move up to the top of the tree so that git commands that expect a
# valid CWD won't fail after we check out the merge branch.
rel_base_path = RunGit(['rev-parse', '--show-cdup']).strip()
if rel_base_path:
os.chdir(rel_base_path)
# Stuff our change into the merge branch.
RunGit(['checkout', '-q', '-b', MERGE_BRANCH, base_branch])
RunGit(['merge', '--squash', cl.GetBranchRef()])
......@@ -618,7 +633,7 @@ def CmdPatch(args):
def CmdRebase(args):
# Provide a wrapper for git svn rebase to help avoid accidental
# git svn dcommit.
RunGit(['svn', 'rebase'])
RunGit(['svn', 'rebase'], redirect_stdout=False)
def GetTreeStatus():
"""Fetches the tree status and returns either 'open', 'closed',
......
......@@ -45,9 +45,8 @@ def GetBranchName():
def GetPatchName():
"""Construct a name for this patch."""
# TODO: perhaps include the hash of the current commit, to distinguish
# patches?
return GetBranchName()
short_sha = Backquote(['git', 'rev-parse', '--short=4', 'HEAD'])
return GetBranchName() + '-' + short_sha
def GetRevision():
......@@ -176,6 +175,10 @@ if __name__ == '__main__':
'-r', GetRevision(),
'--diff', diff_file.name,
]
if options.bot:
args.extend(['--bot', options.bot])
if options.clobber:
args.append('--clobber')
if GetRietveldPatchsetNumber():
args.extend([
'--issue', GetRietveldIssueNumber(),
......
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