diff options
Diffstat (limited to 'project.py')
-rw-r--r-- | project.py | 54 |
1 files changed, 54 insertions, 0 deletions
@@ -1100,6 +1100,23 @@ class Project(object): | |||
1100 | for copyfile in self.copyfiles: | 1100 | for copyfile in self.copyfiles: |
1101 | copyfile._Copy() | 1101 | copyfile._Copy() |
1102 | 1102 | ||
1103 | def GetCommitRevisionId(self): | ||
1104 | """Get revisionId of a commit. | ||
1105 | |||
1106 | Use this method instead of GetRevisionId to get the id of the commit rather | ||
1107 | than the id of the current git object (for example, a tag) | ||
1108 | |||
1109 | """ | ||
1110 | if not self.revisionExpr.startswith(R_TAGS): | ||
1111 | return self.GetRevisionId(self._allrefs) | ||
1112 | |||
1113 | try: | ||
1114 | return self.bare_git.rev_list(self.revisionExpr, '-1')[0] | ||
1115 | except GitError: | ||
1116 | raise ManifestInvalidRevisionError( | ||
1117 | 'revision %s in %s not found' % (self.revisionExpr, | ||
1118 | self.name)) | ||
1119 | |||
1103 | def GetRevisionId(self, all_refs=None): | 1120 | def GetRevisionId(self, all_refs=None): |
1104 | if self.revisionId: | 1121 | if self.revisionId: |
1105 | return self.revisionId | 1122 | return self.revisionId |
@@ -2187,6 +2204,43 @@ class Project(object): | |||
2187 | def _allrefs(self): | 2204 | def _allrefs(self): |
2188 | return self.bare_ref.all | 2205 | return self.bare_ref.all |
2189 | 2206 | ||
2207 | def _getLogs(self, rev1, rev2, oneline=False, color=True): | ||
2208 | """Get logs between two revisions of this project.""" | ||
2209 | comp = '..' | ||
2210 | if rev1: | ||
2211 | revs = [rev1] | ||
2212 | if rev2: | ||
2213 | revs.extend([comp, rev2]) | ||
2214 | cmd = ['log', ''.join(revs)] | ||
2215 | out = DiffColoring(self.config) | ||
2216 | if out.is_on and color: | ||
2217 | cmd.append('--color') | ||
2218 | if oneline: | ||
2219 | cmd.append('--oneline') | ||
2220 | |||
2221 | try: | ||
2222 | log = GitCommand(self, cmd, capture_stdout=True, capture_stderr=True) | ||
2223 | if log.Wait() == 0: | ||
2224 | return log.stdout | ||
2225 | except GitError: | ||
2226 | # worktree may not exist if groups changed for example. In that case, | ||
2227 | # try in gitdir instead. | ||
2228 | if not os.path.exists(self.worktree): | ||
2229 | return self.bare_git.log(*cmd[1:]) | ||
2230 | else: | ||
2231 | raise | ||
2232 | return None | ||
2233 | |||
2234 | def getAddedAndRemovedLogs(self, toProject, oneline=False, color=True): | ||
2235 | """Get the list of logs from this revision to given revisionId""" | ||
2236 | logs = {} | ||
2237 | selfId = self.GetRevisionId(self._allrefs) | ||
2238 | toId = toProject.GetRevisionId(toProject._allrefs) | ||
2239 | |||
2240 | logs['added'] = self._getLogs(selfId, toId, oneline=oneline, color=color) | ||
2241 | logs['removed'] = self._getLogs(toId, selfId, oneline=oneline, color=color) | ||
2242 | return logs | ||
2243 | |||
2190 | class _GitGetByExec(object): | 2244 | class _GitGetByExec(object): |
2191 | def __init__(self, project, bare, gitdir): | 2245 | def __init__(self, project, bare, gitdir): |
2192 | self._project = project | 2246 | self._project = project |