Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Commit V 0.2 for VS 2010

  • Loading branch information...
commit 979d473571c69e75de104ddf6083e6b6c8ded0a2 1 parent 0fecfc4
@yysun authored
Showing with 29,219 additions and 51 deletions.
  1. +3 −5 BasicSccProvider.cs
  2. +30 −10 BasicSccProvider.csproj
  3. +16 −9 BasicSccProvider.sln
  4. +58 −27 GitFileStatusTracker.cs
  5. +296 −0 GitSharp.Core/AbbreviatedObjectId.cs
  6. +99 −0 GitSharp.Core/AbstractIndexTreeVisitor.cs
  7. +129 −0 GitSharp.Core/AlternateRepositoryDatabase.cs
  8. +517 −0 GitSharp.Core/AnyObjectId.cs
  9. +149 −0 GitSharp.Core/BinaryDelta.cs
  10. +131 −0 GitSharp.Core/BlobBasedConfig.cs
  11. +91 −0 GitSharp.Core/ByteArrayExtensions.cs
  12. +96 −0 GitSharp.Core/ByteArrayWindow.cs
  13. +113 −0 GitSharp.Core/ByteBufferWindow.cs
  14. +216 −0 GitSharp.Core/ByteWindow.cs
  15. +117 −0 GitSharp.Core/CachedObjectDatabase.cs
  16. +105 −0 GitSharp.Core/CachedObjectDirectory.cs
  17. +140 −0 GitSharp.Core/Codec.cs
  18. +309 −0 GitSharp.Core/Commit.cs
  19. +9 −0 GitSharp.Core/CompleteAttribute.cs
  20. +1,304 −0 GitSharp.Core/Config.cs
  21. +75 −0 GitSharp.Core/ConsoleUserInfoProvider.cs
  22. +548 −0 GitSharp.Core/Constants.cs
  23. +91 −0 GitSharp.Core/CoreConfig.cs
  24. +78 −0 GitSharp.Core/DeltaOfsPackedObjectLoader.cs
  25. +121 −0 GitSharp.Core/DeltaPackedObjectLoader.cs
  26. +77 −0 GitSharp.Core/DeltaRefPackedObjectLoader.cs
  27. +259 −0 GitSharp.Core/Diff/DiffFormatter.cs
  28. +234 −0 GitSharp.Core/Diff/Edit.cs
  29. +160 −0 GitSharp.Core/Diff/EditList.cs
  30. +645 −0 GitSharp.Core/Diff/MyersDiff.cs
  31. +229 −0 GitSharp.Core/Diff/RawText.cs
  32. +85 −0 GitSharp.Core/Diff/Sequence.cs
  33. +222 −0 GitSharp.Core/DirectoryCache/BaseDirCacheEditor.cs
  34. +886 −0 GitSharp.Core/DirectoryCache/DirCache.cs
  35. +149 −0 GitSharp.Core/DirectoryCache/DirCacheBuildIterator.cs
  36. +268 −0 GitSharp.Core/DirectoryCache/DirCacheBuilder.cs
  37. +294 −0 GitSharp.Core/DirectoryCache/DirCacheEditor.cs
  38. +575 −0 GitSharp.Core/DirectoryCache/DirCacheEntry.cs
  39. +310 −0 GitSharp.Core/DirectoryCache/DirCacheIterator.cs
  40. +650 −0 GitSharp.Core/DirectoryCache/DirCacheTree.cs
  41. +12 −0 GitSharp.Core/Ensure.cs
  42. +35 −0 GitSharp.Core/Exceptions/CancelledException.cs
  43. +52 −0 GitSharp.Core/Exceptions/CheckoutConflictException.cs
  44. +98 −0 GitSharp.Core/Exceptions/CompoundException.cs
  45. +74 −0 GitSharp.Core/Exceptions/ConfigInvalidException.cs
  46. +67 −0 GitSharp.Core/Exceptions/CorruptObjectException.cs
  47. +28 −0 GitSharp.Core/Exceptions/EntryExistsException.cs
  48. +64 −0 GitSharp.Core/Exceptions/ExceptionExtensions.cs
  49. +27 −0 GitSharp.Core/Exceptions/FileLockedException.cs
  50. +83 −0 GitSharp.Core/Exceptions/GitlinksNotSupportedException.cs
  51. +141 −0 GitSharp.Core/Exceptions/IncorrectObjectTypeException.cs
  52. +97 −0 GitSharp.Core/Exceptions/InvalidObjectIdException.cs
  53. +64 −0 GitSharp.Core/Exceptions/InvalidPackException.cs
  54. +90 −0 GitSharp.Core/Exceptions/InvalidPatternException.cs
  55. +90 −0 GitSharp.Core/Exceptions/MissingBundlePrerequisiteException.cs
  56. +126 −0 GitSharp.Core/Exceptions/MissingObjectException.cs
  57. +74 −0 GitSharp.Core/Exceptions/NoClosingBracketException.cs
  58. +65 −0 GitSharp.Core/Exceptions/NoRemoteRepositoryException.cs
  59. +66 −0 GitSharp.Core/Exceptions/ObjectWritingException.cs
  60. +64 −0 GitSharp.Core/Exceptions/PackMismatchException.cs
  61. +73 −0 GitSharp.Core/Exceptions/PackProtocolException.cs
  62. +100 −0 GitSharp.Core/Exceptions/RepositoryNotFoundException.cs
  63. +71 −0 GitSharp.Core/Exceptions/RevWalkException.cs
  64. +80 −0 GitSharp.Core/Exceptions/RevisionSyntaxException.cs
  65. +68 −0 GitSharp.Core/Exceptions/StopWalkException.cs
  66. +65 −0 GitSharp.Core/Exceptions/SymlinksNotSupportedException.cs
  67. +73 −0 GitSharp.Core/Exceptions/TransportException.cs
  68. +89 −0 GitSharp.Core/Exceptions/UnmergedPathException.cs
  69. +115 −0 GitSharp.Core/FileBasedConfig.cs
  70. +240 −0 GitSharp.Core/FileMode.cs
  71. +95 −0 GitSharp.Core/FileTreeEntry.cs
  72. +85 −0 GitSharp.Core/FnMatch/AbstractHead.cs
  73. +56 −0 GitSharp.Core/FnMatch/CharacterHead.cs
  74. +404 −0 GitSharp.Core/FnMatch/FileNameMatcher.cs
  75. +274 −0 GitSharp.Core/FnMatch/GroupHead.cs
  76. +52 −0 GitSharp.Core/FnMatch/IHead.cs
  77. +59 −0 GitSharp.Core/FnMatch/LastHead.cs
  78. +56 −0 GitSharp.Core/FnMatch/RestrictedWildCardHead.cs
  79. +53 −0 GitSharp.Core/FnMatch/WildCardHead.cs
  80. +71 −0 GitSharp.Core/ForceModified.cs
  81. +23 −0 GitSharp.Core/GitException.cs
  82. +1,232 −0 GitSharp.Core/GitIndex.cs
  83. +445 −0 GitSharp.Core/GitSharp.Core.csproj
  84. +78 −0 GitSharp.Core/GitlinkTreeEntry.cs
  85. +238 −0 GitSharp.Core/IgnoreHandler.cs
  86. +54 −0 GitSharp.Core/IndexChangedEventArgs.cs
  87. +214 −0 GitSharp.Core/IndexDiff.cs
  88. +93 −0 GitSharp.Core/IndexTreeVisitor.cs
  89. +279 −0 GitSharp.Core/IndexTreeWalker.cs
  90. +134 −0 GitSharp.Core/InflaterCache.cs
  91. +571 −0 GitSharp.Core/LockFile.cs
  92. +242 −0 GitSharp.Core/Merge/MergeAlgorithm.cs
  93. +126 −0 GitSharp.Core/Merge/MergeChunk.cs
  94. +154 −0 GitSharp.Core/Merge/MergeFormatter.cs
  95. +171 −0 GitSharp.Core/Merge/MergeResult.cs
  96. +164 −0 GitSharp.Core/Merge/MergeStrategy.cs
  97. +278 −0 GitSharp.Core/Merge/Merger.cs
  98. +104 −0 GitSharp.Core/Merge/StrategyOneSided.cs
  99. +193 −0 GitSharp.Core/Merge/StrategySimpleTwoWayInCore.cs
  100. +48 −0 GitSharp.Core/Merge/ThreeWayMergeStrategy.cs
  101. +133 −0 GitSharp.Core/Merge/ThreeWayMerger.cs
  102. +135 −0 GitSharp.Core/MutableObjectId.cs
  103. +72 −0 GitSharp.Core/NullProgressMonitor.cs
  104. +375 −0 GitSharp.Core/ObjectChecker.cs
  105. +457 −0 GitSharp.Core/ObjectDatabase.cs
  106. +647 −0 GitSharp.Core/ObjectDirectory.cs
  107. +234 −0 GitSharp.Core/ObjectId.cs
  108. +212 −0 GitSharp.Core/ObjectIdRef.cs
  109. +78 −0 GitSharp.Core/ObjectIdSubclassMap.cs
  110. +106 −0 GitSharp.Core/ObjectLoader.cs
  111. +139 −0 GitSharp.Core/ObjectType.cs
  112. +397 −0 GitSharp.Core/ObjectWriter.cs
  113. +638 −0 GitSharp.Core/OffsetCache.cs
  114. +638 −0 GitSharp.Core/PackFile.cs
  115. +392 −0 GitSharp.Core/PackIndex.cs
  116. +267 −0 GitSharp.Core/PackIndexV1.cs
  117. +325 −0 GitSharp.Core/PackIndexV2.cs
  118. +277 −0 GitSharp.Core/PackIndexWriter.cs
  119. +80 −0 GitSharp.Core/PackIndexWriterV1.cs
  120. +113 −0 GitSharp.Core/PackIndexWriterV2.cs
  121. +96 −0 GitSharp.Core/PackLock.cs
  122. +128 −0 GitSharp.Core/PackOutputStream.cs
  123. +200 −0 GitSharp.Core/PackReverseIndex.cs
  124. +639 −0 GitSharp.Core/PackWriter.cs
  125. +190 −0 GitSharp.Core/PackedObjectLoader.cs
  126. +153 −0 GitSharp.Core/Patch/BinaryHunk.cs
  127. +246 −0 GitSharp.Core/Patch/CombinedFileHeader.cs
  128. +382 −0 GitSharp.Core/Patch/CombinedHunkHeader.cs
  129. +867 −0 GitSharp.Core/Patch/FileHeader.cs
  130. +145 −0 GitSharp.Core/Patch/FormatError.cs
  131. +466 −0 GitSharp.Core/Patch/HunkHeader.cs
  132. +421 −0 GitSharp.Core/Patch/Patch.cs
  133. +281 −0 GitSharp.Core/PersonIdent.cs
  134. +485 −0 GitSharp.Core/Platform/Linux.cs
  135. +130 −0 GitSharp.Core/Platform/Mac.cs
  136. +192 −0 GitSharp.Core/Platform/Platform.cs
  137. +162 −0 GitSharp.Core/Platform/PlatformObject.cs
Sorry, we could not display the entire diff because too many files (482) changed.
View
8 BasicSccProvider.cs
@@ -16,7 +16,7 @@ namespace GitScc
/////////////////////////////////////////////////////////////////////////////
// BasicSccProvider
[MsVsShell.ProvideLoadKey("Standard", "0.1", "Git Source Control Provider", "Yiyisun@hotmail.com", 15261)]
- [MsVsShell.DefaultRegistryRoot("Software\\Microsoft\\VisualStudio\\9.0Exp")]
+ [MsVsShell.DefaultRegistryRoot("Software\\Microsoft\\VisualStudio\\10.0Exp")]
// Register the package to have information displayed in Help/About dialog box
[MsVsShell.InstalledProductRegistration(false, "#100", "#101", "1.0.0.0", IconResourceID = CommandId.iiconProductIcon)]
// Declare that resources for the package are to be found in the managed assembly resources, and not in a satellite dll
@@ -109,13 +109,11 @@ protected override void Dispose(bool disposing)
private void OnSccCommand(object sender, EventArgs e)
{
- // Toggle the checked state of this command
MenuCommand thisCommand = sender as MenuCommand;
if (thisCommand != null)
{
- //thisCommand.Checked = !thisCommand.Checked;
-
- sccService.Refresh();
+ sccService.OpenTracker();
+ sccService.Refresh();
}
}
View
40 BasicSccProvider.csproj
@@ -1,4 +1,5 @@
-<Project DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003" ToolsVersion="3.5">
+<?xml version="1.0" encoding="utf-8"?>
+<Project DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003" ToolsVersion="4.0">
<PropertyGroup>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
@@ -9,7 +10,12 @@
<AppDesignerFolder>Properties</AppDesignerFolder>
<RootNamespace>GitScc</RootNamespace>
<AssemblyName>GitSccProvider</AssemblyName>
- <TargetFrameworkVersion>v3.5</TargetFrameworkVersion>
+ <TargetFrameworkVersion>v4.0</TargetFrameworkVersion>
+ <FileUpgradeFlags>
+ </FileUpgradeFlags>
+ <OldToolsVersion>4.0</OldToolsVersion>
+ <UpgradeBackupLocation />
+ <TargetFrameworkProfile />
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<DebugSymbols>true</DebugSymbols>
@@ -19,6 +25,7 @@
<DefineConstants>DEBUG;TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
+ <CodeAnalysisRuleSet>AllRules.ruleset</CodeAnalysisRuleSet>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
<DebugType>pdbonly</DebugType>
@@ -27,19 +34,21 @@
<DefineConstants>TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
+ <CodeAnalysisRuleSet>AllRules.ruleset</CodeAnalysisRuleSet>
</PropertyGroup>
<ItemGroup>
- <Reference Include="GitSharp, Version=0.0.0.0, Culture=neutral, processorArchitecture=MSIL">
- <SpecificVersion>False</SpecificVersion>
- <HintPath>lib\GitSharp.dll</HintPath>
+ <Reference Include="Microsoft.VisualStudio.OLE.Interop, Version=7.1.40304.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" />
+ <Reference Include="Microsoft.VisualStudio.Shell.10.0">
+ <HintPath>C:\Program Files (x86)\Microsoft Visual Studio 2010 SDK\VisualStudioIntegration\Common\Assemblies\v4.0\Microsoft.VisualStudio.Shell.10.0.dll</HintPath>
</Reference>
- <Reference Include="GitSharp.Core, Version=0.0.0.0, Culture=neutral, processorArchitecture=MSIL">
+ <Reference Include="Microsoft.VisualStudio.Shell.Immutable.10.0, Version=10.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL">
<SpecificVersion>False</SpecificVersion>
- <HintPath>lib\GitSharp.Core.dll</HintPath>
+ <HintPath>C:\Program Files (x86)\Microsoft Visual Studio 2010 SDK\VisualStudioIntegration\Common\Assemblies\v4.0\Microsoft.VisualStudio.Shell.Immutable.10.0.dll</HintPath>
</Reference>
- <Reference Include="Microsoft.VisualStudio.OLE.Interop, Version=7.1.40304.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" />
- <Reference Include="Microsoft.VisualStudio.Shell.9.0" />
<Reference Include="Microsoft.VisualStudio.Shell.Interop, Version=7.1.40304.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" />
+ <Reference Include="Microsoft.VisualStudio.Shell.Interop.10.0, Version=10.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL">
+ <EmbedInteropTypes>True</EmbedInteropTypes>
+ </Reference>
<Reference Include="Microsoft.VisualStudio.Shell.Interop.8.0, Version=8.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" />
<Reference Include="Microsoft.VisualStudio.Shell.Interop.9.0, Version=9.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" />
<Reference Include="System" />
@@ -79,6 +88,7 @@
<Content Include="Resources\Images_24bit.bmp" />
<Content Include="Resources\Images_32bit.bmp" />
<Content Include="Resources\SccGlyphs.bmp" />
+ <None Include="source.extension.vsixmanifest" />
<None Include="Resources\Product.ico" />
</ItemGroup>
<ItemGroup>
@@ -87,6 +97,16 @@
</VSCTCompile>
<None Include="ClassDiagram.cd" />
</ItemGroup>
+ <ItemGroup>
+ <ProjectReference Include="GitSharp.Core\GitSharp.Core.csproj">
+ <Project>{C46EDD61-C202-465A-93F1-ADE20A83BB59}</Project>
+ <Name>GitSharp.Core</Name>
+ </ProjectReference>
+ <ProjectReference Include="GitSharp\GitSharp.csproj">
+ <Project>{7311850F-619A-4241-B09F-157792C75FBA}</Project>
+ <Name>GitSharp</Name>
+ </ProjectReference>
+ </ItemGroup>
<PropertyGroup>
<!--
To specify a different registry root to register your package, uncomment the TargetRegistryRoot
@@ -97,7 +117,7 @@
<RegisterWithCodebase>true</RegisterWithCodebase>
</PropertyGroup>
<Import Project="$(MSBuildBinPath)\Microsoft.CSharp.targets" />
- <Import Project="$(MSBuildExtensionsPath)\Microsoft\VisualStudio\v9.0\VSSDK\Microsoft.VsSDK.targets" />
+ <Import Project="$(MSBuildExtensionsPath)\Microsoft\VisualStudio\v10.0\VSSDK\Microsoft.VsSDK.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">
View
25 BasicSccProvider.sln
@@ -1,19 +1,21 @@

-Microsoft Visual Studio Solution File, Format Version 10.00
-# Visual Studio 2008
-Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "BasicSccProvider", "BasicSccProvider.csproj", "{ADECE07A-5D80-4950-9DA5-A681CE2F5106}"
-EndProject
+Microsoft Visual Studio Solution File, Format Version 11.00
+# Visual Studio 2010
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "lib", "lib", "{A0417584-B3B4-4991-8435-4B86D643322B}"
ProjectSection(SolutionItems) = preProject
lib\DiffieHellman.dll = lib\DiffieHellman.dll
- lib\GitSharp.Core.dll = lib\GitSharp.Core.dll
- lib\GitSharp.dll = lib\GitSharp.dll
lib\ICSharpCode.SharpZipLib.dll = lib\ICSharpCode.SharpZipLib.dll
lib\Org.Mentalis.Security.dll = lib\Org.Mentalis.Security.dll
lib\Tamir.SharpSSH.dll = lib\Tamir.SharpSSH.dll
lib\Winterdom.IO.FileMap.dll = lib\Winterdom.IO.FileMap.dll
EndProjectSection
EndProject
+Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "BasicSccProvider", "BasicSccProvider.csproj", "{ADECE07A-5D80-4950-9DA5-A681CE2F5106}"
+EndProject
+Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "GitSharp.Core", "GitSharp.Core\GitSharp.Core.csproj", "{C46EDD61-C202-465A-93F1-ADE20A83BB59}"
+EndProject
+Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "GitSharp", "GitSharp\GitSharp.csproj", "{7311850F-619A-4241-B09F-157792C75FBA}"
+EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
@@ -24,11 +26,16 @@ Global
{ADECE07A-5D80-4950-9DA5-A681CE2F5106}.Debug|Any CPU.Build.0 = Debug|Any CPU
{ADECE07A-5D80-4950-9DA5-A681CE2F5106}.Release|Any CPU.ActiveCfg = Release|Any CPU
{ADECE07A-5D80-4950-9DA5-A681CE2F5106}.Release|Any CPU.Build.0 = Release|Any CPU
+ {C46EDD61-C202-465A-93F1-ADE20A83BB59}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
+ {C46EDD61-C202-465A-93F1-ADE20A83BB59}.Debug|Any CPU.Build.0 = Debug|Any CPU
+ {C46EDD61-C202-465A-93F1-ADE20A83BB59}.Release|Any CPU.ActiveCfg = Release|Any CPU
+ {C46EDD61-C202-465A-93F1-ADE20A83BB59}.Release|Any CPU.Build.0 = Release|Any CPU
+ {7311850F-619A-4241-B09F-157792C75FBA}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
+ {7311850F-619A-4241-B09F-157792C75FBA}.Debug|Any CPU.Build.0 = Debug|Any CPU
+ {7311850F-619A-4241-B09F-157792C75FBA}.Release|Any CPU.ActiveCfg = Release|Any CPU
+ {7311850F-619A-4241-B09F-157792C75FBA}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
- GlobalSection(ExtensibilityAddIns) = postSolution
- DebugSamples90.Connect = 1;Configure Project for VSIP Experimental Environment;ConfigVSIPDebug
- EndGlobalSection
EndGlobal
View
85 GitFileStatusTracker.cs
@@ -11,41 +11,42 @@ public class GitFileStatusTracker
{
private RepositoryStatus repositoryStatus;
private Uri workingFolderUri;
- FileSystemWatcher watcher;
+ //private FileSystemWatcher watcher;
+ //private IgnoreRules ignoreRules;
public GitFileStatusTracker()
{
}
-
+
public void Open(string workingFolder)
{
Close();
if (!string.IsNullOrEmpty(workingFolder))
{
- var repo = new Repository(workingFolder);
- if (Repository.IsValid(repo.WorkingDirectory))
+ try
{
+ var repo = new Repository(workingFolder);
this.repositoryStatus = repo.Status;
this.workingFolderUri = new Uri(repo.WorkingDirectory+"\\");
+ //this.ignoreRules = new IgnoreRules(Path.Combine(repo.WorkingDirectory, GitSharp.Core.Constants.GITIGNORE_FILENAME));
+
+ //this.watcher = new FileSystemWatcher(workingFolder + "\\" + GitSharp.Core.Constants.DOT_GIT); //?
+ ////this.watcher = new FileSystemWatcher(workingFolder); //?
- this.watcher = new FileSystemWatcher(repo.WorkingDirectory + "\\.git"); //?
- this.watcher.NotifyFilter = NotifyFilters.LastWrite;
- this.watcher.EnableRaisingEvents = true;
- this.watcher.Changed += new FileSystemEventHandler(watcher_Changed);
+ //this.watcher.NotifyFilter = NotifyFilters.LastWrite;
+ //this.watcher.EnableRaisingEvents = true;
+ //this.watcher.Changed += new FileSystemEventHandler(watcher_Changed);
+ }
+ catch
+ {
}
}
- else
- {
- this.repositoryStatus = null;
- this.workingFolderUri = null;
- this.watcher.Changed -= new FileSystemEventHandler(watcher_Changed);
- this.watcher = null;
- }
+
}
- private DateTime TimeFired;
+ private DateTime TimeFired;
public event EventHandler OnGitRepoChanged;
private object locker = new object();
@@ -54,10 +55,12 @@ void watcher_Changed(object sender, FileSystemEventArgs e)
lock (locker)
{
double delta = DateTime.Now.Subtract(TimeFired).TotalMilliseconds;
- if (OnGitRepoChanged == null || delta < 500) return;
-
+ if (delta < 500) return;
+
+ //if (IsIgnoredFile(e.FullPath)) return;
+
this.repositoryStatus.Update();
- OnGitRepoChanged(this, EventArgs.Empty);
+ if (OnGitRepoChanged != null) OnGitRepoChanged(this, EventArgs.Empty);
TimeFired = DateTime.Now;
}
@@ -71,18 +74,46 @@ public bool HasGitRepository
public void Close()
{
if (this.repositoryStatus != null) this.repositoryStatus.Repository.Close();
-
- if (this.watcher != null)
- {
- this.watcher.Changed -= new FileSystemEventHandler(watcher_Changed);
- this.watcher.Dispose();
- }
+ this.repositoryStatus = null;
+ this.workingFolderUri = null;
+ //this.ignoreRules = null;
+
+ //if (this.watcher != null)
+ //{
+ // this.watcher.Changed -= new FileSystemEventHandler(watcher_Changed);
+ // this.watcher.Dispose();
+ //}
+
}
+ //private bool IsIgnoredFile(string fileName)
+ //{
+ // try
+ // {
+ // if (Directory.Exists(fileName))
+ // {
+ // return this.ignoreRules.IgnoreDir(this.repositoryStatus.Repository.WorkingDirectory, fileName);
+ // }
+ // else if (File.Exists(fileName))
+ // {
+ // return this.ignoreRules.IgnoreDir(this.repositoryStatus.Repository.WorkingDirectory,
+ // Path.GetDirectoryName(fileName)) ||
+ // this.ignoreRules.IgnoreFile(this.repositoryStatus.Repository.WorkingDirectory, fileName);
+ // }
+ // else
+ // return true;
+ // }
+ // catch
+ // {
+ // return false;
+ // }
+ //}
+
public GitFileStatus GetFileStatus(string fileName)
{
- if (!HasGitRepository || !File.Exists(fileName)) return GitFileStatus.NotControlled;
-
+ if (!HasGitRepository || string.IsNullOrEmpty(fileName) || !File.Exists(fileName))
+ return GitFileStatus.NotControlled;
+
fileName = workingFolderUri.MakeRelativeUri(new Uri(fileName)).ToString();
if (this.repositoryStatus.Untracked.Has(fileName))
View
296 GitSharp.Core/AbbreviatedObjectId.cs
@@ -0,0 +1,296 @@
+/*
+ * Copyright (C) 2008, Google Inc.
+ * Copyright (C) 2009, Henon <meinrad.recheis@gmail.com>
+ * Copyright (C) 2009, Gil Ran <gilrun@gmail.com>
+ *
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or
+ * without modification, are permitted provided that the following
+ * conditions are met:
+ *
+ * - Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ *
+ * - Redistributions in binary form must reproduce the above
+ * copyright notice, this list of conditions and the following
+ * disclaimer in the documentation and/or other materials provided
+ * with the distribution.
+ *
+ * - Neither the name of the Git Development Community nor the
+ * names of its contributors may be used to endorse or promote
+ * products derived from this software without specific prior
+ * written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND
+ * CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,
+ * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
+ * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
+ * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+ * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
+ * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
+ * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
+ * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+using System;
+using System.Text;
+using GitSharp.Core.Exceptions;
+using GitSharp.Core.Util;
+
+namespace GitSharp.Core
+{
+ /// <summary>
+ /// A prefix abbreviation of an {@link ObjectId}.
+ ///
+ /// Sometimes Git produces abbreviated SHA-1 strings, using sufficient leading
+ /// digits from the ObjectId name to still be unique within the repository the
+ /// string was generated from. These ids are likely to be unique for a useful
+ /// period of time, especially if they contain at least 6-10 hex digits.
+ ///
+ /// This class converts the hex string into a binary form, to make it more
+ /// efficient for matching against an object.
+ /// </summary>
+ [Serializable]
+ public class AbbreviatedObjectId
+ {
+ /// Number of half-bytes used by this id.
+ private readonly int _nibbles;
+
+ readonly int _w1;
+ readonly int _w2;
+ readonly int _w3;
+ readonly int _w4;
+ readonly int _w5;
+
+ /// <summary>
+ /// Convert an AbbreviatedObjectId from hex characters (US-ASCII).
+ /// </summary>
+ /// <param name="buf">the US-ASCII buffer to read from.</param>
+ /// <param name="offset">position to read the first character from.</param>
+ /// <param name="end">
+ /// one past the last position to read (<code>end-offset</code> is
+ /// the Length of the string).
+ /// </param>
+ /// <returns>the converted object id.</returns>
+ public static AbbreviatedObjectId FromString(byte[] buf, int offset, int end)
+ {
+ if (end - offset > Constants.OBJECT_ID_STRING_LENGTH)
+ {
+ throw new ArgumentException("Invalid id");
+ }
+
+ return FromHexString(buf, offset, end);
+ }
+
+ /// <summary>
+ /// Convert an AbbreviatedObjectId from hex characters.
+ /// </summary>
+ /// <param name="str">
+ /// the string to read from. Must be &lt;= 40 characters.
+ /// </param>
+ /// <returns>the converted object id.</returns>
+ public static AbbreviatedObjectId FromString(string str)
+ {
+ if (str == null)
+ throw new ArgumentNullException ("str");
+ if (str.Length > Constants.OBJECT_ID_STRING_LENGTH)
+ {
+ throw new ArgumentException("Invalid id: " + str);
+ }
+
+ byte[] b = Constants.encodeASCII(str);
+ return FromHexString(b, 0, b.Length);
+ }
+
+ public static int Mask(int nibbles, int word, int v)
+ {
+ int b = (word - 1) * 8;
+ if (b + 8 <= nibbles)
+ {
+ // We have all of the bits required for this word.
+ //
+ return v;
+ }
+
+ if (nibbles <= b)
+ {
+ // We have none of the bits required for this word.
+ //
+ return 0;
+ }
+
+ int s = 32 - (nibbles - b) * 4;
+ return (int)((uint)v >> s) << s; // [henon] unsigned int needed to get the effect of java's rightshift operator >>>
+ }
+
+ public AbbreviatedObjectId(int nibbles, int w1, int w2, int w3, int w4, int w5)
+ {
+ _nibbles = nibbles;
+ _w1 = w1;
+ _w2 = w2;
+ _w3 = w3;
+ _w4 = w4;
+ _w5 = w5;
+ }
+
+ /// <summary>
+ /// Number of hex digits appearing in this id
+ /// </summary>
+ public int Length
+ {
+ get { return _nibbles; }
+ }
+
+ /// <summary>
+ ///
+ /// </summary>
+ /// <returns>
+ /// true if this ObjectId is actually a complete id.
+ /// </returns>
+ public bool isComplete()
+ {
+ return Length == Constants.OBJECT_ID_STRING_LENGTH;
+ }
+
+ /// <summary>
+ ///
+ /// </summary>
+ /// <returns>
+ /// Return a complete <see cref="ObjectId"/>; null if <see cref="isComplete"/> is false.
+ /// </returns>
+ public ObjectId ToObjectId()
+ {
+ return isComplete() ? new ObjectId(_w1, _w2, _w3, _w4, _w5) : null;
+ }
+
+ /// <summary>
+ /// Compares this abbreviation to a full object id.
+ /// </summary>
+ /// <param name="other">the other object id.</param>
+ /// <returns>
+ /// Return &lt;0 if this abbreviation names an object that is less than
+ /// <code>other</code>; 0 if this abbreviation exactly matches the
+ /// first <see cref="Length"/> digits of <code>other.name()</code>;
+ /// &gt;0 if this abbreviation names an object that is after
+ /// <code>other</code>.
+ /// </returns>
+ public int prefixCompare(AnyObjectId other)
+ {
+ if (other == null)
+ {
+ throw new ArgumentNullException("other");
+ }
+
+ int cmp = NB.CompareUInt32(_w1, mask(1, other.W1));
+ if (cmp != 0)
+ {
+ return cmp;
+ }
+
+ cmp = NB.CompareUInt32(_w2, mask(2, other.W2));
+ if (cmp != 0)
+ {
+ return cmp;
+ }
+
+ cmp = NB.CompareUInt32(_w3, mask(3, other.W3));
+ if (cmp != 0)
+ {
+ return cmp;
+ }
+
+ cmp = NB.CompareUInt32(_w4, mask(4, other.W4));
+ if (cmp != 0)
+ {
+ return cmp;
+ }
+
+ return NB.CompareUInt32(_w5, mask(5, other.W5));
+ }
+
+ private int mask(int word, int v)
+ {
+ return Mask(_nibbles, word, v);
+ }
+
+ public override int GetHashCode()
+ {
+ return _w2;
+ }
+
+ public override bool Equals(object obj)
+ {
+ AbbreviatedObjectId b = (obj as AbbreviatedObjectId);
+ if (b != null)
+ {
+ return _nibbles == b._nibbles && _w1 == b._w1 && _w2 == b._w2
+ && _w3 == b._w3 && _w4 == b._w4 && _w5 == b._w5;
+ }
+
+ return false;
+ }
+
+ /// <summary>
+ ///
+ /// </summary>
+ /// <returns>string form of the abbreviation, in lower case hexadecimal.</returns>
+ public string name()
+ {
+ var b = new char[Constants.OBJECT_ID_STRING_LENGTH];
+
+ Hex.FillHexCharArray(b, 0, _w1);
+ if (_nibbles <= 8)
+ {
+ return new string(b, 0, _nibbles);
+ }
+
+ Hex.FillHexCharArray(b, 8, _w2);
+ if (_nibbles <= 16)
+ {
+ return new string(b, 0, _nibbles);
+ }
+
+ Hex.FillHexCharArray(b, 16, _w3);
+ if (_nibbles <= 24)
+ {
+ return new string(b, 0, _nibbles);
+ }
+
+ Hex.FillHexCharArray(b, 24, _w4);
+ if (_nibbles <= 32)
+ {
+ return new string(b, 0, _nibbles);
+ }
+
+ Hex.FillHexCharArray(b, 32, _w5);
+ return new string(b, 0, _nibbles);
+ }
+
+ public override string ToString()
+ {
+ return "AbbreviatedObjectId[" + name() + "]";
+ }
+
+ private static AbbreviatedObjectId FromHexString(byte[] bs, int ptr, int end)
+ {
+ try
+ {
+ int a = Hex.HexUInt32(bs, ptr, end);
+ int b = Hex.HexUInt32(bs, ptr + 8, end);
+ int c = Hex.HexUInt32(bs, ptr + 16, end);
+ int d = Hex.HexUInt32(bs, ptr + 24, end);
+ int e = Hex.HexUInt32(bs, ptr + 32, end);
+ return new AbbreviatedObjectId(end - ptr, a, b, c, d, e);
+ }
+ catch (IndexOutOfRangeException e)
+ {
+ throw new InvalidObjectIdException(bs, ptr, end - ptr, e);
+ }
+ }
+ }
+}
View
99 GitSharp.Core/AbstractIndexTreeVisitor.cs
@@ -0,0 +1,99 @@
+/*
+ * Copyright (C) 2007, Dave Watson <dwatson@mimvista.com>
+ * Copyright (C) 2008, Robin Rosenberg <robin.rosenberg@dewire.com>
+ * Copyright (C) 2006, Shawn O. Pearce <spearce@spearce.org>
+ * Copyright (C) 2008, Kevin Thompson <kevin.thompson@theautomaters.com>
+ *
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or
+ * without modification, are permitted provided that the following
+ * conditions are met:
+ *
+ * - Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ *
+ * - Redistributions in binary form must reproduce the above
+ * copyright notice, this list of conditions and the following
+ * disclaimer in the documentation and/or other materials provided
+ * with the distribution.
+ *
+ * - Neither the name of the Git Development Community nor the
+ * names of its contributors may be used to endorse or promote
+ * products derived from this software without specific prior
+ * written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND
+ * CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,
+ * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
+ * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
+ * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+ * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
+ * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
+ * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
+ * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+using System.IO;
+
+namespace GitSharp.Core
+{
+ public class AbstractIndexTreeVisitor : IndexTreeVisitor
+ {
+ public delegate void FinishVisitTreeDelegate(Tree tree, Tree auxTree, string curDir);
+ public FinishVisitTreeDelegate FinishVisitTree { get; set; }
+
+ public delegate void FinishVisitTreeByIndexDelegate(Tree tree, int i, string curDir);
+ public FinishVisitTreeByIndexDelegate FinishVisitTreeByIndex { get; set; }
+
+ public delegate void VisitEntryDelegate(TreeEntry treeEntry, GitIndex.Entry indexEntry, FileInfo file);
+ public VisitEntryDelegate VisitEntry { get; set; }
+
+ public delegate void VisitEntryAuxDelegate(TreeEntry treeEntry, TreeEntry auxEntry, GitIndex.Entry indexEntry, FileInfo file);
+ public VisitEntryAuxDelegate VisitEntryAux { get; set; }
+
+ #region IndexTreeVisitor Members
+
+ void IndexTreeVisitor.VisitEntry(TreeEntry treeEntry, GitIndex.Entry indexEntry, FileInfo file)
+ {
+ VisitEntryDelegate handler = VisitEntry;
+ if (handler != null)
+ {
+ handler(treeEntry, indexEntry, file);
+ }
+ }
+
+ void IndexTreeVisitor.VisitEntry(TreeEntry treeEntry, TreeEntry auxEntry, GitIndex.Entry indexEntry, FileInfo file)
+ {
+ VisitEntryAuxDelegate handler = VisitEntryAux;
+ if (handler != null)
+ {
+ handler(treeEntry, auxEntry, indexEntry, file);
+ }
+ }
+
+ void IndexTreeVisitor.FinishVisitTree(Tree tree, Tree auxTree, string curDir)
+ {
+ FinishVisitTreeDelegate handler = FinishVisitTree;
+ if (handler != null)
+ {
+ handler(tree, auxTree, curDir);
+ }
+ }
+
+ void IndexTreeVisitor.FinishVisitTree(Tree tree, int i, string curDir)
+ {
+ FinishVisitTreeByIndexDelegate handler = FinishVisitTreeByIndex;
+ if (handler != null)
+ {
+ handler(tree, i, curDir);
+ }
+ }
+
+ #endregion
+ }
+}
View
129 GitSharp.Core/AlternateRepositoryDatabase.cs
@@ -0,0 +1,129 @@
+/*
+ * Copyright (C) 2009, Google Inc.
+ *
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or
+ * without modification, are permitted provided that the following
+ * conditions are met:
+ *
+ * - Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ *
+ * - Redistributions in binary form must reproduce the above
+ * copyright notice, this list of conditions and the following
+ * disclaimer in the documentation and/or other materials provided
+ * with the distribution.
+ *
+ * - Neither the name of the Git Development Community nor the
+ * names of its contributors may be used to endorse or promote
+ * products derived from this software without specific prior
+ * written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND
+ * CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,
+ * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
+ * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
+ * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+ * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
+ * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
+ * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
+ * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+using System.Collections.Generic;
+
+namespace GitSharp.Core
+{
+ /// <summary>
+ /// An ObjectDatabase of another <see cref="Repository"/>.
+ /// <para/>
+ /// This {@code ObjectDatabase} wraps around another {@code Repository}'s object
+ /// database, providing its contents to the caller, and closing the Repository
+ /// when this database is closed. The primary user of this class is
+ /// <see cref="ObjectDirectory"/> , when the {@code info/alternates} file points at the
+ /// {@code objects/} directory of another repository.
+ /// </summary>
+ public sealed class AlternateRepositoryDatabase : ObjectDatabase
+ {
+ private readonly Repository _repository;
+ private readonly ObjectDatabase _objectDatabase;
+
+ /// <param name="alternateRepository">the alternate repository to wrap and export.</param>
+ public AlternateRepositoryDatabase(Repository alternateRepository)
+ {
+ _repository = alternateRepository;
+ _objectDatabase = _repository.ObjectDatabase;
+ }
+
+ /// <returns>the alternate repository objects are borrowed from.</returns>
+ public Repository getRepository()
+ {
+ return _repository;
+ }
+
+ public override void closeSelf()
+ {
+ _repository.Dispose();
+ }
+
+ public override void create()
+ {
+ _repository.Create();
+ }
+
+ public override bool exists()
+ {
+ return _objectDatabase.exists();
+ }
+
+ public override bool hasObject1(AnyObjectId objectId)
+ {
+ return _objectDatabase.hasObject1(objectId);
+ }
+
+ public override bool tryAgain1()
+ {
+ return _objectDatabase.tryAgain1();
+ }
+
+ public override bool hasObject2(string objectName)
+ {
+ return _objectDatabase.hasObject2(objectName);
+ }
+
+ public override ObjectLoader openObject1(WindowCursor curs, AnyObjectId objectId)
+ {
+ return _objectDatabase.openObject1(curs, objectId);
+ }
+
+ public override ObjectLoader openObject2(WindowCursor curs, string objectName, AnyObjectId objectId)
+ {
+ return _objectDatabase.openObject2(curs, objectName, objectId);
+ }
+
+ public override void OpenObjectInAllPacksImplementation(ICollection<PackedObjectLoader> @out, WindowCursor windowCursor, AnyObjectId objectId)
+ {
+ _objectDatabase.OpenObjectInAllPacksImplementation(@out, windowCursor, objectId);
+ }
+
+ protected override ObjectDatabase[] loadAlternates()
+ {
+ return _objectDatabase.getAlternates();
+ }
+
+ public override void closeAlternates()
+ {
+ // Do nothing; these belong to odb to close, not us.
+ }
+
+ public override ObjectDatabase newCachedDatabase()
+ {
+ return _objectDatabase.newCachedDatabase();
+ }
+ }
+}
View
517 GitSharp.Core/AnyObjectId.cs
@@ -0,0 +1,517 @@
+/*
+ * Copyright (C) 2008, Shawn O. Pearce <spearce@spearce.org>
+ * Copyright (C) 2008, Kevin Thompson <kevin.thompson@theautomaters.com>
+ * Copyright (C) 2009, Henon <meinrad.recheis@gmail.com>
+ *
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or
+ * without modification, are permitted provided that the following
+ * conditions are met:
+ *
+ * - Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ *
+ * - Redistributions in binary form must reproduce the above
+ * copyright notice, this list of conditions and the following
+ * disclaimer in the documentation and/or other materials provided
+ * with the distribution.
+ *
+ * - Neither the name of the Git Development Community nor the
+ * names of its contributors may be used to endorse or promote
+ * products derived from this software without specific prior
+ * written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND
+ * CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,
+ * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
+ * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
+ * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+ * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
+ * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
+ * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
+ * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+using System;
+using System.Collections.Generic;
+using System.IO;
+using System.Text;
+using GitSharp.Core.Util;
+
+namespace GitSharp.Core
+{
+ /// <summary>
+ /// A (possibly mutable) SHA-1 abstraction.
+ /// <para />
+ /// If this is an instance of <seealso cref="MutableObjectId"/> the concept of equality
+ /// with this instance can alter at any time, if this instance is modified to
+ /// represent a different object name.
+ /// </summary>
+ public abstract class AnyObjectId : IEquatable<AnyObjectId>,
+#if !__MonoCS__
+ IComparable<ObjectId>,
+#endif
+ IComparable
+ {
+ public static bool operator ==(AnyObjectId one, AnyObjectId another)
+ {
+ if (ReferenceEquals(one, another))
+ {
+ return true;
+ }
+
+ if (ReferenceEquals(one, null))
+ {
+ return false;
+ }
+
+ return one.Equals(another);
+ }
+
+ public static bool operator !=(AnyObjectId one, AnyObjectId another)
+ {
+ return !(one == another);
+ }
+
+ /// <summary>
+ /// Compare to object identifier byte sequences for equality.
+ /// </summary>
+ /// <param name="firstObjectId">the first identifier to compare. Must not be null.</param>
+ /// <param name="secondObjectId">the second identifier to compare. Must not be null.</param>
+ /// <returns></returns>
+ public static bool equals(AnyObjectId firstObjectId, AnyObjectId secondObjectId)
+ {
+ if (ReferenceEquals(firstObjectId, secondObjectId))
+ {
+ return true;
+ }
+
+ // We test word 2 first as odds are someone already used our
+ // word 1 as a hash code, and applying that came up with these
+ // two instances we are comparing for equality. Therefore the
+ // first two words are very likely to be identical. We want to
+ // break away from collisions as quickly as possible.
+ //
+ return firstObjectId.W2 == secondObjectId.W2
+ && firstObjectId.W3 == secondObjectId.W3
+ && firstObjectId.W4 == secondObjectId.W4
+ && firstObjectId.W5 == secondObjectId.W5
+ && firstObjectId.W1 == secondObjectId.W1;
+
+ }
+
+ /// <summary>
+ /// Determine if this ObjectId has exactly the same value as another.
+ /// </summary>
+ /// <param name="other">the other id to compare to. May be null.</param>
+ /// <returns>true only if both ObjectIds have identical bits.</returns>
+ public virtual bool Equals(AnyObjectId other)
+ {
+ if (ReferenceEquals(other, null))
+ {
+ return false;
+ }
+
+ return equals(this, other);
+ }
+
+ public override bool Equals(object obj)
+ {
+ if (obj is AnyObjectId)
+ {
+ return Equals((AnyObjectId)obj);
+ }
+
+ return false;
+ }
+
+ /// <summary>
+ /// Copy this ObjectId to an output writer in hex format.
+ /// </summary>
+ /// <param name="s">the stream to copy to.</param>
+ public void CopyTo(BinaryWriter s)
+ {
+ s.Write(ToHexByteArray());
+ }
+
+ /// <summary>
+ /// Copy this ObjectId to a StringBuilder in hex format.
+ /// </summary>
+ /// <param name="tmp">
+ /// temporary char array to buffer construct into before writing.
+ /// Must be at least large enough to hold 2 digits for each byte
+ /// of object id (40 characters or larger).
+ /// </param>
+ /// <param name="w">the string to append onto.</param>
+ public void CopyTo(char[] tmp, StringBuilder w)
+ {
+ ToHexCharArray(tmp);
+ w.Append(tmp, 0, Constants.OBJECT_ID_STRING_LENGTH);
+ }
+
+ /// <summary>
+ /// Copy this ObjectId to an output writer in hex format.
+ /// </summary>
+ /// <param name="tmp">
+ /// temporary char array to buffer construct into before writing.
+ /// Must be at least large enough to hold 2 digits for each byte
+ /// of object id (40 characters or larger).
+ /// </param>
+ /// <param name="w">the stream to copy to.</param>
+ public void CopyTo(char[] tmp, StreamWriter w)
+ {
+ ToHexCharArray(tmp);
+ w.Write(tmp, 0, Constants.OBJECT_ID_STRING_LENGTH);
+ }
+
+ public void CopyTo(char[] tmp, Encoding e, Stream w)
+ {
+ ToHexCharArray(tmp);
+ var data = e.GetBytes(tmp, 0, Constants.OBJECT_ID_STRING_LENGTH);
+ w.Write(data, 0, data.Length);
+ }
+
+ /// <summary>
+ /// Copy this ObjectId to an output writer in hex format.
+ /// </summary>
+ /// <param name="s">the stream to copy to.</param>
+ public void copyRawTo(Stream s)
+ {
+ var buf = new byte[20];
+ NB.encodeInt32(buf, 0, W1);
+ NB.encodeInt32(buf, 4, W2);
+ NB.encodeInt32(buf, 8, W3);
+ NB.encodeInt32(buf, 12, W4);
+ NB.encodeInt32(buf, 16, W5);
+ s.Write(buf, 0, 20);
+ }
+
+ /// <summary>
+ /// Copy this ObjectId to a byte array.
+ /// </summary>
+ /// <param name="buf">the buffer to copy to.</param>
+ /// <param name="off">the offset within b to write at.</param>
+ public void copyRawTo(byte[] buf, int off)
+ {
+ NB.encodeInt32(buf, 0 + off, W1);
+ NB.encodeInt32(buf, 4 + off, W2);
+ NB.encodeInt32(buf, 8 + off, W3);
+ NB.encodeInt32(buf, 12 + off, W4);
+ NB.encodeInt32(buf, 16 + off, W5);
+ }
+
+ /// <summary>
+ /// Copy this ObjectId to a int array.
+ /// </summary>
+ /// <param name="b">the buffer to copy to.</param>
+ /// <param name="offset">the offset within b to write at.</param>
+ public void copyRawTo(int[] b, int offset)
+ {
+ b[offset] = W1;
+ b[offset + 1] = W2;
+ b[offset + 2] = W3;
+ b[offset + 3] = W4;
+ b[offset + 4] = W5;
+ }
+
+ private byte[] ToHexByteArray()
+ {
+ var dst = new byte[Constants.OBJECT_ID_STRING_LENGTH];
+
+ Hex.FillHexByteArray(dst, 0, W1);
+ Hex.FillHexByteArray(dst, 8, W2);
+ Hex.FillHexByteArray(dst, 16, W3);
+ Hex.FillHexByteArray(dst, 24, W4);
+ Hex.FillHexByteArray(dst, 32, W5);
+
+ return dst;
+ }
+
+ public override int GetHashCode()
+ {
+ return W2;
+ }
+
+ /// <summary>
+ /// Return unique abbreviation (prefix) of this object SHA-1.
+ /// <para/>
+ /// This method is a utility for <code>abbreviate(repo, 8)</code>.
+ /// </summary>
+ /// <param name="repo">repository for checking uniqueness within.</param>
+ /// <returns>SHA-1 abbreviation.</returns>
+ public AbbreviatedObjectId Abbreviate(Repository repo)
+ {
+ return Abbreviate(repo, 8);
+ }
+
+ /// <summary>
+ /// Return unique abbreviation (prefix) of this object SHA-1.
+ /// <para/>
+ /// Current implementation is not guaranteeing uniqueness, it just returns
+ /// fixed-length prefix of SHA-1 string.
+ /// </summary>
+ /// <param name="repo">repository for checking uniqueness within.</param>
+ /// <param name="len">minimum length of the abbreviated string.</param>
+ /// <returns>SHA-1 abbreviation.</returns>
+ public AbbreviatedObjectId Abbreviate(Repository repo, int len)
+ {
+ int a = AbbreviatedObjectId.Mask(len, 1, W1);
+ int b = AbbreviatedObjectId.Mask(len, 2, W2);
+ int c = AbbreviatedObjectId.Mask(len, 3, W3);
+ int d = AbbreviatedObjectId.Mask(len, 4, W4);
+ int e = AbbreviatedObjectId.Mask(len, 5, W5);
+ return new AbbreviatedObjectId(len, a, b, c, d, e);
+ }
+
+ protected AnyObjectId(AnyObjectId other)
+ {
+ if ((ReferenceEquals(other, null)))
+ {
+ throw new ArgumentNullException("other");
+ }
+
+ W1 = other.W1;
+ W2 = other.W2;
+ W3 = other.W3;
+ W4 = other.W4;
+ W5 = other.W5;
+ }
+
+ protected AnyObjectId(int w1, int w2, int w3, int w4, int w5)
+ {
+ W1 = w1;
+ W2 = w2;
+ W3 = w3;
+ W4 = w4;
+ W5 = w5;
+ }
+
+ public int W1 { get; protected set; }
+ public int W2 { get; protected set; }
+ public int W3 { get; protected set; }
+ public int W4 { get; protected set; }
+ public int W5 { get; protected set; }
+
+ /// <summary>
+ /// For ObjectIdMap
+ /// </summary>
+ /// <returns>A discriminator usable for a fan-out style map</returns>
+ public int GetFirstByte()
+ {
+ return (byte)(((uint)W1) >> 24); // W1 >>> 24 in java
+ }
+
+ #region IComparable<ObjectId> Members
+
+ /// <summary>
+ /// Compare this ObjectId to another and obtain a sort ordering.
+ /// </summary>
+ /// <param name="other">the other id to compare to. Must not be null.</param>
+ /// <returns>
+ /// &lt; 0 if this id comes before other; 0 if this id is equal to
+ /// other; &gt; 0 if this id comes after other.
+ /// </returns>
+ public int CompareTo(ObjectId other)
+ {
+ if (this == other)
+ return 0;
+
+ int cmp = NB.CompareUInt32(W1, other.W1);
+ if (cmp != 0)
+ return cmp;
+
+ cmp = NB.CompareUInt32(W2, other.W2);
+ if (cmp != 0)
+ return cmp;
+
+ cmp = NB.CompareUInt32(W3, other.W3);
+ if (cmp != 0)
+ return cmp;
+
+ cmp = NB.CompareUInt32(W4, other.W4);
+ if (cmp != 0)
+ return cmp;
+
+ return NB.CompareUInt32(W5, other.W5);
+ }
+
+ public int CompareTo(byte[] bs, int p)
+ {
+ int cmp = NB.CompareUInt32(W1, NB.DecodeInt32(bs, p));
+ if (cmp != 0)
+ return cmp;
+
+ cmp = NB.CompareUInt32(W2, NB.DecodeInt32(bs, p + 4));
+ if (cmp != 0)
+ return cmp;
+
+ cmp = NB.CompareUInt32(W3, NB.DecodeInt32(bs, p + 8));
+ if (cmp != 0)
+ return cmp;
+
+ cmp = NB.CompareUInt32(W4, NB.DecodeInt32(bs, p + 12));
+ if (cmp != 0)
+ return cmp;
+
+ return NB.CompareUInt32(W5, NB.DecodeInt32(bs, p + 16));
+ }
+
+ public int CompareTo(int[] bs, int p)
+ {
+ int cmp = NB.CompareUInt32(W1, bs[p]);
+ if (cmp != 0)
+ return cmp;
+
+ cmp = NB.CompareUInt32(W2, bs[p + 1]);
+ if (cmp != 0)
+ return cmp;
+
+ cmp = NB.CompareUInt32(W3, bs[p + 2]);
+ if (cmp != 0)
+ return cmp;
+
+ cmp = NB.CompareUInt32(W4, bs[p + 3]);
+ if (cmp != 0)
+ return cmp;
+
+ return NB.CompareUInt32(W5, bs[p + 4]);
+ }
+
+ #endregion
+
+ #region IComparable Members
+
+ public int CompareTo(object obj)
+ {
+ return this.CompareTo((ObjectId)obj);
+ }
+
+ #endregion
+
+ /// <summary>
+ /// Tests if this ObjectId starts with the given abbreviation.
+ /// </summary>
+ /// <param name="abbr">the abbreviation.</param>
+ /// <returns>
+ /// True if this ObjectId begins with the abbreviation; else false.
+ /// </returns>
+ public bool startsWith(AbbreviatedObjectId abbr)
+ {
+ return abbr.prefixCompare(this) == 0;
+ }
+
+ private char[] ToHexCharArray()
+ {
+ var dest = new char[Constants.OBJECT_ID_STRING_LENGTH];
+ ToHexCharArray(dest);
+ return dest;
+ }
+
+ private void ToHexCharArray(char[] dest)
+ {
+ Hex.FillHexCharArray(dest, 0, W1);
+ Hex.FillHexCharArray(dest, 8, W2);
+ Hex.FillHexCharArray(dest, 16, W3);
+ Hex.FillHexCharArray(dest, 24, W4);
+ Hex.FillHexCharArray(dest, 32, W5);
+ }
+
+ /// <summary>
+ /// string form of the SHA-1, in lower case hexadecimal.
+ /// </summary>
+ public string Name
+ {
+ get { return new string(ToHexCharArray()); }
+ }
+
+ public override String ToString()
+ {
+ return "AnyObjectId[" + Name + "]";
+ }
+
+ /// <summary>
+ /// Obtain an immutable copy of this current object name value.
+ /// <para/>
+ /// Only returns <code>this</code> if this instance is an unsubclassed
+ /// instance of {@link ObjectId}; otherwise a new instance is returned
+ /// holding the same value.
+ /// <para/>
+ /// This method is useful to shed any additional memory that may be tied to
+ /// the subclass, yet retain the unique identity of the object id for future
+ /// lookups within maps and repositories.
+ /// </summary>
+ /// <returns>an immutable copy, using the smallest memory footprint possible.</returns>
+ public ObjectId Copy()
+ {
+ if (GetType() == typeof(ObjectId))
+ {
+ return (ObjectId)this;
+ }
+ return new ObjectId(this);
+ }
+
+ /// <summary>
+ /// Obtain an immutable copy of this current object name value.
+ /// <para/>
+ /// See <see cref="Copy"/> if <code>this</code> is a possibly subclassed (but
+ /// immutable) identity and the application needs a lightweight identity
+ /// <i>only</i> reference.
+ /// </summary>
+ /// <returns>
+ /// an immutable copy. May be <code>this</code> if this is already
+ /// an immutable instance.
+ /// </returns>
+ public abstract ObjectId ToObjectId();
+
+ #region Nested Types
+
+ internal class AnyObjectIdEqualityComparer<T> : IEqualityComparer<T>
+ where T : AnyObjectId
+ {
+ #region Implementation of IEqualityComparer<ObjectId>
+
+ /// <summary>
+ /// Determines whether the specified objects are equal.
+ /// </summary>
+ /// <returns>
+ /// true if the specified objects are equal; otherwise, false.
+ /// </returns>
+ /// <param name="x">
+ /// The first object of type <see cref="ObjectId"/> to compare.
+ /// </param>
+ /// <param name="y">
+ /// The second object of type <see cref="ObjectId"/> to compare.
+ /// </param>
+ public bool Equals(T x, T y)
+ {
+ return x == y;
+ }
+
+ /// <summary>
+ /// Returns a hash code for the specified object.
+ /// </summary>
+ /// <returns>
+ /// A hash code for the specified object.
+ /// </returns>
+ /// <param name="obj">
+ /// The <see cref="ObjectId"/> for which a hash code is to be returned.
+ /// </param>
+ /// <exception cref="ArgumentNullException">
+ /// The type of <paramref name="obj"/> is a reference type and <paramref name="obj"/> is null.
+ /// </exception>
+ public int GetHashCode(T obj)
+ {
+ return obj.GetHashCode();
+ }
+
+ #endregion
+ }
+
+ #endregion
+ }
+}
View
149 GitSharp.Core/BinaryDelta.cs
@@ -0,0 +1,149 @@
+/*
+ * Copyright (C) 2007, Robin Rosenberg <robin.rosenberg@dewire.com>
+ * Copyright (C) 2007, Shawn O. Pearce <spearce@spearce.org>
+ * Copyright (C) 2008, Kevin Thompson <kevin.thompson@theautomaters.com>
+ *
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or
+ * without modification, are permitted provided that the following
+ * conditions are met:
+ *
+ * - Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ *
+ * - Redistributions in binary form must reproduce the above
+ * copyright notice, this list of conditions and the following
+ * disclaimer in the documentation and/or other materials provided
+ * with the distribution.
+ *
+ * - Neither the name of the Git Development Community nor the
+ * names of its contributors may be used to endorse or promote
+ * products derived from this software without specific prior
+ * written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND
+ * CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,
+ * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
+ * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
+ * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+ * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
+ * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
+ * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
+ * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+using System;
+
+namespace GitSharp.Core
+{
+ /// <summary>
+ /// Recreate a stream from a base stream and a GIT pack delta.
+ /// <para />
+ /// This entire class is heavily cribbed from <code>patch-delta.c</code> in the
+ /// GIT project. The original delta patching code was written by Nicolas Pitre
+ /// (&lt;nico@cam.org&gt;).
+ /// </summary>
+ public static class BinaryDelta
+ {
+ /// <summary>
+ /// Apply the changes defined by delta to the data in base, yielding a new
+ /// array of bytes.
+ /// </summary>
+ /// <param name="baseData">some byte representing an object of some kind.</param>
+ /// <param name="delta">
+ /// A git pack delta defining the transform from one version to
+ /// another.
+ /// </param>
+ /// <returns>Patched base</returns>
+ public static byte[] Apply(byte[] baseData, byte[] delta)
+ {
+ int deltaPtr = 0;
+
+ // Length of the base object (a variable Length int).
+ //
+ int baseLen = 0;
+ int c, shift = 0;
+ do
+ {
+ c = delta[deltaPtr++] & 0xff;
+ baseLen |= (c & 0x7f) << shift;
+ shift += 7;
+ } while ((c & 0x80) != 0);
+
+ if (baseData.Length != baseLen)
+ {
+ throw new ArgumentException("baseData Length incorrect");
+ }
+
+ // Length of the resulting object (a variable Length int).
+ //
+ int resLen = 0;
+ shift = 0;
+ do
+ {
+ c = delta[deltaPtr++] & 0xff;
+ resLen |= (c & 0x7f) << shift;
+ shift += 7;
+ } while ((c & 0x80) != 0);
+
+ var result = new byte[resLen];
+ int resultPtr = 0;
+ while (deltaPtr < delta.Length)
+ {
+ int cmd = delta[deltaPtr++] & 0xff;
+ if ((cmd & 0x80) != 0)
+ {
+ // Determine the segment of the base which should
+ // be copied into the output. The segment is given
+ // as an offset and a Length.
+ //
+ int copyOffset = 0;
+ if ((cmd & 0x01) != 0)
+ copyOffset = delta[deltaPtr++] & 0xff;
+ if ((cmd & 0x02) != 0)
+ copyOffset |= (delta[deltaPtr++] & 0xff) << 8;
+ if ((cmd & 0x04) != 0)
+ copyOffset |= (delta[deltaPtr++] & 0xff) << 16;
+ if ((cmd & 0x08) != 0)
+ copyOffset |= (delta[deltaPtr++] & 0xff) << 24;
+
+ int copySize = 0;
+ if ((cmd & 0x10) != 0)
+ copySize = delta[deltaPtr++] & 0xff;
+ if ((cmd & 0x20) != 0)
+ copySize |= (delta[deltaPtr++] & 0xff) << 8;
+ if ((cmd & 0x40) != 0)
+ copySize |= (delta[deltaPtr++] & 0xff) << 16;
+ if (copySize == 0)
+ copySize = 0x10000;
+
+ Array.Copy(baseData, copyOffset, result, resultPtr, copySize);
+ resultPtr += copySize;
+ }
+ else if (cmd != 0)
+ {
+ // Anything else the data is literal within the delta
+ // itself.
+ //
+ Array.Copy(delta, deltaPtr, result, resultPtr, cmd);
+ deltaPtr += cmd;
+ resultPtr += cmd;
+ }
+ else
+ {
+ // cmd == 0 has been reserved for future encoding but
+ // for now its not acceptable.
+ //
+ throw new ArgumentException("unsupported command 0");
+ }
+ }
+
+ return result;
+ }
+ }
+}
View
131 GitSharp.Core/BlobBasedConfig.cs
@@ -0,0 +1,131 @@
+/*
+ * Copyright (C) 2009, JetBrains s.r.o.
+ *
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or
+ * without modification, are permitted provided that the following
+ * conditions are met:
+ *
+ * - Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ *
+ * - Redistributions in binary form must reproduce the above
+ * copyright notice, this list of conditions and the following
+ * disclaimer in the documentation and/or other materials provided
+ * with the distribution.
+ *
+ * - Neither the name of the Git Development Community nor the
+ * names of its contributors may be used to endorse or promote
+ * products derived from this software without specific prior
+ * written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND
+ * CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,
+ * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
+ * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
+ * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+ * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
+ * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
+ * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
+ * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+using System.IO;
+using GitSharp.Core.Exceptions;
+using GitSharp.Core.Util;
+
+namespace GitSharp.Core
+{
+ /// <summary>
+ /// The configuration file based on the blobs stored in the repository.
+ /// </summary>
+ public class BlobBasedConfig : Config
+ {
+ /// <summary>
+ /// The constructor from a byte array
+ /// </summary>
+ /// <param name="base">the base configuration file </param>
+ /// <param name="blob">the byte array, should be UTF-8 encoded text. </param>
+ /// <exception cref="ConfigInvalidException">
+ /// The byte array is not a valid configuration format.
+ /// </exception>
+
+ public BlobBasedConfig(Config @base, byte[] blob)
+ : base(@base)
+ {
+ fromText(RawParseUtils.decode(blob));
+ }
+
+ /// <summary> * The constructor from object identifier
+ /// </summary>
+ /// <param name="base">the base configuration file </param>
+ /// <param name="repo">the repository</param>
+ /// <param name="objectid">the object identifier</param>
+ /// <exception cref="IOException">
+ /// the blob cannot be read from the repository. </exception>
+ /// <exception cref="ConfigInvalidException">
+ /// the blob is not a valid configuration format.
+ /// </exception>
+ public BlobBasedConfig(Config @base, Repository repo, ObjectId objectid)
+ : base(@base)
+ {
+ if (repo == null)
+ {
+ throw new System.ArgumentNullException("repo");
+ }
+
+ ObjectLoader loader = repo.OpenBlob(objectid);
+ if (loader == null)
+ {
+ throw new IOException("Blob not found: " + objectid);
+ }
+ fromText(RawParseUtils.decode(loader.Bytes));
+ }
+
+ /// <summary>
+ /// The constructor from commit and path
+ /// </summary>
+ /// <param name="base">The base configuration file</param>
+ /// <param name="commit">The commit that contains the object</param>
+ /// <param name="path">The path within the tree of the commit</param>
+ /// <exception cref="FileNotFoundException">
+ /// the path does not exist in the commit's tree.
+ /// </exception>
+ /// <exception cref="IOException">
+ /// the tree and/or blob cannot be accessed.
+ /// </exception>
+ /// <exception cref="ConfigInvalidException">
+ /// the blob is not a valid configuration format.
+ /// </exception>
+ public BlobBasedConfig(Config @base, Commit commit, string path)
+ : base(@base)
+ {
+ if (commit == null)
+ {
+ throw new System.ArgumentNullException("commit");
+ }
+
+ ObjectId treeId = commit.TreeId;
+ Repository r = commit.Repository;
+ TreeWalk.TreeWalk tree = TreeWalk.TreeWalk.ForPath(r, path, treeId);
+ if (tree == null)
+ {
+ throw new FileNotFoundException("Entry not found by path: " + path);
+ }
+ ObjectId blobId = tree.getObjectId(0);
+ ObjectLoader loader = tree.Repository.OpenBlob(blobId);
+
+ if (loader == null)
+ {
+ throw new IOException("Blob not found: " + blobId + " for path: " + path);
+ }
+
+ fromText(RawParseUtils.decode(loader.Bytes));
+ }
+ }
+}
View
91 GitSharp.Core/ByteArrayExtensions.cs
@@ -0,0 +1,91 @@
+using System;
+
+namespace GitSharp.Core
+{
+ public static class ByteArrayExtensions
+ {
+ public class ParsedLine
+ {
+ public int NextIndex { get; private set;}
+ public byte[] Buffer { get; private set; }
+
+ public ParsedLine(int nextIndex, byte[] buffer)
+ {
+ NextIndex = nextIndex;
+ Buffer = buffer;
+ }
+ }
+
+ public static bool StartsWith(this byte[] buffer, byte[] bufferToCompareWith)
+ {
+ if (buffer == null)
+ {
+ throw new ArgumentNullException("buffer");
+ }
+ if (bufferToCompareWith == null)
+ {
+ throw new ArgumentNullException("bufferToCompareWith");
+ }
+
+ if (buffer.Length < bufferToCompareWith.Length)
+ {
+ return false;
+ }
+
+ int curpos = -1;
+
+ while (++curpos < bufferToCompareWith.Length)
+ {
+ if (bufferToCompareWith[curpos] != buffer[curpos])
+ {
+ return false;
+ }
+ }
+
+ return true;
+ }
+
+ public static ParsedLine ReadLine(this byte[] source, int startIndex)
+ {
+ if (source == null)
+ {
+ throw new ArgumentNullException("source");
+ }
+ if (startIndex < 0)
+ {
+ throw new ArgumentOutOfRangeException("startIndex", "Parameter is expected gretaer or equal than zero.");
+ }
+
+ if (startIndex >= source.Length)
+ {
+ return new ParsedLine(-1, null);
+ }
+
+ int currentIndex = startIndex - 1;
+ int indexModifier = 0;
+
+ while (indexModifier == 0 && ++currentIndex < source.Length)
+ {
+ int num = source[currentIndex];
+ switch (num)
+ {
+ case 13:
+ if ((currentIndex != (source.Length - 1)) && (source[currentIndex + 1] == 10))
+ {
+ indexModifier = 2;
+ }
+ break;
+
+ case 10:
+ indexModifier = 1;
+ break;
+ }
+ }
+
+ var output = new byte[currentIndex - startIndex];
+ Array.Copy(source, startIndex, output, 0, currentIndex - startIndex);
+
+ return new ParsedLine (currentIndex + indexModifier, output);
+ }
+ }
+}
View
96 GitSharp.Core/ByteArrayWindow.cs
@@ -0,0 +1,96 @@
+/*
+ * Copyright (C) 2007, Robin Rosenberg <robin.rosenberg@dewire.com>
+ * Copyright (C) 2008, Shawn O. Pearce <spearce@spearce.org>
+ * Copyright (C) 2009, Henon <meinrad.recheis@gmail.com>
+ *
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or
+ * without modification, are permitted provided that the following
+ * conditions are met:
+ *
+ * - Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ *
+ * - Redistributions in binary form must reproduce the above
+ * copyright notice, this list of conditions and the following
+ * disclaimer in the documentation and/or other materials provided
+ * with the distribution.
+ *
+ * - Neither the name of the Git Development Community nor the
+ * names of its contributors may be used to endorse or promote
+ * products derived from this software without specific prior
+ * written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND
+ * CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,
+ * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
+ * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
+ * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+ * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
+ * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
+ * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
+ * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+using System;
+using ICSharpCode.SharpZipLib.Zip.Compression;
+
+namespace GitSharp.Core
+{
+ /// <summary>
+ /// A <seealso cref="ByteWindow"/> with an underlying byte array for storage.
+ /// </summary>
+ internal class ByteArrayWindow : ByteWindow
+ {
+ private readonly byte[] _array;
+
+ internal ByteArrayWindow(PackFile pack, long o, byte[] b)
+ : base(pack, o, b.Length)
+ {
+ _array = b;
+ }
+
+ protected override int copy(int pos, byte[] dstbuf, int dstoff, int cnt)
+ {
+ cnt = Math.Min(_array.Length - pos, cnt);
+ Array.Copy(_array, pos, dstbuf, dstoff, cnt);
+ return cnt;
+ }
+
+ protected override int Inflate(int pos, byte[] dstbuf, int dstoff, Inflater inf)
+ {
+ while (!inf.IsFinished)
+ {
+ if (inf.IsNeedingInput)
+ {
+ inf.SetInput(_array, pos, _array.Length - pos);
+ break;
+ }
+ dstoff += inf.Inflate(dstbuf, dstoff, dstbuf.Length - dstoff);
+ }
+ while (!inf.IsFinished && !inf.IsNeedingInput)
+ dstoff += inf.Inflate(dstbuf, dstoff, dstbuf.Length - dstoff);
+ return dstoff;
+ }
+
+ protected override void inflateVerify(int pos, Inflater inf)
+ {
+ while (!inf.IsFinished)
+ {
+ if (inf.IsNeedingInput)
+ {
+ inf.SetInput(_array, pos, _array.Length - pos);
+ break;
+ }
+ inf.Inflate(VerifyGarbageBuffer, 0, VerifyGarbageBuffer.Length);
+ }
+ while (!inf.IsFinished && !inf.IsNeedingInput)
+ inf.Inflate(VerifyGarbageBuffer, 0, VerifyGarbageBuffer.Length);
+ }
+ }
+}
View
113 GitSharp.Core/ByteBufferWindow.cs
@@ -0,0 +1,113 @@
+/*
+ * Copyright (C) 2007, Robin Rosenberg <robin.rosenberg@dewire.com>
+ * Copyright (C) 2008, Shawn O. Pearce <spearce@spearce.org>
+ * Copyright (C) 2009, Henon <meinrad.recheis@gmail.com>
+ *
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or
+ * without modification, are permitted provided that the following
+ * conditions are met:
+ *
+ * - Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ *
+ * - Redistributions in binary form must reproduce the above
+ * copyright notice, this list of conditions and the following
+ * disclaimer in the documentation and/or other materials provided
+ * with the distribution.
+ *
+ * - Neither the name of the Git Development Community nor the
+ * names of its contributors may be used to endorse or promote
+ * products derived from this software without specific prior
+ * written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND
+ * CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,
+ * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
+ * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
+ * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+ * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
+ * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
+ * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
+ * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+using System;
+using ICSharpCode.SharpZipLib.Zip.Compression;
+using System.IO;
+
+namespace GitSharp.Core
+{
+ /// <summary>
+ /// A window for accessing git packs using a <see cref="Stream"/> for storage.
+ /// </summary>
+ internal class ByteBufferWindow : ByteWindow, IDisposable
+ {
+ private readonly Stream _stream;
+
+ internal ByteBufferWindow(PackFile pack, long o, Stream b)
+ : base(pack, o, b.Length)
+ {
+ _stream = b;
+ }
+
+ protected override int copy(int pos, byte[] dstbuf, int dstoff, int cnt)
+ {
+ _stream.Position = pos;
+ cnt = (int)Math.Min(_stream.Length - pos, cnt);
+ _stream.Read(dstbuf, dstoff, cnt);
+ return cnt;
+ }
+
+ protected override int Inflate(int pos, byte[] dstbuf, int dstoff, Inflater inf)
+ {
+ var tmp = new byte[512];
+ var s = _stream;
+ s.Position=pos;
+ while ((s.Length-s.Position) > 0 && !inf.IsFinished)
+ {
+ if (inf.IsNeedingInput)
+ {
+ var n = (int)Math.Min((s.Length - s.Position), tmp.Length);
+ s.Read(tmp, 0, n);
+ inf.SetInput(tmp, 0, n);
+ }
+ dstoff += inf.Inflate(dstbuf, dstoff, dstbuf.Length - dstoff);
+ }
+ while (!inf.IsFinished && !inf.IsNeedingInput)
+ dstoff += inf.Inflate(dstbuf, dstoff, dstbuf.Length - dstoff);
+ return dstoff;
+ }
+
+ protected override void inflateVerify(int pos, Inflater inf)
+ {
+ var tmp = new byte[512];
+ var s = _stream;
+ s.Position = pos;
+ while ((s.Length - s.Position) > 0 && !inf.IsFinished)
+ {
+ if (inf.IsNeedingInput)
+ {
+ var n = (int)Math.Min((s.Length - s.Position), tmp.Length);
+ s.Read(tmp, 0, n);
+ inf.SetInput(tmp, 0, n);
+ }
+ inf.Inflate(VerifyGarbageBuffer, 0, VerifyGarbageBuffer.Length);
+ }
+ while (!inf.IsFinished && !inf.IsNeedingInput)
+ inf.Inflate(VerifyGarbageBuffer, 0, VerifyGarbageBuffer.Length);
+ }
+
+ public override void Dispose ()
+ {
+ base.Dispose();
+ _stream.Dispose();
+ }
+
+ }
+}
View
216 GitSharp.Core/ByteWindow.cs
@@ -0,0 +1,216 @@
+/*
+ * Copyright (C) 2007, Robin Rosenberg <robin.rosenberg@dewire.com>
+ * Copyright (C) 2008, Shawn O. Pearce <spearce@spearce.org>
+ * Copyright (C) 2009, Henon <meinrad.recheis@gmail.com>
+ *
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or
+ * without modification, are permitted provided that the following
+ * conditions are met:
+ *
+ * - Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ *
+ * - Redistributions in binary form must reproduce the above
+ * copyright notice, this list of conditions and the following
+ * disclaimer in the documentation and/or other materials provided
+ * with the distribution.
+ *
+ * - Neither the name of the Git Development Community nor the
+ * names of its contributors may be used to endorse or promote
+ * products derived from this software without specific prior
+ * written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND
+ * CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,
+ * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
+ * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
+ * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+ * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
+ * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
+ * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
+ * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+using System;
+using ICSharpCode.SharpZipLib.Zip.Compression;
+
+namespace GitSharp.Core
+{
+ /// <summary>
+ /// A window of data currently stored within a cache.
+ /// <para />
+ /// All bytes in the window can be assumed to be "immediately available", that is
+ /// they are very likely already in memory, unless the operating system's memory
+ /// is very low and has paged part of this process out to disk. Therefore copying
+ /// bytes from a window is very inexpensive.
+ /// </summary>
+ internal abstract class ByteWindow : IDisposable
+ {
+ protected static readonly byte[] VerifyGarbageBuffer = new byte[2048];
+
+ private readonly PackFile _pack;
+ private readonly long _start;
+ private readonly long _end;
+
+ protected ByteWindow(PackFile p, long s, long n)
+ {
+ _pack = p;
+ _start = s;
+ _end = _start + n;
+ }
+
+ internal bool contains(PackFile neededFile, long neededPos)
+ {
+ return _pack == neededFile && _start <= neededPos && neededPos < _end;
+ }
+
+ /// <summary> * Copy bytes from the window to a caller supplied buffer.
+ /// </summary>
+ /// <param name="pos">offset within the file to start copying from.</param>
+ /// <param name="dstbuf">destination buffer to copy into. </param>
+ /// <param name="dstoff">
+ /// Offset within <paramref name="dstbuf"/> to start copying into.
+ /// </param>
+ /// <param name="cnt">
+ /// number of bytes to copy. This value may exceed the number of
+ /// bytes remaining in the window starting at offset
+ /// <paramref name="pos" />.
+ /// </param>
+ /// <returns>
+ /// Number of bytes actually copied; this may be less than
+ /// <paramref name="cnt" /> if <paramref name="cnt" /> exceeded the number of
+ /// bytes available. </returns>
+ internal int copy(long pos, byte[] dstbuf, int dstoff, int cnt)
+ {
+ return copy((int)(pos - _start), dstbuf, dstoff, cnt);
+ }
+
+ /// <summary>
+ /// Copy bytes from the window to a caller supplied buffer.
+ /// </summary>
+ /// <param name="pos">
+ /// offset within the window to start copying from.
+ /// </param>
+ /// <param name="dstbuf">destination buffer to copy into.</param>
+ /// <param name="dstoff">
+ /// offset within <paramref name="dstbuf"/> to start copying into.
+ /// </param>
+ /// <param name="cnt">
+ /// number of bytes to copy. This value may exceed the number of
+ /// bytes remaining in the window starting at offset
+ /// <paramref name="pos" />.
+ /// </param>
+ /// <returns>
+ /// Number of bytes actually copied; this may be less than
+ /// <paramref name="cnt" /> if <paramref name="cnt" /> exceeded
+ /// the number of bytes available.
+ /// </returns>
+ protected abstract int copy(int pos, byte[] dstbuf, int dstoff, int cnt);
+
+ /// <summary>
+ /// Pump bytes into the supplied inflater as input.
+ /// </summary>
+ /// <param name="pos">
+ /// offset within the file to start supplying input from.
+ /// </param>
+ /// <param name="dstbuf">
+ /// destination buffer the inflater should output decompressed
+ /// data to.
+ /// </param>
+ /// <param name="dstoff">
+ /// current offset within <paramref name="dstbuf"/> to inflate into.
+ /// </param>
+ /// <param name="inf">
+ /// the inflater to feed input to. The caller is responsible for
+ /// initializing the inflater as multiple windows may need to
+ /// supply data to the same inflater to completely decompress
+ /// something.
+ /// </param>
+ /// <returns>
+ /// Updated <paramref name="dstoff"/> based on the number of bytes
+ /// successfully copied into <paramref name="dstbuf"/> by
+ /// <paramref name="inf"/>. If the inflater is not yet finished then
+ /// another window's data must still be supplied as input to finish
+ /// decompression.
+ /// </returns>
+ /// <exception cref="InvalidOperationException">
+ /// the inflater encountered an invalid chunk of data. Data
+ /// stream corruption is likely.
+ /// </exception>
+ internal int Inflate(long pos, byte[] dstbuf, int dstoff, Inflater inf)
+ {
+ return Inflate((int)(pos - _start), dstbuf, dstoff, inf);
+ }
+
+ /// <summary>
+ /// Pump bytes into the supplied inflater as input.
+ /// </summary>
+ /// <param name="pos">
+ /// offset within the file to start supplying input from.
+ /// </param>
+ /// <param name="dstbuf">
+ /// destination buffer the inflater should output decompressed
+ /// data to.
+ /// </param>
+ /// <param name="dstoff">
+ /// current offset within <paramref name="dstbuf"/> to inflate into.
+ /// </param>
+ /// <param name="inf">
+ /// the inflater to feed input to. The caller is responsible for
+ /// initializing the inflater as multiple windows may need to
+ /// supply data to the same inflater to completely decompress
+ /// something.
+ /// </param>
+ /// <returns>
+ /// Updated <paramref name="dstoff"/> based on the number of bytes
+ /// successfully copied into <paramref name="dstbuf"/> by
+ /// <paramref name="inf"/>. If the inflater is not yet finished then
+ /// another window's data must still be supplied as input to finish
+ /// decompression.
+ /// </returns>
+ /// <exception cref="InvalidOperationException">
+ /// the inflater encountered an invalid chunk of data. Data
+ /// stream corruption is likely.
+ /// </exception>
+ protected abstract int Inflate(int pos, byte[] dstbuf, int dstoff, Inflater inf);
+
+ internal void inflateVerify(long pos, Inflater inf)
+ {
+ inflateVerify((int)(pos - _start), inf);
+ }
+
+ protected abstract void inflateVerify(int pos, Inflater inf);
+
+ public long End
+ {
+ get { return _end; }
+ }
+
+ public long Start
+ {
+ get { return _start; }
+ }
+
+ public PackFile Pack
+ {
+ get { return _pack; }
+ }
+
+ internal int Size
+ {
+ get { return (int)(_end - _start); }
+ }
+
+ public virtual void Dispose ()
+ {
+ _pack.Dispose();
+ }
+
+ }
+}
View
117 GitSharp.Core/CachedObjectDatabase.cs
@@ -0,0 +1,117 @@
+/*
+ * Copyright (C) 2010, JetBrains s.r.o.
+ *