mercurial/logcmdutil.py
changeset 41097 6a63ba61e71f
parent 40285 96164fb9b913
child 41610 d683aca738cd
equal deleted inserted replaced
41096:f8f61cf246f5 41097:6a63ba61e71f
    53     else:
    53     else:
    54         limit = None
    54         limit = None
    55     return limit
    55     return limit
    56 
    56 
    57 def diffordiffstat(ui, repo, diffopts, node1, node2, match,
    57 def diffordiffstat(ui, repo, diffopts, node1, node2, match,
    58                    changes=None, stat=False, fp=None, prefix='',
    58                    changes=None, stat=False, fp=None, graphwidth=0,
    59                    root='', listsubrepos=False, hunksfilterfn=None):
    59                    prefix='', root='', listsubrepos=False, hunksfilterfn=None):
    60     '''show diff or diffstat.'''
    60     '''show diff or diffstat.'''
    61     if root:
    61     if root:
    62         relroot = pathutil.canonpath(repo.root, repo.getcwd(), root)
    62         relroot = pathutil.canonpath(repo.root, repo.getcwd(), root)
    63     else:
    63     else:
    64         relroot = ''
    64         relroot = ''
    74 
    74 
    75     if stat:
    75     if stat:
    76         diffopts = diffopts.copy(context=0, noprefix=False)
    76         diffopts = diffopts.copy(context=0, noprefix=False)
    77         width = 80
    77         width = 80
    78         if not ui.plain():
    78         if not ui.plain():
    79             width = ui.termwidth()
    79             width = ui.termwidth() - graphwidth
    80 
    80 
    81     chunks = repo[node2].diff(repo[node1], match, changes, opts=diffopts,
    81     chunks = repo[node2].diff(repo[node1], match, changes, opts=diffopts,
    82                               prefix=prefix, relroot=relroot,
    82                               prefix=prefix, relroot=relroot,
    83                               hunksfilterfn=hunksfilterfn)
    83                               hunksfilterfn=hunksfilterfn)
    84 
    84 
   128         return scmutil.matchall(ctx.repo())
   128         return scmutil.matchall(ctx.repo())
   129 
   129 
   130     def _makehunksfilter(self, ctx):
   130     def _makehunksfilter(self, ctx):
   131         return None
   131         return None
   132 
   132 
   133     def showdiff(self, ui, ctx, diffopts, stat=False):
   133     def showdiff(self, ui, ctx, diffopts, graphwidth=0, stat=False):
   134         repo = ctx.repo()
   134         repo = ctx.repo()
   135         node = ctx.node()
   135         node = ctx.node()
   136         prev = ctx.p1().node()
   136         prev = ctx.p1().node()
   137         diffordiffstat(ui, repo, diffopts, prev, node,
   137         diffordiffstat(ui, repo, diffopts, prev, node,
   138                        match=self._makefilematcher(ctx), stat=stat,
   138                        match=self._makefilematcher(ctx), stat=stat,
       
   139                        graphwidth=graphwidth,
   139                        hunksfilterfn=self._makehunksfilter(ctx))
   140                        hunksfilterfn=self._makehunksfilter(ctx))
   140 
   141 
   141 def changesetlabels(ctx):
   142 def changesetlabels(ctx):
   142     labels = ['log.changeset', 'changeset.%s' % ctx.phasestr()]
   143     labels = ['log.changeset', 'changeset.%s' % ctx.phasestr()]
   143     if ctx.obsolete():
   144     if ctx.obsolete():
   191             self._show(ctx, copies, props)
   192             self._show(ctx, copies, props)
   192 
   193 
   193     def _show(self, ctx, copies, props):
   194     def _show(self, ctx, copies, props):
   194         '''show a single changeset or file revision'''
   195         '''show a single changeset or file revision'''
   195         changenode = ctx.node()
   196         changenode = ctx.node()
       
   197         graphwidth = props.get('graphwidth', 0)
   196 
   198 
   197         if self.ui.quiet:
   199         if self.ui.quiet:
   198             self.ui.write("%s\n" % scmutil.formatchangeid(ctx),
   200             self.ui.write("%s\n" % scmutil.formatchangeid(ctx),
   199                           label='log.node')
   201                           label='log.node')
   200             return
   202             return
   283             else:
   285             else:
   284                 self.ui.write(columns['summary'] % description.splitlines()[0],
   286                 self.ui.write(columns['summary'] % description.splitlines()[0],
   285                               label='log.summary')
   287                               label='log.summary')
   286         self.ui.write("\n")
   288         self.ui.write("\n")
   287 
   289 
   288         self._showpatch(ctx)
   290         self._showpatch(ctx, graphwidth)
   289 
   291 
   290     def _showobsfate(self, ctx):
   292     def _showobsfate(self, ctx):
   291         # TODO: do not depend on templater
   293         # TODO: do not depend on templater
   292         tres = formatter.templateresources(self.repo.ui, self.repo)
   294         tres = formatter.templateresources(self.repo.ui, self.repo)
   293         t = formatter.maketemplater(self.repo.ui, '{join(obsfate, "\n")}',
   295         t = formatter.maketemplater(self.repo.ui, '{join(obsfate, "\n")}',
   302 
   304 
   303     def _exthook(self, ctx):
   305     def _exthook(self, ctx):
   304         '''empty method used by extension as a hook point
   306         '''empty method used by extension as a hook point
   305         '''
   307         '''
   306 
   308 
   307     def _showpatch(self, ctx):
   309     def _showpatch(self, ctx, graphwidth=0):
   308         if self._includestat:
   310         if self._includestat:
   309             self._differ.showdiff(self.ui, ctx, self._diffopts, stat=True)
   311             self._differ.showdiff(self.ui, ctx, self._diffopts,
       
   312                                   graphwidth, stat=True)
   310         if self._includestat and self._includediff:
   313         if self._includestat and self._includediff:
   311             self.ui.write("\n")
   314             self.ui.write("\n")
   312         if self._includediff:
   315         if self._includediff:
   313             self._differ.showdiff(self.ui, ctx, self._diffopts, stat=False)
   316             self._differ.showdiff(self.ui, ctx, self._diffopts,
       
   317                                   graphwidth, stat=False)
   314         if self._includestat or self._includediff:
   318         if self._includestat or self._includediff:
   315             self.ui.write("\n")
   319             self.ui.write("\n")
   316 
   320 
   317 class changesetformatter(changesetprinter):
   321 class changesetformatter(changesetprinter):
   318     """Format changeset information by generic formatter"""
   322     """Format changeset information by generic formatter"""
   431         '''show a single changeset or file revision'''
   435         '''show a single changeset or file revision'''
   432         props = props.copy()
   436         props = props.copy()
   433         props['ctx'] = ctx
   437         props['ctx'] = ctx
   434         props['index'] = index = next(self._counter)
   438         props['index'] = index = next(self._counter)
   435         props['revcache'] = {'copies': copies}
   439         props['revcache'] = {'copies': copies}
       
   440         graphwidth = props.get('graphwidth', 0)
   436 
   441 
   437         # write separator, which wouldn't work well with the header part below
   442         # write separator, which wouldn't work well with the header part below
   438         # since there's inherently a conflict between header (across items) and
   443         # since there's inherently a conflict between header (across items) and
   439         # separator (per item)
   444         # separator (per item)
   440         if self._parts['separator'] and index > 0:
   445         if self._parts['separator'] and index > 0:
   451                     self.ui.write(h)
   456                     self.ui.write(h)
   452 
   457 
   453         # write changeset metadata, then patch if requested
   458         # write changeset metadata, then patch if requested
   454         key = self._parts[self._tref]
   459         key = self._parts[self._tref]
   455         self.ui.write(self.t.render(key, props))
   460         self.ui.write(self.t.render(key, props))
   456         self._showpatch(ctx)
   461         self._showpatch(ctx, graphwidth)
   457 
   462 
   458         if self._parts['footer']:
   463         if self._parts['footer']:
   459             if not self.footer:
   464             if not self.footer:
   460                 self.footer = self.t.render(self._parts['footer'], props)
   465                 self.footer = self.t.render(self._parts['footer'], props)
   461 
   466