Skip to content

Commit 754f93a

Browse files
committed
simplifications and code cleanup from pascal
1 parent af3a3f2 commit 754f93a

File tree

2 files changed

+15
-16
lines changed

2 files changed

+15
-16
lines changed

src/GitVersionCore.Tests/ExecuteCoreTests.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,13 +28,13 @@ public void CacheKeySameAfterReNormalizing()
2828
var targetUrl = "https://github.com/GitTools/GitVersion.git";
2929
var targetBranch = "refs/head/master";
3030
var gitPreparer = new GitPreparer(targetUrl, null, new Authentication(), false, fixture.RepositoryPath);
31+
//var cacheKey0 = GitVersionCacheKeyFactory.Create(fileSystem, gitPreparer, null);
32+
gitPreparer.Initialise(true, targetBranch);
3133
var cacheKey1 = GitVersionCacheKeyFactory.Create(fileSystem, gitPreparer, null);
3234
gitPreparer.Initialise(true, targetBranch);
3335
var cacheKey2 = GitVersionCacheKeyFactory.Create(fileSystem, gitPreparer, null);
34-
gitPreparer.Initialise(true, targetBranch);
35-
var cacheKey3 = GitVersionCacheKeyFactory.Create(fileSystem, gitPreparer, null);
3636

37-
cacheKey3.Value.ShouldBe(cacheKey2.Value);
37+
cacheKey2.Value.ShouldBe(cacheKey1.Value);
3838
});
3939
}
4040

src/GitVersionCore/GitVersionCacheKeyFactory.cs

Lines changed: 12 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
using System.IO;
77
using System.Security.Cryptography;
88
using System.Text;
9+
using System.Linq;
910

1011
public class GitVersionCacheKeyFactory
1112
{
@@ -33,20 +34,20 @@ private static string GetGitSystemHash(GitPreparer gitPreparer, IFileSystem file
3334
// lifted from https://msdn.microsoft.com/en-us/library/bb513869.aspx
3435
public static List<string> TraverseTree(string root)
3536
{
36-
var result = new List<string>();
37-
result.Add(root);
37+
var result = new List<string> { root };
38+
3839
// Data structure to hold names of subfolders to be
3940
// examined for files.
40-
Stack<string> dirs = new Stack<string>(20);
41+
var dirs = new Stack<string>(20);
4142

42-
if (!System.IO.Directory.Exists(root))
43+
if (!Directory.Exists(root))
4344
{
4445
throw new ArgumentException();
4546
}
4647

4748
dirs.Push(root);
4849

49-
while (dirs.Count > 0)
50+
while (dirs.Any())
5051
{
5152
string currentDir = dirs.Pop();
5253

@@ -56,7 +57,7 @@ public static List<string> TraverseTree(string root)
5657
string[] subDirs;
5758
try
5859
{
59-
subDirs = System.IO.Directory.GetDirectories(currentDir);
60+
subDirs = Directory.GetDirectories(currentDir);
6061
}
6162
// An UnauthorizedAccessException exception will be thrown if we do not have
6263
// discovery permission on a folder or file. It may or may not be acceptable
@@ -72,7 +73,7 @@ public static List<string> TraverseTree(string root)
7273
Logger.WriteError(e.Message);
7374
continue;
7475
}
75-
catch (System.IO.DirectoryNotFoundException e)
76+
catch (DirectoryNotFoundException e)
7677
{
7778
Logger.WriteError(e.Message);
7879
continue;
@@ -81,7 +82,7 @@ public static List<string> TraverseTree(string root)
8182
string[] files = null;
8283
try
8384
{
84-
files = System.IO.Directory.GetFiles(currentDir);
85+
files = Directory.GetFiles(currentDir);
8586
}
8687

8788
catch (UnauthorizedAccessException e)
@@ -90,19 +91,17 @@ public static List<string> TraverseTree(string root)
9091
continue;
9192
}
9293

93-
catch (System.IO.DirectoryNotFoundException e)
94+
catch (DirectoryNotFoundException e)
9495
{
9596
Logger.WriteError(e.Message);
9697
continue;
9798
}
98-
// Perform the required action on each file here.
99-
// Modify this block to perform your required task.
99+
100100
foreach (string file in files)
101101
{
102102
try
103103
{
104-
// Perform whatever action is required in your scenario.
105-
System.IO.FileInfo fi = new System.IO.FileInfo(file);
104+
var fi = new FileInfo(file);
106105
result.Add(fi.Name);
107106
result.Add(File.ReadAllText(file));
108107
//Logger.WriteInfo(string.Format("{0}: {1}, {2}", fi.Name, fi.Length, fi.CreationTime));

0 commit comments

Comments
 (0)