Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(108)

Side by Side Diff: gcl.py

Issue 8771042: Enforces using cwd in all svn calls. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/tools/depot_tools
Patch Set: Address comments Created 9 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « no previous file | gclient_scm.py » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 #!/usr/bin/env python 1 #!/usr/bin/env python
2 # Copyright (c) 2011 The Chromium Authors. All rights reserved. 2 # Copyright (c) 2011 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 """\ 6 """\
7 Wrapper script around Rietveld's upload.py that simplifies working with groups 7 Wrapper script around Rietveld's upload.py that simplifies working with groups
8 of files. 8 of files.
9 """ 9 """
10 10
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after
80 home = os.getenv(home_var) 80 home = os.getenv(home_var)
81 if home != None: 81 if home != None:
82 full_path = os.path.join(home, filename) 82 full_path = os.path.join(home, filename)
83 if os.path.exists(full_path): 83 if os.path.exists(full_path):
84 return full_path 84 return full_path
85 return None 85 return None
86 86
87 87
88 def UnknownFiles(): 88 def UnknownFiles():
89 """Runs svn status and returns unknown files.""" 89 """Runs svn status and returns unknown files."""
90 return [item[1] for item in SVN.CaptureStatus([]) if item[0][0] == '?'] 90 return [
91 item[1] for item in SVN.CaptureStatus([], GetRepositoryRoot())
92 if item[0][0] == '?'
93 ]
91 94
92 95
93 def GetRepositoryRoot(): 96 def GetRepositoryRoot():
94 """Returns the top level directory of the current repository. 97 """Returns the top level directory of the current repository.
95 98
96 The directory is returned as an absolute path. 99 The directory is returned as an absolute path.
97 """ 100 """
98 global REPOSITORY_ROOT 101 global REPOSITORY_ROOT
99 if not REPOSITORY_ROOT: 102 if not REPOSITORY_ROOT:
100 REPOSITORY_ROOT = SVN.GetCheckoutRoot(os.getcwd()) 103 REPOSITORY_ROOT = SVN.GetCheckoutRoot(os.getcwd())
(...skipping 30 matching lines...) Expand all
131 if filename not in FILES_CACHE: 134 if filename not in FILES_CACHE:
132 # Don't try to look up twice. 135 # Don't try to look up twice.
133 FILES_CACHE[filename] = None 136 FILES_CACHE[filename] = None
134 # First we check if we have a cached version. 137 # First we check if we have a cached version.
135 try: 138 try:
136 cached_file = os.path.join(GetCacheDir(), filename) 139 cached_file = os.path.join(GetCacheDir(), filename)
137 except (gclient_utils.Error, subprocess2.CalledProcessError): 140 except (gclient_utils.Error, subprocess2.CalledProcessError):
138 return None 141 return None
139 if (not os.path.exists(cached_file) or 142 if (not os.path.exists(cached_file) or
140 (time.time() - os.stat(cached_file).st_mtime) > max_age): 143 (time.time() - os.stat(cached_file).st_mtime) > max_age):
141 dir_info = SVN.CaptureInfo('.') 144 dir_info = SVN.CaptureLocalInfo([], '.')
142 repo_root = dir_info['Repository Root'] 145 repo_root = dir_info['Repository Root']
143 if use_root: 146 if use_root:
144 url_path = repo_root 147 url_path = repo_root
145 else: 148 else:
146 url_path = dir_info['URL'] 149 url_path = dir_info['URL']
147 while True: 150 while True:
148 # Look in the repository at the current level for the file. 151 # Look in the repository at the current level for the file.
149 for _ in range(5): 152 for _ in range(5):
150 content = None 153 content = None
151 try: 154 try:
(...skipping 389 matching lines...) Expand 10 before | Expand all | Expand 10 after
541 values = ChangeInfo._LoadOldFormat(content) 544 values = ChangeInfo._LoadOldFormat(content)
542 save = True 545 save = True
543 except ValueError: 546 except ValueError:
544 ErrorExit( 547 ErrorExit(
545 ('Changelist file %s is corrupt.\n' 548 ('Changelist file %s is corrupt.\n'
546 'Either run "gcl delete %s" or manually edit the file') % ( 549 'Either run "gcl delete %s" or manually edit the file') % (
547 info_file, changename)) 550 info_file, changename))
548 files = values['files'] 551 files = values['files']
549 if update_status: 552 if update_status:
550 for item in files[:]: 553 for item in files[:]:
551 filename = os.path.join(local_root, item[1]) 554 status_result = SVN.CaptureStatus(item[1], local_root)
552 status_result = SVN.CaptureStatus(filename)
553 if not status_result or not status_result[0][0]: 555 if not status_result or not status_result[0][0]:
554 # File has been reverted. 556 # File has been reverted.
555 save = True 557 save = True
556 files.remove(item) 558 files.remove(item)
557 continue 559 continue
558 status = status_result[0][0] 560 status = status_result[0][0]
559 if status != item[0]: 561 if status != item[0]:
560 save = True 562 save = True
561 files[files.index(item)] = (status, item[1]) 563 files[files.index(item)] = (status, item[1])
562 change_info = ChangeInfo( 564 change_info = ChangeInfo(
(...skipping 108 matching lines...) Expand 10 before | Expand all | Expand 10 after
671 673
672 # Get a list of all files in changelists. 674 # Get a list of all files in changelists.
673 files_in_cl = {} 675 files_in_cl = {}
674 for cl in GetCLs(): 676 for cl in GetCLs():
675 change_info = ChangeInfo.Load(cl, GetRepositoryRoot(), 677 change_info = ChangeInfo.Load(cl, GetRepositoryRoot(),
676 fail_on_not_found=True, update_status=False) 678 fail_on_not_found=True, update_status=False)
677 for status, filename in change_info.GetFiles(): 679 for status, filename in change_info.GetFiles():
678 files_in_cl[filename] = change_info.name 680 files_in_cl[filename] = change_info.name
679 681
680 # Get all the modified files. 682 # Get all the modified files.
681 status_result = SVN.CaptureStatus(None) 683 status_result = SVN.CaptureStatus(None, GetRepositoryRoot())
682 for line in status_result: 684 for line in status_result:
683 status = line[0] 685 status = line[0]
684 filename = line[1] 686 filename = line[1]
685 if status[0] == "?": 687 if status[0] == "?":
686 continue 688 continue
687 if dir_prefix: 689 if dir_prefix:
688 filename = os.path.join(dir_prefix, filename) 690 filename = os.path.join(dir_prefix, filename)
689 change_list_name = "" 691 change_list_name = ""
690 if filename in files_in_cl: 692 if filename in files_in_cl:
691 change_list_name = files_in_cl[filename] 693 change_list_name = files_in_cl[filename]
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
726 if (files.get('') or (show_unknown_files and len(unknown_files))): 728 if (files.get('') or (show_unknown_files and len(unknown_files))):
727 print "\n--- Not in any changelist:" 729 print "\n--- Not in any changelist:"
728 for item in files.get('', []): 730 for item in files.get('', []):
729 print "".join(item) 731 print "".join(item)
730 if show_unknown_files: 732 if show_unknown_files:
731 for filename in unknown_files: 733 for filename in unknown_files:
732 print "? %s" % filename 734 print "? %s" % filename
733 return 0 735 return 0
734 736
735 737
736 def GenerateDiff(files, root=None): 738 def GenerateDiff(files):
737 return SVN.GenerateDiff(files, root=root) 739 return SVN.GenerateDiff(
740 files, GetRepositoryRoot(), full_move=False, revision=None)
738 741
739 742
740 def OptionallyDoPresubmitChecks(change_info, committing, args): 743 def OptionallyDoPresubmitChecks(change_info, committing, args):
741 if FilterFlag(args, "--no_presubmit") or FilterFlag(args, "--force"): 744 if FilterFlag(args, "--no_presubmit") or FilterFlag(args, "--force"):
742 return presubmit_support.PresubmitOutput() 745 return presubmit_support.PresubmitOutput()
743 return DoPresubmitChecks(change_info, committing, True) 746 return DoPresubmitChecks(change_info, committing, True)
744 747
745 748
746 def defer_attributes(a, b): 749 def defer_attributes(a, b):
747 """Copy attributes from an object (like a function) to another.""" 750 """Copy attributes from an object (like a function) to another."""
(...skipping 282 matching lines...) Expand 10 before | Expand all | Expand 10 after
1030 if viewvc_url: 1033 if viewvc_url:
1031 change_info.description += "\nCommitted: " + viewvc_url + revision 1034 change_info.description += "\nCommitted: " + viewvc_url + revision
1032 change_info.CloseIssue() 1035 change_info.CloseIssue()
1033 os.chdir(previous_cwd) 1036 os.chdir(previous_cwd)
1034 return 0 1037 return 0
1035 1038
1036 1039
1037 def CMDchange(args): 1040 def CMDchange(args):
1038 """Creates or edits a changelist. 1041 """Creates or edits a changelist.
1039 1042
1040 Only scans the current directory and subdirectories.""" 1043 Only scans the current directory and subdirectories.
1044 """
1045 # Verify the user is running the change command from a read-write checkout.
1046 svn_info = SVN.CaptureLocalInfo([], '.')
1047 if not svn_info:
1048 ErrorExit("Current checkout is unversioned. Please retry with a versioned "
1049 "directory.")
1050
1041 if len(args) == 0: 1051 if len(args) == 0:
1042 # Generate a random changelist name. 1052 # Generate a random changelist name.
1043 changename = GenerateChangeName() 1053 changename = GenerateChangeName()
1044 elif args[0] == '--force': 1054 elif args[0] == '--force':
1045 changename = GenerateChangeName() 1055 changename = GenerateChangeName()
1046 else: 1056 else:
1047 changename = args[0] 1057 changename = args[0]
1048 change_info = ChangeInfo.Load(changename, GetRepositoryRoot(), False, True) 1058 change_info = ChangeInfo.Load(changename, GetRepositoryRoot(), False, True)
1049 1059
1050 # Verify the user is running the change command from a read-write checkout.
1051 svn_info = SVN.CaptureInfo('.')
1052 if not svn_info:
1053 ErrorExit("Current checkout is unversioned. Please retry with a versioned "
1054 "directory.")
1055
1056 if len(args) == 2: 1060 if len(args) == 2:
1057 if not os.path.isfile(args[1]): 1061 if not os.path.isfile(args[1]):
1058 ErrorExit('The change "%s" doesn\'t exist.' % args[1]) 1062 ErrorExit('The change "%s" doesn\'t exist.' % args[1])
1059 f = open(args[1], 'rU') 1063 f = open(args[1], 'rU')
1060 override_description = f.read() 1064 override_description = f.read()
1061 f.close() 1065 f.close()
1062 else: 1066 else:
1063 override_description = None 1067 override_description = None
1064 1068
1065 if change_info.issue and not change_info.NeedsUpload(): 1069 if change_info.issue and not change_info.NeedsUpload():
(...skipping 366 matching lines...) Expand 10 before | Expand all | Expand 10 after
1432 return command(argv[1:]) 1436 return command(argv[1:])
1433 # Unknown command, try to pass that to svn 1437 # Unknown command, try to pass that to svn
1434 return CMDpassthru(argv) 1438 return CMDpassthru(argv)
1435 except (gclient_utils.Error, subprocess2.CalledProcessError), e: 1439 except (gclient_utils.Error, subprocess2.CalledProcessError), e:
1436 print >> sys.stderr, 'Got an exception' 1440 print >> sys.stderr, 'Got an exception'
1437 print >> sys.stderr, str(e) 1441 print >> sys.stderr, str(e)
1438 return 1 1442 return 1
1439 except upload.ClientLoginError, e: 1443 except upload.ClientLoginError, e:
1440 print >> sys.stderr, 'Got an exception logging in to Rietveld' 1444 print >> sys.stderr, 'Got an exception logging in to Rietveld'
1441 print >> sys.stderr, str(e) 1445 print >> sys.stderr, str(e)
1446 return 1
1442 except urllib2.HTTPError, e: 1447 except urllib2.HTTPError, e:
1443 if e.code != 500: 1448 if e.code != 500:
1444 raise 1449 raise
1445 print >> sys.stderr, ( 1450 print >> sys.stderr, (
1446 'AppEngine is misbehaving and returned HTTP %d, again. Keep faith ' 1451 'AppEngine is misbehaving and returned HTTP %d, again. Keep faith '
1447 'and retry or visit go/isgaeup.\n%s') % (e.code, str(e)) 1452 'and retry or visit go/isgaeup.\n%s') % (e.code, str(e))
1448 return 1 1453 return 1
1449 1454
1450 1455
1451 if __name__ == "__main__": 1456 if __name__ == "__main__":
1452 fix_encoding.fix_encoding() 1457 fix_encoding.fix_encoding()
1453 sys.exit(main(sys.argv[1:])) 1458 sys.exit(main(sys.argv[1:]))
OLDNEW
« no previous file with comments | « no previous file | gclient_scm.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698