[svn.haxx.se] · SVN Dev · SVN Users · SVN Org · TSVN Dev · TSVN Users · Subclipse Dev · Subclipse Users · this month's index

Re: svn list - sorting (natural sort)

From: Ryan Schmidt <subversion-2004_at_ryandesign.com>
Date: 2005-02-06 18:59:27 CET

On 06.02.2005, at 00:46, allan juul wrote:

> is there a way to tweak the sort order of a "svn list URL" ?
>
> our tagging are basically numbers:
>
> module/v_1
> module/v_3
> module/v_20
> module/v_112
>
> the above list will be sorted like this :
>
> module/v_1
> module/v_112
> module/v_20
> module/v_3
>
> it's not the greatest issue, but would sometimes be nice to be able to
> supply a "sort-by" option on the command line.

I think the "Unix way" would be to pipe the output of "svn list URL" to
a separate sorting program.

The man page for "sort" didn't hint at a way to get it to do
natural-order sorting, so here's a PHP script you can pipe your output
through:

#!/usr/local/bin/php
<?php

$lines = array();
while (($line = fgets(STDIN, 1024)) !== false) {
        $lines[] = $line;
}

usort($lines, 'strnatcmp');

echo implode($lines, '');

?>

This doesn't have "sort"'s nice ability to specify which
space-delimited field to sort on, but that could of course be added.

You could undoubtedly write a similar script in Perl or Ruby or C or
any other language you like; I just happen to like PHP.

Ways to do this in Perl, Ruby and C are available here:

http://sourcefrog.net/projects/natsort/

(Yes, SourceFrog, not SourceForge.)

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@subversion.tigris.org
For additional commands, e-mail: users-help@subversion.tigris.org
Received on Sun Feb 6 19:02:30 2005

This is an archived mail posted to the Subversion Users mailing list.

This site is subject to the Apache Privacy Policy and the Apache Public Forum Archive Policy.