| OLD | NEW | 
|---|
| 1 #!/usr/bin/env python | 1 #!/usr/bin/env python | 
| 2 # Copyright (c) 2012 The Chromium Authors. All rights reserved. | 2 # Copyright (c) 2012 The Chromium Authors. All rights reserved. | 
| 3 # Use of this source code is governed by a BSD-style license that can be | 3 # Use of this source code is governed by a BSD-style license that can be | 
| 4 # found in the LICENSE file. | 4 # found in the LICENSE file. | 
| 5 | 5 | 
| 6 # Copyright (C) 2008 Evan Martin <martine@danga.com> | 6 # Copyright (C) 2008 Evan Martin <martine@danga.com> | 
| 7 | 7 | 
| 8 """A git-command for integrating reviews on Rietveld.""" | 8 """A git-command for integrating reviews on Rietveld.""" | 
| 9 | 9 | 
| 10 from distutils.version import LooseVersion | 10 from distutils.version import LooseVersion | 
| (...skipping 1844 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
| 1855     print('Are you sure you didn\'t mean \'git cl dcommit\'?') | 1855     print('Are you sure you didn\'t mean \'git cl dcommit\'?') | 
| 1856     ask_for_data('[Press enter to push or ctrl-C to quit]') | 1856     ask_for_data('[Press enter to push or ctrl-C to quit]') | 
| 1857   return SendUpstream(parser, args, 'push') | 1857   return SendUpstream(parser, args, 'push') | 
| 1858 | 1858 | 
| 1859 | 1859 | 
| 1860 @subcommand.usage('<patch url or issue id>') | 1860 @subcommand.usage('<patch url or issue id>') | 
| 1861 def CMDpatch(parser, args): | 1861 def CMDpatch(parser, args): | 
| 1862   """Patches in a code review.""" | 1862   """Patches in a code review.""" | 
| 1863   parser.add_option('-b', dest='newbranch', | 1863   parser.add_option('-b', dest='newbranch', | 
| 1864                     help='create a new branch off trunk for the patch') | 1864                     help='create a new branch off trunk for the patch') | 
| 1865   parser.add_option('-f', action='store_true', dest='force', | 1865   parser.add_option('-f', '--force', action='store_true', | 
| 1866                     help='with -b, clobber any existing branch') | 1866                     help='with -b, clobber any existing branch') | 
| 1867   parser.add_option('--reject', action='store_true', dest='reject', | 1867   parser.add_option('-d', '--directory', action='store', metavar='DIR', | 
|  | 1868                     help='Change to the directory DIR immediately, ' | 
|  | 1869                          'before doing anything else.') | 
|  | 1870   parser.add_option('--reject', action='store_true', | 
| 1868                     help='failed patches spew .rej files rather than ' | 1871                     help='failed patches spew .rej files rather than ' | 
| 1869                         'attempting a 3-way merge') | 1872                         'attempting a 3-way merge') | 
| 1870   parser.add_option('-n', '--no-commit', action='store_true', dest='nocommit', | 1873   parser.add_option('-n', '--no-commit', action='store_true', dest='nocommit', | 
| 1871                     help="don't commit after patch applies") | 1874                     help="don't commit after patch applies") | 
| 1872   (options, args) = parser.parse_args(args) | 1875   (options, args) = parser.parse_args(args) | 
| 1873   if len(args) != 1: | 1876   if len(args) != 1: | 
| 1874     parser.print_help() | 1877     parser.print_help() | 
| 1875     return 1 | 1878     return 1 | 
| 1876   issue_arg = args[0] | 1879   issue_arg = args[0] | 
| 1877 | 1880 | 
| 1878   # TODO(maruel): Use apply_issue.py | 1881   # TODO(maruel): Use apply_issue.py | 
| 1879   # TODO(ukai): use gerrit-cherry-pick for gerrit repository? | 1882   # TODO(ukai): use gerrit-cherry-pick for gerrit repository? | 
| 1880 | 1883 | 
| 1881   if options.newbranch: | 1884   if options.newbranch: | 
| 1882     if options.force: | 1885     if options.force: | 
| 1883       RunGit(['branch', '-D', options.newbranch], | 1886       RunGit(['branch', '-D', options.newbranch], | 
| 1884           stderr=subprocess2.PIPE, error_ok=True) | 1887           stderr=subprocess2.PIPE, error_ok=True) | 
| 1885     RunGit(['checkout', '-b', options.newbranch, | 1888     RunGit(['checkout', '-b', options.newbranch, | 
| 1886             Changelist().GetUpstreamBranch()]) | 1889             Changelist().GetUpstreamBranch()]) | 
| 1887 | 1890 | 
| 1888   return PatchIssue(issue_arg, options.reject, options.nocommit) | 1891   return PatchIssue(issue_arg, options.reject, options.nocommit, | 
|  | 1892                     options.directory) | 
| 1889 | 1893 | 
| 1890 | 1894 | 
| 1891 def PatchIssue(issue_arg, reject, nocommit): | 1895 def PatchIssue(issue_arg, reject, nocommit, directory): | 
| 1892   if type(issue_arg) is int or issue_arg.isdigit(): | 1896   if type(issue_arg) is int or issue_arg.isdigit(): | 
| 1893     # Input is an issue id.  Figure out the URL. | 1897     # Input is an issue id.  Figure out the URL. | 
| 1894     issue = int(issue_arg) | 1898     issue = int(issue_arg) | 
| 1895     cl = Changelist(issue=issue) | 1899     cl = Changelist(issue=issue) | 
| 1896     patchset = cl.GetMostRecentPatchset() | 1900     patchset = cl.GetMostRecentPatchset() | 
| 1897     patch_data = cl.GetPatchSetDiff(issue, patchset) | 1901     patch_data = cl.GetPatchSetDiff(issue, patchset) | 
| 1898   else: | 1902   else: | 
| 1899     # Assume it's a URL to the patch. Default to https. | 1903     # Assume it's a URL to the patch. Default to https. | 
| 1900     issue_url = gclient_utils.UpgradeToHttps(issue_arg) | 1904     issue_url = gclient_utils.UpgradeToHttps(issue_arg) | 
| 1901     match = re.match(r'.*?/issue(\d+)_(\d+).diff', issue_url) | 1905     match = re.match(r'.*?/issue(\d+)_(\d+).diff', issue_url) | 
| (...skipping 21 matching lines...) Expand all  Loading... | 
| 1923     DieWithError('Git patch mungling failed.') | 1927     DieWithError('Git patch mungling failed.') | 
| 1924   logging.info(patch_data) | 1928   logging.info(patch_data) | 
| 1925   env = os.environ.copy() | 1929   env = os.environ.copy() | 
| 1926   # 'cat' is a magical git string that disables pagers on all platforms. | 1930   # 'cat' is a magical git string that disables pagers on all platforms. | 
| 1927   env['GIT_PAGER'] = 'cat' | 1931   env['GIT_PAGER'] = 'cat' | 
| 1928 | 1932 | 
| 1929   # We use "git apply" to apply the patch instead of "patch" so that we can | 1933   # We use "git apply" to apply the patch instead of "patch" so that we can | 
| 1930   # pick up file adds. | 1934   # pick up file adds. | 
| 1931   # The --index flag means: also insert into the index (so we catch adds). | 1935   # The --index flag means: also insert into the index (so we catch adds). | 
| 1932   cmd = ['git', 'apply', '--index', '-p0'] | 1936   cmd = ['git', 'apply', '--index', '-p0'] | 
|  | 1937   if directory: | 
|  | 1938     cmd.extend(('--directory', directory)) | 
| 1933   if reject: | 1939   if reject: | 
| 1934     cmd.append('--reject') | 1940     cmd.append('--reject') | 
| 1935   elif IsGitVersionAtLeast('1.7.12'): | 1941   elif IsGitVersionAtLeast('1.7.12'): | 
| 1936     cmd.append('--3way') | 1942     cmd.append('--3way') | 
| 1937   try: | 1943   try: | 
| 1938     subprocess2.check_call(cmd, env=env, | 1944     subprocess2.check_call(cmd, env=env, | 
| 1939                            stdin=patch_data, stdout=subprocess2.VOID) | 1945                            stdin=patch_data, stdout=subprocess2.VOID) | 
| 1940   except subprocess2.CalledProcessError: | 1946   except subprocess2.CalledProcessError: | 
| 1941     DieWithError('Failed to apply the patch') | 1947     DieWithError('Failed to apply the patch') | 
| 1942 | 1948 | 
| (...skipping 210 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
| 2153   """shows differences between local tree and last upload.""" | 2159   """shows differences between local tree and last upload.""" | 
| 2154   cl = Changelist() | 2160   cl = Changelist() | 
| 2155   branch = cl.GetBranch() | 2161   branch = cl.GetBranch() | 
| 2156   TMP_BRANCH = 'git-cl-diff' | 2162   TMP_BRANCH = 'git-cl-diff' | 
| 2157   base_branch = RunGit(['merge-base', cl.GetUpstreamBranch(), 'HEAD']).strip() | 2163   base_branch = RunGit(['merge-base', cl.GetUpstreamBranch(), 'HEAD']).strip() | 
| 2158 | 2164 | 
| 2159   # Create a new branch based on the merge-base | 2165   # Create a new branch based on the merge-base | 
| 2160   RunGit(['checkout', '-q', '-b', TMP_BRANCH, base_branch]) | 2166   RunGit(['checkout', '-q', '-b', TMP_BRANCH, base_branch]) | 
| 2161   try: | 2167   try: | 
| 2162     # Patch in the latest changes from rietveld. | 2168     # Patch in the latest changes from rietveld. | 
| 2163     rtn = PatchIssue(cl.GetIssue(), False, False) | 2169     rtn = PatchIssue(cl.GetIssue(), False, False, None) | 
| 2164     if rtn != 0: | 2170     if rtn != 0: | 
| 2165       return rtn | 2171       return rtn | 
| 2166 | 2172 | 
| 2167     # Switch back to starting brand and diff against the temporary | 2173     # Switch back to starting brand and diff against the temporary | 
| 2168     # branch containing the latest rietveld patch. | 2174     # branch containing the latest rietveld patch. | 
| 2169     subprocess2.check_call(['git', 'diff', TMP_BRANCH, branch]) | 2175     subprocess2.check_call(['git', 'diff', TMP_BRANCH, branch]) | 
| 2170   finally: | 2176   finally: | 
| 2171     RunGit(['checkout', '-q', branch]) | 2177     RunGit(['checkout', '-q', branch]) | 
| 2172     RunGit(['branch', '-D', TMP_BRANCH]) | 2178     RunGit(['branch', '-D', TMP_BRANCH]) | 
| 2173 | 2179 | 
| (...skipping 128 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
| 2302         ('AppEngine is misbehaving and returned HTTP %d, again. Keep faith ' | 2308         ('AppEngine is misbehaving and returned HTTP %d, again. Keep faith ' | 
| 2303           'and retry or visit go/isgaeup.\n%s') % (e.code, str(e))) | 2309           'and retry or visit go/isgaeup.\n%s') % (e.code, str(e))) | 
| 2304 | 2310 | 
| 2305 | 2311 | 
| 2306 if __name__ == '__main__': | 2312 if __name__ == '__main__': | 
| 2307   # These affect sys.stdout so do it outside of main() to simplify mocks in | 2313   # These affect sys.stdout so do it outside of main() to simplify mocks in | 
| 2308   # unit testing. | 2314   # unit testing. | 
| 2309   fix_encoding.fix_encoding() | 2315   fix_encoding.fix_encoding() | 
| 2310   colorama.init() | 2316   colorama.init() | 
| 2311   sys.exit(main(sys.argv[1:])) | 2317   sys.exit(main(sys.argv[1:])) | 
| OLD | NEW | 
|---|