mercurial/destutil.py
changeset 28137 b54c0246295b
parent 28105 1fc7b5363871
child 28138 5ad2017454ee
equal deleted inserted replaced
28136:5853878bbc2a 28137:b54c0246295b
   135     return rev, movemark, activemark
   135     return rev, movemark, activemark
   136 
   136 
   137 msgdestmerge = {
   137 msgdestmerge = {
   138     # too many matching divergent bookmark
   138     # too many matching divergent bookmark
   139     'toomanybookmarks':
   139     'toomanybookmarks':
   140         (_("multiple matching bookmarks to merge -"
   140         {'merge':
   141            " please merge with an explicit rev or bookmark"),
   141             (_("multiple matching bookmarks to merge -"
   142          _("run 'hg heads' to see all heads")),
   142                " please merge with an explicit rev or bookmark"),
       
   143              _("run 'hg heads' to see all heads")),
       
   144         },
   143     # no other matching divergent bookmark
   145     # no other matching divergent bookmark
   144     'nootherbookmarks':
   146     'nootherbookmarks':
   145         (_("no matching bookmark to merge - "
   147         {'merge':
   146            "please merge with an explicit rev or bookmark"),
   148             (_("no matching bookmark to merge - "
   147          _("run 'hg heads' to see all heads")),
   149                "please merge with an explicit rev or bookmark"),
       
   150              _("run 'hg heads' to see all heads")),
       
   151         },
   148     # branch have too many unbookmarked heads, no obvious destination
   152     # branch have too many unbookmarked heads, no obvious destination
   149     'toomanyheads':
   153     'toomanyheads':
   150         (_("branch '%s' has %d heads - please merge with an explicit rev"),
   154         {'merge':
   151          _("run 'hg heads .' to see heads")),
   155             (_("branch '%s' has %d heads - please merge with an explicit rev"),
       
   156              _("run 'hg heads .' to see heads")),
       
   157         },
   152     # branch have no other unbookmarked heads
   158     # branch have no other unbookmarked heads
   153     'bookmarkedheads':
   159     'bookmarkedheads':
   154         (_("heads are bookmarked - please merge with an explicit rev"),
   160         {'merge':
   155          _("run 'hg heads' to see all heads")),
   161             (_("heads are bookmarked - please merge with an explicit rev"),
       
   162              _("run 'hg heads' to see all heads")),
       
   163         },
   156     # branch have just a single heads, but there is other branches
   164     # branch have just a single heads, but there is other branches
   157     'nootherbranchheads':
   165     'nootherbranchheads':
   158         (_("branch '%s' has one head - please merge with an explicit rev"),
   166         {'merge':
   159          _("run 'hg heads' to see all heads")),
   167             (_("branch '%s' has one head - please merge with an explicit rev"),
       
   168              _("run 'hg heads' to see all heads")),
       
   169         },
   160     # repository have a single head
   170     # repository have a single head
   161     'nootherheads':
   171     'nootherheads':
   162         (_('nothing to merge'),
   172             {'merge':
       
   173                 (_('nothing to merge'),
   163          None),
   174          None),
       
   175         },
   164     # repository have a single head and we are not on it
   176     # repository have a single head and we are not on it
   165     'nootherheadsbehind':
   177     'nootherheadsbehind':
   166         (_('nothing to merge'),
   178         {'merge':
   167          _("use 'hg update' instead")),
   179             (_('nothing to merge'),
       
   180              _("use 'hg update' instead")),
       
   181         },
   168     # We are not on a head
   182     # We are not on a head
   169     'notatheads':
   183     'notatheads':
   170         (_('working directory not at a head revision'),
   184         {'merge':
   171          _("use 'hg update' or merge with an explicit revision"))
   185             (_('working directory not at a head revision'),
   172         }
   186              _("use 'hg update' or merge with an explicit revision"))
   173 
   187         },
   174 def _destmergebook(repo):
   188     }
       
   189 
       
   190 def _destmergebook(repo, action='merge'):
   175     """find merge destination in the active bookmark case"""
   191     """find merge destination in the active bookmark case"""
   176     node = None
   192     node = None
   177     bmheads = repo.bookmarkheads(repo._activebookmark)
   193     bmheads = repo.bookmarkheads(repo._activebookmark)
   178     curhead = repo[repo._activebookmark].node()
   194     curhead = repo[repo._activebookmark].node()
   179     if len(bmheads) == 2:
   195     if len(bmheads) == 2:
   180         if curhead == bmheads[0]:
   196         if curhead == bmheads[0]:
   181             node = bmheads[1]
   197             node = bmheads[1]
   182         else:
   198         else:
   183             node = bmheads[0]
   199             node = bmheads[0]
   184     elif len(bmheads) > 2:
   200     elif len(bmheads) > 2:
   185         msg, hint = msgdestmerge['toomanybookmarks']
   201         msg, hint = msgdestmerge['toomanybookmarks'][action]
   186         raise error.Abort(msg, hint=hint)
   202         raise error.Abort(msg, hint=hint)
   187     elif len(bmheads) <= 1:
   203     elif len(bmheads) <= 1:
   188         msg, hint = msgdestmerge['nootherbookmarks']
   204         msg, hint = msgdestmerge['nootherbookmarks'][action]
   189         raise error.Abort(msg, hint=hint)
   205         raise error.Abort(msg, hint=hint)
   190     assert node is not None
   206     assert node is not None
   191     return node
   207     return node
   192 
   208 
   193 def _destmergebranch(repo):
   209 def _destmergebranch(repo, action='merge'):
   194     """find merge destination based on branch heads"""
   210     """find merge destination based on branch heads"""
   195     node = None
   211     node = None
   196     parent = repo.dirstate.p1()
   212     parent = repo.dirstate.p1()
   197     branch = repo.dirstate.branch()
   213     branch = repo.dirstate.branch()
   198     bheads = repo.branchheads(branch)
   214     bheads = repo.branchheads(branch)
   201     if parent not in bheads:
   217     if parent not in bheads:
   202         # Case A: working copy if not on a head.
   218         # Case A: working copy if not on a head.
   203         #
   219         #
   204         # This is probably a user mistake We bailout pointing at 'hg update'
   220         # This is probably a user mistake We bailout pointing at 'hg update'
   205         if len(repo.heads()) <= 1:
   221         if len(repo.heads()) <= 1:
   206             msg, hint = msgdestmerge['nootherheadsbehind']
   222             msg, hint = msgdestmerge['nootherheadsbehind'][action]
   207         else:
   223         else:
   208             msg, hint = msgdestmerge['notatheads']
   224             msg, hint = msgdestmerge['notatheads'][action]
   209         raise error.Abort(msg, hint=hint)
   225         raise error.Abort(msg, hint=hint)
   210     elif len(nbhs) > 2:
   226     elif len(nbhs) > 2:
   211         # Case B: There is more than 2 anonymous heads
   227         # Case B: There is more than 2 anonymous heads
   212         #
   228         #
   213         # This means that there will be more than 1 candidate. This is
   229         # This means that there will be more than 1 candidate. This is
   214         # ambiguous. We abort asking the user to pick as explicit destination
   230         # ambiguous. We abort asking the user to pick as explicit destination
   215         # instead.
   231         # instead.
   216         msg, hint = msgdestmerge['toomanyheads']
   232         msg, hint = msgdestmerge['toomanyheads'][action]
   217         msg %= (branch, len(bheads))
   233         msg %= (branch, len(bheads))
   218         raise error.Abort(msg, hint=hint)
   234         raise error.Abort(msg, hint=hint)
   219     elif len(nbhs) <= 1:
   235     elif len(nbhs) <= 1:
   220         # Case B: There is no other anonymous head that the one we are one
   236         # Case B: There is no other anonymous head that the one we are one
   221         #
   237         #
   222         # This means that there is no natural candidate to merge with.
   238         # This means that there is no natural candidate to merge with.
   223         # We abort, with various messages for various cases.
   239         # We abort, with various messages for various cases.
   224         if len(bheads) > 1:
   240         if len(bheads) > 1:
   225             msg, hint = msgdestmerge['bookmarkedheads']
   241             msg, hint = msgdestmerge['bookmarkedheads'][action]
   226         elif len(repo.heads()) > 1:
   242         elif len(repo.heads()) > 1:
   227             msg, hint = msgdestmerge['nootherbranchheads']
   243             msg, hint = msgdestmerge['nootherbranchheads'][action]
   228             msg %= branch
   244             msg %= branch
   229         else:
   245         else:
   230             msg, hint = msgdestmerge['nootherheads']
   246             msg, hint = msgdestmerge['nootherheads'][action]
   231         raise error.Abort(msg, hint=hint)
   247         raise error.Abort(msg, hint=hint)
   232     elif parent == nbhs[0]:
   248     elif parent == nbhs[0]:
   233         node = nbhs[-1]
   249         node = nbhs[-1]
   234     else:
   250     else:
   235         node = nbhs[0]
   251         node = nbhs[0]
   236     assert node is not None
   252     assert node is not None
   237     return node
   253     return node
   238 
   254 
   239 def destmerge(repo):
   255 def destmerge(repo, action='merge'):
       
   256     """return the default destination for a merge
       
   257 
       
   258     (or raise exception about why it can't pick one)
       
   259 
       
   260     :action: the action being performed, controls emitted error message
       
   261     """
   240     if repo._activebookmark:
   262     if repo._activebookmark:
   241         node = _destmergebook(repo)
   263         node = _destmergebook(repo, action=action)
   242     else:
   264     else:
   243         node = _destmergebranch(repo)
   265         node = _destmergebranch(repo, action=action)
   244     return repo[node].rev()
   266     return repo[node].rev()
   245 
   267 
   246 histeditdefaultrevset = 'reverse(only(.) and not public() and not ::merge())'
   268 histeditdefaultrevset = 'reverse(only(.) and not public() and not ::merge())'
   247 
   269 
   248 def desthistedit(ui, repo):
   270 def desthistedit(ui, repo):