File tree Expand file tree Collapse file tree 3 files changed +17
-1
lines changed
Expand file tree Collapse file tree 3 files changed +17
-1
lines changed Original file line number Diff line number Diff line change 55#include " signals.hh"
66#include " users.hh"
77#include " fs-sink.hh"
8+ #include " sync.hh"
89
910#include < git2/attr.h>
1011#include < git2/blob.h>
@@ -1276,4 +1277,17 @@ ref<GitRepo> getTarballCache()
12761277 return GitRepo::openRepo (repoDir, true , true );
12771278}
12781279
1280+ GitRepo::WorkdirInfo GitRepo::getCachedWorkdirInfo (const std::filesystem::path & path)
1281+ {
1282+ static Sync<std::unordered_map<std::filesystem::path, WorkdirInfo>> _cache;
1283+ {
1284+ auto cache (_cache.lock ());
1285+ auto i = cache->find (path);
1286+ if (i != cache->end ()) return i->second ;
1287+ }
1288+ auto workdirInfo = GitRepo::openRepo (path)->getWorkdirInfo ();
1289+ _cache.lock ()->emplace (path, workdirInfo);
1290+ return workdirInfo;
1291+ }
1292+
12791293}
Original file line number Diff line number Diff line change @@ -70,6 +70,8 @@ struct GitRepo
7070
7171 virtual WorkdirInfo getWorkdirInfo () = 0;
7272
73+ static WorkdirInfo getCachedWorkdirInfo (const std::filesystem::path & path);
74+
7375 /* Get the ref that HEAD points to. */
7476 virtual std::optional<std::string> getWorkdirRef () = 0;
7577
Original file line number Diff line number Diff line change @@ -431,7 +431,7 @@ struct GitInputScheme : InputScheme
431431 // If this is a local directory and no ref or revision is
432432 // given, then allow the use of an unclean working tree.
433433 if (!input.getRef () && !input.getRev () && repoInfo.isLocal )
434- repoInfo.workdirInfo = GitRepo::openRepo (repoInfo.url )-> getWorkdirInfo ( );
434+ repoInfo.workdirInfo = GitRepo::getCachedWorkdirInfo (repoInfo.url );
435435
436436 return repoInfo;
437437 }
You can’t perform that action at this time.
0 commit comments