Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/mono/libgit2sharp.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authornulltoken <emeric.fermas@gmail.com>2012-02-04 23:43:42 +0400
committernulltoken <emeric.fermas@gmail.com>2012-02-04 23:43:42 +0400
commit3a50ef84727690b6b92494efca7e252629c0e85c (patch)
tree66ac7c3c3c937017c0043edb151f6cf37107b626 /LibGit2Sharp
parentacd62ff7c8c19702621635d05db7f2c8007e49b4 (diff)
When unstaging, delegate the reset of the index from the HEAD to libgit2
Diffstat (limited to 'LibGit2Sharp')
-rw-r--r--LibGit2Sharp/Core/NativeMethods.cs7
-rw-r--r--LibGit2Sharp/Index.cs40
-rwxr-xr-xLibGit2Sharp/TreeEntry.cs2
3 files changed, 21 insertions, 28 deletions
diff --git a/LibGit2Sharp/Core/NativeMethods.cs b/LibGit2Sharp/Core/NativeMethods.cs
index 8b6173b3..4c9b4c5f 100644
--- a/LibGit2Sharp/Core/NativeMethods.cs
+++ b/LibGit2Sharp/Core/NativeMethods.cs
@@ -160,6 +160,11 @@ namespace LibGit2Sharp.Core
int stage = 0);
[DllImport(libgit2)]
+ public static extern int git_index_add2(
+ IndexSafeHandle index,
+ GitIndexEntry entry);
+
+ [DllImport(libgit2)]
public static extern uint git_index_entrycount(IndexSafeHandle index);
[DllImport(libgit2)]
@@ -415,7 +420,7 @@ namespace LibGit2Sharp.Core
public static extern int git_tree_entry_2object(out IntPtr obj, RepositorySafeHandle repo, IntPtr entry);
[DllImport(libgit2)]
- public static extern int git_tree_entry_attributes(IntPtr entry);
+ public static extern uint git_tree_entry_attributes(IntPtr entry);
[DllImport(libgit2)]
public static extern IntPtr git_tree_entry_byindex(IntPtr tree, uint idx);
diff --git a/LibGit2Sharp/Index.cs b/LibGit2Sharp/Index.cs
index 58364edb..02f378af 100644
--- a/LibGit2Sharp/Index.cs
+++ b/LibGit2Sharp/Index.cs
@@ -17,6 +17,8 @@ namespace LibGit2Sharp
private readonly IndexSafeHandle handle;
private readonly Repository repo;
+ private static readonly Utf8Marshaler utf8Marshaler = new Utf8Marshaler();
+
internal Index(Repository repo)
{
this.repo = repo;
@@ -219,10 +221,7 @@ namespace LibGit2Sharp
RemoveFromIndex(kvp.Key);
}
- bool doesExistInWorkingDirectory =
- !(kvp.Value.Has(FileStatus.Removed) || kvp.Value.Has(FileStatus.Nonexistent) ||
- kvp.Value.Has(FileStatus.Missing));
- RestorePotentialPreviousVersionOfHeadIntoIndex(kvp.Key, doesExistInWorkingDirectory);
+ RestorePotentialPreviousVersionOfHeadIntoIndex(kvp.Key);
}
UpdatePhysicalIndex();
@@ -435,34 +434,23 @@ namespace LibGit2Sharp
Ensure.Success(res);
}
- private void RestorePotentialPreviousVersionOfHeadIntoIndex(string relativePath,
- bool doesExistInWorkingDirectory)
+ private void RestorePotentialPreviousVersionOfHeadIntoIndex(string relativePath)
{
- // TODO: Warning! Hack. Should be moved down to libgit2 (git reset HEAD filename)
- TreeEntry entry = repo.Head[relativePath];
- if (entry == null || entry.Type != GitObjectType.Blob)
+ TreeEntry treeEntry = repo.Head[relativePath];
+ if (treeEntry == null || treeEntry.Type != GitObjectType.Blob)
{
return;
}
- string filename = Path.Combine(repo.Info.WorkingDirectory, relativePath);
-
- string randomFileName = null;
- if (doesExistInWorkingDirectory)
- {
- randomFileName = Path.GetRandomFileName();
- File.Move(filename, Path.Combine(repo.Info.WorkingDirectory, randomFileName));
- }
-
- File.WriteAllBytes(filename, ((Blob)(entry.Target)).Content);
- AddToIndex(relativePath);
-
- File.Delete(filename);
+ var indexEntry = new GitIndexEntry
+ {
+ Mode = treeEntry.Attributes,
+ oid = treeEntry.Target.Id.Oid,
+ Path = utf8Marshaler.MarshalManagedToNative(relativePath),
+ };
- if (doesExistInWorkingDirectory)
- {
- File.Move(Path.Combine(repo.Info.WorkingDirectory, randomFileName), filename);
- }
+ NativeMethods.git_index_add2(handle, indexEntry);
+ utf8Marshaler.CleanUpNativeData(indexEntry.Path);
}
private void UpdatePhysicalIndex()
diff --git a/LibGit2Sharp/TreeEntry.cs b/LibGit2Sharp/TreeEntry.cs
index 3fc488c0..a51a9c8a 100755
--- a/LibGit2Sharp/TreeEntry.cs
+++ b/LibGit2Sharp/TreeEntry.cs
@@ -34,7 +34,7 @@ namespace LibGit2Sharp
/// <summary>
/// Gets the UNIX file attributes.
/// </summary>
- public int Attributes { get; private set; }
+ public uint Attributes { get; private set; }
/// <summary>
/// Gets the filename.