コード例 #1
0
        public virtual void TestParse_explicit_bad_encoded2()
        {
            ByteArrayOutputStream b = new ByteArrayOutputStream();

            b.Write(Sharpen.Runtime.GetBytesForString("tree 9788669ad918b6fcce64af8882fc9a81cb6aba67\n"
                                                      , "UTF-8"));
            b.Write(Sharpen.Runtime.GetBytesForString("author F\u00f6r fattare <*****@*****.**> 1218123387 +0700\n"
                                                      , "UTF-8"));
            b.Write(Sharpen.Runtime.GetBytesForString("committer C O. Miter <*****@*****.**> 1218123390 -0500\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"));
            RevCommit c;

            c = new RevCommit(Id("9473095c4cb2f12aefe1db8a355fe3fafba42f67"));
            // bogus id
            c.ParseCanonical(new RevWalk(db), b.ToByteArray());
            NUnit.Framework.Assert.AreEqual("ISO-8859-1", c.Encoding.Name());
            NUnit.Framework.Assert.AreEqual("F\u00f6r fattare", c.GetAuthorIdent().GetName());
            NUnit.Framework.Assert.AreEqual("\u304d\u308c\u3044", c.GetShortMessage());
            NUnit.Framework.Assert.AreEqual("\u304d\u308c\u3044\n\nHi\n", c.GetFullMessage());
        }
コード例 #2
0
ファイル: RevCommit.cs プロジェクト: TetradogOther/NGit
        /// <summary>Parse a commit from its canonical format.</summary>
        /// <remarks>
        /// Parse a commit from its canonical format.
        /// This method inserts the commit directly into the caller supplied revision
        /// pool, making it appear as though the commit 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 commit within. The commit's
        /// tree and parent pointers will be obtained from this pool.
        /// </param>
        /// <param name="raw">the canonical formatted commit to be parsed.</param>
        /// <returns>
        /// the parsed commit, in an isolated revision pool that is not
        /// available to the caller.
        /// </returns>
        public static NGit.Revwalk.RevCommit Parse(RevWalk rw, byte[] raw)
        {
            ObjectInserter.Formatter fmt = new ObjectInserter.Formatter();
            bool retain = rw.IsRetainBody();

            rw.SetRetainBody(true);
            NGit.Revwalk.RevCommit r = rw.LookupCommit(fmt.IdFor(Constants.OBJ_COMMIT, raw));
            r.ParseCanonical(rw, raw);
            rw.SetRetainBody(retain);
            return(r);
        }
コード例 #3
0
        public virtual void TestParse_WeirdHeaderOnlyCommit()
        {
            StringBuilder b = new StringBuilder();

            b.Append("tree 9788669ad918b6fcce64af8882fc9a81cb6aba67\n");
            b.Append("author A U. Thor <*****@*****.**> 1218123387 +0700\n");
            b.Append("committer C O. Miter <*****@*****.**> 1218123390 -0500\n");
            RevCommit c;

            c = new RevCommit(Id("9473095c4cb2f12aefe1db8a355fe3fafba42f67"));
            c.ParseCanonical(new RevWalk(db), Sharpen.Runtime.GetBytesForString(b.ToString(),
                                                                                "UTF-8"));
            NUnit.Framework.Assert.AreEqual(string.Empty, c.GetFullMessage());
            NUnit.Framework.Assert.AreEqual(string.Empty, c.GetShortMessage());
        }
コード例 #4
0
        /// <exception cref="System.Exception"></exception>
        private RevCommit Create(string msg)
        {
            StringBuilder b = new StringBuilder();

            b.Append("tree 9788669ad918b6fcce64af8882fc9a81cb6aba67\n");
            b.Append("author A U. Thor <*****@*****.**> 1218123387 +0700\n");
            b.Append("committer C O. Miter <*****@*****.**> 1218123390 -0500\n");
            b.Append("\n");
            b.Append(msg);
            RevCommit c;

            c = new RevCommit(Id("9473095c4cb2f12aefe1db8a355fe3fafba42f67"));
            c.ParseCanonical(new RevWalk(db), Sharpen.Runtime.GetBytesForString(b.ToString(),
                                                                                "UTF-8"));
            return(c);
        }
コード例 #5
0
        private RevCommit Parse(string msg)
        {
            StringBuilder buf = new StringBuilder();

            buf.Append("tree " + ObjectId.ZeroId.Name + "\n");
            buf.Append("author A. U. Thor <*****@*****.**> 1 +0000\n");
            buf.Append("committer A. U. Thor <*****@*****.**> 1 +0000\n");
            buf.Append("\n");
            buf.Append(msg);
            RevWalk walk = new RevWalk(db);

            walk.SetRetainBody(true);
            RevCommit c = new RevCommit(ObjectId.ZeroId);

            c.ParseCanonical(walk, Constants.Encode(buf.ToString()));
            return(c);
        }
コード例 #6
0
        public virtual void TestParse_incompleteAuthorAndCommitter()
        {
            StringBuilder b = new StringBuilder();

            b.Append("tree 9788669ad918b6fcce64af8882fc9a81cb6aba67\n");
            b.Append("author <*****@*****.**> 1218123387 +0700\n");
            b.Append("committer <> 1218123390 -0500\n");
            RevCommit c;

            c = new RevCommit(Id("9473095c4cb2f12aefe1db8a355fe3fafba42f67"));
            c.ParseCanonical(new RevWalk(db), Sharpen.Runtime.GetBytesForString(b.ToString(),
                                                                                "UTF-8"));
            NUnit.Framework.Assert.AreEqual(new PersonIdent(string.Empty, "*****@*****.**"
                                                            , 1218123387000l, 7), c.GetAuthorIdent());
            NUnit.Framework.Assert.AreEqual(new PersonIdent(string.Empty, string.Empty, 1218123390000l
                                                            , -5), c.GetCommitterIdent());
        }
コード例 #7
0
 public virtual void TestParse_explicit_bad_encoded()
 {
     ByteArrayOutputStream b = new ByteArrayOutputStream();
     b.Write(Sharpen.Runtime.GetBytesForString("tree 9788669ad918b6fcce64af8882fc9a81cb6aba67\n"
         , "UTF-8"));
     b.Write(Sharpen.Runtime.GetBytesForString("author F\u00f6r fattare <*****@*****.**> 1218123387 +0700\n"
         , "ISO-8859-1"));
     b.Write(Sharpen.Runtime.GetBytesForString("committer C O. Miter <*****@*****.**> 1218123390 -0500\n"
         , "UTF-8"));
     b.Write(Sharpen.Runtime.GetBytesForString("encoding EUC-JP\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"));
     RevCommit c;
     c = new RevCommit(Id("9473095c4cb2f12aefe1db8a355fe3fafba42f67"));
     // bogus id
     c.ParseCanonical(new RevWalk(db), b.ToByteArray());
     NUnit.Framework.Assert.AreEqual("Japanese (EUC)", c.Encoding.EncodingName);
     NUnit.Framework.Assert.AreEqual("F\u00f6r fattare", c.GetAuthorIdent().GetName());
     NUnit.Framework.Assert.AreEqual("\u304d\u308c\u3044", c.GetShortMessage());
     NUnit.Framework.Assert.AreEqual("\u304d\u308c\u3044\n\nHi\n", c.GetFullMessage());
 }
コード例 #8
0
 /// <exception cref="System.Exception"></exception>
 private RevCommit Create(string msg)
 {
     StringBuilder b = new StringBuilder();
     b.Append("tree 9788669ad918b6fcce64af8882fc9a81cb6aba67\n");
     b.Append("author A U. Thor <*****@*****.**> 1218123387 +0700\n");
     b.Append("committer C O. Miter <*****@*****.**> 1218123390 -0500\n");
     b.Append("\n");
     b.Append(msg);
     RevCommit c;
     c = new RevCommit(Id("9473095c4cb2f12aefe1db8a355fe3fafba42f67"));
     c.ParseCanonical(new RevWalk(db), Sharpen.Runtime.GetBytesForString(b.ToString(),
         "UTF-8"));
     return c;
 }
コード例 #9
0
 public virtual void TestParse_WeirdHeaderOnlyCommit()
 {
     StringBuilder b = new StringBuilder();
     b.Append("tree 9788669ad918b6fcce64af8882fc9a81cb6aba67\n");
     b.Append("author A U. Thor <*****@*****.**> 1218123387 +0700\n");
     b.Append("committer C O. Miter <*****@*****.**> 1218123390 -0500\n");
     RevCommit c;
     c = new RevCommit(Id("9473095c4cb2f12aefe1db8a355fe3fafba42f67"));
     c.ParseCanonical(new RevWalk(db), Sharpen.Runtime.GetBytesForString(b.ToString(),
         "UTF-8"));
     NUnit.Framework.Assert.AreEqual(string.Empty, c.GetFullMessage());
     NUnit.Framework.Assert.AreEqual(string.Empty, c.GetShortMessage());
 }
コード例 #10
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());
 }
コード例 #11
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
                                                                           ).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);
        }
コード例 #12
0
ファイル: FooterLineTest.cs プロジェクト: LunarLanding/ngit
		private RevCommit Parse(string msg)
		{
			StringBuilder buf = new StringBuilder();
			buf.Append("tree " + ObjectId.ZeroId.Name + "\n");
			buf.Append("author A. U. Thor <*****@*****.**> 1 +0000\n");
			buf.Append("committer A. U. Thor <*****@*****.**> 1 +0000\n");
			buf.Append("\n");
			buf.Append(msg);
			RevWalk walk = new RevWalk(db);
			walk.SetRetainBody(true);
			RevCommit c = new RevCommit(ObjectId.ZeroId);
			c.ParseCanonical(walk, Constants.Encode(buf.ToString()));
			return c;
		}
コード例 #13
0
		public virtual void TestParse_incompleteAuthorAndCommitter()
		{
			StringBuilder b = new StringBuilder();
			b.Append("tree 9788669ad918b6fcce64af8882fc9a81cb6aba67\n");
			b.Append("author <*****@*****.**> 1218123387 +0700\n");
			b.Append("committer <> 1218123390 -0500\n");
			RevCommit c;
			c = new RevCommit(Id("9473095c4cb2f12aefe1db8a355fe3fafba42f67"));
			c.ParseCanonical(new RevWalk(db), Sharpen.Runtime.GetBytesForString(b.ToString(), 
				"UTF-8"));
			NUnit.Framework.Assert.AreEqual(new PersonIdent(string.Empty, "*****@*****.**"
				, 1218123387000l, 7), c.GetAuthorIdent());
			NUnit.Framework.Assert.AreEqual(new PersonIdent(string.Empty, string.Empty, 1218123390000l
				, -5), c.GetCommitterIdent());
		}