Esempio n. 1
0
        /// <exception cref="NGit.Errors.IncorrectObjectTypeException"></exception>
        /// <exception cref="System.IO.IOException"></exception>
        private CanonicalTreeParser ParserFor(AnyObjectId id)
        {
            CanonicalTreeParser p = new CanonicalTreeParser();

            p.Reset(reader, id);
            return(p);
        }
Esempio n. 2
0
 /// <summary>Back door to quickly create a subtree iterator for any subtree.</summary>
 /// <remarks>
 /// Back door to quickly create a subtree iterator for any subtree.
 /// <p>
 /// Don't use this unless you are ObjectWalk. The method is meant to be
 /// called only once the current entry has been identified as a tree and its
 /// identity has been converted into an ObjectId.
 /// </remarks>
 /// <param name="reader">reader to load the tree data from.</param>
 /// <param name="id">ObjectId of the tree to open.</param>
 /// <returns>a new parser that walks over the current subtree.</returns>
 /// <exception cref="System.IO.IOException">a loose object or pack file could not be read.
 ///     </exception>
 public NGit.Treewalk.CanonicalTreeParser CreateSubtreeIterator0(ObjectReader reader
                                                                 , AnyObjectId id)
 {
     NGit.Treewalk.CanonicalTreeParser p = new NGit.Treewalk.CanonicalTreeParser(this);
     p.Reset(reader, id);
     return(p);
 }
Esempio n. 3
0
 /// <summary>Reset this parser to walk through the given tree.</summary>
 /// <remarks>Reset this parser to walk through the given tree.</remarks>
 /// <param name="reader">reader to use during repository access.</param>
 /// <param name="id">
 /// identity of the tree being parsed; used only in exception
 /// messages if data corruption is found.
 /// </param>
 /// <returns>the root level parser.</returns>
 /// <exception cref="NGit.Errors.MissingObjectException">the object supplied is not available from the repository.
 ///     </exception>
 /// <exception cref="NGit.Errors.IncorrectObjectTypeException">
 /// the object supplied as an argument is not actually a tree and
 /// cannot be parsed as though it were a tree.
 /// </exception>
 /// <exception cref="System.IO.IOException">a loose object or pack file could not be read.
 ///     </exception>
 public virtual NGit.Treewalk.CanonicalTreeParser ResetRoot(ObjectReader reader, AnyObjectId
                                                            id)
 {
     NGit.Treewalk.CanonicalTreeParser p = this;
     while (p.parent != null)
     {
         p = (NGit.Treewalk.CanonicalTreeParser)p.parent;
     }
     p.Reset(reader, id);
     return(p);
 }
Esempio n. 4
0
        /// <summary>Back door to quickly create a subtree iterator for any subtree.</summary>
        /// <remarks>
        /// Back door to quickly create a subtree iterator for any subtree.
        /// <p/>
        /// Don't use this unless you are ObjectWalk. The method is meant to be
        /// called only once the current entry has been identified as a tree and its
        /// identity has been converted into an ObjectId.
        /// </remarks>
        /// <param name="reader">reader to load the tree data from.</param>
        /// <param name="id">ObjectId of the tree to open.</param>
        /// <returns>a new parser that walks over the current subtree.</returns>
        /// <exception cref="System.IO.IOException">a loose object or pack file could not be read.
        /// 	</exception>
        public NGit.Treewalk.CanonicalTreeParser CreateSubtreeIterator0(ObjectReader reader
			, AnyObjectId id)
        {
            NGit.Treewalk.CanonicalTreeParser p = new NGit.Treewalk.CanonicalTreeParser(this);
            p.Reset(reader, id);
            return p;
        }
Esempio n. 5
0
		public virtual void TestTreeIteratorWithGitmodules()
		{
			ObjectId subId = ObjectId.FromString("abcd1234abcd1234abcd1234abcd1234abcd1234");
			string path = "sub";
			Config gitmodules = new Config();
			gitmodules.SetString(ConfigConstants.CONFIG_SUBMODULE_SECTION, path, ConfigConstants
				.CONFIG_KEY_PATH, "sub");
			gitmodules.SetString(ConfigConstants.CONFIG_SUBMODULE_SECTION, path, ConfigConstants
				.CONFIG_KEY_URL, "git://example.com/sub");
			RevCommit commit = testDb.GetRevWalk().ParseCommit(testDb.Commit().NoParents().Add
				(Constants.DOT_GIT_MODULES, gitmodules.ToText()).Edit(new _PathEdit_397(subId, path
				)).Create());
			CanonicalTreeParser p = new CanonicalTreeParser();
			p.Reset(testDb.GetRevWalk().GetObjectReader(), commit.Tree);
			SubmoduleWalk gen = SubmoduleWalk.ForPath(db, p, "sub");
			NUnit.Framework.Assert.AreEqual(path, gen.GetPath());
			NUnit.Framework.Assert.AreEqual(subId, gen.GetObjectId());
			NUnit.Framework.Assert.AreEqual(new FilePath(db.WorkTree, path), gen.GetDirectory
				());
			NUnit.Framework.Assert.IsNull(gen.GetConfigUpdate());
			NUnit.Framework.Assert.IsNull(gen.GetConfigUrl());
			NUnit.Framework.Assert.AreEqual("sub", gen.GetModulesPath());
			NUnit.Framework.Assert.IsNull(gen.GetModulesUpdate());
			NUnit.Framework.Assert.AreEqual("git://example.com/sub", gen.GetModulesUrl());
			NUnit.Framework.Assert.IsNull(gen.GetRepository());
			NUnit.Framework.Assert.IsFalse(gen.Next());
		}
Esempio n. 6
0
		public static IEnumerable<DiffEntry> CompareCommits (NGit.Repository repo, AnyObjectId reference, ObjectId compared)
		{
			var diff = new MyersDiff (repo);

			var firstTree = new CanonicalTreeParser ();
			firstTree.Reset (repo.NewObjectReader (), new RevWalk (repo).ParseTree (reference));
			diff.SetNewTree (firstTree);
			
			if (compared != ObjectId.ZeroId) {
				var secondTree = new CanonicalTreeParser ();
				secondTree.Reset (repo.NewObjectReader (), new RevWalk (repo).ParseTree (compared));

				if (compared != ObjectId.ZeroId)
					diff.SetOldTree (secondTree);
			}
			return diff.Call ();
		}
Esempio n. 7
0
 /// <exception cref="System.IO.IOException"></exception>
 private AbstractTreeIterator GetTreeIterator(string name)
 {
     ObjectId id = db.Resolve(name);
     if (id == null)
     {
         throw new ArgumentException(name);
     }
     CanonicalTreeParser p = new CanonicalTreeParser();
     ObjectReader or = db.NewObjectReader();
     try
     {
         p.Reset(or, new RevWalk(db).ParseTree(id));
         return p;
     }
     finally
     {
         or.Release();
     }
 }
Esempio n. 8
0
		public override string ToString()
		{
			byte[] raw = ToByteArray();
			CanonicalTreeParser p = new CanonicalTreeParser();
			p.Reset(raw);
			StringBuilder r = new StringBuilder();
			r.Append("Tree={");
			if (!p.Eof)
			{
				r.Append('\n');
				try
				{
					new ObjectChecker().CheckTree(raw);
				}
				catch (CorruptObjectException error)
				{
					r.Append("*** ERROR: ").Append(error.Message).Append("\n");
					r.Append('\n');
				}
			}
			while (!p.Eof)
			{
				FileMode mode = p.EntryFileMode;
				r.Append(mode);
				r.Append(' ');
				r.Append(Constants.TypeString(mode.GetObjectType()));
				r.Append(' ');
				r.Append(p.EntryObjectId.Name);
				r.Append(' ');
				r.Append(p.EntryPathString);
				r.Append('\n');
				p.Next();
			}
			r.Append("}");
			return r.ToString();
		}
 public virtual void TestEmptyTree_AtEOF()
 {
     ctp.Reset(new byte[0]);
     NUnit.Framework.Assert.IsTrue(ctp.Eof);
 }
Esempio n. 10
0
		/// <summary>
		/// Set the tree used by this walk for finding
		/// <code>.gitmodules</code>
		/// .
		/// <p>
		/// The root tree is not read until the first submodule is encountered by the
		/// walk.
		/// <p>
		/// This method need only be called if constructing a walk manually instead of
		/// with one of the static factory methods above.
		/// </summary>
		/// <param name="id">ID of a tree containing .gitmodules</param>
		/// <returns>this generator</returns>
		/// <exception cref="System.IO.IOException">System.IO.IOException</exception>
		public virtual NGit.Submodule.SubmoduleWalk SetRootTree(AnyObjectId id)
		{
			CanonicalTreeParser p = new CanonicalTreeParser();
			p.Reset(walk.ObjectReader, id);
			rootTree = p;
			modulesConfig = null;
			return this;
		}