/// <summary>
            /// Check if an entry's content is different from the cache,
            /// File status information is used and status is same we
            /// consider the file identical to the state in the working
            /// directory.
            /// </summary>
            /// <remarks>
            /// Check if an entry's content is different from the cache,
            /// File status information is used and status is same we
            /// consider the file identical to the state in the working
            /// directory. Native git uses more stat fields than we
            /// have accessible in Java.
            /// </remarks>
            /// <param name="wd">working directory to compare content with</param>
            /// <param name="forceContentCheck">
            /// True if the actual file content
            /// should be checked if modification time differs.
            /// </param>
            /// <returns>true if content is most likely different.</returns>
            public virtual bool IsModified(FilePath wd, bool forceContentCheck)
            {
                if (this.IsAssumedValid())
                {
                    return(false);
                }
                if (this.IsUpdateNeeded())
                {
                    return(true);
                }
                FilePath file   = this.GetFile(wd);
                long     length = file.Length();

                if (length == 0)
                {
                    if (!file.Exists())
                    {
                        return(true);
                    }
                }
                if (length != this.size)
                {
                    return(true);
                }
                // JDK1.6 has file.canExecute
                // if (file.canExecute() != FileMode.EXECUTABLE_FILE.equals(mode))
                // return true;
                int exebits = FileMode.EXECUTABLE_FILE.GetBits() ^ FileMode.REGULAR_FILE.GetBits(
                    );

                if (this._enclosing.Config_filemode() && FileMode.EXECUTABLE_FILE.Equals(this.mode
                                                                                         ))
                {
                    if (!this._enclosing.File_canExecute(file) && this._enclosing.File_hasExecute())
                    {
                        return(true);
                    }
                }
                else
                {
                    if (FileMode.REGULAR_FILE.Equals(this.mode & ~exebits))
                    {
                        if (!file.IsFile())
                        {
                            return(true);
                        }
                        if (this._enclosing.Config_filemode() && this._enclosing.File_canExecute(file) &&
                            this._enclosing.File_hasExecute())
                        {
                            return(true);
                        }
                    }
                    else
                    {
                        if (FileMode.SYMLINK.Equals(this.mode))
                        {
                            return(true);
                        }
                        else
                        {
                            if (FileMode.TREE.Equals(this.mode))
                            {
                                if (!file.IsDirectory())
                                {
                                    return(true);
                                }
                            }
                            else
                            {
                                System.Console.Out.WriteLine(MessageFormat.Format(JGitText.Get().doesNotHandleMode
                                                                                  , this.mode, file));
                                return(true);
                            }
                        }
                    }
                }
                // Git under windows only stores seconds so we round the timestamp
                // Java gives us if it looks like the timestamp in index is seconds
                // only. Otherwise we compare the timestamp at millisecond prevision.
                long javamtime = this.mtime / 1000000L;
                long lastm     = file.LastModified();

                if (javamtime % 1000 == 0)
                {
                    lastm = lastm - lastm % 1000;
                }
                if (lastm != javamtime)
                {
                    if (!forceContentCheck)
                    {
                        return(true);
                    }
                    try
                    {
                        InputStream @is = new FileInputStream(file);
                        try
                        {
                            ObjectId newId = new ObjectInserter.Formatter().IdFor(Constants.OBJ_BLOB, file.Length
                                                                                      (), @is);
                            return(!newId.Equals(this.sha1));
                        }
                        catch (IOException e)
                        {
                            Sharpen.Runtime.PrintStackTrace(e);
                        }
                        finally
                        {
                            try
                            {
                                @is.Close();
                            }
                            catch (IOException e)
                            {
                                // can't happen, but if it does we ignore it
                                Sharpen.Runtime.PrintStackTrace(e);
                            }
                        }
                    }
                    catch (FileNotFoundException e)
                    {
                        // should not happen because we already checked this
                        Sharpen.Runtime.PrintStackTrace(e);
                        throw new Error(e);
                    }
                }
                return(false);
            }
Exemple #2
0
 public virtual void Test025_computeSha1NoStore()
 {
     byte[] data = Sharpen.Runtime.GetBytesForString("test025 some data, more than 16 bytes to get good coverage"
         , "ISO-8859-1");
     ObjectId id = new ObjectInserter.Formatter().IdFor(Constants.OBJ_BLOB, data);
     NUnit.Framework.Assert.AreEqual("4f561df5ecf0dfbd53a0dc0f37262fef075d9dde", id.Name
         );
 }
Exemple #3
0
 public virtual void TestDelta_SmallObjectChain()
 {
     ObjectInserter.Formatter fmt = new ObjectInserter.Formatter();
     byte[] data0 = new byte[512];
     Arrays.Fill(data0, unchecked((byte)unchecked((int)(0xf3))));
     ObjectId id0 = fmt.IdFor(Constants.OBJ_BLOB, data0);
     TemporaryBuffer.Heap pack = new TemporaryBuffer.Heap(64 * 1024);
     PackHeader(pack, 4);
     ObjectHeader(pack, Constants.OBJ_BLOB, data0.Length);
     Deflate(pack, data0);
     byte[] data1 = Clone(unchecked((int)(0x01)), data0);
     byte[] delta1 = Delta(data0, data1);
     ObjectId id1 = fmt.IdFor(Constants.OBJ_BLOB, data1);
     ObjectHeader(pack, Constants.OBJ_REF_DELTA, delta1.Length);
     id0.CopyRawTo(pack);
     Deflate(pack, delta1);
     byte[] data2 = Clone(unchecked((int)(0x02)), data1);
     byte[] delta2 = Delta(data1, data2);
     ObjectId id2 = fmt.IdFor(Constants.OBJ_BLOB, data2);
     ObjectHeader(pack, Constants.OBJ_REF_DELTA, delta2.Length);
     id1.CopyRawTo(pack);
     Deflate(pack, delta2);
     byte[] data3 = Clone(unchecked((int)(0x03)), data2);
     byte[] delta3 = Delta(data2, data3);
     ObjectId id3 = fmt.IdFor(Constants.OBJ_BLOB, data3);
     ObjectHeader(pack, Constants.OBJ_REF_DELTA, delta3.Length);
     id2.CopyRawTo(pack);
     Deflate(pack, delta3);
     Digest(pack);
     PackParser ip = Index(pack.ToByteArray());
     ip.SetAllowThin(true);
     ip.Parse(NullProgressMonitor.INSTANCE);
     NUnit.Framework.Assert.IsTrue(wc.Has(id3), "has blob");
     ObjectLoader ol = wc.Open(id3);
     NUnit.Framework.Assert.IsNotNull(ol, "created loader");
     NUnit.Framework.Assert.AreEqual(Constants.OBJ_BLOB, ol.GetType());
     NUnit.Framework.Assert.AreEqual(data3.Length, ol.GetSize());
     NUnit.Framework.Assert.IsFalse(ol.IsLarge(), "is large");
     NUnit.Framework.Assert.IsNotNull(ol.GetCachedBytes());
     NUnit.Framework.Assert.IsTrue(Arrays.Equals(data3, ol.GetCachedBytes()));
     ObjectStream @in = ol.OpenStream();
     NUnit.Framework.Assert.IsNotNull(@in, "have stream");
     NUnit.Framework.Assert.AreEqual(Constants.OBJ_BLOB, @in.GetType());
     NUnit.Framework.Assert.AreEqual(data3.Length, @in.GetSize());
     byte[] act = new byte[data3.Length];
     IOUtil.ReadFully(@in, act, 0, data3.Length);
     NUnit.Framework.Assert.IsTrue(Arrays.Equals(act, data3), "same content");
     NUnit.Framework.Assert.AreEqual(-1, @in.Read(), "stream at EOF");
     @in.Close();
 }
Exemple #4
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;
 }
Exemple #5
0
		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 TestParse_PublicParseMethod()
 {
     ObjectInserter.Formatter fmt = new ObjectInserter.Formatter();
     NGit.CommitBuilder src = new NGit.CommitBuilder();
     src.TreeId = fmt.IdFor(Constants.OBJ_TREE, new byte[] {  });
     src.Author = author;
     src.Committer = committer;
     src.Message = "Test commit\n\nThis is a test.\n";
     RevCommit p = RevCommit.Parse(src.Build());
     NUnit.Framework.Assert.AreEqual(src.TreeId, p.Tree);
     NUnit.Framework.Assert.AreEqual(0, p.ParentCount);
     NUnit.Framework.Assert.AreEqual(author, p.GetAuthorIdent());
     NUnit.Framework.Assert.AreEqual(committer, p.GetCommitterIdent());
     NUnit.Framework.Assert.AreEqual("Test commit", p.GetShortMessage());
     NUnit.Framework.Assert.AreEqual(src.Message, p.GetFullMessage());
 }
Exemple #7
0
		public virtual void TestPackFormat_LargeObject()
		{
			int type = Constants.OBJ_BLOB;
			byte[] data = GetRng().NextBytes(streamThreshold + 5);
			ObjectId id = new ObjectInserter.Formatter().IdFor(type, data);
			Write(id, CompressPackFormat(type, data));
			ObjectLoader ol;
			{
				FileInputStream fs = new FileInputStream(Path(id));
				try
				{
					ol = UnpackedObject.Open(fs, Path(id), id, wc);
				}
				finally
				{
					fs.Close();
				}
			}
			NUnit.Framework.Assert.IsNotNull(ol, "created loader");
			NUnit.Framework.Assert.AreEqual(type, ol.GetType());
			NUnit.Framework.Assert.AreEqual(data.Length, ol.GetSize());
			NUnit.Framework.Assert.IsTrue(ol.IsLarge(), "is large");
			try
			{
				ol.GetCachedBytes();
				NUnit.Framework.Assert.Fail("Should have thrown LargeObjectException");
			}
			catch (LargeObjectException tooBig)
			{
				NUnit.Framework.Assert.AreEqual(MessageFormat.Format(JGitText.Get().largeObjectException
					, id.Name), tooBig.Message);
			}
			ObjectStream @in = ol.OpenStream();
			NUnit.Framework.Assert.IsNotNull(@in, "have stream");
			NUnit.Framework.Assert.AreEqual(type, @in.GetType());
			NUnit.Framework.Assert.AreEqual(data.Length, @in.GetSize());
			byte[] data2 = new byte[data.Length];
			IOUtil.ReadFully(@in, data2, 0, data.Length);
			NUnit.Framework.Assert.IsTrue(Arrays.Equals(data2, data), "same content");
			NUnit.Framework.Assert.AreEqual(-1, @in.Read(), "stream at EOF");
			@in.Close();
		}
Exemple #8
0
		public virtual void TestStandardFormat_LargeObject_TrailingGarbage()
		{
			int type = Constants.OBJ_BLOB;
			byte[] data = GetRng().NextBytes(streamThreshold + 5);
			ObjectId id = new ObjectInserter.Formatter().IdFor(type, data);
			byte[] gz = CompressStandardFormat(type, data);
			byte[] tr = new byte[gz.Length + 1];
			System.Array.Copy(gz, 0, tr, 0, gz.Length);
			Write(id, tr);
			ObjectLoader ol;
			{
				FileInputStream fs = new FileInputStream(Path(id));
				try
				{
					ol = UnpackedObject.Open(fs, Path(id), id, wc);
				}
				finally
				{
					fs.Close();
				}
			}
			byte[] tmp = new byte[data.Length];
			InputStream @in = ol.OpenStream();
			IOUtil.ReadFully(@in, tmp, 0, tmp.Length);
			try
			{
				@in.Close();
				NUnit.Framework.Assert.Fail("close did not throw CorruptObjectException");
			}
			catch (CorruptObjectException coe)
			{
				NUnit.Framework.Assert.AreEqual(MessageFormat.Format(JGitText.Get().objectIsCorrupt
					, id.Name, JGitText.Get().corruptObjectBadStream), coe.Message);
			}
		}