dahlbyk/posh-git — pull request #52 by aroben (2012-06-04 17:16:36+00:00)
Title: Cache Get-GitStatus results to speed up the prompt

Get-GitStatus now caches the last status result and reuses it when possible. We invalidate the cache when either:

1. the .git directory changes, or
2. any files within the .git or working directories change.

We implement (1) by caching the last .git directory for which we computed status and comparing it to the current .git directory. We implement (2) by listening for events from System.IO.FileSystemWatcher objects to find out when any files in the directories we care about have changed.

Note that this doesn't make Get-GitStatus any faster when it *does* have to compute status. (And presumably actually makes it a tiny bit slower because of the extra work to maintain the cache.) But it makes Get-GitStatus much faster overall since status often doesn't have to be computed at all.