| OLD | NEW |
| 1 #!/usr/bin/python | 1 #!/usr/bin/python |
| 2 # Copyright (c) 2006-2009 The Chromium Authors. All rights reserved. | 2 # Copyright (c) 2006-2009 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 # Wrapper script around Rietveld's upload.py that groups files into | 6 # Wrapper script around Rietveld's upload.py that groups files into |
| 7 # changelists. | 7 # changelists. |
| 8 | 8 |
| 9 import getpass | 9 import getpass |
| 10 import os | 10 import os |
| (...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 69 empty string is also returned. | 69 empty string is also returned. |
| 70 """ | 70 """ |
| 71 output = RunShell(["svn", "propget", property_name, file]) | 71 output = RunShell(["svn", "propget", property_name, file]) |
| 72 if (output.startswith("svn: ") and | 72 if (output.startswith("svn: ") and |
| 73 output.endswith("is not under version control")): | 73 output.endswith("is not under version control")): |
| 74 return "" | 74 return "" |
| 75 else: | 75 else: |
| 76 return output | 76 return output |
| 77 | 77 |
| 78 | 78 |
| 79 def GetSVNStatus(file): | |
| 80 """Returns the svn 1.5 svn status emulated output. | |
| 81 | |
| 82 @file can be a string (one file) or a list of files.""" | |
| 83 command = ["svn", "status", "--xml"] | |
| 84 if file is None: | |
| 85 pass | |
| 86 elif isinstance(file, basestring): | |
| 87 command.append(file) | |
| 88 else: | |
| 89 command.extend(file) | |
| 90 | |
| 91 status_letter = { | |
| 92 '': ' ', | |
| 93 'added': 'A', | |
| 94 'conflicted': 'C', | |
| 95 'deleted': 'D', | |
| 96 'ignored': 'I', | |
| 97 'missing': '!', | |
| 98 'modified': 'M', | |
| 99 'normal': ' ', | |
| 100 'replaced': 'R', | |
| 101 'unversioned': '?', | |
| 102 # TODO(maruel): Find the corresponding strings for X, ~ | |
| 103 } | |
| 104 output = RunShell(command) | |
| 105 dom = gclient.ParseXML(output) | |
| 106 results = [] | |
| 107 if dom: | |
| 108 # /status/target/entry/(wc-status|commit|author|date) | |
| 109 for target in dom.getElementsByTagName('target'): | |
| 110 base_path = target.getAttribute('path') | |
| 111 for entry in target.getElementsByTagName('entry'): | |
| 112 file = entry.getAttribute('path') | |
| 113 wc_status = entry.getElementsByTagName('wc-status') | |
| 114 assert len(wc_status) == 1 | |
| 115 # Emulate svn 1.5 status ouput... | |
| 116 statuses = [' ' for i in range(7)] | |
| 117 # Col 0 | |
| 118 xml_item_status = wc_status[0].getAttribute('item') | |
| 119 if xml_item_status in status_letter: | |
| 120 statuses[0] = status_letter[xml_item_status] | |
| 121 else: | |
| 122 raise Exception('Unknown item status "%s"; please implement me!' % | |
| 123 xml_item_status) | |
| 124 # Col 1 | |
| 125 xml_props_status = wc_status[0].getAttribute('props') | |
| 126 if xml_props_status == 'modified': | |
| 127 statuses[1] = 'M' | |
| 128 elif xml_props_status == 'conflicted': | |
| 129 statuses[1] = 'C' | |
| 130 elif (not xml_props_status or xml_props_status == 'none' or | |
| 131 xml_props_status == 'normal'): | |
| 132 pass | |
| 133 else: | |
| 134 raise Exception('Unknown props status "%s"; please implement me!' % | |
| 135 xml_props_status) | |
| 136 # Col 3 | |
| 137 if wc_status[0].getAttribute('copied') == 'true': | |
| 138 statuses[3] = '+' | |
| 139 item = (''.join(statuses), file) | |
| 140 results.append(item) | |
| 141 return results | |
| 142 | |
| 143 | |
| 144 def UnknownFiles(extra_args): | 79 def UnknownFiles(extra_args): |
| 145 """Runs svn status and prints unknown files. | 80 """Runs svn status and prints unknown files. |
| 146 | 81 |
| 147 Any args in |extra_args| are passed to the tool to support giving alternate | 82 Any args in |extra_args| are passed to the tool to support giving alternate |
| 148 code locations. | 83 code locations. |
| 149 """ | 84 """ |
| 150 return [item[1] for item in GetSVNStatus(extra_args) if item[0][0] == '?'] | 85 return [item[1] for item in gclient.CaptureSVNStatus(extra_args) |
| 86 if item[0][0] == '?'] |
| 151 | 87 |
| 152 | 88 |
| 153 def GetRepositoryRoot(): | 89 def GetRepositoryRoot(): |
| 154 """Returns the top level directory of the current repository. | 90 """Returns the top level directory of the current repository. |
| 155 | 91 |
| 156 The directory is returned as an absolute path. | 92 The directory is returned as an absolute path. |
| 157 """ | 93 """ |
| 158 global repository_root | 94 global repository_root |
| 159 if not repository_root: | 95 if not repository_root: |
| 160 infos = gclient.CaptureSVNInfo(os.getcwd(), print_error=False) | 96 infos = gclient.CaptureSVNInfo(os.getcwd(), print_error=False) |
| (...skipping 320 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 481 files = [] | 417 files = [] |
| 482 for line in split_data[1].splitlines(): | 418 for line in split_data[1].splitlines(): |
| 483 status = line[:7] | 419 status = line[:7] |
| 484 file = line[7:] | 420 file = line[7:] |
| 485 files.append((status, file)) | 421 files.append((status, file)) |
| 486 description = split_data[2] | 422 description = split_data[2] |
| 487 save = False | 423 save = False |
| 488 if update_status: | 424 if update_status: |
| 489 for file in files: | 425 for file in files: |
| 490 filename = os.path.join(GetRepositoryRoot(), file[1]) | 426 filename = os.path.join(GetRepositoryRoot(), file[1]) |
| 491 status_result = GetSVNStatus(filename) | 427 status_result = gclient.CaptureSVNStatus(filename) |
| 492 if not status_result or not status_result[0][0]: | 428 if not status_result or not status_result[0][0]: |
| 493 # File has been reverted. | 429 # File has been reverted. |
| 494 save = True | 430 save = True |
| 495 files.remove(file) | 431 files.remove(file) |
| 496 continue | 432 continue |
| 497 status = status_result[0][0] | 433 status = status_result[0][0] |
| 498 if status != file[0]: | 434 if status != file[0]: |
| 499 save = True | 435 save = True |
| 500 files[files.index(file)] = (status, file[1]) | 436 files[files.index(file)] = (status, file[1]) |
| 501 change_info = ChangeInfo(changename, issue, description, files) | 437 change_info = ChangeInfo(changename, issue, description, files) |
| (...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 540 dir_prefix = os.getcwd()[len(GetRepositoryRoot()):].strip(os.sep) | 476 dir_prefix = os.getcwd()[len(GetRepositoryRoot()):].strip(os.sep) |
| 541 | 477 |
| 542 # Get a list of all files in changelists. | 478 # Get a list of all files in changelists. |
| 543 files_in_cl = {} | 479 files_in_cl = {} |
| 544 for cl in GetCLs(): | 480 for cl in GetCLs(): |
| 545 change_info = LoadChangelistInfo(cl) | 481 change_info = LoadChangelistInfo(cl) |
| 546 for status, filename in change_info.files: | 482 for status, filename in change_info.files: |
| 547 files_in_cl[filename] = change_info.name | 483 files_in_cl[filename] = change_info.name |
| 548 | 484 |
| 549 # Get all the modified files. | 485 # Get all the modified files. |
| 550 status_result = GetSVNStatus(None) | 486 status_result = gclient.CaptureSVNStatus(None) |
| 551 for line in status_result: | 487 for line in status_result: |
| 552 status = line[0] | 488 status = line[0] |
| 553 filename = line[1] | 489 filename = line[1] |
| 554 if status[0] == "?": | 490 if status[0] == "?": |
| 555 continue | 491 continue |
| 556 if dir_prefix: | 492 if dir_prefix: |
| 557 filename = os.path.join(dir_prefix, filename) | 493 filename = os.path.join(dir_prefix, filename) |
| 558 change_list_name = "" | 494 change_list_name = "" |
| 559 if filename in files_in_cl: | 495 if filename in files_in_cl: |
| 560 change_list_name = files_in_cl[filename] | 496 change_list_name = files_in_cl[filename] |
| (...skipping 585 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1146 # the files. This allows commands such as 'gcl diff xxx' to work. | 1082 # the files. This allows commands such as 'gcl diff xxx' to work. |
| 1147 args =["svn", command] | 1083 args =["svn", command] |
| 1148 root = GetRepositoryRoot() | 1084 root = GetRepositoryRoot() |
| 1149 args.extend([os.path.join(root, x) for x in change_info.FileList()]) | 1085 args.extend([os.path.join(root, x) for x in change_info.FileList()]) |
| 1150 RunShell(args, True) | 1086 RunShell(args, True) |
| 1151 return 0 | 1087 return 0 |
| 1152 | 1088 |
| 1153 | 1089 |
| 1154 if __name__ == "__main__": | 1090 if __name__ == "__main__": |
| 1155 sys.exit(main()) | 1091 sys.exit(main()) |
| OLD | NEW |