OLD | NEW |
1 # Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 # Copyright (c) 2010 The Chromium Authors. All rights reserved. |
2 # Use of this source code is governed by a BSD-style license that can be | 2 # Use of this source code is governed by a BSD-style license that can be |
3 # found in the LICENSE file. | 3 # found in the LICENSE file. |
4 | 4 |
5 """Gclient-specific SCM-specific operations.""" | 5 """Gclient-specific SCM-specific operations.""" |
6 | 6 |
7 import logging | 7 import logging |
8 import os | 8 import os |
9 import posixpath | 9 import posixpath |
10 import re | 10 import re |
| 11 import sys |
11 import time | 12 import time |
12 | 13 |
13 import scm | 14 import scm |
14 import gclient_utils | 15 import gclient_utils |
15 | 16 |
16 | 17 |
17 class DiffFilterer(object): | 18 class DiffFilterer(object): |
18 """Simple class which tracks which file is being diffed and | 19 """Simple class which tracks which file is being diffed and |
19 replaces instances of its file name in the original and | 20 replaces instances of its file name in the original and |
20 working copy lines of the svn/git diff output.""" | 21 working copy lines of the svn/git diff output.""" |
(...skipping 21 matching lines...) Expand all Loading... |
42 if (line.startswith(self.index_string)): | 43 if (line.startswith(self.index_string)): |
43 self.SetCurrentFile(line[len(self.index_string):]) | 44 self.SetCurrentFile(line[len(self.index_string):]) |
44 line = self._Replace(line) | 45 line = self._Replace(line) |
45 else: | 46 else: |
46 if (line.startswith(self.original_prefix) or | 47 if (line.startswith(self.original_prefix) or |
47 line.startswith(self.working_prefix)): | 48 line.startswith(self.working_prefix)): |
48 line = self._Replace(line) | 49 line = self._Replace(line) |
49 print(line) | 50 print(line) |
50 | 51 |
51 | 52 |
| 53 def ask_for_data(prompt): |
| 54 try: |
| 55 return raw_input(prompt) |
| 56 except KeyboardInterrupt: |
| 57 # Hide the exception. |
| 58 sys.exit(1) |
| 59 |
| 60 |
52 ### SCM abstraction layer | 61 ### SCM abstraction layer |
53 | 62 |
54 # Factory Method for SCM wrapper creation | 63 # Factory Method for SCM wrapper creation |
55 | 64 |
56 def GetScmName(url): | 65 def GetScmName(url): |
57 if url: | 66 if url: |
58 url, _ = gclient_utils.SplitUrlRevision(url) | 67 url, _ = gclient_utils.SplitUrlRevision(url) |
59 if (url.startswith('git://') or url.startswith('ssh://') or | 68 if (url.startswith('git://') or url.startswith('ssh://') or |
60 url.endswith('.git')): | 69 url.endswith('.git')): |
61 return 'git' | 70 return 'git' |
(...skipping 284 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
346 merge_output = scm.GIT.Capture(['merge', '--ff-only', upstream_branch], | 355 merge_output = scm.GIT.Capture(['merge', '--ff-only', upstream_branch], |
347 cwd=self.checkout_path) | 356 cwd=self.checkout_path) |
348 except gclient_utils.CheckCallError, e: | 357 except gclient_utils.CheckCallError, e: |
349 if re.match('fatal: Not possible to fast-forward, aborting.', e.stderr): | 358 if re.match('fatal: Not possible to fast-forward, aborting.', e.stderr): |
350 if not printed_path: | 359 if not printed_path: |
351 print('\n_____ %s%s' % (self.relpath, rev_str)) | 360 print('\n_____ %s%s' % (self.relpath, rev_str)) |
352 printed_path = True | 361 printed_path = True |
353 while True: | 362 while True: |
354 try: | 363 try: |
355 # TODO(maruel): That can't work with --jobs. | 364 # TODO(maruel): That can't work with --jobs. |
356 action = str(raw_input("Cannot fast-forward merge, attempt to " | 365 action = ask_for_data( |
357 "rebase? (y)es / (q)uit / (s)kip : ")) | 366 'Cannot fast-forward merge, attempt to rebase? ' |
| 367 '(y)es / (q)uit / (s)kip : ') |
358 except ValueError: | 368 except ValueError: |
359 gclient_utils.Error('Invalid Character') | 369 raise gclient_utils.Error('Invalid Character') |
360 continue | |
361 if re.match(r'yes|y', action, re.I): | 370 if re.match(r'yes|y', action, re.I): |
362 self._AttemptRebase(upstream_branch, files, options, | 371 self._AttemptRebase(upstream_branch, files, options, |
363 printed_path=printed_path) | 372 printed_path=printed_path) |
364 printed_path = True | 373 printed_path = True |
365 break | 374 break |
366 elif re.match(r'quit|q', action, re.I): | 375 elif re.match(r'quit|q', action, re.I): |
367 raise gclient_utils.Error("Can't fast-forward, please merge or " | 376 raise gclient_utils.Error("Can't fast-forward, please merge or " |
368 "rebase manually.\n" | 377 "rebase manually.\n" |
369 "cd %s && git " % self.checkout_path | 378 "cd %s && git " % self.checkout_path |
370 + "rebase %s" % upstream_branch) | 379 + "rebase %s" % upstream_branch) |
(...skipping 162 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
533 if branch: | 542 if branch: |
534 rebase_cmd.append(branch) | 543 rebase_cmd.append(branch) |
535 | 544 |
536 try: | 545 try: |
537 rebase_output = scm.GIT.Capture(rebase_cmd, cwd=self.checkout_path) | 546 rebase_output = scm.GIT.Capture(rebase_cmd, cwd=self.checkout_path) |
538 except gclient_utils.CheckCallError, e: | 547 except gclient_utils.CheckCallError, e: |
539 if (re.match(r'cannot rebase: you have unstaged changes', e.stderr) or | 548 if (re.match(r'cannot rebase: you have unstaged changes', e.stderr) or |
540 re.match(r'cannot rebase: your index contains uncommitted changes', | 549 re.match(r'cannot rebase: your index contains uncommitted changes', |
541 e.stderr)): | 550 e.stderr)): |
542 while True: | 551 while True: |
543 rebase_action = str(raw_input("Cannot rebase because of unstaged " | 552 rebase_action = ask_for_data( |
544 "changes.\n'git reset --hard HEAD' ?\n" | 553 'Cannot rebase because of unstaged changes.\n' |
545 "WARNING: destroys any uncommitted " | 554 '\'git reset --hard HEAD\' ?\n' |
546 "work in your current branch!" | 555 'WARNING: destroys any uncommitted work in your current branch!' |
547 " (y)es / (q)uit / (s)how : ")) | 556 ' (y)es / (q)uit / (s)how : ') |
548 if re.match(r'yes|y', rebase_action, re.I): | 557 if re.match(r'yes|y', rebase_action, re.I): |
549 self._Run(['reset', '--hard', 'HEAD'], options) | 558 self._Run(['reset', '--hard', 'HEAD'], options) |
550 # Should this be recursive? | 559 # Should this be recursive? |
551 rebase_output = scm.GIT.Capture(rebase_cmd, cwd=self.checkout_path) | 560 rebase_output = scm.GIT.Capture(rebase_cmd, cwd=self.checkout_path) |
552 break | 561 break |
553 elif re.match(r'quit|q', rebase_action, re.I): | 562 elif re.match(r'quit|q', rebase_action, re.I): |
554 raise gclient_utils.Error("Please merge or rebase manually\n" | 563 raise gclient_utils.Error("Please merge or rebase manually\n" |
555 "cd %s && git " % self.checkout_path | 564 "cd %s && git " % self.checkout_path |
556 + "%s" % ' '.join(rebase_cmd)) | 565 + "%s" % ' '.join(rebase_cmd)) |
557 elif re.match(r'show|s', rebase_action, re.I): | 566 elif re.match(r'show|s', rebase_action, re.I): |
(...skipping 366 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
924 | 933 |
925 This method returns a new list to be used as a command.""" | 934 This method returns a new list to be used as a command.""" |
926 new_command = command[:] | 935 new_command = command[:] |
927 if revision: | 936 if revision: |
928 new_command.extend(['--revision', str(revision).strip()]) | 937 new_command.extend(['--revision', str(revision).strip()]) |
929 # --force was added to 'svn update' in svn 1.5. | 938 # --force was added to 'svn update' in svn 1.5. |
930 if ((options.force or options.manually_grab_svn_rev) and | 939 if ((options.force or options.manually_grab_svn_rev) and |
931 scm.SVN.AssertVersion("1.5")[0]): | 940 scm.SVN.AssertVersion("1.5")[0]): |
932 new_command.append('--force') | 941 new_command.append('--force') |
933 return new_command | 942 return new_command |
OLD | NEW |