Пример #1
0
 private IEnumerable <ShallowCommit> TranslateMergeParents(ShallowCommit commit, Dictionary <ShallowCommit, ShallowCommit> originalMerges)
 {
     ShallowCommit[] parents = originalMerges[commit].Parents.Where(m => commitMap.ContainsKey(m.Sha)).Select(parent => commitMap[parent.Sha]).ToArray();
     if (!parents.Any())
     {
         return(commit.Parents);
     }
     // ensure to take first zipped parent
     parents[0] = commit.Parents.First();
     return(parents);
 }
Пример #2
0
        private void RewriteMerges(IRepository repo, Dictionary <ShallowCommit, ShallowCommit> originalMerges)
        {
            int count = 0;

            this.logger.Log("0% Rewriting " + originalMerges.Keys.Count + " commits", replace: true);
            repo.Refs.RewriteHistory(new RewriteHistoryOptions {
                CommitParentsRewriter = commit =>
                {
                    this.logger.Log((100 * ++count / originalMerges.Keys.Count) + "% Rewriting commit " + commit.Sha, replace: true);
                    return(TranslateMergeParents(ShallowCommit.FromCommit(commit), originalMerges).Select(p => repo.Lookup(p.Sha) as Commit));
                }
            }, originalMerges.Keys.Select(p => repo.Lookup(p.Sha) as Commit));

            // cleanup original refs
            foreach (var @ref in repo.Refs.FromGlob("refs/original/*"))
            {
                repo.Refs.Remove(@ref);
            }
        }
Пример #3
0
        private void CherryPickCommits(IRepository repo, ShallowCommit[] commits, string branchName)
        {
            this.logger.Log("Zipping branch " + branchName + "...");
            ShallowCommit previous = null;

            for (int i = 0; i < commits.Length; i++)
            {
                var original = commits[i];
                this.logger.Log((100 * (i + 1) / commits.Length) + "% Zipping commit " + original.Sha, replace: true);

                if (commitMap.ContainsKey(original.Sha))
                {
                    if (repo.Branches[branchName] == null)
                    {
                        previous = commitMap[original.Sha];
                    }
                    else
                    {
                        // FIXME This should ideally be done by rearranging the history
                        this.logger.Log("... cherry-picked");
                        previous = CherryPickCommit(repo, original);
                    }
                    continue;
                }


                if (repo.Branches[branchName] == null)
                {
                    repo.Checkout(repo.CreateBranch(branchName, (previous ?? original).Sha));

                    if (previous == null)
                    {
                        commitMap[original.Sha] = original;
                        continue;
                    }
                }

                previous = CherryPickCommit(repo, original);
                commitMap[original.Sha] = previous;
            }
        }
Пример #4
0
        private ShallowCommit CherryPickCommit(IRepository repo, ShallowCommit original)
        {
            if (this.config.DryRun)
            {
                return(original);
            }

            var commit  = repo.Lookup(original.Sha) as Commit;
            var options = new CherryPickOptions();

            if (commit.Parents.Count() > 1)
            {
                options.Mainline = 1;
            }

            try
            {
                return(ShallowCommit.FromCommit(repo.CherryPick(commit, new Signature(commit.Author.Name, commit.Author.Email, commit.Author.When), options).Commit));
            }
            catch (EmptyCommitException)
            {
                return(ShallowCommit.FromCommit(this.CommitWorktree(repo, commit)));
            }
            catch (Exception e)
            {
                if (!config.Retry)
                {
                    throw;
                }

                this.logger.Log("An error occurred: \n" + e);
                this.logger.Log("Press any key after fixing conflicts manually.", true);
                Console.ReadKey();

                return(ShallowCommit.FromCommit(this.CommitWorktree(repo, commit)));
            }
        }
Пример #5
0
 /// <summary>
 /// Returns the Sha of a commit.
 /// </summary>
 protected static string Sha(ShallowCommit commit)
 {
     return(commit.Sha);
 }