scmrepo icon indicating copy to clipboard operation
scmrepo copied to clipboard

optimize is_dirty in dulwich?

Open skshetry opened this issue 3 years ago • 0 comments

I wonder if we should optimize this further, i.e. use generator and return False if there is any changes rather than collecting everything. :)

Something like:

from itertools import chain, zip_longest

with open_repo_closing(repo) as r:
        # 1. Get status of staged
        tracked_changes = get_tree_changes(r)
        # 2. Get status of unstaged
        index = r.open_index()
        normalizer = r.get_blob_normalizer()
        filter_callback = normalizer.checkin_normalize

        unstaged_changes = get_unstaged_changes(index, r.path, filter_callback)
        untracked_paths = get_untracked_paths(
            r.path,
            r.path,
            index,
            exclude_ignored=not ignored,
            untracked_files=untracked_files,
        )
        return any(chain.from_iterable(zip_longest(untracked_paths, unstaged_changes)))

The only doubt that I have is that it won't reuse IgnoreManager, which I think already happens for status. No strong opinion though, we could also propose this in dulwich.

Originally posted by @skshetry in https://github.com/iterative/scmrepo/pull/74#discussion_r883319219

skshetry avatar May 31 '22 09:05 skshetry