Пример #1
0
 public override void Start(int totalTasks)
 {
     if (!IsMainThread())
     {
         throw new InvalidOperationException();
     }
     pm.Start(totalTasks);
 }
Пример #2
0
        internal MergeCommandResult Apply(NGit.ProgressMonitor monitor, Stash stash)
        {
            monitor.Start(1);
            monitor.BeginTask("Applying stash", 100);
            ObjectId  cid     = _repo.Resolve(stash.CommitId);
            RevWalk   rw      = new RevWalk(_repo);
            RevCommit wip     = rw.ParseCommit(cid);
            RevCommit oldHead = wip.Parents.First();

            rw.ParseHeaders(oldHead);
            MergeCommandResult res = GitUtil.MergeTrees(monitor, _repo, oldHead, wip, "Stash", false);

            monitor.EndTask();
            return(res);
        }
Пример #3
0
		/// <summary>Parse the pack stream.</summary>
		/// <remarks>Parse the pack stream.</remarks>
		/// <param name="receiving">
		/// receives progress feedback during the initial receiving
		/// objects phase. If null,
		/// <see cref="NGit.NullProgressMonitor">NGit.NullProgressMonitor</see>
		/// will be
		/// used.
		/// </param>
		/// <param name="resolving">receives progress feedback during the resolving objects phase.
		/// 	</param>
		/// <returns>
		/// the pack lock, if one was requested by setting
		/// <see cref="SetLockMessage(string)">SetLockMessage(string)</see>
		/// .
		/// </returns>
		/// <exception cref="System.IO.IOException">the stream is malformed, or contains corrupt objects.
		/// 	</exception>
		public virtual PackLock Parse(ProgressMonitor receiving, ProgressMonitor resolving
			)
		{
			if (receiving == null)
			{
				receiving = NullProgressMonitor.INSTANCE;
			}
			if (resolving == null)
			{
				resolving = NullProgressMonitor.INSTANCE;
			}
			if (receiving == resolving)
			{
				receiving.Start(2);
			}
			try
			{
				ReadPackHeader();
				entries = new PackedObjectInfo[(int)objectCount];
				baseById = new ObjectIdOwnerMap<PackParser.DeltaChain>();
				baseByPos = new LongMap<PackParser.UnresolvedDelta>();
				deferredCheckBlobs = new BlockList<PackedObjectInfo>();
				receiving.BeginTask(JGitText.Get().receivingObjects, (int)objectCount);
				try
				{
					for (int done = 0; done < objectCount; done++)
					{
						IndexOneObject();
						receiving.Update(1);
						if (receiving.IsCancelled())
						{
							throw new IOException(JGitText.Get().downloadCancelled);
						}
					}
					ReadPackFooter();
					EndInput();
				}
				finally
				{
					receiving.EndTask();
				}
				if (!deferredCheckBlobs.IsEmpty())
				{
					DoDeferredCheckBlobs();
				}
				if (deltaCount > 0)
				{
					if (resolving is BatchingProgressMonitor)
					{
						((BatchingProgressMonitor)resolving).SetDelayStart(1000, TimeUnit.MILLISECONDS);
					}
					resolving.BeginTask(JGitText.Get().resolvingDeltas, deltaCount);
					ResolveDeltas(resolving);
					if (entryCount < objectCount)
					{
						if (!IsAllowThin())
						{
							throw new IOException(MessageFormat.Format(JGitText.Get().packHasUnresolvedDeltas
								, Sharpen.Extensions.ValueOf(objectCount - entryCount)));
						}
						ResolveDeltasWithExternalBases(resolving);
						if (entryCount < objectCount)
						{
							throw new IOException(MessageFormat.Format(JGitText.Get().packHasUnresolvedDeltas
								, Sharpen.Extensions.ValueOf(objectCount - entryCount)));
						}
					}
					resolving.EndTask();
				}
				packDigest = null;
				baseById = null;
				baseByPos = null;
			}
			finally
			{
				try
				{
					if (readCurs != null)
					{
						readCurs.Release();
					}
				}
				finally
				{
					readCurs = null;
				}
				try
				{
					inflater.Release();
				}
				finally
				{
					inflater = null;
				}
			}
			return null;
		}
Пример #4
0
        public Stash Create(NGit.ProgressMonitor monitor, string message)
        {
            if (monitor != null)
            {
                monitor.Start(1);
                monitor.BeginTask("Stashing changes", 100);
            }

            UserConfig config = _repo.GetConfig().Get(UserConfig.KEY);
            RevWalk    rw     = new RevWalk(_repo);
            ObjectId   headId = _repo.Resolve(Constants.HEAD);
            var        parent = rw.ParseCommit(headId);

            PersonIdent author = new PersonIdent(config.GetAuthorName() ?? "unknown", config.GetAuthorEmail() ?? "unknown@(none).");

            if (string.IsNullOrEmpty(message))
            {
                // Use the commit summary as message
                message = parent.Abbreviate(7).ToString() + " " + parent.GetShortMessage();
                int i = message.IndexOfAny(new char[] { '\r', '\n' });
                if (i != -1)
                {
                    message = message.Substring(0, i);
                }
            }

            // Create the index tree commit
            ObjectInserter inserter = _repo.NewObjectInserter();
            DirCache       dc       = _repo.ReadDirCache();

            if (monitor != null)
            {
                monitor.Update(10);
            }

            var tree_id = dc.WriteTree(inserter);

            inserter.Release();

            if (monitor != null)
            {
                monitor.Update(10);
            }

            string   commitMsg   = "index on " + _repo.GetBranch() + ": " + message;
            ObjectId indexCommit = GitUtil.CreateCommit(_repo, commitMsg + "\n", new ObjectId[] { headId }, tree_id, author, author);

            if (monitor != null)
            {
                monitor.Update(20);
            }

            // Create the working dir commit
            tree_id   = WriteWorkingDirectoryTree(parent.Tree, dc);
            commitMsg = "WIP on " + _repo.GetBranch() + ": " + message;
            var wipCommit = GitUtil.CreateCommit(_repo, commitMsg + "\n", new ObjectId[] { headId, indexCommit }, tree_id, author, author);

            if (monitor != null)
            {
                monitor.Update(20);
            }

            string   prevCommit = null;
            FileInfo sf         = StashRefFile;

            if (sf.Exists)
            {
                prevCommit = File.ReadAllText(sf.FullName).Trim(' ', '\t', '\r', '\n');
            }

            Stash s = new Stash(prevCommit, wipCommit.Name, author, commitMsg);

            FileInfo stashLog = StashLogFile;

            File.AppendAllText(stashLog.FullName, s.FullLine + "\n");
            File.WriteAllText(sf.FullName, s.CommitId + "\n");

            if (monitor != null)
            {
                monitor.Update(5);
            }

            // Wipe all local changes
            GitUtil.HardReset(_repo, Constants.HEAD);

            monitor.EndTask();
            s.StashCollection = this;
            return(s);
        }
Пример #5
0
		/// <summary>Consume data from the input stream until the packfile is indexed.</summary>
		/// <remarks>Consume data from the input stream until the packfile is indexed.</remarks>
		/// <param name="progress">progress feedback</param>
		/// <exception cref="System.IO.IOException">System.IO.IOException</exception>
		public virtual void Index(ProgressMonitor progress)
		{
			progress.Start(2);
			try
			{
				try
				{
					ReadPackHeader();
					entries = new PackedObjectInfo[(int)objectCount];
					baseById = new ObjectIdSubclassMap<IndexPack.DeltaChain>();
					baseByPos = new LongMap<IndexPack.UnresolvedDelta>();
					deferredCheckBlobs = new AList<PackedObjectInfo>();
					progress.BeginTask(JGitText.Get().receivingObjects, (int)objectCount);
					for (int done = 0; done < objectCount; done++)
					{
						IndexOneObject();
						progress.Update(1);
						if (progress.IsCancelled())
						{
							throw new IOException(JGitText.Get().downloadCancelled);
						}
					}
					ReadPackFooter();
					EndInput();
					if (!deferredCheckBlobs.IsEmpty())
					{
						DoDeferredCheckBlobs();
					}
					progress.EndTask();
					if (deltaCount > 0)
					{
						if (packOut == null)
						{
							throw new IOException(JGitText.Get().needPackOut);
						}
						ResolveDeltas(progress);
						if (entryCount < objectCount)
						{
							if (!fixThin)
							{
								throw new IOException(MessageFormat.Format(JGitText.Get().packHasUnresolvedDeltas
									, (objectCount - entryCount)));
							}
							FixThinPack(progress);
						}
					}
					if (packOut != null && (keepEmpty || entryCount > 0))
					{
						packOut.GetChannel().Force(true);
					}
					packDigest = null;
					baseById = null;
					baseByPos = null;
					if (dstIdx != null && (keepEmpty || entryCount > 0))
					{
						WriteIdx();
					}
				}
				finally
				{
					try
					{
						if (readCurs != null)
						{
							readCurs.Release();
						}
					}
					finally
					{
						readCurs = null;
					}
					try
					{
						inflater.Release();
					}
					finally
					{
						inflater = null;
						objectDatabase.Close();
					}
					progress.EndTask();
					if (packOut != null)
					{
						packOut.Close();
					}
				}
				if (keepEmpty || entryCount > 0)
				{
					if (dstPack != null)
					{
						dstPack.SetReadOnly();
					}
					if (dstIdx != null)
					{
						dstIdx.SetReadOnly();
					}
				}
			}
			catch (IOException err)
			{
				if (dstPack != null)
				{
					FileUtils.Delete(dstPack);
				}
				if (dstIdx != null)
				{
					FileUtils.Delete(dstIdx);
				}
				throw;
			}
		}