def _get_last_commit(self, commit_id, paths): # git apparently considers merge commits to have "touched" a path # if the path is changed in either branch being merged, even though # the --name-only output doesn't include those files. So, we have # to filter out the merge commits that don't actually include any # of the referenced paths in the list of files. files = [] # don't skip first commit we're called with because it might be # a valid change commit; however... skip = 0 while commit_id and not files: output = self._git.git.log( commit_id, '--', *paths, pretty='format:%H', name_only=True, max_count=1, skip=skip) lines = output.split('\n') commit_id = lines[0] files = prefix_paths_union(paths, set(lines[1:])) # *do* skip subsequent merge commits or we'll get stuck on an infinite # loop matching and then diregarding the merge commit over and over skip = 1 if commit_id: return commit_id, files else: return None, set()
def last_commit_ids(self, commit, paths): """ Find the ID of the last commit to touch each path. """ result = {} paths = set(paths) orig_commit_id = commit_id = commit._id timeout = float(tg.config.get('lcd_timeout', 60)) start_time = time() while paths and commit_id: if time() - start_time > timeout: log.error('last_commit_ids timeout for %s on %s', orig_commit_id, ', '.join(paths)) return result lines = self._git.git.log( orig_commit_id, '--', *paths, pretty='format:%H', name_only=True, max_count=1, no_merges=True).split('\n') commit_id = lines[0] changes = set(lines[1:]) changed = prefix_paths_union(paths, changes) for path in changed: result[path] = commit_id paths -= changed return result
def _get_last_commit(self, commit_id, paths): # git apparently considers merge commits to have "touched" a path # if the path is changed in either branch being merged, even though # the --name-only output doesn't include those files. So, we have # to filter out the merge commits that don't actually include any # of the referenced paths in the list of files. files = [] # don't skip first commit we're called with because it might be # a valid change commit; however... skip = 0 while commit_id and not files: output = self._git.git.log(commit_id, '--', *paths, pretty='format:%H', name_only=True, max_count=1, skip=skip) lines = output.split('\n') commit_id = lines[0] files = prefix_paths_union(paths, set(lines[1:])) # *do* skip subsequent merge commits or we'll get stuck on an infinite # loop matching and then diregarding the merge commit over and over skip = 1 if commit_id: return commit_id, files else: return None, set()
def last_commit_ids(self, commit, paths): """ Find the ID of the last commit to touch each path. """ result = {} paths = set(paths) orig_commit_id = commit_id = commit._id timeout = float(tg.config.get('lcd_timeout', 60)) start_time = time() while paths and commit_id: if time() - start_time > timeout: log.error('last_commit_ids timeout for %s on %s', orig_commit_id, ', '.join(paths)) return result lines = self._git.git.log(orig_commit_id, '--', *paths, pretty='format:%H', name_only=True, max_count=1, no_merges=True).split('\n') commit_id = lines[0] changes = set(lines[1:]) changed = prefix_paths_union(paths, changes) for path in changed: result[path] = commit_id paths -= changed return result
def test_prefix(self): a = set(['a1', 'a2', 'a3']) b = set(['b1', 'a2/foo', 'b3/foo']) self.assertEqual(prefix_paths_union(a, b), {'a2'})
def test_exact(self): a = set(['a1', 'a2', 'a3']) b = set(['b1', 'a2', 'a3']) self.assertEqual(prefix_paths_union(a, b), {'a2', 'a3'})
def test_disjoint(self): a = set(['a1', 'a2', 'a3']) b = set(['b1', 'b1/foo', 'b2']) self.assertEqual(prefix_paths_union(a, b), set())
def test_prefix(self): a = set(['a1', 'a2', 'a3']) b = set(['b1', 'a2/foo', 'b3/foo']) self.assertItemsEqual(prefix_paths_union(a, b), ['a2'])
def test_exact(self): a = set(['a1', 'a2', 'a3']) b = set(['b1', 'a2', 'a3']) self.assertItemsEqual(prefix_paths_union(a, b), ['a2', 'a3'])
def test_disjoint(self): a = set(['a1', 'a2', 'a3']) b = set(['b1', 'b1/foo', 'b2']) self.assertItemsEqual(prefix_paths_union(a, b), [])