public static read ( |
||
indexLocation | Location of the index file on disk. | |
Résultat |
/// <summary> /// Create a new in-core index representation and read an index from disk. /// <para /> /// The new index will be read before it is returned to the caller. Read /// failures are reported as exceptions and therefore prevent the method from /// returning a partially populated index. /// </summary> /// <param name="indexLocation">Location of the index file on disk.</param> /// <returns> a cache representing the contents of the specified index file (if /// it exists) or an empty cache if the file does not exist. /// </returns> /// <exception cref="IOException"> /// The index file is present but could not be read. /// </exception> /// <exception cref="CorruptObjectException"> /// The index file is using a format or extension that this /// library does not support. /// </exception> public static DirCache read(FileInfo indexLocation) { var c = new DirCache(indexLocation); c.read(); return(c); }
public void testCorruptChecksumAtFooter() { var dc = new DirCache(pathOf("gitgit.index.badchecksum")); try { dc.read(); Assert.Fail("Cache loaded despite corrupt checksum"); } catch (CorruptObjectException err) { Assert.AreEqual("DIRC checksum mismatch", err.Message); } }
public void testReadIndex_LsFiles() { List<CGitIndexRecord> ls = ReadLsFiles(); var dc = new DirCache(_index); Assert.AreEqual(0, dc.getEntryCount()); dc.read(); Assert.AreEqual(ls.Count, dc.getEntryCount()); int i = 0; foreach (var val in ls) { AssertAreEqual(val, dc.getEntry(i)); i++; } }
/// <summary> /// Create a new in-core index representation, lock it, and read from disk. /// <para /> /// The new index will be locked and then read before it is returned to the /// caller. Read failures are reported as exceptions and therefore prevent /// the method from returning a partially populated index. On read failure, /// the lock is released. /// </summary> /// <param name="indexLocation"> /// location of the index file on disk. /// </param> /// <returns> /// A cache representing the contents of the specified index file (if /// it exists) or an empty cache if the file does not exist. /// </returns> /// <exception cref="IOException"> /// The index file is present but could not be read, or the lock /// could not be obtained. /// </exception> /// <exception cref="CorruptObjectException"> /// the index file is using a format or extension that this /// library does not support. /// </exception> public static DirCache Lock(FileInfo indexLocation) { var c = new DirCache(indexLocation); if (!c.Lock()) { throw new IOException("Cannot lock " + indexLocation); } try { c.read(); } catch (Exception) { c.unlock(); throw; } return(c); }
public void testTreeWalk_LsFiles() { global::GitSharp.Core.Repository db = createBareRepository(); List<CGitIndexRecord> ls = ReadLsFiles(); var dc = new DirCache(_index); Assert.AreEqual(0, dc.getEntryCount()); dc.read(); Assert.AreEqual(ls.Count, dc.getEntryCount()); var rItr = ls.GetEnumerator(); var tw = new TreeWalk(db); tw.reset(); tw.Recursive = true; tw.addTree(new DirCacheIterator(dc)); while (rItr.MoveNext()) { Assert.IsTrue(tw.next()); var dcItr = tw.getTree<DirCacheIterator>(0, typeof(DirCacheIterator)); Assert.IsNotNull(dcItr); AssertAreEqual(rItr.Current, dcItr.getDirCacheEntry()); } }
public void testReadIndex_DirCacheTree() { List<CGitIndexRecord> cList = ReadLsFiles(); List<CGitLsTreeRecord> cTree = ReadLsTree(); var dc = new DirCache(_index); Assert.AreEqual(0, dc.getEntryCount()); dc.read(); Assert.AreEqual(cList.Count, dc.getEntryCount()); DirCacheTree jTree = dc.getCacheTree(false); Assert.IsNotNull(jTree); Assert.AreEqual(string.Empty, jTree.getNameString()); Assert.AreEqual(string.Empty, jTree.getPathString()); Assert.IsTrue(jTree.isValid()); Assert.AreEqual(ObjectId .FromString("698dd0b8d0c299f080559a1cffc7fe029479a408"), jTree .getObjectId()); Assert.AreEqual(cList.Count, jTree.getEntrySpan()); var subtrees = new List<CGitLsTreeRecord>(); foreach (CGitLsTreeRecord r in cTree) { if (FileMode.Tree.Equals(r.Mode)) subtrees.Add(r); } Assert.AreEqual(subtrees.Count, jTree.getChildCount()); for (int i = 0; i < jTree.getChildCount(); i++) { DirCacheTree sj = jTree.getChild(i); CGitLsTreeRecord sc = subtrees[i]; Assert.AreEqual(sc.Path, sj.getNameString()); Assert.AreEqual(sc.Path + "/", sj.getPathString()); Assert.IsTrue(sj.isValid()); Assert.AreEqual(sc.Id, sj.getObjectId()); } }
/// <summary> /// Create a new in-core index representation, lock it, and read from disk. /// <para /> /// The new index will be locked and then read before it is returned to the /// caller. Read failures are reported as exceptions and therefore prevent /// the method from returning a partially populated index. On read failure, /// the lock is released. /// </summary> /// <param name="indexLocation"> /// location of the index file on disk. /// </param> /// <returns> /// A cache representing the contents of the specified index file (if /// it exists) or an empty cache if the file does not exist. /// </returns> /// <exception cref="IOException"> /// The index file is present but could not be read, or the lock /// could not be obtained. /// </exception> /// <exception cref="CorruptObjectException"> /// the index file is using a format or extension that this /// library does not support. /// </exception> public static DirCache Lock(FileInfo indexLocation) { var c = new DirCache(indexLocation); if (!c.Lock()) { throw new IOException("Cannot lock " + indexLocation); } try { c.read(); } catch (Exception) { c.unlock(); throw; } return c; }
/// <summary> /// Create a new in-core index representation and read an index from disk. /// <para /> /// The new index will be read before it is returned to the caller. Read /// failures are reported as exceptions and therefore prevent the method from /// returning a partially populated index. /// </summary> /// <param name="indexLocation">Location of the index file on disk.</param> /// <returns> a cache representing the contents of the specified index file (if /// it exists) or an empty cache if the file does not exist. /// </returns> /// <exception cref="IOException"> /// The index file is present but could not be read. /// </exception> /// <exception cref="CorruptObjectException"> /// The index file is using a format or extension that this /// library does not support. /// </exception> public static DirCache read(FileInfo indexLocation) { var c = new DirCache(indexLocation); c.read(); return c; }
public void testUnsupportedRequiredExtension() { var dc = new DirCache(pathOf("gitgit.index.aaaa")); try { dc.read(); Assert.Fail("Cache loaded an unsupported extension"); } catch (CorruptObjectException err) { Assert.AreEqual("DIRC extension 'aaaa'" + " not supported by this version.", err.Message); } }
public void testUnsupportedOptionalExtension() { var dc = new DirCache(pathOf("gitgit.index.ZZZZ")); dc.read(); Assert.AreEqual(1, dc.getEntryCount()); Assert.AreEqual("A", dc.getEntry(0).getPathString()); }
public void testReadIndex_LsFiles() { List<CGitIndexRecord> ls = ReadLsFiles(); var dc = new DirCache(_index); Assert.AreEqual(0, dc.getEntryCount()); dc.read(); Assert.AreEqual(ls.Count, dc.getEntryCount()); var cache = new List<DirCacheEntry>(); for (int i = 0; i < dc.getEntryCount(); i++) { cache.Add(dc.getEntry(i)); } ls.Sort((x, y) => x.Path.CompareTo(y.Path)); cache.Sort((x, y) => x.getPathString().CompareTo(y.getPathString())); int j = 0; foreach (var val in ls) { AssertAreEqual(val, cache[j]); j++; } }