Mercurial > public > mercurial-scm > hg
comparison mercurial/cmdutil.py @ 10055:e400a511e63a
cmdutil: extract repo dependent closures in templatekw
author | Patrick Mezard <pmezard@gmail.com> |
---|---|
date | Sun, 13 Dec 2009 18:06:23 +0100 |
parents | 1a85861f59af |
children | 1a114aca93fa |
comparison
equal
deleted
inserted
replaced
10054:1a85861f59af | 10055:e400a511e63a |
---|---|
810 def _show(self, ctx, copies, props): | 810 def _show(self, ctx, copies, props): |
811 '''show a single changeset or file revision''' | 811 '''show a single changeset or file revision''' |
812 | 812 |
813 showlist = templatekw.showlist | 813 showlist = templatekw.showlist |
814 | 814 |
815 def showparents(ctx, templ, **args): | 815 def showparents(repo, ctx, templ, **args): |
816 parents = [[('rev', p.rev()), ('node', p.hex())] | 816 parents = [[('rev', p.rev()), ('node', p.hex())] |
817 for p in self._meaningful_parentrevs(ctx)] | 817 for p in self._meaningful_parentrevs(ctx)] |
818 return showlist(templ, 'parent', parents, **args) | 818 return showlist(templ, 'parent', parents, **args) |
819 | 819 |
820 def showcopies(ctx, templ, **args): | 820 def showcopies(repo, ctx, templ, **args): |
821 c = [{'name': x[0], 'source': x[1]} for x in copies] | 821 c = [{'name': x[0], 'source': x[1]} for x in copies] |
822 return showlist(templ, 'file_copy', c, plural='file_copies', **args) | 822 return showlist(templ, 'file_copy', c, plural='file_copies', **args) |
823 | 823 |
824 files = [] | 824 files = [] |
825 def getfiles(): | 825 def getfiles(): |
826 if not files: | 826 if not files: |
827 files[:] = self.repo.status(ctx.parents()[0].node(), | 827 files[:] = self.repo.status(ctx.parents()[0].node(), |
828 ctx.node())[:3] | 828 ctx.node())[:3] |
829 return files | 829 return files |
830 def showmods(ctx, templ, **args): | 830 def showmods(repo, ctx, templ, **args): |
831 return showlist(templ, 'file_mod', getfiles()[0], **args) | 831 return showlist(templ, 'file_mod', getfiles()[0], **args) |
832 def showadds(ctx, templ, **args): | 832 def showadds(repo, ctx, templ, **args): |
833 return showlist(templ, 'file_add', getfiles()[1], **args) | 833 return showlist(templ, 'file_add', getfiles()[1], **args) |
834 def showdels(ctx, templ, **args): | 834 def showdels(repo, ctx, templ, **args): |
835 return showlist(templ, 'file_del', getfiles()[2], **args) | 835 return showlist(templ, 'file_del', getfiles()[2], **args) |
836 def showmanifest(ctx, templ, **args): | 836 |
837 args = args.copy() | 837 def showlatesttag(repo, ctx, templ, **args): |
838 args.update(dict(rev=self.repo.manifest.rev(ctx.changeset()[0]), | |
839 node=hex(ctx.changeset()[0]))) | |
840 return templ('manifest', **args) | |
841 | |
842 def showdiffstat(ctx, templ, **args): | |
843 diff = patch.diff(self.repo, ctx.parents()[0].node(), ctx.node()) | |
844 files, adds, removes = 0, 0, 0 | |
845 for i in patch.diffstatdata(util.iterlines(diff)): | |
846 files += 1 | |
847 adds += i[1] | |
848 removes += i[2] | |
849 return '%s: +%s/-%s' % (files, adds, removes) | |
850 | |
851 def showlatesttag(ctx, templ, **args): | |
852 return self._latesttaginfo(ctx.rev())[2] | 838 return self._latesttaginfo(ctx.rev())[2] |
853 def showlatesttagdistance(ctx, templ, **args): | 839 def showlatesttagdistance(repo, ctx, templ, **args): |
854 return self._latesttaginfo(ctx.rev())[1] | 840 return self._latesttaginfo(ctx.rev())[1] |
855 | 841 |
856 defprops = { | 842 defprops = { |
857 'file_adds': showadds, | 843 'file_adds': showadds, |
858 'file_dels': showdels, | 844 'file_dels': showdels, |
859 'file_mods': showmods, | 845 'file_mods': showmods, |
860 'file_copies': showcopies, | 846 'file_copies': showcopies, |
861 'manifest': showmanifest, | 847 'parents': showparents, |
862 'parents': showparents, | |
863 'diffstat': showdiffstat, | |
864 'latesttag': showlatesttag, | 848 'latesttag': showlatesttag, |
865 'latesttagdistance': showlatesttagdistance, | 849 'latesttagdistance': showlatesttagdistance, |
866 } | 850 } |
867 props = props.copy() | 851 props = props.copy() |
868 props.update(templatekw.keywords) | 852 props.update(templatekw.keywords) |
869 props.update(defprops) | 853 props.update(defprops) |
870 props['templ'] = self.t | 854 props['templ'] = self.t |
871 props['ctx'] = ctx | 855 props['ctx'] = ctx |
856 props['repo'] = self.repo | |
872 | 857 |
873 # find correct templates for current mode | 858 # find correct templates for current mode |
874 | 859 |
875 tmplmodes = [ | 860 tmplmodes = [ |
876 (True, None), | 861 (True, None), |