laullon/gitx

fix for sorting of stashes

Closed this issue · 2 comments

Hi,

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

- (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.

ebertech@48a7d85

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.

don't worry, make a pull request, I'll test it

done and done