]> Nutra Git (v1) - gamesguru/git-remote-gcrypt.git/commitdiff
Implement stable sort (Lacking in POSIX)
authorroot <root@localhost>
Thu, 14 Feb 2013 00:00:00 +0000 (00:00 +0000)
committerroot <root@localhost>
Thu, 14 Feb 2013 00:00:00 +0000 (00:00 +0000)
git-remote-gcrypt

index 6f6a009db363293778b7b4c50ba41afb80975ce3..9dce8ec9b01a99dcbd59141fd8493488f0e67479 100755 (executable)
@@ -40,6 +40,12 @@ isurl() { isnull "${2%%$1://*}"; }
 
 xgrep() { command grep "$@" || : ; }
 sort_C() { LC_ALL=C command sort "$@"; }
+sort_stable_k2()
+{
+       awk '{ printf("%08d %s\n", NR, $0) }' | sort_C -k3,3 -k1,1 |
+               awk '{ print $2 " " $3 }'
+}
+
 tac() { sed '1!G;h;$!d'; }
 
 # Split $1 into $prefix_:$suffix_
@@ -437,8 +443,7 @@ do_push()
 $1
 EOF
 
-       # POSIX compat issue: sort -s (stable), but supported in bsd and gnu
-       Branchlist=$(xecho "$Branchlist" | sort_C -k2 -s | tac | uniq -s40)
+       Branchlist=$(xecho "$Branchlist" | sort_stable_k2 | tac | uniq -s40)
 
        TmpPack_Encrypted="$Localdir/tmp_pack_ENCRYPTED_.$$"
        TmpObjlist="$Localdir/tmp_packrevlist.$$"