@@ -105,11 +105,7 @@ RepoStatus* getRepoStatus(Duration allottedTime)
105
105
106
106
RepoStatus* ret = new RepoStatus;
107
107
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);
113
109
114
110
ret.flags = asyncGetFlags(allottedTime);
115
111
@@ -208,8 +204,11 @@ StatusFlags asyncGetFlags(Duration allottedTime)
208
204
209
205
// / Gets the name of the current Git head, or a shortened SHA
210
206
// / if there is no symbolic name.
211
- string getHead (string repoRoot)
207
+ string getHead (string repoRoot, Duration allottedTime )
212
208
{
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.
213
212
214
213
immutable headPath = buildPath(repoRoot, " .git" , " HEAD" );
215
214
immutable headSHA = headPath.readAndStrip();
@@ -229,12 +228,16 @@ string getHead(string repoRoot)
229
228
string ret = searchDirectoryForHead(remotesPath, headSHA);
230
229
if (! ret.empty)
231
230
return relativePath (ret, remotesPath);
231
+ else if (pastTime(allottedTime))
232
+ return headSHA[0 .. 7 ];
232
233
233
234
// We didn't find anything in remotes. Let's check tags.
234
235
immutable tagsPath = buildPath(refsPath, " tags" );
235
236
ret = searchDirectoryForHead(tagsPath, headSHA);
236
237
if (! ret.empty)
237
238
return relativePath (ret, tagsPath);
239
+ else if (pastTime(allottedTime))
240
+ return headSHA[0 .. 7 ];
238
241
239
242
// We didn't find anything in remotes. Let's check packed-refs
240
243
auto packedRefs = File (buildPath(repoRoot, " .git" , " packed-refs" ))
@@ -254,6 +257,8 @@ string getHead(string repoRoot)
254
257
255
258
if (sha == headSHA)
256
259
return refPath.baseName.idup;
260
+ else if (pastTime(allottedTime))
261
+ return headSHA[0 .. 7 ];
257
262
}
258
263
259
264
// Still nothing. Just return a shortened version of the HEAD sha
0 commit comments