Ejemplo n.º 1
0
        private RevTree ParseTree(Repository repo, ObjectId id)
        {
            RevWalk rw = new RevWalk(repo);

            RevTree tree;

            try
            {
                tree = rw.LookupTree(id);
            }
            finally
            {
                rw.Release();
            }
            return(tree);
        }
        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());
        }
        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());
        }
Ejemplo n.º 4
0
        private RevTree ParseTree(Repository repo, ObjectId id)
        {
            RevWalk rw = new RevWalk(repo);

            RevTree tree;
            try
            {
                tree = rw.LookupTree(id);
            }
            finally
            {
                rw.Release();
            }
            return tree;
        }
Ejemplo n.º 5
0
        internal virtual void ParseCanonical(RevWalk walk, byte[] raw)
        {
            MutableObjectId idBuffer = walk.idBuffer;

            idBuffer.FromString(raw, 5);
            tree = walk.LookupTree(idBuffer);
            int ptr = 46;

            if (parents == null)
            {
                NGit.Revwalk.RevCommit[] pList = new NGit.Revwalk.RevCommit[1];
                int nParents = 0;
                for (; ;)
                {
                    if (raw[ptr] != 'p')
                    {
                        break;
                    }
                    idBuffer.FromString(raw, ptr + 7);
                    NGit.Revwalk.RevCommit p = walk.LookupCommit(idBuffer);
                    if (nParents == 0)
                    {
                        pList[nParents++] = p;
                    }
                    else
                    {
                        if (nParents == 1)
                        {
                            pList    = new NGit.Revwalk.RevCommit[] { pList[0], p };
                            nParents = 2;
                        }
                        else
                        {
                            if (pList.Length <= nParents)
                            {
                                NGit.Revwalk.RevCommit[] old = pList;
                                pList = new NGit.Revwalk.RevCommit[pList.Length + 32];
                                System.Array.Copy(old, 0, pList, 0, nParents);
                            }
                            pList[nParents++] = p;
                        }
                    }
                    ptr += 48;
                }
                if (nParents != pList.Length)
                {
                    NGit.Revwalk.RevCommit[] old = pList;
                    pList = new NGit.Revwalk.RevCommit[nParents];
                    System.Array.Copy(old, 0, pList, 0, nParents);
                }
                parents = pList;
            }
            // extract time from "committer "
            ptr = RawParseUtils.Committer(raw, ptr);
            if (ptr > 0)
            {
                ptr = RawParseUtils.NextLF(raw, ptr, '>');
                // In 2038 commitTime will overflow unless it is changed to long.
                commitTime = RawParseUtils.ParseBase10(raw, ptr, null);
            }
            if (walk.IsRetainBody())
            {
                buffer = raw;
            }
            flags |= PARSED;
        }
Ejemplo n.º 6
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());
		}
Ejemplo n.º 7
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());
		}
Ejemplo n.º 8
0
		internal virtual void ParseCanonical(RevWalk walk, byte[] raw)
		{
			MutableObjectId idBuffer = walk.idBuffer;
			idBuffer.FromString(raw, 5);
			tree = walk.LookupTree(idBuffer);
			int ptr = 46;
			if (parents == null)
			{
				NGit.Revwalk.RevCommit[] pList = new NGit.Revwalk.RevCommit[1];
				int nParents = 0;
				for (; ; )
				{
					if (raw[ptr] != 'p')
					{
						break;
					}
					idBuffer.FromString(raw, ptr + 7);
					NGit.Revwalk.RevCommit p = walk.LookupCommit(idBuffer);
					if (nParents == 0)
					{
						pList[nParents++] = p;
					}
					else
					{
						if (nParents == 1)
						{
							pList = new NGit.Revwalk.RevCommit[] { pList[0], p };
							nParents = 2;
						}
						else
						{
							if (pList.Length <= nParents)
							{
								NGit.Revwalk.RevCommit[] old = pList;
								pList = new NGit.Revwalk.RevCommit[pList.Length + 32];
								System.Array.Copy(old, 0, pList, 0, nParents);
							}
							pList[nParents++] = p;
						}
					}
					ptr += 48;
				}
				if (nParents != pList.Length)
				{
					NGit.Revwalk.RevCommit[] old = pList;
					pList = new NGit.Revwalk.RevCommit[nParents];
					System.Array.Copy(old, 0, pList, 0, nParents);
				}
				parents = pList;
			}
			// extract time from "committer "
			ptr = RawParseUtils.Committer(raw, ptr);
			if (ptr > 0)
			{
				ptr = RawParseUtils.NextLF(raw, ptr, '>');
				// In 2038 commitTime will overflow unless it is changed to long.
				commitTime = RawParseUtils.ParseBase10(raw, ptr, null);
			}
			if (walk.IsRetainBody())
			{
				buffer = raw;
			}
			flags |= PARSED;
		}
Ejemplo n.º 9
0
 public virtual void TestParse_NoParents()
 {
     ObjectId treeId = Id("9788669ad918b6fcce64af8882fc9a81cb6aba67");
     string authorName = "A U. Thor";
     string authorEmail = "*****@*****.**";
     int authorTime = 1218123387;
     string authorTimeZone = "+0700";
     string committerName = "C O. Miter";
     string committerEmail = "*****@*****.**";
     int committerTime = 1218123390;
     string committerTimeZone = "-0500";
     StringBuilder body = new StringBuilder();
     body.Append("tree ");
     body.Append(treeId.Name);
     body.Append("\n");
     body.Append("author ");
     body.Append(authorName);
     body.Append(" <");
     body.Append(authorEmail);
     body.Append("> ");
     body.Append(authorTime);
     body.Append(" ");
     body.Append(authorTimeZone);
     body.Append(" \n");
     body.Append("committer ");
     body.Append(committerName);
     body.Append(" <");
     body.Append(committerEmail);
     body.Append("> ");
     body.Append(committerTime);
     body.Append(" ");
     body.Append(committerTimeZone);
     body.Append("\n");
     body.Append("\n");
     RevWalk rw = new RevWalk(db);
     RevCommit c;
     c = new RevCommit(Id("9473095c4cb2f12aefe1db8a355fe3fafba42f67"));
     NUnit.Framework.Assert.IsNull(c.Tree);
     NUnit.Framework.Assert.IsNull(c.parents);
     c.ParseCanonical(rw, Sharpen.Runtime.GetBytesForString(body.ToString(), "UTF-8"));
     NUnit.Framework.Assert.IsNotNull(c.Tree);
     NUnit.Framework.Assert.AreEqual(treeId, c.Tree.Id);
     NUnit.Framework.Assert.AreSame(rw.LookupTree(treeId), c.Tree);
     NUnit.Framework.Assert.IsNotNull(c.parents);
     NUnit.Framework.Assert.AreEqual(0, c.parents.Length);
     NUnit.Framework.Assert.AreEqual(string.Empty, c.GetFullMessage());
     PersonIdent cAuthor = c.GetAuthorIdent();
     NUnit.Framework.Assert.IsNotNull(cAuthor);
     NUnit.Framework.Assert.AreEqual(authorName, cAuthor.GetName());
     NUnit.Framework.Assert.AreEqual(authorEmail, cAuthor.GetEmailAddress());
     NUnit.Framework.Assert.AreEqual((long)authorTime * 1000, cAuthor.GetWhen().GetTime
         ());
     NUnit.Framework.Assert.AreEqual(Sharpen.Extensions.GetTimeZone("GMT" + authorTimeZone
         ), cAuthor.GetTimeZone());
     PersonIdent cCommitter = c.GetCommitterIdent();
     NUnit.Framework.Assert.IsNotNull(cCommitter);
     NUnit.Framework.Assert.AreEqual(committerName, cCommitter.GetName());
     NUnit.Framework.Assert.AreEqual(committerEmail, cCommitter.GetEmailAddress());
     NUnit.Framework.Assert.AreEqual((long)committerTime * 1000, cCommitter.GetWhen().
         GetTime());
     NUnit.Framework.Assert.AreEqual(Sharpen.Extensions.GetTimeZone("GMT" + committerTimeZone
         ), cCommitter.GetTimeZone());
 }
        public virtual void TestParse_NoParents()
        {
            ObjectId      treeId            = Id("9788669ad918b6fcce64af8882fc9a81cb6aba67");
            string        authorName        = "A U. Thor";
            string        authorEmail       = "*****@*****.**";
            int           authorTime        = 1218123387;
            string        authorTimeZone    = "+0700";
            string        committerName     = "C O. Miter";
            string        committerEmail    = "*****@*****.**";
            int           committerTime     = 1218123390;
            string        committerTimeZone = "-0500";
            StringBuilder body = new StringBuilder();

            body.Append("tree ");
            body.Append(treeId.Name);
            body.Append("\n");
            body.Append("author ");
            body.Append(authorName);
            body.Append(" <");
            body.Append(authorEmail);
            body.Append("> ");
            body.Append(authorTime);
            body.Append(" ");
            body.Append(authorTimeZone);
            body.Append(" \n");
            body.Append("committer ");
            body.Append(committerName);
            body.Append(" <");
            body.Append(committerEmail);
            body.Append("> ");
            body.Append(committerTime);
            body.Append(" ");
            body.Append(committerTimeZone);
            body.Append("\n");
            body.Append("\n");
            RevWalk   rw = new RevWalk(db);
            RevCommit c;

            c = new RevCommit(Id("9473095c4cb2f12aefe1db8a355fe3fafba42f67"));
            NUnit.Framework.Assert.IsNull(c.Tree);
            NUnit.Framework.Assert.IsNull(c.parents);
            c.ParseCanonical(rw, Sharpen.Runtime.GetBytesForString(body.ToString(), "UTF-8"));
            NUnit.Framework.Assert.IsNotNull(c.Tree);
            NUnit.Framework.Assert.AreEqual(treeId, c.Tree.Id);
            NUnit.Framework.Assert.AreSame(rw.LookupTree(treeId), c.Tree);
            NUnit.Framework.Assert.IsNotNull(c.parents);
            NUnit.Framework.Assert.AreEqual(0, c.parents.Length);
            NUnit.Framework.Assert.AreEqual(string.Empty, c.GetFullMessage());
            PersonIdent cAuthor = c.GetAuthorIdent();

            NUnit.Framework.Assert.IsNotNull(cAuthor);
            NUnit.Framework.Assert.AreEqual(authorName, cAuthor.GetName());
            NUnit.Framework.Assert.AreEqual(authorEmail, cAuthor.GetEmailAddress());
            NUnit.Framework.Assert.AreEqual((long)authorTime * 1000, cAuthor.GetWhen().GetTime
                                                ());
            NUnit.Framework.Assert.AreEqual(Sharpen.Extensions.GetTimeZone("GMT" + authorTimeZone
                                                                           ).BaseUtcOffset, cAuthor.GetTimeZone().BaseUtcOffset);
            PersonIdent cCommitter = c.GetCommitterIdent();

            NUnit.Framework.Assert.IsNotNull(cCommitter);
            NUnit.Framework.Assert.AreEqual(committerName, cCommitter.GetName());
            NUnit.Framework.Assert.AreEqual(committerEmail, cCommitter.GetEmailAddress());
            NUnit.Framework.Assert.AreEqual((long)committerTime * 1000, cCommitter.GetWhen().
                                            GetTime());
            NUnit.Framework.Assert.AreEqual(Sharpen.Extensions.GetTimeZone("GMT" + committerTimeZone
                                                                           ).BaseUtcOffset, cCommitter.GetTimeZone().BaseUtcOffset);
        }