Skip to content

fix version cache key in msbuild task #594

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Aug 20, 2015
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 6 additions & 3 deletions src/GitVersionTask/VersionAndBranchFinder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -27,17 +27,20 @@ public static VersionVariables GetVersion(string directory, Authentication authe
var gitDir = GitDirFinder.TreeWalkForDotGitDir(directory);
using (var repo = RepositoryLoader.GetRepo(gitDir))
{
var ticks = DirectoryDateFinder.GetLastDirectoryWrite(directory);
var key = string.Format("{0}:{1}:{2}", repo.Head.CanonicalName, repo.Head.Tip.Sha, ticks);
var ticks = DirectoryDateFinder.GetLastDirectoryWrite(gitDir);
var key = string.Format("{0}:{1}:{2}",gitDir, repo.Head.CanonicalName, repo.Head.Tip.Sha);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ticks is no longer used?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

var key = string.Format("{0}:{1}:{2}:{3}",gitDir, repo.Head.CanonicalName, repo.Head.Tip.Sha, ticks); ?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we dont want ticks in the key. they are used in the second step. a static dictionary is bascially a memory leak. keying on ticks is not great since we gradually add more to the dictionary on every change.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Makes sense, if tip sha has changed, recalc. Got it

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The dictionary should probably be changed to a ConcurrentDictionary too, to avoid race conditions and concurrency issues if (and with Roslyn; when) the build is parallelized.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@asbjornu agreed. make it so


Logger.WriteInfo("CacheKey: " + key );
CachedVersion result;
if (versionCacheVersions.TryGetValue(key, out result))
{
if (result.Timestamp != ticks)
{
Logger.WriteInfo("Change detected. flushing cache.");
Logger.WriteInfo(string.Format("Change detected. Flushing cache. OldTimeStamp: {0}. NewTimeStamp: {1}", result.Timestamp, ticks));
result.VersionVariables = ExecuteCore.ExecuteGitVersion(fileSystem, null, null, authentication, null, noFetch, directory, null);
result.Timestamp = ticks;
}
Logger.WriteInfo("Returning version from cache");
return result.VersionVariables;
}
Logger.WriteInfo("Version not in cache. Calculating version.");
Expand Down