public virtual void TestParse_OnlyLFMessage()
        {
            RevTag c = Create("\n");

            NUnit.Framework.Assert.AreEqual("\n", c.GetFullMessage());
            NUnit.Framework.Assert.AreEqual(string.Empty, c.GetShortMessage());
        }
        public virtual void TestParse_ShortLineOnlyNoLF()
        {
            string shortMsg = "This is a short message.";
            RevTag c        = Create(shortMsg);

            NUnit.Framework.Assert.AreEqual(shortMsg, c.GetFullMessage());
            NUnit.Framework.Assert.AreEqual(shortMsg, c.GetShortMessage());
        }
        public virtual void TestParse_NoMessage()
        {
            string msg = string.Empty;
            RevTag c   = Create(msg);

            NUnit.Framework.Assert.AreEqual(msg, c.GetFullMessage());
            NUnit.Framework.Assert.AreEqual(msg, c.GetShortMessage());
        }
        public virtual void TestParse_ShortLineOnlyEmbeddedAndEndingLF()
        {
            string fullMsg  = "This is a\nshort message.\n";
            string shortMsg = "This is a short message.";
            RevTag c        = Create(fullMsg);

            NUnit.Framework.Assert.AreEqual(fullMsg, c.GetFullMessage());
            NUnit.Framework.Assert.AreEqual(shortMsg, c.GetShortMessage());
        }
        public virtual void TestParse_GitStyleMessage()
        {
            string shortMsg = "This fixes a bug.";
            string body     = "We do it with magic and pixie dust and stuff.\n" + "\n" + "Signed-off-by: A U. Thor <*****@*****.**>\n";
            string fullMsg  = shortMsg + "\n" + "\n" + body;
            RevTag c        = Create(fullMsg);

            NUnit.Framework.Assert.AreEqual(fullMsg, c.GetFullMessage());
            NUnit.Framework.Assert.AreEqual(shortMsg, c.GetShortMessage());
        }
		public override void SetUp()
		{
			base.SetUp();
			diskRepo = CreateBareRepository();
			refdir = (RefDirectory)diskRepo.RefDatabase;
			repo = new TestRepository<Repository>(diskRepo);
			A = repo.Commit().Create();
			B = repo.Commit(repo.GetRevWalk().ParseCommit(A));
			v1_0 = repo.Tag("v1_0", B);
			repo.GetRevWalk().ParseBody(v1_0);
		}
Exemple #7
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 TestParse_PublicParseMethod()
        {
            ObjectInserter.Formatter fmt = new ObjectInserter.Formatter();
            TagBuilder src = new TagBuilder();

            src.SetObjectId(fmt.IdFor(Constants.OBJ_TREE, new byte[] {  }), Constants.OBJ_TREE
                            );
            src.SetTagger(committer);
            src.SetTag("a.test");
            src.SetMessage("Test tag\n\nThis is a test.\n");
            RevTag p = RevTag.Parse(src.Build());

            NUnit.Framework.Assert.AreEqual(src.GetObjectId(), p.GetObject());
            NUnit.Framework.Assert.AreEqual(committer, p.GetTaggerIdent());
            NUnit.Framework.Assert.AreEqual("a.test", p.GetTagName());
            NUnit.Framework.Assert.AreEqual("Test tag", p.GetShortMessage());
            NUnit.Framework.Assert.AreEqual(src.GetMessage(), p.GetFullMessage());
        }
        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());
        }
		/// <exception cref="System.IO.IOException"></exception>
		private void AdvertiseTag(RevTag tag, string refName)
		{
			RevObject o = tag;
			do
			{
				// Fully unwrap here so later on we have these already parsed.
				RevObject target = ((RevTag)o).GetObject();
				try
				{
					walk.ParseHeaders(target);
				}
				catch (IOException)
				{
					return;
				}
				target.Add(ADVERTISED);
				o = target;
			}
			while (o is RevTag);
			AdvertiseAny(tag.GetObject(), refName);
		}
Exemple #15
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());
		}
Exemple #16
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;
		}
Exemple #17
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());
		}
Exemple #18
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());
		}
Exemple #19
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());
		}