Skip to content

Commit

Permalink
Refactor GetBlob
Browse files Browse the repository at this point in the history
The name didn't really match what it does. Also, remove
the Copy function to save a function call.

This is part of the work required for git-tfs#144
  • Loading branch information
sc68cal committed May 15, 2012
1 parent f8e7b1f commit 01293b3
Show file tree
Hide file tree
Showing 5 changed files with 7 additions and 12 deletions.
2 changes: 1 addition & 1 deletion GitTfs/Core/Changes/Git/Add.cs
Expand Up @@ -16,7 +16,7 @@ public Add(IGitRepository repository, GitChangeInfo changeInfo)
public void Apply(ITfsWorkspace workspace)
{
var workspaceFile = workspace.GetLocalPath(Path);
Repository.GetBlob(NewSha, workspaceFile);
Repository.CopyBlob(NewSha, workspaceFile);
workspace.Add(Path);
}
}
Expand Down
2 changes: 1 addition & 1 deletion GitTfs/Core/Changes/Git/Modify.cs
Expand Up @@ -19,7 +19,7 @@ public void Apply(ITfsWorkspace workspace)
{
workspace.Edit(Path);
var workspaceFile = workspace.GetLocalPath(Path);
_repository.GetBlob(NewSha, workspaceFile);
_repository.CopyBlob(NewSha, workspaceFile);
}
}
}
2 changes: 1 addition & 1 deletion GitTfs/Core/Changes/Git/RenameEdit.cs
Expand Up @@ -22,7 +22,7 @@ public void Apply(ITfsWorkspace workspace)
workspace.Edit(Path);
workspace.Rename(Path, PathTo, Score);
var workspaceFile = workspace.GetLocalPath(PathTo);
_repository.GetBlob(NewSha, workspaceFile);
_repository.CopyBlob(NewSha, workspaceFile);
}
}
}
11 changes: 3 additions & 8 deletions GitTfs/Core/GitRepository.cs
Expand Up @@ -404,23 +404,18 @@ public bool WorkingCopyHasUnstagedOrUncommitedChanges
}
}

public void GetBlob(string sha, string outputFile)
public void CopyBlob(string sha, string outputFile)
{
using(LibGit2Sharp.Repository repo = new LibGit2Sharp.Repository(GitDir))
{
Blob blob;
if ((blob = repo.Lookup<Blob>(sha)) != null)
using (Stream stream = blob.ContentStream)
Copy(stream, outputFile);
using (var destination = File.Create(outputFile))
stream.CopyTo(destination);
}
}

private void Copy(Stream gitstream, string file)
{
using (var destination = File.Create(file))
gitstream.CopyTo(destination);
}

public string HashAndInsertObject(string filename)
{
using (Repository repo = new Repository(GitDir))
Expand Down
2 changes: 1 addition & 1 deletion GitTfs/Core/IGitRepository.cs
Expand Up @@ -20,7 +20,7 @@ public interface IGitRepository : IGitHelpers
IEnumerable<IGitChangedFile> GetChangedFiles(string from, string to);
string GetChangeSummary(string from, string to);
bool WorkingCopyHasUnstagedOrUncommitedChanges { get; }
void GetBlob(string sha, string outputFile);
void CopyBlob(string sha, string outputFile);
GitCommit GetCommit(string commitish);
Dictionary<string, GitObject> GetObjects();
string GetCommitMessage(string head, string parentCommitish);
Expand Down

0 comments on commit 01293b3

Please sign in to comment.