From f72048b96418881710e75deda4aed77cd852b89e Mon Sep 17 00:00:00 2001 From: "Sean M. Collins" Date: Mon, 21 May 2012 15:27:00 -0400 Subject: [PATCH] Replace GitSharp in GitCommit and GitTreeEntry The paths returned from LibGit2Sharp are platform dependent, while the paths returned from TFS are URIs that use a forward slash. --- GitTfs/Commands/Verify.cs | 2 +- GitTfs/Core/GitCommit.cs | 16 ++++++++-------- GitTfs/Core/GitRepository.cs | 3 +-- GitTfs/Core/GitTfsRemote.cs | 2 +- GitTfs/Core/GitTreeEntry.cs | 18 ++++++++++++------ GitTfs/Core/TfsChangeset.cs | 2 +- 6 files changed, 24 insertions(+), 19 deletions(-) diff --git a/GitTfs/Commands/Verify.cs b/GitTfs/Commands/Verify.cs index a5e8abe2..0de6b7fa 100644 --- a/GitTfs/Commands/Verify.cs +++ b/GitTfs/Commands/Verify.cs @@ -63,7 +63,7 @@ namespace Sep.Git.Tfs.Commands { _stdout.WriteLine("Comparing TFS changeset " + changeset.ChangesetId + " to git commit " + changeset.GitCommit); var tfsTree = changeset.Remote.GetChangeset(changeset.ChangesetId).GetTree().ToDictionary(entry => entry.FullName.ToLowerInvariant()); - var gitTree = changeset.Remote.Repository.GetCommit(changeset.GitCommit).GetTree().ToDictionary(entry => entry.Entry.FullName.ToLowerInvariant()); + var gitTree = changeset.Remote.Repository.GetCommit(changeset.GitCommit).GetTree().ToDictionary(entry => entry.Entry.Path.ToLowerInvariant()); var all = tfsTree.Keys.Union(gitTree.Keys); var inBoth = tfsTree.Keys.Intersect(gitTree.Keys); diff --git a/GitTfs/Core/GitCommit.cs b/GitTfs/Core/GitCommit.cs index efd1485d..e2adcd83 100644 --- a/GitTfs/Core/GitCommit.cs +++ b/GitTfs/Core/GitCommit.cs @@ -1,7 +1,7 @@ using System.Collections.Generic; using System.Diagnostics; using System.Linq; -using GitSharp.Core; +using LibGit2Sharp; namespace Sep.Git.Tfs.Core { @@ -16,23 +16,23 @@ namespace Sep.Git.Tfs.Core public IEnumerable GetTree() { - var treesToDescend = new Queue(new[] {_commit.TreeEntry}); + var treesToDescend = new Queue(new[] {_commit.Tree}); while(treesToDescend.Any()) { var currentTree = treesToDescend.Dequeue(); - foreach(var entry in currentTree.Members) + foreach(var entry in currentTree) { - if(entry is Tree) + if(entry.Type == GitObjectType.Tree) { - treesToDescend.Enqueue((Tree) entry); + treesToDescend.Enqueue((Tree)entry.Target); } - else if (entry is FileTreeEntry) + else if (entry.Type == GitObjectType.Blob) { - yield return new GitTreeEntry((FileTreeEntry)entry); + yield return new GitTreeEntry(entry); } else { - Trace.WriteLine("Not including " + entry.FullName + ": type is " + entry.GetType().Name); + Trace.WriteLine("Not including " + entry.Name + ": type is " + entry.GetType().Name); } } } diff --git a/GitTfs/Core/GitRepository.cs b/GitTfs/Core/GitRepository.cs index 4d091065..cac2eb10 100644 --- a/GitTfs/Core/GitRepository.cs +++ b/GitTfs/Core/GitRepository.cs @@ -224,8 +224,7 @@ namespace Sep.Git.Tfs.Core public GitCommit GetCommit(string commitish) { - GitSharp.Core.Repository repo = new GitSharp.Core.Repository(new DirectoryInfo(GitDir)); - return _container.With(repo.MapCommit(commitish)).GetInstance(); + return new GitCommit(_repository.Lookup(commitish)); } public IEnumerable GetLastParentTfsCommits(string head) diff --git a/GitTfs/Core/GitTfsRemote.cs b/GitTfs/Core/GitTfsRemote.cs index 9539d68d..7035ded7 100644 --- a/GitTfs/Core/GitTfsRemote.cs +++ b/GitTfs/Core/GitTfsRemote.cs @@ -146,7 +146,7 @@ namespace Sep.Git.Tfs.Core if(!tfsPath.StartsWith(TfsRepositoryPath,StringComparison.InvariantCultureIgnoreCase)) return null; tfsPath = tfsPath.Substring(TfsRepositoryPath.Length); while (tfsPath.StartsWith("/")) - tfsPath = tfsPath.Substring(1); + tfsPath = tfsPath.Substring(1).Replace("/","\\"); return tfsPath; } diff --git a/GitTfs/Core/GitTreeEntry.cs b/GitTfs/Core/GitTreeEntry.cs index c8bc22a5..ae8b16b2 100644 --- a/GitTfs/Core/GitTreeEntry.cs +++ b/GitTfs/Core/GitTreeEntry.cs @@ -1,13 +1,14 @@ -using System.IO; -using GitSharp.Core; +using System; +using System.IO; +using LibGit2Sharp; namespace Sep.Git.Tfs.Core { public class GitTreeEntry : ITreeEntry { - private readonly FileTreeEntry _entry; + private readonly TreeEntry _entry; - public GitTreeEntry(FileTreeEntry entry) + public GitTreeEntry(TreeEntry entry) { _entry = entry; } @@ -16,12 +17,17 @@ namespace Sep.Git.Tfs.Core public string FullName { - get { return _entry.FullName; } + get { return _entry.Path; } } public Stream OpenRead() { - return new MemoryStream(_entry.OpenReader().CachedBytes); + if (_entry.Type == GitObjectType.Blob) + { + return ((Blob)_entry.Target).ContentStream; + } + else + throw new InvalidOperationException("Invalid object type"); } } } \ No newline at end of file diff --git a/GitTfs/Core/TfsChangeset.cs b/GitTfs/Core/TfsChangeset.cs index 4023fb5d..50d14409 100644 --- a/GitTfs/Core/TfsChangeset.cs +++ b/GitTfs/Core/TfsChangeset.cs @@ -168,7 +168,7 @@ namespace Sep.Git.Tfs.Core { if(item.DeletionId == 0) { - // Download the content directly into the index as a blob: + // Download the content directly into the git database as a blob: using (var temp = item.DownloadFile()) { index.Update(Mode.NewFile, pathInGitRepo, temp);