Skip to content

Commit

Permalink
Merge branch 'develop'
Browse files Browse the repository at this point in the history
  • Loading branch information
Sebastian Hönel committed Feb 6, 2019
2 parents cbe13c8 + c813eb2 commit 193f531
Show file tree
Hide file tree
Showing 5 changed files with 131 additions and 5 deletions.
19 changes: 16 additions & 3 deletions GitTools/Analysis/ExtendedAnalyzer/ExtendedAnalyzer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -40,15 +40,22 @@ public class ExtendedAnalyzer : BaseAnalyzer<ExtendedCommitDetails>
private readonly BaseLogger<ExtendedAnalyzer> logger =
Program.CreateLogger<ExtendedAnalyzer>();

/// <summary>
/// Can be set to true in the constructor.
/// </summary>
public Boolean SkipSizeAnalysis { get; protected set; }

/// <summary>
/// This is a forwarding constructor that does not do any other
/// initialization than <see cref="BaseAnalyzer{T}.BaseAnalyzer(string, GitCommitSpan)"/>.
/// </summary>
/// <param name="repoPathOrUrl"></param>
/// <param name="span"></param>
public ExtendedAnalyzer(String repoPathOrUrl, GitCommitSpan span)
/// <param name="skipSizeAnalysis"></param>
public ExtendedAnalyzer(String repoPathOrUrl, GitCommitSpan span, Boolean skipSizeAnalysis)
: base(repoPathOrUrl, span)
{
this.SkipSizeAnalysis = skipSizeAnalysis;
}

/// <summary>
Expand Down Expand Up @@ -87,12 +94,17 @@ public override IEnumerable<ExtendedCommitDetails> AnalyzeCommits()
{
MinutesSincePreviousCommit = parents.Count == 0 ? -.1 :
Math.Round(
(pair.Child.Committer.When.DateTime -
(parents.OrderByDescending(p => p.Committer.When.DateTime).First().Committer.When.DateTime)).TotalMinutes, 4)
(pair.Child.Committer.When.UtcDateTime -
(parents.OrderByDescending(p => p.Committer.When.UtcDateTime).First().Committer.When.UtcDateTime)).TotalMinutes, 4)
};
// We are interested in how many files were affected by this commit
// for the kinds added, deleted, modified, renamed
if (this.SkipSizeAnalysis)
{
goto AfterSizes;
}
#region added/deleted
foreach (var change in pair.RelevantTreeChanges.Where(rtc => rtc.Status == ChangeKind.Added || rtc.Status == ChangeKind.Deleted))
{
Expand Down Expand Up @@ -146,6 +158,7 @@ public override IEnumerable<ExtendedCommitDetails> AnalyzeCommits()
}
#endregion
AfterSizes:
bag.Add(ecd);
reporter.ReportProgress(Interlocked.Increment(ref done), total);
Expand Down
4 changes: 4 additions & 0 deletions GitTools/App.config
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,10 @@
<assemblyIdentity name="Remotion.Linq.EagerFetching" publicKeyToken="fee00910d6e5f53b" culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-2.2.0.0" newVersion="2.2.0.0" />
</dependentAssembly>
<dependentAssembly>
<assemblyIdentity name="System.Core" publicKeyToken="b77a5c561934e089" culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-4.0.0.0" newVersion="4.0.0.0" />
</dependentAssembly>
</assemblyBinding>
</runtime>
</configuration>
18 changes: 18 additions & 0 deletions GitTools/GitTools.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,15 @@
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<ItemGroup>
<Reference Include="Antlr3.Runtime, Version=3.5.0.2, Culture=neutral, PublicKeyToken=eb42632606e9261f, processorArchitecture=MSIL">
<HintPath>..\packages\Antlr3.Runtime.3.5.1\lib\net40-client\Antlr3.Runtime.dll</HintPath>
</Reference>
<Reference Include="CommandLine, Version=1.9.71.2, Culture=neutral, PublicKeyToken=de6f01bd326f8c32, processorArchitecture=MSIL">
<HintPath>..\packages\CommandLineParser.1.9.71\lib\net45\CommandLine.dll</HintPath>
</Reference>
<Reference Include="Iesi.Collections, Version=4.0.0.4000, Culture=neutral, PublicKeyToken=aa95f207798dfdb4, processorArchitecture=MSIL">
<HintPath>..\packages\Iesi.Collections.4.0.4\lib\net461\Iesi.Collections.dll</HintPath>
</Reference>
<Reference Include="LibGit2Sharp, Version=0.25.0.0, Culture=neutral, PublicKeyToken=7cbde695407f0333, processorArchitecture=MSIL">
<HintPath>..\packages\LibGit2Sharp.0.25.0\lib\netstandard2.0\LibGit2Sharp.dll</HintPath>
</Reference>
Expand Down Expand Up @@ -73,10 +79,20 @@
<Reference Include="Newtonsoft.Json, Version=11.0.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed, processorArchitecture=MSIL">
<HintPath>..\packages\Newtonsoft.Json.11.0.2\lib\net45\Newtonsoft.Json.dll</HintPath>
</Reference>
<Reference Include="NHibernate, Version=5.1.0.0, Culture=neutral, PublicKeyToken=aa95f207798dfdb4, processorArchitecture=MSIL">
<HintPath>..\packages\NHibernate.5.1.3\lib\net461\NHibernate.dll</HintPath>
</Reference>
<Reference Include="Remotion.Linq, Version=2.1.0.0, Culture=neutral, PublicKeyToken=fee00910d6e5f53b, processorArchitecture=MSIL">
<HintPath>..\packages\Remotion.Linq.2.1.2\lib\net45\Remotion.Linq.dll</HintPath>
</Reference>
<Reference Include="Remotion.Linq.EagerFetching, Version=2.1.0.0, Culture=neutral, PublicKeyToken=fee00910d6e5f53b, processorArchitecture=MSIL">
<HintPath>..\packages\Remotion.Linq.EagerFetching.2.1.0\lib\net45\Remotion.Linq.EagerFetching.dll</HintPath>
</Reference>
<Reference Include="System" />
<Reference Include="System.Buffers, Version=4.0.2.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51, processorArchitecture=MSIL">
<HintPath>..\packages\System.Buffers.4.4.0\lib\netstandard2.0\System.Buffers.dll</HintPath>
</Reference>
<Reference Include="System.Configuration" />
<Reference Include="System.Core" />
<Reference Include="System.Memory, Version=4.0.1.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51, processorArchitecture=MSIL">
<HintPath>..\packages\System.Memory.4.5.1\lib\netstandard2.0\System.Memory.dll</HintPath>
Expand All @@ -88,6 +104,8 @@
<Reference Include="System.Runtime.CompilerServices.Unsafe, Version=4.0.4.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL">
<HintPath>..\packages\System.Runtime.CompilerServices.Unsafe.4.5.1\lib\netstandard2.0\System.Runtime.CompilerServices.Unsafe.dll</HintPath>
</Reference>
<Reference Include="System.ServiceModel" />
<Reference Include="System.Transactions" />
<Reference Include="System.ValueTuple">
<HintPath>..\packages\System.ValueTuple.4.4.0\lib\net461\System.ValueTuple.dll</HintPath>
<Private>True</Private>
Expand Down
90 changes: 88 additions & 2 deletions GitTools/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
using System.Text;
using System.Threading;
using Util;
using Util.Data;
using Util.Extensions;
using Util.Logging;

Expand Down Expand Up @@ -127,7 +128,30 @@ static void Main(string[] args)
{
logger.LogInformation($"Repository is located in {repo.Info.WorkingDirectory}");
var span = new GitCommitSpan(repo, options.Since, options.Until);


#region Check for commands
if (options.CmdCountCommits)
{
System.Diagnostics.Debugger.Launch();
logger.LogInformation($"Counting commits between {span.SinceAsString} and {span.UntilAsString}..");

var commits = span.OrderBy(c => c.Author.When.DateTime).ToList();

var json = JsonConvert.SerializeObject(new {
Count = commits.Count,
SHA1s = commits.Select(c => c.ShaShort())
});

using (var writer = File.CreateText(options.OutputFile))
{
writer.Write(json);
}

logger.LogInformation($"Wrote JSON to {options.OutputFile}");
Environment.Exit((int)ExitCodes.OK);
}
#endregion

using (var writer = File.CreateText(options.OutputFile))
{
// Now we extract some info and write it out later.
Expand All @@ -148,7 +172,7 @@ static void Main(string[] args)
analyzer = new SimpleAnalyzer(options.RepoPath, span);
break;
case AnalysisType.Extended:
analyzer = new ExtendedAnalyzer(options.RepoPath, span);
analyzer = new ExtendedAnalyzer(options.RepoPath, span, options.SkipSizeInExtendedAnalysis);
break;
default:
throw new Exception($"The {nameof(AnalysisType)} '{options.AnalysisType.ToString()}' is not supported.");
Expand Down Expand Up @@ -199,6 +223,60 @@ static void Main(string[] args)

Environment.Exit((int)ExitCodes.OK);
}

/// <summary>
/// This method was temporarily added and used to correct a value.
/// It is no longer referenced or used anymore, but kept in code
/// for reference.
/// </summary>
/// <param name="options"></param>
[Obsolete("Do not use. This method only corrected the field 'MinutesSincePreviousCommit' which was not calculated correctly as it was not using UTC DateTimes before.")]
public static void FixedMinutesSincePrevCommit(CommandLineOptions options)
{
var projects = new[] {
"https://github.com/apache/camel.git",
"https://github.com/apache/hbase.git",
"https://github.com/elastic/elasticsearch.git",
"https://github.com/JetBrains/kotlin.git",
"https://github.com/kiegroup/drools.git",
"https://github.com/orientechnologies/orientdb.git",
"https://github.com/ReactiveX/RxJava.git",
"https://github.com/restlet/restlet-framework-java.git",
"https://github.com/spring-projects/spring-framework.git"
};

var config = Util.Configuration.ReadDefault();
DataFactory.Configure(config,
Program.CreateLogger<DataFactory>(), new DirectoryInfo(options.TempDirectory).Parent.FullName);
using (var tempSess = DataFactory.Instance.OpenSession())
{
logger.LogDebug("Successfully probed the configured database.");
}

foreach (var p in projects)
{
using (var repo = p.OpenRepository(options.TempDirectory, null, true))
{
var span = new GitCommitSpan(repo, options.Since, options.Until);
var analyzer = new ExtendedAnalyzer(options.RepoPath, span, true);
analyzer.ExecutionPolicy = ExecutionPolicy.Parallel;

var commits = new HashSet<ExtendedCommitDetails>(analyzer.AnalyzeCommits());

using (var sess = DataFactory.Instance.OpenSession())
{
var q = sess.CreateSQLQuery("UPDATE gtools_ex SET MinutesSincePreviousCommit = :prev where SHA1 = :sha");

foreach (var c in commits)
{
q.SetParameter("prev", c.MinutesSincePreviousCommit);
q.SetParameter("sha", c.SHA1);
q.ExecuteUpdate();
}
}
}
}
}
}


Expand Down Expand Up @@ -227,6 +305,9 @@ internal class CommandLineOptions
[Option('o', "out-file", Required = true, HelpText = "A path to a file to write the analysis' result to.")]
public String OutputFile { get; set; }

[Option('k', "skip-size", Required = false, DefaultValue = false, HelpText = "If specified, will skip any size-related measurements in the " + nameof(ExtendedCommitDetails) + ".")]
public Boolean SkipSizeInExtendedAnalysis { get; set; }

[Option('e', "exec-policy", Required = false, DefaultValue = ExecutionPolicy.Parallel, HelpText = "Optional. Set the execution policy for the analysis. Allowed values are " + nameof(ExecutionPolicy.Parallel) + " and " + nameof(ExecutionPolicy.Linear) + ". The former is faster while the latter uses only minimal resources.")]
[JsonConverter(typeof(StringEnumConverter))]
public ExecutionPolicy ExecutionPolicy { get; set; } = ExecutionPolicy.Parallel;
Expand All @@ -235,6 +316,11 @@ internal class CommandLineOptions
[JsonConverter(typeof(StringEnumConverter))]
public LogLevel LogLevel { get; set; } = LogLevel.Information;

#region Command-Options
[Option("cmd-count-commits", Required = false, DefaultValue = false, HelpText = "Command. Counts the amount of commits as delimited by since/until. Writes a JSON-formatted object to the console, including the commits' IDs.")]
public Boolean CmdCountCommits { get; set; }
#endregion

[Option('h', "help", Required = false, DefaultValue = false, HelpText = "Print this help-text and exit.")]
public Boolean ShowHelp { get; set; }

Expand Down
5 changes: 5 additions & 0 deletions GitTools/packages.config
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
<?xml version="1.0" encoding="utf-8"?>
<packages>
<package id="Antlr3.Runtime" version="3.5.1" targetFramework="net461" />
<package id="CommandLineParser" version="1.9.71" targetFramework="net461" />
<package id="Iesi.Collections" version="4.0.4" targetFramework="net461" />
<package id="LibGit2Sharp" version="0.25.0" targetFramework="net461" />
<package id="LibGit2Sharp.NativeBinaries" version="1.0.210" targetFramework="net461" />
<package id="LINQtoCSV" version="1.5.0.0" targetFramework="net461" />
Expand All @@ -13,6 +15,9 @@
<package id="Microsoft.Extensions.Options" version="2.1.1" targetFramework="net461" />
<package id="Microsoft.Extensions.Primitives" version="2.1.1" targetFramework="net461" />
<package id="Newtonsoft.Json" version="11.0.2" targetFramework="net461" />
<package id="NHibernate" version="5.1.3" targetFramework="net461" />
<package id="Remotion.Linq" version="2.1.2" targetFramework="net461" />
<package id="Remotion.Linq.EagerFetching" version="2.1.0" targetFramework="net461" />
<package id="System.Buffers" version="4.4.0" targetFramework="net461" />
<package id="System.Memory" version="4.5.1" targetFramework="net461" />
<package id="System.Numerics.Vectors" version="4.4.0" targetFramework="net461" />
Expand Down

0 comments on commit 193f531

Please sign in to comment.