Kiln » TortoiseHg » TortoiseHg
Clone URL:  
Pushed to one repository · View In Graph Contained in 2.0, 2.0.1, and 2.0.2

stable status: Sort files in two passes: Sort by ascending path then sort by column

Until now the files in the status dialog could be sorted by checked state,
status, filename, extension or size. However, when sorting by extension, the
order of the files with the same extension was unspecified (same thing happened
when sorting by size or by checked state).

This patch fixes that problem by sorting in two passes:
1. Sort the list by file path (alphabetically, in ascending order)
2. Sort by the selected sort column

Changeset 5bf7eb26713e

Parent 171ee1daf089

by Angel Ezquerra

Changes to one file · Browse files at 5bf7eb26713e Showing diff from parent 171ee1daf089 Diff from another changeset...

 
628
629
630
631
632
633
634
635
636
637
638
639
640
641
 
 
 
 
 
 
 
 
 
 
 
 
642
643
 
 
 
 
644
645
 
 
 
 
 
 
 
 
 
 
 
 
 
 
646
647
648
 
628
629
630
 
 
 
 
 
 
 
 
 
 
 
631
632
633
634
635
636
637
638
639
640
641
642
643
 
644
645
646
647
648
 
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
@@ -628,21 +628,38 @@
    return rank   - if col == COL_PATH: - c = self.checked - self.rows.sort(lambda x, y: cmp(c[x[col]], c[y[col]])) - elif col == COL_STATUS: - # We want to sort the list by status, and then, for files which have - # the same status, we want them to be sorted alphabetically (without - # taking into account the case) - # Since since Python 2.3 the sort function is guaranteed to be - # stable, we can do that by sorting in two passes (first sort by - # path and then by status) - self.rows.sort(lambda x, y: \ + # We want to sort the list by one of the columns (checked state, + # mercurial status, file path, file extension, etc) + # However, for files which have the same status or extension, etc, + # we want them to be sorted alphabetically (without taking into account + # the case) + # Since Python 2.3 the sort function is guaranteed to be stable. + # Thus we can perform the sort in two passes: + # 1.- Perform a secondary sort by path + # 2.- Perform a primary sort by the actual column that we are sorting on + + # Secondary sort: + self.rows.sort(lambda x, y: \   cmp(x[COL_PATH].lower(), y[COL_PATH].lower())) - self.rows.sort(key=lambda x: getStatusRank(x[col])) + + if col == COL_PATH_DISPLAY: + # Already sorted! + pass   else: - self.rows.sort(lambda x, y: cmp(x[col], y[col])) + if order == Qt.DescendingOrder: + # We want the secondary sort to be by _ascending_ path, + # even when the primary sort is in descending order + self.rows.reverse() + + # Now we can perform the primary sort + if col == COL_PATH: + c = self.checked + self.rows.sort(lambda x, y: cmp(c[x[col]], c[y[col]])) + elif col == COL_STATUS: + self.rows.sort(key=lambda x: getStatusRank(x[col])) + else: + self.rows.sort(lambda x, y: cmp(x[col], y[col])) +   if order == Qt.DescendingOrder:   self.rows.reverse()   self.layoutChanged.emit()