Exemplo n.º 1
0
        public static Commit WithRevision(this Commit commit, FileInfo file, string revision, DateTime time = default(DateTime),
                                          string mergepoint = null, bool isDead = false)
        {
            var mergepointRevision = (mergepoint == null) ? Revision.Empty : Revision.Create(mergepoint);

            var fileRevision = file.CreateRevision(revision, commit.CommitId, time: time, mergepoint: mergepoint, isDead: isDead);

            commit.Add(fileRevision);
            file.AddCommit(commit, fileRevision.Revision);

            return(commit);
        }
Exemplo n.º 2
0
		/// <summary>
		/// Apply a commit.
		/// </summary>
		public void Apply(Commit commit)
		{
			var state = this[commit.Branch];
			state.Apply(commit);

			// find any file revisions that are branchpoints for branches and update the state of those branches
			var branches = commit
					.SelectMany(f => f.File.GetBranchesAtRevision(f.Revision))
					.Distinct()
					.Where(b => m_branches.ContainsKey(b));

			foreach (var branch in branches)
			{
				var tempCommit = new Commit("");
				foreach (var fr in commit.Where(f => f.File.GetBranchesAtRevision(f.Revision).Contains(branch)))
					tempCommit.Add(fr);
				this[branch].Apply(tempCommit);
			}
		}
Exemplo n.º 3
0
			private Commit MakeCommit(List<FileRevision> revisions, int start, int end)
			{
				var commit = new Commit(MakeCommitId(revisions[start]));

				for (int i = start; i < end; i++)
				{
					commit.Add(revisions[i]);
					// need to wait for the first revision to be added, so that the commit message is set
					if (i == start)
						m_debugLog.WriteLine("Commit {0}{1}{2}", commit.CommitId, Environment.NewLine, commit.Message);
					m_debugLog.WriteLine("  {0} r{1}", revisions[i].File.Name, revisions[i].Revision);
				}

				m_debugLog.WriteLine();
				return commit;
			}
Exemplo n.º 4
0
		private void CreateHeadOnlyCommit(string branch, BranchStreamCollection streams, FileCollection allFiles, string branchMergeFrom)
		{
			var headOnlyState = m_headOnlyState[branch];
			var commitId = String.Format("headonly-{0}", branch);
			var commit = new Commit(commitId);

			var message = String.Format("Adding head-only files to {0}", m_branchRenamer.Process(branch));

			foreach (var file in headOnlyState.LiveFiles.OrderBy(i => i, StringComparer.OrdinalIgnoreCase))
			{
				var fileRevision = new FileRevision(allFiles[file], headOnlyState[file],
						mergepoint: Revision.Empty, time: DateTime.Now, author: "", commitId: commitId);
				fileRevision.AddMessage(message);
				commit.Add(fileRevision);
			}

			// check for a merge
			if (branchMergeFrom != null)
			{
				Commit mergeSource = streams.Head(branchMergeFrom);
				if (mergeSource.CommitId.StartsWith("headonly-"))
				{
					commit.MergeFrom = mergeSource;

					// check for deleted files
					var fileLookup = new HashSet<string>(commit.Select(r => r.File.Name));
					foreach (var r in mergeSource)
					{
						if (!fileLookup.Contains(r.File.Name))
						{
							var fileRevision = new FileRevision(
									file: r.File,
									revision: Revision.Empty,   // a bit lazy, but I think we can get away with it
									mergepoint: Revision.Empty,
									time: DateTime.Now,
									author: "",
									commitId: commitId,
									isDead: true);
							fileRevision.AddMessage(message);
							commit.Add(fileRevision);
						}
					}
				}
			}

			if (commit.Any())
			{
				m_log.WriteLine("Added commit {0}", commitId);
				streams.AppendCommit(commit);
			}
		}