Ejemplo n.º 1
0
 public virtual void TestBuildOneFile_FinishWriteCommit()
 {
     string        path         = "a-file-path";
     FileMode      mode         = FileMode.REGULAR_FILE;
     long          lastModified = 1218123387057L;
     int           length       = 1342;
     DirCacheEntry entOrig;
     {
         DirCache        dc = db.LockDirCache();
         DirCacheBuilder b  = dc.Builder();
         NUnit.Framework.Assert.IsNotNull(b);
         entOrig              = new DirCacheEntry(path);
         entOrig.FileMode     = mode;
         entOrig.LastModified = lastModified;
         entOrig.SetLength(length);
         NUnit.Framework.Assert.AreNotSame(path, entOrig.PathString);
         NUnit.Framework.Assert.AreEqual(path, entOrig.PathString);
         NUnit.Framework.Assert.AreEqual(ObjectId.ZeroId, entOrig.GetObjectId());
         NUnit.Framework.Assert.AreEqual(mode.GetBits(), entOrig.RawMode);
         NUnit.Framework.Assert.AreEqual(0, entOrig.Stage);
         NUnit.Framework.Assert.AreEqual(lastModified, entOrig.LastModified);
         NUnit.Framework.Assert.AreEqual(length, entOrig.Length);
         NUnit.Framework.Assert.IsFalse(entOrig.IsAssumeValid);
         b.Add(entOrig);
         b.Finish();
         NUnit.Framework.Assert.AreEqual(1, dc.GetEntryCount());
         NUnit.Framework.Assert.AreSame(entOrig, dc.GetEntry(0));
         dc.Write();
         NUnit.Framework.Assert.IsTrue(dc.Commit());
     }
     {
         DirCache dc = db.ReadDirCache();
         NUnit.Framework.Assert.AreEqual(1, dc.GetEntryCount());
         DirCacheEntry entRead = dc.GetEntry(0);
         NUnit.Framework.Assert.AreNotSame(entOrig, entRead);
         NUnit.Framework.Assert.AreEqual(path, entRead.PathString);
         NUnit.Framework.Assert.AreEqual(ObjectId.ZeroId, entOrig.GetObjectId());
         NUnit.Framework.Assert.AreEqual(mode.GetBits(), entOrig.RawMode);
         NUnit.Framework.Assert.AreEqual(0, entOrig.Stage);
         NUnit.Framework.Assert.AreEqual(lastModified, entOrig.LastModified);
         NUnit.Framework.Assert.AreEqual(length, entOrig.Length);
         NUnit.Framework.Assert.IsFalse(entOrig.IsAssumeValid);
     }
 }
Ejemplo n.º 2
0
 private static void AssertEqual(DirCacheCGitCompatabilityTest.CGitIndexRecord c,
                                 DirCacheEntry j)
 {
     NUnit.Framework.Assert.IsNotNull(c);
     NUnit.Framework.Assert.IsNotNull(j);
     NUnit.Framework.Assert.AreEqual(c.path, j.PathString);
     NUnit.Framework.Assert.AreEqual(c.id, j.GetObjectId());
     NUnit.Framework.Assert.AreEqual(c.mode, j.RawMode);
     NUnit.Framework.Assert.AreEqual(c.stage, j.Stage);
 }
Ejemplo n.º 3
0
        /// <summary>
        /// Updates the file in the working tree with content and mode from an entry
        /// in the index.
        /// </summary>
        /// <remarks>
        /// Updates the file in the working tree with content and mode from an entry
        /// in the index. The new content is first written to a new temporary file in
        /// the same directory as the real file. Then that new file is renamed to the
        /// final filename.
        /// TODO: this method works directly on File IO, we may need another
        /// abstraction (like WorkingTreeIterator). This way we could tell e.g.
        /// Eclipse that Files in the workspace got changed
        /// </remarks>
        /// <param name="repo"></param>
        /// <param name="f">
        /// the file to be modified. The parent directory for this file
        /// has to exist already
        /// </param>
        /// <param name="entry">the entry containing new mode and content</param>
        /// <exception cref="System.IO.IOException">System.IO.IOException</exception>
        public static void CheckoutEntry(Repository repo, FilePath f, DirCacheEntry entry
                                         )
        {
            ObjectLoader     ol        = repo.Open(entry.GetObjectId());
            FilePath         parentDir = f.GetParentFile();
            FilePath         tmpFile   = FilePath.CreateTempFile("._" + f.GetName(), null, parentDir);
            FileOutputStream channel   = new FileOutputStream(tmpFile);

            try
            {
                ol.CopyTo(channel);
            }
            finally
            {
                channel.Close();
            }
            FS fs = repo.FileSystem;
            WorkingTreeOptions opt = repo.GetConfig().Get(WorkingTreeOptions.KEY);

            if (opt.IsFileMode() && fs.SupportsExecute())
            {
                if (FileMode.EXECUTABLE_FILE.Equals(entry.RawMode))
                {
                    if (!fs.CanExecute(tmpFile))
                    {
                        fs.SetExecute(tmpFile, true);
                    }
                }
                else
                {
                    if (fs.CanExecute(tmpFile))
                    {
                        fs.SetExecute(tmpFile, false);
                    }
                }
            }
            if (!tmpFile.RenameTo(f))
            {
                // tried to rename which failed. Let' delete the target file and try
                // again
                FileUtils.Delete(f);
                if (!tmpFile.RenameTo(f))
                {
                    throw new IOException(MessageFormat.Format(JGitText.Get().couldNotWriteFile, tmpFile
                                                               .GetPath(), f.GetPath()));
                }
            }
            entry.LastModified = f.LastModified();
            entry.SetLength((int)ol.GetSize());
        }
Ejemplo n.º 4
0
        private void CopyMetaDataHelper(bool keepStage)
        {
            DirCacheEntry e = new DirCacheEntry("some/path", DirCacheEntry.STAGE_2);

            e.IsAssumeValid = false;
            e.SetCreationTime(2L);
            e.FileMode     = FileMode.EXECUTABLE_FILE;
            e.LastModified = 3L;
            e.SetLength(100L);
            e.SetObjectId(ObjectId.FromString("0123456789012345678901234567890123456789"));
            e.IsUpdateNeeded = true;
            DirCacheEntry f = new DirCacheEntry("someother/path", DirCacheEntry.STAGE_1);

            f.IsAssumeValid = true;
            f.SetCreationTime(10L);
            f.FileMode     = FileMode.SYMLINK;
            f.LastModified = 20L;
            f.SetLength(100000000L);
            f.SetObjectId(ObjectId.FromString("1234567890123456789012345678901234567890"));
            f.IsUpdateNeeded = true;
            e.CopyMetaData(f, keepStage);
            NUnit.Framework.Assert.IsTrue(e.IsAssumeValid);
            NUnit.Framework.Assert.AreEqual(10L, e.GetCreationTime());
            NUnit.Framework.Assert.AreEqual(ObjectId.FromString("1234567890123456789012345678901234567890"
                                                                ), e.GetObjectId());
            NUnit.Framework.Assert.AreEqual(FileMode.SYMLINK, e.FileMode);
            NUnit.Framework.Assert.AreEqual(20L, e.LastModified);
            NUnit.Framework.Assert.AreEqual(100000000L, e.Length);
            if (keepStage)
            {
                NUnit.Framework.Assert.AreEqual(DirCacheEntry.STAGE_2, e.Stage);
            }
            else
            {
                NUnit.Framework.Assert.AreEqual(DirCacheEntry.STAGE_1, e.Stage);
            }
            NUnit.Framework.Assert.IsTrue(e.IsUpdateNeeded);
            NUnit.Framework.Assert.AreEqual("some/path", e.PathString);
        }
Ejemplo n.º 5
0
 /// <summary>
 /// adds a entry to the index builder which is a copy of the specified
 /// DirCacheEntry
 /// </summary>
 /// <param name="e">the entry which should be copied</param>
 /// <returns>the entry which was added to the index</returns>
 private DirCacheEntry Keep(DirCacheEntry e)
 {
     DirCacheEntry newEntry = new DirCacheEntry(e.PathString, e.Stage);
     newEntry.FileMode = e.FileMode;
     newEntry.SetObjectId(e.GetObjectId());
     newEntry.LastModified = e.LastModified;
     newEntry.SetLength(e.Length);
     builder.Add(newEntry);
     return newEntry;
 }
Ejemplo n.º 6
0
        /// <summary>
        /// Updates the file in the working tree with content and mode from an entry
        /// in the index.
        /// </summary>
        /// <remarks>
        /// Updates the file in the working tree with content and mode from an entry
        /// in the index. The new content is first written to a new temporary file in
        /// the same directory as the real file. Then that new file is renamed to the
        /// final filename.
        /// <p>
        /// TODO: this method works directly on File IO, we may need another
        /// abstraction (like WorkingTreeIterator). This way we could tell e.g.
        /// Eclipse that Files in the workspace got changed
        /// </p>
        /// </remarks>
        /// <param name="repo"></param>
        /// <param name="f">
        /// the file to be modified. The parent directory for this file
        /// has to exist already
        /// </param>
        /// <param name="entry">the entry containing new mode and content</param>
        /// <param name="or">object reader to use for checkout</param>
        /// <exception cref="System.IO.IOException">System.IO.IOException</exception>
        public static void CheckoutEntry(Repository repo, FilePath f, DirCacheEntry entry
			, ObjectReader or)
        {
            ObjectLoader ol = or.Open(entry.GetObjectId());
            FilePath parentDir = f.GetParentFile();
            FilePath tmpFile = FilePath.CreateTempFile("._" + f.GetName(), null, parentDir);
            WorkingTreeOptions opt = repo.GetConfig().Get(WorkingTreeOptions.KEY);
            FileOutputStream rawChannel = new FileOutputStream(tmpFile);
            OutputStream channel;
            if (opt.GetAutoCRLF() == CoreConfig.AutoCRLF.TRUE)
            {
                channel = new AutoCRLFOutputStream(rawChannel);
            }
            else
            {
                channel = rawChannel;
            }
            try
            {
                ol.CopyTo(channel);
            }
            finally
            {
                channel.Close();
            }
            FS fs = repo.FileSystem;
            if (opt.IsFileMode() && fs.SupportsExecute())
            {
                if (FileMode.EXECUTABLE_FILE.Equals(entry.RawMode))
                {
                    if (!fs.CanExecute(tmpFile))
                    {
                        fs.SetExecute(tmpFile, true);
                    }
                }
                else
                {
                    if (fs.CanExecute(tmpFile))
                    {
                        fs.SetExecute(tmpFile, false);
                    }
                }
            }
            if (!tmpFile.RenameTo(f))
            {
                // tried to rename which failed. Let' delete the target file and try
                // again
                FileUtils.Delete(f);
                if (!tmpFile.RenameTo(f))
                {
                    throw new IOException(MessageFormat.Format(JGitText.Get().couldNotWriteFile, tmpFile
                        .GetPath(), f.GetPath()));
                }
            }
            entry.LastModified = f.LastModified();
            if (opt.GetAutoCRLF() != CoreConfig.AutoCRLF.FALSE)
            {
                entry.SetLength(f.Length());
            }
            else
            {
                // AutoCRLF wants on-disk-size
                entry.SetLength((int)ol.GetSize());
            }
        }
		private static void AssertEqual(DirCacheCGitCompatabilityTest.CGitIndexRecord c, 
			DirCacheEntry j)
		{
			NUnit.Framework.Assert.IsNotNull(c);
			NUnit.Framework.Assert.IsNotNull(j);
			NUnit.Framework.Assert.AreEqual(c.path, j.PathString);
			NUnit.Framework.Assert.AreEqual(c.id, j.GetObjectId());
			NUnit.Framework.Assert.AreEqual(c.mode, j.RawMode);
			NUnit.Framework.Assert.AreEqual(c.stage, j.Stage);
		}
Ejemplo n.º 8
0
		public virtual void TestBuildOneFile_FinishWriteCommit()
		{
			string path = "a-file-path";
			FileMode mode = FileMode.REGULAR_FILE;
			long lastModified = 1218123387057L;
			int length = 1342;
			DirCacheEntry entOrig;
			{
				DirCache dc = db.LockDirCache();
				DirCacheBuilder b = dc.Builder();
				NUnit.Framework.Assert.IsNotNull(b);
				entOrig = new DirCacheEntry(path);
				entOrig.FileMode = mode;
				entOrig.LastModified = lastModified;
				entOrig.SetLength(length);
				NUnit.Framework.Assert.AreNotSame(path, entOrig.PathString);
				NUnit.Framework.Assert.AreEqual(path, entOrig.PathString);
				NUnit.Framework.Assert.AreEqual(ObjectId.ZeroId, entOrig.GetObjectId());
				NUnit.Framework.Assert.AreEqual(mode.GetBits(), entOrig.RawMode);
				NUnit.Framework.Assert.AreEqual(0, entOrig.Stage);
				NUnit.Framework.Assert.AreEqual(lastModified, entOrig.LastModified);
				NUnit.Framework.Assert.AreEqual(length, entOrig.Length);
				NUnit.Framework.Assert.IsFalse(entOrig.IsAssumeValid);
				b.Add(entOrig);
				b.Finish();
				NUnit.Framework.Assert.AreEqual(1, dc.GetEntryCount());
				NUnit.Framework.Assert.AreSame(entOrig, dc.GetEntry(0));
				dc.Write();
				NUnit.Framework.Assert.IsTrue(dc.Commit());
			}
			{
				DirCache dc = db.ReadDirCache();
				NUnit.Framework.Assert.AreEqual(1, dc.GetEntryCount());
				DirCacheEntry entRead = dc.GetEntry(0);
				NUnit.Framework.Assert.AreNotSame(entOrig, entRead);
				NUnit.Framework.Assert.AreEqual(path, entRead.PathString);
				NUnit.Framework.Assert.AreEqual(ObjectId.ZeroId, entOrig.GetObjectId());
				NUnit.Framework.Assert.AreEqual(mode.GetBits(), entOrig.RawMode);
				NUnit.Framework.Assert.AreEqual(0, entOrig.Stage);
				NUnit.Framework.Assert.AreEqual(lastModified, entOrig.LastModified);
				NUnit.Framework.Assert.AreEqual(length, entOrig.Length);
				NUnit.Framework.Assert.IsFalse(entOrig.IsAssumeValid);
			}
		}
Ejemplo n.º 9
0
		private void CopyMetaDataHelper(bool keepStage)
		{
			DirCacheEntry e = new DirCacheEntry("some/path", DirCacheEntry.STAGE_2);
			e.IsAssumeValid = false;
			e.SetCreationTime(2L);
			e.FileMode = FileMode.EXECUTABLE_FILE;
			e.LastModified = 3L;
			e.SetLength(100L);
			e.SetObjectId(ObjectId.FromString("0123456789012345678901234567890123456789"));
			e.IsUpdateNeeded = true;
			DirCacheEntry f = new DirCacheEntry("someother/path", DirCacheEntry.STAGE_1);
			f.IsAssumeValid = true;
			f.SetCreationTime(10L);
			f.FileMode = FileMode.SYMLINK;
			f.LastModified = 20L;
			f.SetLength(100000000L);
			f.SetObjectId(ObjectId.FromString("1234567890123456789012345678901234567890"));
			f.IsUpdateNeeded = true;
			e.CopyMetaData(f, keepStage);
			NUnit.Framework.Assert.IsTrue(e.IsAssumeValid);
			NUnit.Framework.Assert.AreEqual(10L, e.GetCreationTime());
			NUnit.Framework.Assert.AreEqual(ObjectId.FromString("1234567890123456789012345678901234567890"
				), e.GetObjectId());
			NUnit.Framework.Assert.AreEqual(FileMode.SYMLINK, e.FileMode);
			NUnit.Framework.Assert.AreEqual(20L, e.LastModified);
			NUnit.Framework.Assert.AreEqual(100000000L, e.Length);
			if (keepStage)
			{
				NUnit.Framework.Assert.AreEqual(DirCacheEntry.STAGE_2, e.Stage);
			}
			else
			{
				NUnit.Framework.Assert.AreEqual(DirCacheEntry.STAGE_1, e.Stage);
			}
			NUnit.Framework.Assert.IsTrue(e.IsUpdateNeeded);
			NUnit.Framework.Assert.AreEqual("some/path", e.PathString);
		}