From 948e12b8d7e17b107a93096d0a5e688c6680022d Mon Sep 17 00:00:00 2001 From: Yuriy Syrovetskiy Date: Wed, 12 Aug 2015 17:28:19 +0300 Subject: [PATCH 1/3] [+] lazy loading of submodules --- src/git.coffee | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/git.coffee b/src/git.coffee index d1927a19..4e9f806b 100644 --- a/src/git.coffee +++ b/src/git.coffee @@ -157,6 +157,9 @@ Repository::submoduleForPath = (path) -> path = @relativize(path) return null unless path + if @submodules instanceof Function + @submodules() + for submodulePath, submoduleRepo of @submodules if path is submodulePath return submoduleRepo @@ -228,5 +231,6 @@ openSubmodules = (repository) -> exports.open = (repositoryPath) -> repository = openRepository(repositoryPath) - openSubmodules(repository) if repository? + if repository? + repository.submodules = -> openSubmodules(repository) repository From 7f70f2cdb3bc7c1b66f359fbce71630be493bec1 Mon Sep 17 00:00:00 2001 From: Yuriy Syrovetskiy Date: Wed, 12 Aug 2015 17:49:44 +0300 Subject: [PATCH 2/3] [+] test --- spec/git-spec.coffee | 2 ++ 1 file changed, 2 insertions(+) diff --git a/spec/git-spec.coffee b/spec/git-spec.coffee index 1c001efe..376efd30 100644 --- a/spec/git-spec.coffee +++ b/spec/git-spec.coffee @@ -23,6 +23,8 @@ describe "git", -> describe "when the path is a repository", -> it "returns a repository", -> expect(git.open(__dirname)).not.toBeNull() + it "has @submodules unevaluated", -> + expect(typeof(git.open(__dirname).submodules)).toBe('function') describe "when the path isn't a repository", -> it "returns null", -> From e1cfd668d210ce048ced7a03d83dcdac7d676e26 Mon Sep 17 00:00:00 2001 From: Yuriy Syrovetskiy Date: Wed, 12 Aug 2015 17:57:06 +0300 Subject: [PATCH 3/3] [+] clarification --- src/git.coffee | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/git.coffee b/src/git.coffee index 4e9f806b..02441d83 100644 --- a/src/git.coffee +++ b/src/git.coffee @@ -232,5 +232,7 @@ openSubmodules = (repository) -> exports.open = (repositoryPath) -> repository = openRepository(repositoryPath) if repository? + # openSubmodules may be long (e.g., on network FS), + # so loading them lazily repository.submodules = -> openSubmodules(repository) repository