Пример #1
0
        /// <summary>Parse an annotated tag from its canonical format.</summary>
        /// <remarks>
        /// Parse an annotated tag from its canonical format.
        /// This method inserts the tag directly into the caller supplied revision
        /// pool, making it appear as though the tag exists in the repository, even
        /// if it doesn't. The repository under the pool is not affected.
        /// </remarks>
        /// <param name="rw">
        /// the revision pool to allocate the tag within. The tag's object
        /// pointer will be obtained from this pool.
        /// </param>
        /// <param name="raw">the canonical formatted tag to be parsed.</param>
        /// <returns>
        /// the parsed tag, in an isolated revision pool that is not
        /// available to the caller.
        /// </returns>
        /// <exception cref="NGit.Errors.CorruptObjectException">the tag contains a malformed header that cannot be handled.
        ///     </exception>
        public static NGit.Revwalk.RevTag Parse(RevWalk rw, byte[] raw)
        {
            ObjectInserter.Formatter fmt = new ObjectInserter.Formatter();
            bool retain = rw.IsRetainBody();

            rw.SetRetainBody(true);
            NGit.Revwalk.RevTag r = rw.LookupTag(fmt.IdFor(Constants.OBJ_TAG, raw));
            r.ParseCanonical(rw, raw);
            rw.SetRetainBody(retain);
            return(r);
        }
        /// <exception cref="System.Exception"></exception>
        private RevTag Create(string msg)
        {
            StringBuilder b = new StringBuilder();

            b.Append("object 9788669ad918b6fcce64af8882fc9a81cb6aba67\n");
            b.Append("type tree\n");
            b.Append("tag v1.2.3.4.5\n");
            b.Append("tagger A U. Thor <*****@*****.**> 1218123387 +0700\n");
            b.Append("\n");
            b.Append(msg);
            RevTag c;

            c = new RevTag(Id("9473095c4cb2f12aefe1db8a355fe3fafba42f67"));
            c.ParseCanonical(new RevWalk(db), Sharpen.Runtime.GetBytesForString(b.ToString(),
                                                                                "UTF-8"));
            return(c);
        }
        public virtual void TestParseAllFields()
        {
            ObjectId      treeId      = Id("9788669ad918b6fcce64af8882fc9a81cb6aba67");
            string        name        = "v1.2.3.4.5";
            string        taggerName  = "A U. Thor";
            string        taggerEmail = "*****@*****.**";
            int           taggerTime  = 1218123387;
            StringBuilder body        = new StringBuilder();

            body.Append("object ");
            body.Append(treeId.Name);
            body.Append("\n");
            body.Append("type tree\n");
            body.Append("tag ");
            body.Append(name);
            body.Append("\n");
            body.Append("tagger ");
            body.Append(taggerName);
            body.Append(" <");
            body.Append(taggerEmail);
            body.Append("> ");
            body.Append(taggerTime);
            body.Append(" +0700\n");
            body.Append("\n");
            RevWalk rw = new RevWalk(db);
            RevTag  c;

            c = new RevTag(Id("9473095c4cb2f12aefe1db8a355fe3fafba42f67"));
            NUnit.Framework.Assert.IsNull(c.GetObject());
            NUnit.Framework.Assert.IsNull(c.GetTagName());
            c.ParseCanonical(rw, Sharpen.Runtime.GetBytesForString(body.ToString(), "UTF-8"));
            NUnit.Framework.Assert.IsNotNull(c.GetObject());
            NUnit.Framework.Assert.AreEqual(treeId, c.GetObject().Id);
            NUnit.Framework.Assert.AreSame(rw.LookupTree(treeId), c.GetObject());
            NUnit.Framework.Assert.IsNotNull(c.GetTagName());
            NUnit.Framework.Assert.AreEqual(name, c.GetTagName());
            NUnit.Framework.Assert.AreEqual(string.Empty, c.GetFullMessage());
            PersonIdent cTagger = c.GetTaggerIdent();

            NUnit.Framework.Assert.IsNotNull(cTagger);
            NUnit.Framework.Assert.AreEqual(taggerName, cTagger.GetName());
            NUnit.Framework.Assert.AreEqual(taggerEmail, cTagger.GetEmailAddress());
        }
        /// <exception cref="System.Exception"></exception>
        private void TestOneType(int typeCode)
        {
            ObjectId      id = Id("9788669ad918b6fcce64af8882fc9a81cb6aba67");
            StringBuilder b  = new StringBuilder();

            b.Append("object " + id.Name + "\n");
            b.Append("type " + Constants.TypeString(typeCode) + "\n");
            b.Append("tag v1.2.3.4.5\n");
            b.Append("tagger A U. Thor <*****@*****.**> 1218123387 +0700\n");
            b.Append("\n");
            RevWalk rw = new RevWalk(db);
            RevTag  c;

            c = new RevTag(Id("9473095c4cb2f12aefe1db8a355fe3fafba42f67"));
            NUnit.Framework.Assert.IsNull(c.GetObject());
            NUnit.Framework.Assert.IsNull(c.GetTagName());
            c.ParseCanonical(rw, Sharpen.Runtime.GetBytesForString(b.ToString(), "UTF-8"));
            NUnit.Framework.Assert.IsNotNull(c.GetObject());
            NUnit.Framework.Assert.AreEqual(id, c.GetObject().Id);
            NUnit.Framework.Assert.AreSame(rw.LookupAny(id, typeCode), c.GetObject());
        }
        public virtual void TestParseOldStyleNoTagger()
        {
            ObjectId treeId  = Id("9788669ad918b6fcce64af8882fc9a81cb6aba67");
            string   name    = "v1.2.3.4.5";
            string   message = "test\n" + "\n" + "-----BEGIN PGP SIGNATURE-----\n" + "Version: GnuPG v1.4.1 (GNU/Linux)\n"
                               + "\n" + "iD8DBQBC0b9oF3Y\n" + "-----END PGP SIGNATURE------n";
            //
            //
            //
            //
            //
            //
            StringBuilder body = new StringBuilder();

            body.Append("object ");
            body.Append(treeId.Name);
            body.Append("\n");
            body.Append("type tree\n");
            body.Append("tag ");
            body.Append(name);
            body.Append("\n");
            body.Append("\n");
            body.Append(message);
            RevWalk rw = new RevWalk(db);
            RevTag  c;

            c = new RevTag(Id("9473095c4cb2f12aefe1db8a355fe3fafba42f67"));
            NUnit.Framework.Assert.IsNull(c.GetObject());
            NUnit.Framework.Assert.IsNull(c.GetTagName());
            c.ParseCanonical(rw, Sharpen.Runtime.GetBytesForString(body.ToString(), "UTF-8"));
            NUnit.Framework.Assert.IsNotNull(c.GetObject());
            NUnit.Framework.Assert.AreEqual(treeId, c.GetObject().Id);
            NUnit.Framework.Assert.AreSame(rw.LookupTree(treeId), c.GetObject());
            NUnit.Framework.Assert.IsNotNull(c.GetTagName());
            NUnit.Framework.Assert.AreEqual(name, c.GetTagName());
            NUnit.Framework.Assert.AreEqual("test", c.GetShortMessage());
            NUnit.Framework.Assert.AreEqual(message, c.GetFullMessage());
            NUnit.Framework.Assert.IsNull(c.GetTaggerIdent());
        }
        public virtual void TestParse_explicit_bad_encoded2()
        {
            ByteArrayOutputStream b = new ByteArrayOutputStream();

            b.Write(Sharpen.Runtime.GetBytesForString("object 9788669ad918b6fcce64af8882fc9a81cb6aba67\n"
                                                      , "UTF-8"));
            b.Write(Sharpen.Runtime.GetBytesForString("type tree\n", "UTF-8"));
            b.Write(Sharpen.Runtime.GetBytesForString("tag v1.2.3.4.5\n", "UTF-8"));
            b.Write(Sharpen.Runtime.GetBytesForString("tagger F\u00f6r fattare <*****@*****.**> 1218123387 +0700\n"
                                                      , "UTF-8"));
            b.Write(Sharpen.Runtime.GetBytesForString("encoding ISO-8859-1\n", "UTF-8"));
            b.Write(Sharpen.Runtime.GetBytesForString("\n", "UTF-8"));
            b.Write(Sharpen.Runtime.GetBytesForString("\u304d\u308c\u3044\n", "UTF-8"));
            b.Write(Sharpen.Runtime.GetBytesForString("\n", "UTF-8"));
            b.Write(Sharpen.Runtime.GetBytesForString("Hi\n", "UTF-8"));
            RevTag c;

            c = new RevTag(Id("9473095c4cb2f12aefe1db8a355fe3fafba42f67"));
            c.ParseCanonical(new RevWalk(db), b.ToByteArray());
            NUnit.Framework.Assert.AreEqual("F\u00f6r fattare", c.GetTaggerIdent().GetName());
            NUnit.Framework.Assert.AreEqual("\u304d\u308c\u3044", c.GetShortMessage());
            NUnit.Framework.Assert.AreEqual("\u304d\u308c\u3044\n\nHi\n", c.GetFullMessage());
        }
Пример #7
0
		/// <exception cref="System.Exception"></exception>
		private void TestOneType(int typeCode)
		{
			ObjectId id = Id("9788669ad918b6fcce64af8882fc9a81cb6aba67");
			StringBuilder b = new StringBuilder();
			b.Append("object " + id.Name + "\n");
			b.Append("type " + Constants.TypeString(typeCode) + "\n");
			b.Append("tag v1.2.3.4.5\n");
			b.Append("tagger A U. Thor <*****@*****.**> 1218123387 +0700\n");
			b.Append("\n");
			RevWalk rw = new RevWalk(db);
			RevTag c;
			c = new RevTag(Id("9473095c4cb2f12aefe1db8a355fe3fafba42f67"));
			NUnit.Framework.Assert.IsNull(c.GetObject());
			NUnit.Framework.Assert.IsNull(c.GetTagName());
			c.ParseCanonical(rw, Sharpen.Runtime.GetBytesForString(b.ToString(), "UTF-8"));
			NUnit.Framework.Assert.IsNotNull(c.GetObject());
			NUnit.Framework.Assert.AreEqual(id, c.GetObject().Id);
			NUnit.Framework.Assert.AreSame(rw.LookupAny(id, typeCode), c.GetObject());
		}
Пример #8
0
		public virtual void TestParse_explicit_bad_encoded2()
		{
			ByteArrayOutputStream b = new ByteArrayOutputStream();
			b.Write(Sharpen.Runtime.GetBytesForString("object 9788669ad918b6fcce64af8882fc9a81cb6aba67\n"
				, "UTF-8"));
			b.Write(Sharpen.Runtime.GetBytesForString("type tree\n", "UTF-8"));
			b.Write(Sharpen.Runtime.GetBytesForString("tag v1.2.3.4.5\n", "UTF-8"));
			b.Write(Sharpen.Runtime.GetBytesForString("tagger F\u00f6r fattare <*****@*****.**> 1218123387 +0700\n"
				, "UTF-8"));
			b.Write(Sharpen.Runtime.GetBytesForString("encoding ISO-8859-1\n", "UTF-8"));
			b.Write(Sharpen.Runtime.GetBytesForString("\n", "UTF-8"));
			b.Write(Sharpen.Runtime.GetBytesForString("\u304d\u308c\u3044\n", "UTF-8"));
			b.Write(Sharpen.Runtime.GetBytesForString("\n", "UTF-8"));
			b.Write(Sharpen.Runtime.GetBytesForString("Hi\n", "UTF-8"));
			RevTag c;
			c = new RevTag(Id("9473095c4cb2f12aefe1db8a355fe3fafba42f67"));
			c.ParseCanonical(new RevWalk(db), b.ToByteArray());
			NUnit.Framework.Assert.AreEqual("F\u00f6r fattare", c.GetTaggerIdent().GetName());
			NUnit.Framework.Assert.AreEqual("\u304d\u308c\u3044", c.GetShortMessage());
			NUnit.Framework.Assert.AreEqual("\u304d\u308c\u3044\n\nHi\n", c.GetFullMessage());
		}
Пример #9
0
		/// <exception cref="System.Exception"></exception>
		private RevTag Create(string msg)
		{
			StringBuilder b = new StringBuilder();
			b.Append("object 9788669ad918b6fcce64af8882fc9a81cb6aba67\n");
			b.Append("type tree\n");
			b.Append("tag v1.2.3.4.5\n");
			b.Append("tagger A U. Thor <*****@*****.**> 1218123387 +0700\n");
			b.Append("\n");
			b.Append(msg);
			RevTag c;
			c = new RevTag(Id("9473095c4cb2f12aefe1db8a355fe3fafba42f67"));
			c.ParseCanonical(new RevWalk(db), Sharpen.Runtime.GetBytesForString(b.ToString(), 
				"UTF-8"));
			return c;
		}
Пример #10
0
		public virtual void TestParseOldStyleNoTagger()
		{
			ObjectId treeId = Id("9788669ad918b6fcce64af8882fc9a81cb6aba67");
			string name = "v1.2.3.4.5";
			string message = "test\n" + "\n" + "-----BEGIN PGP SIGNATURE-----\n" + "Version: GnuPG v1.4.1 (GNU/Linux)\n"
				 + "\n" + "iD8DBQBC0b9oF3Y\n" + "-----END PGP SIGNATURE------n";
			//
			//
			//
			//
			//
			//
			StringBuilder body = new StringBuilder();
			body.Append("object ");
			body.Append(treeId.Name);
			body.Append("\n");
			body.Append("type tree\n");
			body.Append("tag ");
			body.Append(name);
			body.Append("\n");
			body.Append("\n");
			body.Append(message);
			RevWalk rw = new RevWalk(db);
			RevTag c;
			c = new RevTag(Id("9473095c4cb2f12aefe1db8a355fe3fafba42f67"));
			NUnit.Framework.Assert.IsNull(c.GetObject());
			NUnit.Framework.Assert.IsNull(c.GetTagName());
			c.ParseCanonical(rw, Sharpen.Runtime.GetBytesForString(body.ToString(), "UTF-8"));
			NUnit.Framework.Assert.IsNotNull(c.GetObject());
			NUnit.Framework.Assert.AreEqual(treeId, c.GetObject().Id);
			NUnit.Framework.Assert.AreSame(rw.LookupTree(treeId), c.GetObject());
			NUnit.Framework.Assert.IsNotNull(c.GetTagName());
			NUnit.Framework.Assert.AreEqual(name, c.GetTagName());
			NUnit.Framework.Assert.AreEqual("test", c.GetShortMessage());
			NUnit.Framework.Assert.AreEqual(message, c.GetFullMessage());
			NUnit.Framework.Assert.IsNull(c.GetTaggerIdent());
		}
Пример #11
0
		public virtual void TestParseAllFields()
		{
			ObjectId treeId = Id("9788669ad918b6fcce64af8882fc9a81cb6aba67");
			string name = "v1.2.3.4.5";
			string taggerName = "A U. Thor";
			string taggerEmail = "*****@*****.**";
			int taggerTime = 1218123387;
			StringBuilder body = new StringBuilder();
			body.Append("object ");
			body.Append(treeId.Name);
			body.Append("\n");
			body.Append("type tree\n");
			body.Append("tag ");
			body.Append(name);
			body.Append("\n");
			body.Append("tagger ");
			body.Append(taggerName);
			body.Append(" <");
			body.Append(taggerEmail);
			body.Append("> ");
			body.Append(taggerTime);
			body.Append(" +0700\n");
			body.Append("\n");
			RevWalk rw = new RevWalk(db);
			RevTag c;
			c = new RevTag(Id("9473095c4cb2f12aefe1db8a355fe3fafba42f67"));
			NUnit.Framework.Assert.IsNull(c.GetObject());
			NUnit.Framework.Assert.IsNull(c.GetTagName());
			c.ParseCanonical(rw, Sharpen.Runtime.GetBytesForString(body.ToString(), "UTF-8"));
			NUnit.Framework.Assert.IsNotNull(c.GetObject());
			NUnit.Framework.Assert.AreEqual(treeId, c.GetObject().Id);
			NUnit.Framework.Assert.AreSame(rw.LookupTree(treeId), c.GetObject());
			NUnit.Framework.Assert.IsNotNull(c.GetTagName());
			NUnit.Framework.Assert.AreEqual(name, c.GetTagName());
			NUnit.Framework.Assert.AreEqual(string.Empty, c.GetFullMessage());
			PersonIdent cTagger = c.GetTaggerIdent();
			NUnit.Framework.Assert.IsNotNull(cTagger);
			NUnit.Framework.Assert.AreEqual(taggerName, cTagger.GetName());
			NUnit.Framework.Assert.AreEqual(taggerEmail, cTagger.GetEmailAddress());
		}