OLD | NEW |
1 # Copyright 2014 The Chromium Authors. All rights reserved. | 1 # Copyright 2014 The Chromium Authors. All rights reserved. |
2 # Use of this source code is governed by a BSD-style license that can be | 2 # Use of this source code is governed by a BSD-style license that can be |
3 # found in the LICENSE file. | 3 # found in the LICENSE file. |
4 | 4 |
5 from base64 import b64decode | 5 from base64 import b64decode |
6 from itertools import izip | 6 from itertools import izip |
7 import json | 7 import json |
8 import posixpath | 8 import posixpath |
9 import traceback | 9 import traceback |
10 | 10 |
(...skipping 157 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
168 # commit info JSON content. | 168 # commit info JSON content. |
169 fetch_future = self._fetcher.FetchAsync(self._base_url + _JSON_FORMAT) | 169 fetch_future = self._fetcher.FetchAsync(self._base_url + _JSON_FORMAT) |
170 content_future = self._ResolveFetchContent(self._base_url, fetch_future) | 170 content_future = self._ResolveFetchContent(self._base_url, fetch_future) |
171 return content_future.Then(lambda json: _ParseGitilesJson(json)[key]) | 171 return content_future.Then(lambda json: _ParseGitilesJson(json)[key]) |
172 | 172 |
173 def GetCommitID(self): | 173 def GetCommitID(self): |
174 '''Returns a future that resolves to the commit ID for this branch. | 174 '''Returns a future that resolves to the commit ID for this branch. |
175 ''' | 175 ''' |
176 return self._GetCommitInfo('commit') | 176 return self._GetCommitInfo('commit') |
177 | 177 |
| 178 def GetPreviousCommitID(self): |
| 179 '''Returns a future that resolves to the previous commit ID for this branch. |
| 180 ''' |
| 181 return self._GetCommitInfo('parents').Then(lambda parents: parents[0]) |
| 182 |
178 def StatAsync(self, path): | 183 def StatAsync(self, path): |
179 dir_, filename = posixpath.split(path) | 184 dir_, filename = posixpath.split(path) |
180 def stat(content): | 185 def stat(content): |
181 stat_info = _CreateStatInfo(content) | 186 stat_info = _CreateStatInfo(content) |
182 if stat_info.version is None: | 187 if stat_info.version is None: |
183 raise FileSystemError('Failed to find version of dir %s' % dir_) | 188 raise FileSystemError('Failed to find version of dir %s' % dir_) |
184 if IsDirectory(path): | 189 if IsDirectory(path): |
185 return stat_info | 190 return stat_info |
186 if filename not in stat_info.child_versions: | 191 if filename not in stat_info.child_versions: |
187 raise FileNotFoundError( | 192 raise FileNotFoundError( |
188 '%s from %s was not in child versions for Stat' % (filename, path)) | 193 '%s from %s was not in child versions for Stat' % (filename, path)) |
189 return StatInfo(stat_info.child_versions[filename]) | 194 return StatInfo(stat_info.child_versions[filename]) |
190 fetch_future = self._FetchAsync(ToDirectory(dir_) + _JSON_FORMAT) | 195 fetch_future = self._FetchAsync(ToDirectory(dir_) + _JSON_FORMAT) |
191 return self._ResolveFetchContent(path, fetch_future).Then(stat) | 196 return self._ResolveFetchContent(path, fetch_future).Then(stat) |
192 | 197 |
193 def GetIdentity(self): | 198 def GetIdentity(self): |
194 # NOTE: Do not use commit information to create the string identity. | 199 # NOTE: Do not use commit information to create the string identity. |
195 # Doing so will mess up caching. | 200 # Doing so will mess up caching. |
196 if self._commit is None and self._branch != 'master': | 201 if self._commit is None and self._branch != 'master': |
197 str_id = GITILES_BRANCH_BASE | 202 str_id = GITILES_BRANCH_BASE |
198 else: | 203 else: |
199 str_id = GITILES_BASE | 204 str_id = GITILES_BASE |
200 return '@'.join((self.__class__.__name__, StringIdentity(str_id))) | 205 return '@'.join((self.__class__.__name__, StringIdentity(str_id))) |
OLD | NEW |