Permalink
Browse files

Emitting hash of message body. First stab at emitting change ratio.

  • Loading branch information...
1 parent 317018a commit 258c30c5931f4e024f13723fa8806b6c0d5e66e6 @yreynhout committed Apr 22, 2012
@@ -0,0 +1,61 @@
+<?xml version="1.0" encoding="utf-8"?>
+<Project ToolsVersion="4.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
+ <PropertyGroup>
+ <Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
+ <Platform Condition=" '$(Platform)' == '' ">x86</Platform>
+ <ProductVersion>8.0.30703</ProductVersion>
+ <SchemaVersion>2.0</SchemaVersion>
+ <ProjectGuid>{DCA099AE-2F00-41C5-BA28-368C6868D489}</ProjectGuid>
+ <OutputType>Exe</OutputType>
+ <AppDesignerFolder>Properties</AppDesignerFolder>
+ <RootNamespace>Seabites.ChangeOverTime</RootNamespace>
+ <AssemblyName>spitcot</AssemblyName>
+ <TargetFrameworkVersion>v4.0</TargetFrameworkVersion>
+ <TargetFrameworkProfile>
+ </TargetFrameworkProfile>
+ <FileAlignment>512</FileAlignment>
+ </PropertyGroup>
+ <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|x86' ">
+ <PlatformTarget>x86</PlatformTarget>
+ <DebugSymbols>true</DebugSymbols>
+ <DebugType>full</DebugType>
+ <Optimize>false</Optimize>
+ <OutputPath>bin\Debug\</OutputPath>
+ <DefineConstants>DEBUG;TRACE</DefineConstants>
+ <ErrorReport>prompt</ErrorReport>
+ <WarningLevel>4</WarningLevel>
+ </PropertyGroup>
+ <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|x86' ">
+ <PlatformTarget>x86</PlatformTarget>
+ <DebugType>pdbonly</DebugType>
+ <Optimize>true</Optimize>
+ <OutputPath>bin\Release\</OutputPath>
+ <DefineConstants>TRACE</DefineConstants>
+ <ErrorReport>prompt</ErrorReport>
+ <WarningLevel>4</WarningLevel>
+ </PropertyGroup>
+ <ItemGroup>
+ <Reference Include="System" />
+ <Reference Include="System.Core" />
+ <Reference Include="System.Xml.Linq" />
+ <Reference Include="System.Data.DataSetExtensions" />
+ <Reference Include="Microsoft.CSharp" />
+ <Reference Include="System.Data" />
+ <Reference Include="System.Xml" />
+ </ItemGroup>
+ <ItemGroup>
+ <Compile Include="Program.cs" />
+ <Compile Include="Properties\AssemblyInfo.cs" />
+ </ItemGroup>
+ <ItemGroup>
+ <None Include="app.config" />
+ </ItemGroup>
+ <Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
+ <!-- To modify your build process, add your task inside one of the targets below and uncomment it.
+ Other similar extension points exist, see Microsoft.Common.targets.
+ <Target Name="BeforeBuild">
+ </Target>
+ <Target Name="AfterBuild">
+ </Target>
+ -->
+</Project>
View
@@ -0,0 +1,123 @@
+//using System;
+//using System.Collections.Generic;
+//using System.IO;
+//using System.Linq;
+
+//namespace Seabites.ChangeOverTime {
+// class Program {
+// static void Main(string[] args) {
+// var allMethods = new AllMethods();
+// foreach(var file in
+// Directory.EnumerateFiles(args[0], "*.csv", SearchOption.TopDirectoryOnly).
+// OrderBy(path => Convert.ToInt32(Path.GetFileNameWithoutExtension(path)))) {
+// var allMethodsInCommit = ReadMethodsInCommit(file).ToList();
+// var changes = allMethods.WhatHasChanged(allMethodsInCommit);
+// var changeRatioInCommit = from mapped in (from change in changes
+// select new {change.ChangeType, Count = 1})
+// group mapped by mapped.ChangeType
+// into reduced
+// select new {ChangeType = reduced.Key, Count = reduced.Sum(i => i.Count)};
+
+
+// }
+// }
+
+// static IEnumerable<CSharpMethod> ReadMethodsInCommit(string path) {
+// using(var file = File.OpenRead(path)) {
+// using(var csvReader = new StreamReader(file)) {
+// string csvEntry;
+// while((csvEntry = csvReader.ReadLine()) == null) {
+// yield return CSharpMethod.Parse(csvEntry);
+// }
+// }
+// }
+// }
+// }
+
+// public class AllMethods {
+// List<CSharpMethod> _methods;
+
+// public AllMethods() {
+// _methods = new List<CSharpMethod>();
+// }
+
+// public IEnumerable<CSharpMethodChange> WhatHasChanged(IEnumerable<CSharpMethod> methods) {
+// foreach(var removed in _methods.Except(methods)) {
+// yield return new CSharpMethodChange(ChangeType.Removed, removed);
+// }
+// foreach(var added in methods.Except(_methods)) {
+// yield return new CSharpMethodChange(ChangeType.Removed, added);
+// }
+// foreach(var modified in methods.Intersect(_methods)) {
+// if(modified.)
+// yield return new CSharpMethodChange(ChangeType.Removed, added);
+// }
+// }
+// }
+
+
+
+// public class CSharpMethodChange {
+// readonly ChangeType _typeOfChange;
+// readonly CSharpMethod _method;
+
+// public CSharpMethodChange(ChangeType typeOfChange, CSharpMethod method) {
+// _typeOfChange = typeOfChange;
+// _method = method;
+// }
+
+// public ChangeType ChangeType {
+// get {
+// return _typeOfChange;
+// }
+// }
+// }
+
+// public enum ChangeType {
+// Added,
+// Removed,
+// Modified
+// }
+
+// public class CSharpMethod {
+// readonly string _fullmethodname;
+// readonly string _length;
+// readonly string _linecount;
+// readonly string _file;
+// readonly string _commitHash;
+// readonly string _committer;
+// readonly string _commitDate;
+
+// CSharpMethod(string fullmethodname, string length, string linecount, string file, string commitHash, string committer, string commitDate) {
+// if (fullmethodname == null) throw new ArgumentNullException("fullmethodname");
+// _fullmethodname = fullmethodname;
+// _length = length;
+// _linecount = linecount;
+// _file = file;
+// _commitHash = commitHash;
+// _committer = committer;
+// _commitDate = commitDate;
+// }
+
+// public static CSharpMethod Parse(string csvEntry) {
+// var data = csvEntry.Split(',');
+// return new CSharpMethod(data[0], data[1], data[2], data[3], data[4], data[5], data[6]);
+// }
+
+// public bool Equals(CSharpMethod other) {
+// if (ReferenceEquals(null, other)) return false;
+// if (ReferenceEquals(this, other)) return true;
+// return Equals(other._fullmethodname, _fullmethodname);
+// }
+
+// public override bool Equals(object obj) {
+// if (ReferenceEquals(null, obj)) return false;
+// if (ReferenceEquals(this, obj)) return true;
+// if (obj.GetType() != typeof (CSharpMethod)) return false;
+// return Equals((CSharpMethod) obj);
+// }
+
+// public override int GetHashCode() {
+// return _fullmethodname.GetHashCode();
+// }
+// }
@@ -0,0 +1,36 @@
+using System.Reflection;
+using System.Runtime.CompilerServices;
+using System.Runtime.InteropServices;
+
+// General Information about an assembly is controlled through the following
+// set of attributes. Change these attribute values to modify the information
+// associated with an assembly.
+[assembly: AssemblyTitle("ChangeOverTime")]
+[assembly: AssemblyDescription("")]
+[assembly: AssemblyConfiguration("")]
+[assembly: AssemblyCompany("")]
+[assembly: AssemblyProduct("ChangeOverTime")]
+[assembly: AssemblyCopyright("Copyright © 2012")]
+[assembly: AssemblyTrademark("")]
+[assembly: AssemblyCulture("")]
+
+// Setting ComVisible to false makes the types in this assembly not visible
+// to COM components. If you need to access a type in this assembly from
+// COM, set the ComVisible attribute to true on that type.
+[assembly: ComVisible(false)]
+
+// The following GUID is for the ID of the typelib if this project is exposed to COM
+[assembly: Guid("36aee991-6c75-4fab-9c6e-843c53632d04")]
+
+// Version information for an assembly consists of the following four values:
+//
+// Major Version
+// Minor Version
+// Build Number
+// Revision
+//
+// You can specify all the values or you can default the Build and Revision Numbers
+// by using the '*' as shown below:
+// [assembly: AssemblyVersion("1.0.*")]
+[assembly: AssemblyVersion("1.0.0.0")]
+[assembly: AssemblyFileVersion("1.0.0.0")]
@@ -0,0 +1,3 @@
+<?xml version="1.0"?>
+<configuration>
+<startup><supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.0"/></startup></configuration>
View
@@ -7,7 +7,7 @@ Usage:
> stgalyzer &lt;path to your local git file repo&gt;
Spits out a .csv file under .\analysis for each commit containing all csharp methods at that point in the working copy in the following format:
-> FullMethodName,MethodLength,MethodLineCount,FilePath,CommitHash,Committer,CommitDate
+> FullMethodName,MethodBodyLength,MethodBodyLineCount,MethodBodyHash,FilePath,CommitHash,Committer,CommitDate
Right now, it's hard-coded to do this for the 'master' branch. There's a problem with the namespace of nested types. If you find it, send me a pull request.
@@ -9,6 +9,8 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = ".nuget", ".nuget", "{B6D5A2
.nuget\NuGet.targets = .nuget\NuGet.targets
EndProjectSection
EndProject
+Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ChangeOverTime", "ChangeOverTime\ChangeOverTime.csproj", "{DCA099AE-2F00-41C5-BA28-368C6868D489}"
+EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|x86 = Debug|x86
@@ -19,6 +21,10 @@ Global
{ADA8B86A-A95C-49AD-8A85-C124E56D21CE}.Debug|x86.Build.0 = Debug|x86
{ADA8B86A-A95C-49AD-8A85-C124E56D21CE}.Release|x86.ActiveCfg = Release|x86
{ADA8B86A-A95C-49AD-8A85-C124E56D21CE}.Release|x86.Build.0 = Release|x86
+ {DCA099AE-2F00-41C5-BA28-368C6868D489}.Debug|x86.ActiveCfg = Debug|x86
+ {DCA099AE-2F00-41C5-BA28-368C6868D489}.Debug|x86.Build.0 = Debug|x86
+ {DCA099AE-2F00-41C5-BA28-368C6868D489}.Release|x86.ActiveCfg = Release|x86
+ {DCA099AE-2F00-41C5-BA28-368C6868D489}.Release|x86.Build.0 = Release|x86
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
@@ -3,26 +3,26 @@
namespace Seabites.SharpTemporalGitalyzer {
public class CSharpMethod {
readonly string _fullmethodname;
- readonly CSharpMethodBodyLineCountAndLength _bodyLineCountAndLength;
+ readonly CSharpMethodBodyStatistics _bodyStatistics;
readonly string _file;
readonly Commit _commit;
- public CSharpMethod(string fullmethodname, CSharpMethodBodyLineCountAndLength bodyLineCountAndLength, string file, Commit commit) {
+ public CSharpMethod(string fullmethodname, CSharpMethodBodyStatistics bodyStatistics, string file, Commit commit) {
_fullmethodname = fullmethodname;
- _bodyLineCountAndLength = bodyLineCountAndLength;
+ _bodyStatistics = bodyStatistics;
_file = file;
_commit = commit;
}
public void WriteAsCsv(TextWriter writer) {
writer.WriteLine(
- "{0},{1},{2},{3},{4},{5},{6}",
- _fullmethodname, _bodyLineCountAndLength.Length, _bodyLineCountAndLength.LineCount, _file, _commit.Hash, _commit.Committer, _commit.CommitDate);
+ "{0},{1},{2},{3},{4},{5},{6},{7}",
+ _fullmethodname, _bodyStatistics.Length, _bodyStatistics.LineCount, _bodyStatistics.Hash, _file, _commit.Hash, _commit.Committer, _commit.CommitDate);
}
public static void WriteCsvHeader(TextWriter writer) {
writer.WriteLine(
- "FullMethodName,MethodLength,MethodLineCount,FilePath,CommitHash,Committer,CommitDate");
+ "FullMethodName,MethodBodyLength,MethodBodyLineCount,MethodBodyHash,FilePath,CommitHash,Committer,CommitDate");
}
}
}
@@ -1,11 +1,13 @@
namespace Seabites.SharpTemporalGitalyzer {
- public struct CSharpMethodBodyLineCountAndLength {
+ public struct CSharpMethodBodyStatistics {
readonly int _lineCount;
readonly int _length;
+ readonly int _hash;
- public CSharpMethodBodyLineCountAndLength(int lineCount, int length) {
+ public CSharpMethodBodyStatistics(int lineCount, int length, int hash) {
_lineCount = lineCount;
_length = length;
+ _hash = hash;
}
public int Length {
@@ -15,5 +17,9 @@ public struct CSharpMethodBodyLineCountAndLength {
public int LineCount {
get { return _lineCount; }
}
+
+ public int Hash {
+ get { return _hash; }
+ }
}
}
@@ -4,14 +4,15 @@
namespace Seabites.SharpTemporalGitalyzer {
public static class ExtensionOfMethodDeclaration {
- public static CSharpMethodBodyLineCountAndLength GetBodyLineCountAndLength(this MethodDeclaration declaration) {
+ public static CSharpMethodBodyStatistics GetBodyLineCountAndLength(this MethodDeclaration declaration) {
using (var writer = new StringWriter()) {
var visitor = new CSharpOutputVisitor(writer, FormattingOptionsFactory.CreateAllman());
declaration.AcceptVisitor(visitor);
var bodyAsString = writer.ToString();
- return new CSharpMethodBodyLineCountAndLength(
+ return new CSharpMethodBodyStatistics(
bodyAsString.Split(new[] {Environment.NewLine}, StringSplitOptions.None).Length,
- bodyAsString.Length);
+ bodyAsString.Length,
+ bodyAsString.GetHashCode());
}
}
}
@@ -66,7 +66,7 @@
<Reference Include="System.Xml" />
</ItemGroup>
<ItemGroup>
- <Compile Include="CSharpMethodBodyLineCountAndLength.cs" />
+ <Compile Include="CSharpMethodBodyStatistics.cs" />
<Compile Include="Commit.cs" />
<Compile Include="CSharpFile.cs" />
<Compile Include="CSharpMethod.cs" />

0 comments on commit 258c30c

Please sign in to comment.