Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
From 68e1b50e28bf780f68424ac36602c3de9fdf51e7 Mon Sep 17 00:00:00 2001
From: Daniel Schierbeck <daniel.schierbeck@gmail.com>
Date: Sat, 17 Oct 2009 17:01:28 +0200
Subject: [PATCH] Changed type of Core.GitIndex.Members to a list
Using an array gave weird exceptions on Mono 2.0.
---
Core/GitIndex.cs | 4 ++--
Core/IndexTreeWalker.cs | 7 ++++---
Tests/T0007_Index.cs | 27 ++++++++++++++-------------
3 files changed, 20 insertions(+), 18 deletions(-)
diff --git a/Core/GitIndex.cs b/Core/GitIndex.cs
index 07dde8c..7ea36a0 100644
--- a/Core/GitIndex.cs
+++ b/Core/GitIndex.cs
@@ -123,9 +123,9 @@ namespace GitSharp.Core
/// <returns>
/// The index entries sorted
/// </returns>
- public Entry[] Members
+ public List<Entry> Members
{
- get { return _entries.Values.ToArray(); }
+ get { return _entries.Values.ToList(); }
}
/// <summary>
diff --git a/Core/IndexTreeWalker.cs b/Core/IndexTreeWalker.cs
index 672ca49..8becac0 100644
--- a/Core/IndexTreeWalker.cs
+++ b/Core/IndexTreeWalker.cs
@@ -40,13 +40,14 @@
using System.Diagnostics;
using System.IO;
+using System.Collections.Generic;
namespace GitSharp.Core
{
public class IndexTreeWalker
{
// Fields
- private readonly GitIndex.Entry[] _indexMembers;
+ private readonly List<GitIndex.Entry> _indexMembers;
private readonly Tree _mainTree;
private readonly Tree _newTree;
private readonly FileSystemInfo _root;
@@ -236,7 +237,7 @@ namespace GitSharp.Core
TreeEntry m = mi.hasNext() ? mi.next() : null;
TreeEntry a = ai.hasNext() ? ai.next() : null;
int curIndexPos = IndexCounter;
- GitIndex.Entry entry = (IndexCounter < _indexMembers.Length) ? _indexMembers[IndexCounter++] : null;
+ GitIndex.Entry entry = (IndexCounter < _indexMembers.Count) ? _indexMembers[IndexCounter++] : null;
while (((m != null) || (a != null)) || (entry != null))
{
int cmpma = Compare(m, a);
@@ -267,7 +268,7 @@ namespace GitSharp.Core
if (pi != null)
{
- entry = (IndexCounter < _indexMembers.Length) ? _indexMembers[IndexCounter++] : null;
+ entry = (IndexCounter < _indexMembers.Count) ? _indexMembers[IndexCounter++] : null;
}
}
}
diff --git a/Tests/T0007_Index.cs b/Tests/T0007_Index.cs
index dc77ab7..14ed205 100644
--- a/Tests/T0007_Index.cs
+++ b/Tests/T0007_Index.cs
@@ -39,6 +39,7 @@
using System;
using System.Diagnostics;
using System.IO;
+using System.Collections.Generic;
using GitSharp.Core;
using GitSharp.Core.Exceptions;
using GitSharp.Core.Util;
@@ -122,7 +123,7 @@ namespace GitSharp.Tests
var indexr = new GitIndex(db);
indexr.Read();
- Assert.AreEqual(0, indexr.Members.Length);
+ Assert.AreEqual(0, indexr.Members.Count);
}
[Test]
@@ -130,7 +131,7 @@ namespace GitSharp.Tests
{
var index = new GitIndex(db);
index.Read();
- Assert.AreEqual(0, index.Members.Length);
+ Assert.AreEqual(0, index.Members.Count);
}
[Test]
@@ -228,21 +229,21 @@ namespace GitSharp.Tests
var index2 = new GitIndex(db);
index2.ReadTree(db.MapTree(ObjectId.FromString("0036d433dc4f10ec47b61abc3ec5033c78d34f84")));
- GitIndex.Entry[] members = index2.Members;
- Assert.AreEqual(3, members.Length);
+ List<GitIndex.Entry> members = index2.Members;
+ Assert.AreEqual(3, members.Count);
Assert.AreEqual("a.b", members[0].Name);
Assert.AreEqual("a/b", members[1].Name);
Assert.AreEqual("a@b", members[2].Name);
- Assert.AreEqual(3, members.Length);
+ Assert.AreEqual(3, members.Count);
var indexr = new GitIndex(db);
indexr.Read();
- GitIndex.Entry[] membersr = indexr.Members;
- Assert.AreEqual(3, membersr.Length);
+ List<GitIndex.Entry> membersr = indexr.Members;
+ Assert.AreEqual(3, membersr.Count);
Assert.AreEqual("a.b", membersr[0].Name);
Assert.AreEqual("a/b", membersr[1].Name);
Assert.AreEqual("a@b", membersr[2].Name);
- Assert.AreEqual(3, membersr.Length);
+ Assert.AreEqual(3, membersr.Count);
if (CanRunGitStatus)
{
@@ -274,8 +275,8 @@ namespace GitSharp.Tests
var index2 = new GitIndex(db);
index2.ReadTree(db.MapTree(ObjectId.FromString("5e0bf0aad57706894c15fdf0681c9bc7343274fc")));
- GitIndex.Entry[] members = index2.Members;
- Assert.AreEqual(6, members.Length);
+ List<GitIndex.Entry> members = index2.Members;
+ Assert.AreEqual(6, members.Count);
Assert.AreEqual("a.b", members[0].Name);
Assert.AreEqual("a/a/a/a", members[1].Name);
Assert.AreEqual("a/b", members[2].Name);
@@ -286,8 +287,8 @@ namespace GitSharp.Tests
// reread and test
var indexr = new GitIndex(db);
indexr.Read();
- GitIndex.Entry[] membersr = indexr.Members;
- Assert.AreEqual(6, membersr.Length);
+ List<GitIndex.Entry> membersr = indexr.Members;
+ Assert.AreEqual(6, membersr.Count);
Assert.AreEqual("a.b", membersr[0].Name);
Assert.AreEqual("a/a/a/a", membersr[1].Name);
Assert.AreEqual("a/b", membersr[2].Name);
@@ -343,7 +344,7 @@ namespace GitSharp.Tests
Delete(Directory.GetParent(aslashb.FullName));
var index2 = new GitIndex(db);
- Assert.AreEqual(0, index2.Members.Length);
+ Assert.AreEqual(0, index2.Members.Count);
index2.ReadTree(db.MapTree(ObjectId.FromString("0036d433dc4f10ec47b61abc3ec5033c78d34f84")));
--
1.6.0.4
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment