Skip to content

Commit 1347928

Browse files
committed
Possibly bail after each HEAD check if out of time
1 parent 0456ca6 commit 1347928

File tree

1 file changed

+11
-6
lines changed

1 file changed

+11
-6
lines changed

git.d

+11-6
Original file line numberDiff line numberDiff line change
@@ -105,11 +105,7 @@ RepoStatus* getRepoStatus(Duration allottedTime)
105105

106106
RepoStatus* ret = new RepoStatus;
107107

108-
// getHead is not time-boxed since its time to run
109-
// varies vary little in proportion to the repo size.
110-
// Unless you have thousands of Git heads (WTF?), this shouldn't
111-
// take long at all.
112-
ret.head = getHead(repoRoot);
108+
ret.head = getHead(repoRoot, allottedTime);
113109

114110
ret.flags = asyncGetFlags(allottedTime);
115111

@@ -208,8 +204,11 @@ StatusFlags asyncGetFlags(Duration allottedTime)
208204

209205
/// Gets the name of the current Git head, or a shortened SHA
210206
/// if there is no symbolic name.
211-
string getHead(string repoRoot)
207+
string getHead(string repoRoot, Duration allottedTime)
212208
{
209+
// getHead doesn't use async I/O because it is assumed that
210+
// reading one-line files will take a negligible amount of time.
211+
// If this assumption proves false, we should revisit it.
213212

214213
immutable headPath = buildPath(repoRoot, ".git", "HEAD");
215214
immutable headSHA = headPath.readAndStrip();
@@ -229,12 +228,16 @@ string getHead(string repoRoot)
229228
string ret = searchDirectoryForHead(remotesPath, headSHA);
230229
if (!ret.empty)
231230
return relativePath(ret, remotesPath);
231+
else if (pastTime(allottedTime))
232+
return headSHA[0 .. 7];
232233

233234
// We didn't find anything in remotes. Let's check tags.
234235
immutable tagsPath = buildPath(refsPath, "tags");
235236
ret = searchDirectoryForHead(tagsPath, headSHA);
236237
if (!ret.empty)
237238
return relativePath(ret, tagsPath);
239+
else if (pastTime(allottedTime))
240+
return headSHA[0 .. 7];
238241

239242
// We didn't find anything in remotes. Let's check packed-refs
240243
auto packedRefs = File(buildPath(repoRoot, ".git", "packed-refs"))
@@ -254,6 +257,8 @@ string getHead(string repoRoot)
254257

255258
if (sha == headSHA)
256259
return refPath.baseName.idup;
260+
else if (pastTime(allottedTime))
261+
return headSHA[0 .. 7];
257262
}
258263

259264
// Still nothing. Just return a shortened version of the HEAD sha

0 commit comments

Comments
 (0)