# HG changeset patch # User Pulkit Goyal <7895pulkit@gmail.com> # Date 1528711723 -19800 # Node ID cb45a7173e5b6f345cd2440de6da86df802819b6 # Parent c58ebf5d2f57e7b334b43bff5a02ccaa82b9fb82 evolve: factor out logic to merge branches in separate function This patch moves the logic to merge branches while resolving content-divergence to a separate function. This makes code clear and better to understand. diff -r c58ebf5d2f57 -r cb45a7173e5b hgext3rd/evolve/evolvecmd.py --- a/hgext3rd/evolve/evolvecmd.py Mon Jun 11 01:00:57 2018 +0530 +++ b/hgext3rd/evolve/evolvecmd.py Mon Jun 11 15:38:43 2018 +0530 @@ -525,35 +525,9 @@ # interrupted evolve evolvestate.delete() - divbranch = divergent.branch() - basebranch = base.branch() - othbranch = other.branch() - # content divergent changes were on different branches, ask user to - # select one - if divbranch != othbranch: - - if basebranch == othbranch and basebranch != divbranch: - # we will be amending the divergent changeset so branch will be - # preserved - pass - elif basebranch == divbranch and basebranch != othbranch: - repo.dirstate.setbranch(othbranch) - else: - # all the three branches are different - index = ui.promptchoice(_("content divergent changesets on " - "different branches.\nchoose branch" - " for the resolution changeset. (a) " - "%s or (b) %s or (c) %s? $$ &a $$ &b" - " $$ &c") % - (basebranch, divbranch, othbranch), 0) - - if index == 0: - repo.dirstate.setbranch(basebranch) - elif index == 1: - pass - elif index == 2: - repo.dirstate.setbranch(othbranch) - + # merge the branches + mergebranches(repo, divergent, other, base) + # merge the commit messages desc, conflicts = mergecommitmessages(base.description(), divergent.description(), other.description()) @@ -590,6 +564,43 @@ finally: repo.ui.restoreconfig(emtpycommitallowed) +def mergebranches(repo, divergent, other, base): + """merges the branch information for content-divergent changesets and sets + the dirstate branch accordingly + If unable to merge, prompts user to select a branch + + If the branch name is different from the branch of divergent changeset, it + sets the current branch using repo.dirstate.setbranch() + """ + divbranch = divergent.branch() + basebranch = base.branch() + othbranch = other.branch() + # content divergent changes were on different branches, ask user to + # select one + if divbranch != othbranch: + + if basebranch == othbranch and basebranch != divbranch: + # we will be amending the divergent changeset so branch will be + # preserved + pass + elif basebranch == divbranch and basebranch != othbranch: + repo.dirstate.setbranch(othbranch) + else: + # all the three branches are different + index = repo.ui.promptchoice(_("content divergent changesets on " + "different branches.\nchoose branch" + " for the resolution changeset. (a) " + "%s or (b) %s or (c) %s? $$ &a $$ &b" + " $$ &c") % + (basebranch, divbranch, othbranch), 0) + + if index == 0: + repo.dirstate.setbranch(basebranch) + elif index == 1: + pass + elif index == 2: + repo.dirstate.setbranch(othbranch) + def mergecommitmessages(basedesc, divdesc, othdesc): """merges the commit messages and return the new merged message and whether there were conflicts or not while merging the messages"""