diff options
Diffstat (limited to 'project.py')
-rwxr-xr-x | project.py | 39 |
1 files changed, 31 insertions, 8 deletions
@@ -134,6 +134,7 @@ class DownloadedChange(object): | |||
134 | 134 | ||
135 | class ReviewableBranch(object): | 135 | class ReviewableBranch(object): |
136 | _commit_cache = None | 136 | _commit_cache = None |
137 | _base_exists = None | ||
137 | 138 | ||
138 | def __init__(self, project, branch, base): | 139 | def __init__(self, project, branch, base): |
139 | self.project = project | 140 | self.project = project |
@@ -147,14 +148,19 @@ class ReviewableBranch(object): | |||
147 | @property | 148 | @property |
148 | def commits(self): | 149 | def commits(self): |
149 | if self._commit_cache is None: | 150 | if self._commit_cache is None: |
150 | self._commit_cache = self.project.bare_git.rev_list('--abbrev=8', | 151 | args = ('--abbrev=8', '--abbrev-commit', '--pretty=oneline', '--reverse', |
151 | '--abbrev-commit', | 152 | '--date-order', not_rev(self.base), R_HEADS + self.name, '--') |
152 | '--pretty=oneline', | 153 | try: |
153 | '--reverse', | 154 | self._commit_cache = self.project.bare_git.rev_list(*args) |
154 | '--date-order', | 155 | except GitError: |
155 | not_rev(self.base), | 156 | # We weren't able to probe the commits for this branch. Was it tracking |
156 | R_HEADS + self.name, | 157 | # a branch that no longer exists? If so, return no commits. Otherwise, |
157 | '--') | 158 | # rethrow the error as we don't know what's going on. |
159 | if self.base_exists: | ||
160 | raise | ||
161 | |||
162 | self._commit_cache = [] | ||
163 | |||
158 | return self._commit_cache | 164 | return self._commit_cache |
159 | 165 | ||
160 | @property | 166 | @property |
@@ -173,6 +179,23 @@ class ReviewableBranch(object): | |||
173 | R_HEADS + self.name, | 179 | R_HEADS + self.name, |
174 | '--') | 180 | '--') |
175 | 181 | ||
182 | @property | ||
183 | def base_exists(self): | ||
184 | """Whether the branch we're tracking exists. | ||
185 | |||
186 | Normally it should, but sometimes branches we track can get deleted. | ||
187 | """ | ||
188 | if self._base_exists is None: | ||
189 | try: | ||
190 | self.project.bare_git.rev_parse('--verify', not_rev(self.base)) | ||
191 | # If we're still here, the base branch exists. | ||
192 | self._base_exists = True | ||
193 | except GitError: | ||
194 | # If we failed to verify, the base branch doesn't exist. | ||
195 | self._base_exists = False | ||
196 | |||
197 | return self._base_exists | ||
198 | |||
176 | def UploadForReview(self, people, | 199 | def UploadForReview(self, people, |
177 | auto_topic=False, | 200 | auto_topic=False, |
178 | draft=False, | 201 | draft=False, |