laullon/gitx — Issue #158: fix for sorting of stashes
Author: ebertech
Created: 2012-02-22 01:10:40+00:00
State: open

Hi,

Stashes don't sort properly for me. I think the reason is that the view calls

```objc
- (void)addChild:(PBSourceViewItem *)child
{
if (!child)
return;

[self.children addObject:child];
child.parent = self;
// the line below is the culprit
[self.children sortUsingDescriptors:[NSArray arrayWithObject:[[NSSortDescriptor alloc] initWithKey:@"title" ascending:YES selector:@selector(localizedCaseInsensitiveCompare:)]]];
}
```

This sorts the stash using string comparisons on the title which will sort based on the first character of the message of the stash.

I'm on Snow Leopard so the master branch doesn't compile for me but I branched off a commit from December 2011 and it built. Either way, the change is really small.

https://github.com/ebertech/gitx/commit/48a7d852afabb3b7488c6f62896a94d1f03a45c9

Basically, I omitted the sorting of the elements after they are added to the view. Just for my preference, I changed the format of the displayed name to be:

```
stash@{1}: name
```

I was going to leave it at that but the without changing the sorting order but the problem is once you get to > 10 stashes it'll still be doing string sorting. I also could have parsed the resulting name but I figured that just adds useless overhead since the list is already sorted when it comes in from git. Instead of adding yet another attribute, I figured it was easier to just not sort and leave the items in their natural order which the git command returns.

I'm also not submitting this as a full pull request because I can't test on Lion so I don't want to break anything but the changes look so minor I don't think they should break anything.