From 178d06c779aec8a23d751fa1a4a58b99bd5912ce Mon Sep 17 00:00:00 2001 From: "maruel@chromium.org" Date: Sat, 16 May 2009 01:40:42 +0000 Subject: [PATCH] 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 --- git-cl.py | 33 ++++++++++++++++++++++++--------- git-try.py | 9 ++++++--- 2 files changed, 30 insertions(+), 12 deletions(-) diff --git a/git-cl.py b/git-cl.py index 4763fd169..a8ebf6cef 100755 --- a/git-cl.py +++ b/git-cl.py @@ -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', diff --git a/git-try.py b/git-try.py index 9e18eb30f..b289a2056 100755 --- a/git-try.py +++ b/git-try.py @@ -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(),