Mercurial > public > mercurial-scm > hg
comparison mercurial/commands.py @ 22926:2d0b60b5abc0
summary: make status code more readable
In commands.summary(), we currently zip a list of labels with a list
of statuses. This means the order of the status list has to match the
list of the labels, which in turn means the status elements have to be
inserted into specific places in the list. Let's instead group the
labels and status data we want to display in a single list of pairs.
author | Martin von Zweigbergk <martinvonz@gmail.com> |
---|---|
date | Fri, 03 Oct 2014 09:29:48 -0700 |
parents | 3d51e756b1ec |
children | 8792ac090e3b |
comparison
equal
deleted
inserted
replaced
22925:68df36ce3d8a | 22926:2d0b60b5abc0 |
---|---|
5785 ui.write(' [%s]' % current, label='bookmarks.current') | 5785 ui.write(' [%s]' % current, label='bookmarks.current') |
5786 for m in marks: | 5786 for m in marks: |
5787 ui.write(' ' + m, label='log.bookmark') | 5787 ui.write(' ' + m, label='log.bookmark') |
5788 ui.write('\n', label='log.bookmark') | 5788 ui.write('\n', label='log.bookmark') |
5789 | 5789 |
5790 st = list(repo.status(unknown=True))[:5] | 5790 status = repo.status(unknown=True) |
5791 | 5791 |
5792 c = repo.dirstate.copies() | 5792 c = repo.dirstate.copies() |
5793 copied, renamed = [], [] | 5793 copied, renamed = [], [] |
5794 for d, s in c.iteritems(): | 5794 for d, s in c.iteritems(): |
5795 if s in st[2]: | 5795 if s in status.removed: |
5796 st[2].remove(s) | 5796 status.removed.remove(s) |
5797 renamed.append(d) | 5797 renamed.append(d) |
5798 else: | 5798 else: |
5799 copied.append(d) | 5799 copied.append(d) |
5800 if d in st[1]: | 5800 if d in status.added: |
5801 st[1].remove(d) | 5801 status.added.remove(d) |
5802 st.insert(3, renamed) | |
5803 st.insert(4, copied) | |
5804 | 5802 |
5805 ms = mergemod.mergestate(repo) | 5803 ms = mergemod.mergestate(repo) |
5806 st.append([f for f in ms if ms[f] == 'u']) | 5804 unresolved = [f for f in ms if ms[f] == 'u'] |
5807 | 5805 |
5808 subs = [s for s in ctx.substate if ctx.sub(s).dirty()] | 5806 subs = [s for s in ctx.substate if ctx.sub(s).dirty()] |
5809 st.append(subs) | 5807 |
5810 | 5808 labels = [(ui.label(_('%d modified'), 'status.modified'), status.modified), |
5811 labels = [ui.label(_('%d modified'), 'status.modified'), | 5809 (ui.label(_('%d added'), 'status.added'), status.added), |
5812 ui.label(_('%d added'), 'status.added'), | 5810 (ui.label(_('%d removed'), 'status.removed'), status.removed), |
5813 ui.label(_('%d removed'), 'status.removed'), | 5811 (ui.label(_('%d renamed'), 'status.copied'), renamed), |
5814 ui.label(_('%d renamed'), 'status.copied'), | 5812 (ui.label(_('%d copied'), 'status.copied'), copied), |
5815 ui.label(_('%d copied'), 'status.copied'), | 5813 (ui.label(_('%d deleted'), 'status.deleted'), status.deleted), |
5816 ui.label(_('%d deleted'), 'status.deleted'), | 5814 (ui.label(_('%d unknown'), 'status.unknown'), status.unknown), |
5817 ui.label(_('%d unknown'), 'status.unknown'), | 5815 (ui.label(_('%d unresolved'), 'resolve.unresolved'), unresolved), |
5818 ui.label(_('%d unresolved'), 'resolve.unresolved'), | 5816 (ui.label(_('%d subrepos'), 'status.modified'), subs)] |
5819 ui.label(_('%d subrepos'), 'status.modified')] | |
5820 t = [] | 5817 t = [] |
5821 for s, l in zip(st, labels): | 5818 for l, s in labels: |
5822 if s: | 5819 if s: |
5823 t.append(l % len(s)) | 5820 t.append(l % len(s)) |
5824 | 5821 |
5825 t = ', '.join(t) | 5822 t = ', '.join(t) |
5826 cleanworkdir = False | 5823 cleanworkdir = False |
5832 elif branch != parents[0].branch(): | 5829 elif branch != parents[0].branch(): |
5833 t += _(' (new branch)') | 5830 t += _(' (new branch)') |
5834 elif (parents[0].closesbranch() and | 5831 elif (parents[0].closesbranch() and |
5835 pnode in repo.branchheads(branch, closed=True)): | 5832 pnode in repo.branchheads(branch, closed=True)): |
5836 t += _(' (head closed)') | 5833 t += _(' (head closed)') |
5837 elif not (st[0] or st[1] or st[2] or st[3] or st[4] or st[8]): | 5834 elif not (status.modified or status.added or status.removed or renamed or |
5835 copied or subs): | |
5838 t += _(' (clean)') | 5836 t += _(' (clean)') |
5839 cleanworkdir = True | 5837 cleanworkdir = True |
5840 elif pnode not in bheads: | 5838 elif pnode not in bheads: |
5841 t += _(' (new branch head)') | 5839 t += _(' (new branch head)') |
5842 | 5840 |