当前位置: 首页>>代码示例>>C#>>正文


C# DirCacheEntry.SetLength方法代码示例

本文整理汇总了C#中NGit.Dircache.DirCacheEntry.SetLength方法的典型用法代码示例。如果您正苦于以下问题:C# DirCacheEntry.SetLength方法的具体用法?C# DirCacheEntry.SetLength怎么用?C# DirCacheEntry.SetLength使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在NGit.Dircache.DirCacheEntry的用法示例。


在下文中一共展示了DirCacheEntry.SetLength方法的12个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: ResetIndex

		/// <summary>Resets the index to represent exactly some filesystem content.</summary>
		/// <remarks>
		/// Resets the index to represent exactly some filesystem content. E.g. the
		/// following call will replace the index with the working tree content:
		/// <p>
		/// <code>resetIndex(new FileSystemIterator(db))</code>
		/// <p>
		/// This method can be used by testcases which first prepare a new commit
		/// somewhere in the filesystem (e.g. in the working-tree) and then want to
		/// have an index which matches their prepared content.
		/// </remarks>
		/// <param name="treeItr">
		/// a
		/// <see cref="NGit.Treewalk.FileTreeIterator">NGit.Treewalk.FileTreeIterator</see>
		/// which determines which files should
		/// go into the new index
		/// </param>
		/// <exception cref="System.IO.FileNotFoundException">System.IO.FileNotFoundException
		/// 	</exception>
		/// <exception cref="System.IO.IOException">System.IO.IOException</exception>
		protected internal virtual void ResetIndex(FileTreeIterator treeItr)
		{
			ObjectInserter inserter = db.NewObjectInserter();
			DirCacheBuilder builder = db.LockDirCache().Builder();
			DirCacheEntry dce;
			while (!treeItr.Eof)
			{
				long len = treeItr.GetEntryLength();
				dce = new DirCacheEntry(treeItr.EntryPathString);
				dce.FileMode = treeItr.EntryFileMode;
				dce.LastModified = treeItr.GetEntryLastModified();
				dce.SetLength((int)len);
				FileInputStream @in = new FileInputStream(treeItr.GetEntryFile());
				dce.SetObjectId(inserter.Insert(Constants.OBJ_BLOB, len, @in));
				@in.Close();
				builder.Add(dce);
				treeItr.Next(1);
			}
			builder.Commit();
			inserter.Flush();
			inserter.Release();
		}
开发者ID:shoff,项目名称:ngit,代码行数:42,代码来源:RepositoryTestCase.cs

示例2: Apply

 public override void Apply(DirCacheEntry ent)
 {
     ent.FileMode = FileMode.REGULAR_FILE;
     ent.SetLength(length);
     ent.SetObjectId(data);
 }
开发者ID:JamesChan,项目名称:ngit,代码行数:6,代码来源:DirCacheCheckoutTest.cs

示例3: ContentMerge

		/// <exception cref="System.IO.FileNotFoundException"></exception>
		/// <exception cref="System.InvalidOperationException"></exception>
		/// <exception cref="System.IO.IOException"></exception>
		private bool ContentMerge(CanonicalTreeParser @base, CanonicalTreeParser ours, CanonicalTreeParser
			 theirs)
		{
			MergeFormatter fmt = new MergeFormatter();
			RawText baseText = @base == null ? RawText.EMPTY_TEXT : GetRawText(@base.EntryObjectId
				, db);
			// do the merge
			MergeResult<RawText> result = mergeAlgorithm.Merge(RawTextComparator.DEFAULT, baseText
				, GetRawText(ours.EntryObjectId, db), GetRawText(theirs.EntryObjectId, db));
			FilePath of = null;
			FileOutputStream fos;
			if (!inCore)
			{
				FilePath workTree = db.WorkTree;
				if (workTree == null)
				{
					// TODO: This should be handled by WorkingTreeIterators which
					// support write operations
					throw new NotSupportedException();
				}
				of = new FilePath(workTree, tw.PathString);
				fos = new FileOutputStream(of);
				try
				{
					fmt.FormatMerge(fos, result, Arrays.AsList(commitNames), Constants.CHARACTER_ENCODING
						);
				}
				finally
				{
					fos.Close();
				}
			}
			else
			{
				if (!result.ContainsConflicts())
				{
					// When working inCore, only trivial merges can be handled,
					// so we generate objects only in conflict free cases
					of = FilePath.CreateTempFile("merge_", "_temp", null);
					fos = new FileOutputStream(of);
					try
					{
						fmt.FormatMerge(fos, result, Arrays.AsList(commitNames), Constants.CHARACTER_ENCODING
							);
					}
					finally
					{
						fos.Close();
					}
				}
			}
			if (result.ContainsConflicts())
			{
				// a conflict occured, the file will contain conflict markers
				// the index will be populated with the three stages and only the
				// workdir (if used) contains the halfways merged content
				Add(tw.RawPath, @base, DirCacheEntry.STAGE_1);
				Add(tw.RawPath, ours, DirCacheEntry.STAGE_2);
				Add(tw.RawPath, theirs, DirCacheEntry.STAGE_3);
				mergeResults.Put(tw.PathString, result.Upcast ());
				return false;
			}
			else
			{
				// no conflict occured, the file will contain fully merged content.
				// the index will be populated with the new merged version
				DirCacheEntry dce = new DirCacheEntry(tw.PathString);
				dce.FileMode = tw.GetFileMode(0);
				dce.LastModified = of.LastModified();
				dce.SetLength((int)of.Length());
				InputStream @is = new FileInputStream(of);
				try
				{
					dce.SetObjectId(oi.Insert(Constants.OBJ_BLOB, of.Length(), @is));
				}
				finally
				{
					@is.Close();
					if (inCore)
					{
						FileUtils.Delete(of);
					}
				}
				builder.Add(dce);
				return true;
			}
		}
开发者ID:stewartwhaley,项目名称:monodevelop,代码行数:90,代码来源:ResolveMerger.cs

示例4: UpdateIndex

        /// <summary>Updates the index after a content merge has happened.</summary>
        /// <remarks>
        /// Updates the index after a content merge has happened. If no conflict has
        /// occurred this includes persisting the merged content to the object
        /// database. In case of conflicts this method takes care to write the
        /// correct stages to the index.
        /// </remarks>
        /// <param name="base"></param>
        /// <param name="ours"></param>
        /// <param name="theirs"></param>
        /// <param name="result"></param>
        /// <param name="of"></param>
        /// <exception cref="System.IO.FileNotFoundException">System.IO.FileNotFoundException
        /// 	</exception>
        /// <exception cref="System.IO.IOException">System.IO.IOException</exception>
        private void UpdateIndex(CanonicalTreeParser @base, CanonicalTreeParser ours, CanonicalTreeParser
			 theirs, MergeResult<RawText> result, FilePath of)
        {
            if (result.ContainsConflicts())
            {
                // a conflict occurred, the file will contain conflict markers
                // the index will be populated with the three stages and only the
                // workdir (if used) contains the halfways merged content
                Add(tw.RawPath, @base, DirCacheEntry.STAGE_1);
                Add(tw.RawPath, ours, DirCacheEntry.STAGE_2);
                Add(tw.RawPath, theirs, DirCacheEntry.STAGE_3);
                mergeResults.Put(tw.PathString, result.Upcast ());
            }
            else
            {
                // no conflict occurred, the file will contain fully merged content.
                // the index will be populated with the new merged version
                DirCacheEntry dce = new DirCacheEntry(tw.PathString);
                int newMode = MergeFileModes(tw.GetRawMode(0), tw.GetRawMode(1), tw.GetRawMode(2)
                    );
                // set the mode for the new content. Fall back to REGULAR_FILE if
                // you can't merge modes of OURS and THEIRS
                dce.FileMode = (newMode == FileMode.MISSING.GetBits()) ? FileMode.REGULAR_FILE :
                    FileMode.FromBits(newMode);
                dce.LastModified = of.LastModified();
                dce.SetLength((int)of.Length());
                InputStream @is = new FileInputStream(of);
                try
                {
                    dce.SetObjectId(oi.Insert(Constants.OBJ_BLOB, of.Length(), @is));
                }
                finally
                {
                    @is.Close();
                    if (inCore)
                    {
                        FileUtils.Delete(of);
                    }
                }
                builder.Add(dce);
            }
        }
开发者ID:kenji-tan,项目名称:ngit,代码行数:57,代码来源:ResolveMerger.cs

示例5: AddEntryToBuilder

        /// <exception cref="System.IO.IOException"></exception>
        private DirCacheEntry AddEntryToBuilder(string path, FilePath file, ObjectInserter
			 newObjectInserter, DirCacheBuilder builder, int stage)
        {
            FileInputStream inputStream = new FileInputStream(file);
            ObjectId id = newObjectInserter.Insert(Constants.OBJ_BLOB, file.Length(), inputStream
                );
            inputStream.Close();
            DirCacheEntry entry = new DirCacheEntry(path, stage);
            entry.SetObjectId(id);
            entry.FileMode = FileMode.REGULAR_FILE;
            entry.LastModified = file.LastModified();
            entry.SetLength((int)file.Length());
            builder.Add(entry);
            return entry;
        }
开发者ID:stinos,项目名称:ngit,代码行数:16,代码来源:AddCommandTest.cs

示例6: Add

        /// <summary>adds a new path with the specified stage to the index builder</summary>
        /// <param name="path"></param>
        /// <param name="p"></param>
        /// <param name="stage"></param>
        /// <param name="lastMod"></param>
        /// <param name="len"></param>
        /// <returns>the entry which was added to the index</returns>
        private DirCacheEntry Add(byte[] path, CanonicalTreeParser p, int stage, long lastMod
			, long len)
        {
            if (p != null && !p.EntryFileMode.Equals(FileMode.TREE))
            {
                DirCacheEntry e = new DirCacheEntry(path, stage);
                e.FileMode = p.EntryFileMode;
                e.SetObjectId(p.EntryObjectId);
                e.LastModified = lastMod;
                e.SetLength(len);
                builder.Add(e);
                return e;
            }
            return null;
        }
开发者ID:stinos,项目名称:ngit,代码行数:22,代码来源:ResolveMerger.cs

示例7: Keep

 /// <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;
 }
开发者ID:stinos,项目名称:ngit,代码行数:16,代码来源:ResolveMerger.cs

示例8: CheckoutEntry

        /// <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());
            }
        }
开发者ID:stinos,项目名称:ngit,代码行数:88,代码来源:DirCacheCheckout.cs

示例9: Apply

			public override void Apply(DirCacheEntry ent)
			{
				ent.FileMode = FileMode.REGULAR_FILE;
				ent.SetLength(1);
				ent.SetObjectId(ObjectId.ZeroId);
			}
开发者ID:LunarLanding,项目名称:ngit,代码行数:6,代码来源:DirCachePathEditTest.cs

示例10: TestBuildOneFile_FinishWriteCommit

		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);
			}
		}
开发者ID:shoff,项目名称:ngit,代码行数:44,代码来源:DirCacheBuilderTest.cs

示例11: CopyMetaDataHelper

		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);
		}
开发者ID:LunarLanding,项目名称:ngit,代码行数:37,代码来源:DirCacheEntryTest.cs

示例12: TestBuildOneFile_Commit_IndexChangedEvent

		public virtual void TestBuildOneFile_Commit_IndexChangedEvent()
		{
			// empty
			string path = "a-file-path";
			FileMode mode = FileMode.REGULAR_FILE;
			// "old" date in 2008
			long lastModified = 1218123387057L;
			int length = 1342;
			DirCacheEntry entOrig;
			bool receivedEvent = false;
			DirCache dc = db.LockDirCache();
			IndexChangedListener listener = new _IndexChangedListener_212();
			ListenerList l = db.Listeners;
			l.AddIndexChangedListener(listener);
			DirCacheBuilder b = dc.Builder();
			entOrig = new DirCacheEntry(path);
			entOrig.FileMode = mode;
			entOrig.LastModified = lastModified;
			entOrig.SetLength(length);
			b.Add(entOrig);
			try
			{
				b.Commit();
			}
			catch (_T123327308)
			{
				receivedEvent = true;
			}
			if (!receivedEvent)
			{
				NUnit.Framework.Assert.Fail("did not receive IndexChangedEvent");
			}
			// do the same again, as this doesn't change index compared to first
			// round we should get no event this time
			dc = db.LockDirCache();
			listener = new _IndexChangedListener_239();
			l = db.Listeners;
			l.AddIndexChangedListener(listener);
			b = dc.Builder();
			entOrig = new DirCacheEntry(path);
			entOrig.FileMode = mode;
			entOrig.LastModified = lastModified;
			entOrig.SetLength(length);
			b.Add(entOrig);
			try
			{
				b.Commit();
			}
			catch (_T123327308)
			{
				NUnit.Framework.Assert.Fail("unexpected IndexChangedEvent");
			}
		}
开发者ID:LunarLanding,项目名称:ngit,代码行数:53,代码来源:DirCacheBuilderTest.cs


注:本文中的NGit.Dircache.DirCacheEntry.SetLength方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。