OLD | NEW |
---|---|
1 #!/usr/bin/python | 1 #!/usr/bin/python |
2 # git-cl -- a git-command for integrating reviews on Rietveld | 2 # git-cl -- a git-command for integrating reviews on Rietveld |
3 # Copyright (C) 2008 Evan Martin <martine@danga.com> | 3 # Copyright (C) 2008 Evan Martin <martine@danga.com> |
4 | 4 |
5 import getpass | 5 import getpass |
6 import optparse | 6 import optparse |
7 import os | 7 import os |
8 import re | 8 import re |
9 import readline | 9 import readline |
10 import subprocess | 10 import subprocess |
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
44 DieWithError('Command "%s" failed.\n' % (' '.join(cmd)) + | 44 DieWithError('Command "%s" failed.\n' % (' '.join(cmd)) + |
45 (error_message or output)) | 45 (error_message or output)) |
46 return output | 46 return output |
47 | 47 |
48 | 48 |
49 def RunGit(args, **kwargs): | 49 def RunGit(args, **kwargs): |
50 cmd = ['git'] + args | 50 cmd = ['git'] + args |
51 return RunCommand(cmd, **kwargs) | 51 return RunCommand(cmd, **kwargs) |
52 | 52 |
53 | 53 |
54 class Settings: | 54 class Settings(object): |
55 def __init__(self): | 55 def __init__(self): |
56 self.server = None | 56 self.server = None |
57 self.cc = None | 57 self.cc = None |
58 self.root = None | 58 self.root = None |
59 self.is_git_svn = None | 59 self.is_git_svn = None |
60 self.svn_branch = None | 60 self.svn_branch = None |
61 self.tree_status_url = None | 61 self.tree_status_url = None |
62 self.viewvc_url = None | 62 self.viewvc_url = None |
63 | 63 |
64 def GetServer(self, error_ok=False): | 64 def GetServer(self, error_ok=False): |
65 if not self.server: | 65 if not self.server: |
66 if not error_ok: | 66 if not error_ok: |
67 error_message = ('You must configure your review setup by running ' | 67 error_message = ('You must configure your review setup by running ' |
68 '"git cl config".') | 68 '"git cl config".') |
69 self.server = self._GetConfig('rietveld.server', | 69 self.server = self._GetConfig('rietveld.server', |
70 error_message=error_message) | 70 error_message=error_message) |
71 else: | 71 else: |
72 self.server = self._GetConfig('rietveld.server', error_ok=True) | 72 self.server = self._GetConfig('rietveld.server', error_ok=True) |
73 return self.server | 73 return self.server |
74 | 74 |
75 def GetCCList(self): | 75 def GetCCList(self): |
76 """Return the users cc'd on this CL. | |
77 | |
78 Return is a string suitable for passing to gcl with the --cc flag. | |
79 """ | |
76 if self.cc is None: | 80 if self.cc is None: |
77 self.cc = self._GetConfig('rietveld.cc', error_ok=True) | 81 self.cc = self._GetConfig('rietveld.cc', error_ok=True) |
82 more_cc = self._GetConfig('rietveld.extra_cc', error_ok=True) | |
Mandeep Singh Baines
2009/12/04 19:28:17
What is the use case for rietveld.extra_cc? I'm gu
| |
83 if more_cc is not None: | |
84 self.cc += ',' + more_cc | |
78 return self.cc | 85 return self.cc |
79 | 86 |
80 def GetRoot(self): | 87 def GetRoot(self): |
81 if not self.root: | 88 if not self.root: |
82 self.root = os.path.abspath(RunGit(['rev-parse', '--show-cdup']).strip()) | 89 self.root = os.path.abspath(RunGit(['rev-parse', '--show-cdup']).strip()) |
83 return self.root | 90 return self.root |
84 | 91 |
85 def GetIsGitSvn(self): | 92 def GetIsGitSvn(self): |
86 """Return true if this repo looks like it's using git-svn.""" | 93 """Return true if this repo looks like it's using git-svn.""" |
87 if self.is_git_svn is None: | 94 if self.is_git_svn is None: |
(...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
188 def IssueURL(issue): | 195 def IssueURL(issue): |
189 """Get the URL for a particular issue.""" | 196 """Get the URL for a particular issue.""" |
190 return 'http://%s/%s' % (settings.GetServer(), issue) | 197 return 'http://%s/%s' % (settings.GetServer(), issue) |
191 | 198 |
192 | 199 |
193 def ShortBranchName(branch): | 200 def ShortBranchName(branch): |
194 """Convert a name like 'refs/heads/foo' to just 'foo'.""" | 201 """Convert a name like 'refs/heads/foo' to just 'foo'.""" |
195 return branch.replace('refs/heads/', '') | 202 return branch.replace('refs/heads/', '') |
196 | 203 |
197 | 204 |
198 class Changelist: | 205 class Changelist(object): |
199 def __init__(self, branchref=None): | 206 def __init__(self, branchref=None): |
200 # Poke settings so we get the "configure your server" message if necessary. | 207 # Poke settings so we get the "configure your server" message if necessary. |
201 settings.GetServer() | 208 settings.GetServer() |
202 self.branchref = branchref | 209 self.branchref = branchref |
203 if self.branchref: | 210 if self.branchref: |
204 self.branch = ShortBranchName(self.branchref) | 211 self.branch = ShortBranchName(self.branchref) |
205 else: | 212 else: |
206 self.branch = None | 213 self.branch = None |
207 self.upstream_branch = None | 214 self.upstream_branch = None |
208 self.has_issue = False | 215 self.has_issue = False |
(...skipping 693 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
902 command = argv[1] | 909 command = argv[1] |
903 for name, _, func in COMMANDS: | 910 for name, _, func in COMMANDS: |
904 if name == command: | 911 if name == command: |
905 return func(argv[2:]) | 912 return func(argv[2:]) |
906 print 'unknown command: %s' % command | 913 print 'unknown command: %s' % command |
907 Usage(argv[0]) | 914 Usage(argv[0]) |
908 | 915 |
909 | 916 |
910 if __name__ == '__main__': | 917 if __name__ == '__main__': |
911 sys.exit(main(sys.argv)) | 918 sys.exit(main(sys.argv)) |
OLD | NEW |