| OLD | NEW |
| 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 OS 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 """Display active git branches and code changes in a ChromiumOS workspace.""" | 6 """Display active git branches and code changes in a ChromiumOS workspace.""" |
| 7 | 7 |
| 8 import optparse | 8 import optparse |
| 9 import os | 9 import os |
| 10 import re | 10 import re |
| 11 import subprocess | 11 import subprocess |
| 12 | 12 |
| (...skipping 24 matching lines...) Expand all Loading... |
| 37 | 37 |
| 38 def ShowName(relative_name, color): | 38 def ShowName(relative_name, color): |
| 39 """Display the directory name.""" | 39 """Display the directory name.""" |
| 40 | 40 |
| 41 if color: | 41 if color: |
| 42 print('\033[44m\033[37m%s\033[0m' % relative_name) | 42 print('\033[44m\033[37m%s\033[0m' % relative_name) |
| 43 else: | 43 else: |
| 44 print relative_name | 44 print relative_name |
| 45 | 45 |
| 46 | 46 |
| 47 def GetBranches(full_name, relative_name, color): | 47 def GetBranches(full_name, color): |
| 48 """Return a list of branch descriptions.""" | 48 """Return a list of branch descriptions.""" |
| 49 | 49 |
| 50 command = ['git', 'branch', '-vv'] | 50 command = ['git', 'branch', '-vv'] |
| 51 | 51 |
| 52 if color: | 52 if color: |
| 53 command.append('--color') | 53 command.append('--color') |
| 54 | 54 |
| 55 branches = RunCommand(full_name, command).splitlines() | 55 branches = RunCommand(full_name, command).splitlines() |
| 56 | 56 |
| 57 if re.search(r"\(no branch\)", branches[0]): | 57 if re.search(r"\(no branch\)", branches[0]): |
| 58 return [] | 58 return [] |
| 59 | 59 |
| 60 return branches | 60 return branches |
| 61 | 61 |
| 62 def GetStatus(full_name, relative_name, color): | 62 def GetStatus(full_name, color): |
| 63 """Return a list of files that have modifications.""" | 63 """Return a list of files that have modifications.""" |
| 64 | 64 |
| 65 command = ['git', 'status', '-s'] | 65 command = ['git', 'status', '-s'] |
| 66 | 66 |
| 67 return RunCommand(full_name, command).splitlines() | 67 return RunCommand(full_name, command).splitlines() |
| 68 | 68 |
| 69 | 69 |
| 70 def GetHistory(full_name, relative_name, color, author, days): | 70 def GetHistory(full_name, color, author, days): |
| 71 """Return a list of oneline log messages. | 71 """Return a list of oneline log messages. |
| 72 | 72 |
| 73 The messages are for the author going back a specified number of days. | 73 The messages are for the author going back a specified number of days. |
| 74 """ | 74 """ |
| 75 | 75 |
| 76 command = ['git', 'log', | 76 command = ['git', 'log', |
| 77 '--author=' + author, | 77 '--author=' + author, |
| 78 '--after=' + '-' + str(days) + 'days', | 78 '--after=' + '-' + str(days) + 'days', |
| 79 '--pretty=oneline', | 79 '--pretty=oneline', |
| 80 'm/master'] | 80 'm/master'] |
| 81 | 81 |
| 82 return RunCommand(full_name, command).splitlines() | 82 return RunCommand(full_name, command).splitlines() |
| 83 | 83 |
| 84 | 84 |
| 85 def ShowDir(full_name, relative_name, color, logs, author, days): | 85 def ShowDir(full_name, color, logs, author, days): |
| 86 """Display active work in a single git repository.""" | 86 """Display active work in a single git repository.""" |
| 87 | 87 |
| 88 branches = GetBranches(full_name, relative_name, color) | 88 branches = GetBranches(full_name, color) |
| 89 status = GetStatus(full_name, relative_name, color) | 89 status = GetStatus(full_name, color) |
| 90 | 90 |
| 91 if logs: | 91 if logs: |
| 92 history = GetHistory(full_name, relative_name, color, author, days) | 92 history = GetHistory(full_name, color, author, days) |
| 93 else: | 93 else: |
| 94 history = [] | 94 history = [] |
| 95 | 95 |
| 96 if branches or status or history: | 96 if branches or status or history: |
| 97 ShowName(relative_name, color) | 97 # We want to use the full path for testing, but we want to use the |
| 98 # relative path for display. |
| 99 ShowName(os.path.relpath(full_name), color) |
| 98 | 100 |
| 99 if branches: print '\n'.join(branches) | 101 if branches: print '\n'.join(branches) |
| 100 if status: print '\n'.join(status) | 102 if status: print '\n'.join(status) |
| 101 if history: print '\n'.join(history) | 103 if history: print '\n'.join(history) |
| 102 | 104 |
| 103 if branches or status or history: | 105 if branches or status or history: |
| 104 print "" | 106 print "" |
| 105 | 107 |
| 106 | 108 |
| 107 def FindRoot(): | 109 def FindRoot(): |
| (...skipping 30 matching lines...) Expand all Loading... |
| 138 options, arguments = parser.parse_args() | 140 options, arguments = parser.parse_args() |
| 139 | 141 |
| 140 if arguments: | 142 if arguments: |
| 141 parser.print_usage() | 143 parser.print_usage() |
| 142 return 1 | 144 return 1 |
| 143 | 145 |
| 144 color = os.isatty(1) | 146 color = os.isatty(1) |
| 145 root = FindRoot() | 147 root = FindRoot() |
| 146 repos = RunCommand(root, ['repo', 'forall', '-c', 'pwd']).splitlines() | 148 repos = RunCommand(root, ['repo', 'forall', '-c', 'pwd']).splitlines() |
| 147 | 149 |
| 148 # We want to use the full path for testing, but we want to use the relative | 150 for full in repos: |
| 149 # path for display. | 151 ShowDir(full, color, options.logs, options.author, options.days) |
| 150 reldirs = [re.sub('^' + re.escape(root) + '/', '', p) for p in repos] | |
| 151 | |
| 152 for full, relative in zip(repos, reldirs): | |
| 153 ShowDir(full, relative, color, options.logs, options.author, options.days) | |
| 154 | 152 |
| 155 | 153 |
| 156 if __name__ == '__main__': | 154 if __name__ == '__main__': |
| 157 main() | 155 main() |
| OLD | NEW |