#!/usr/bin/perl -w # # $Id: //guest/jeffery_g_smith/perforce/utils/sttop4/main/sortmeta.pl#6 $ # # StarTeam to Perforce Converter, phase IIa: sort metadata # # Copyright 1998 Perforce Software. All rights reserved. # Based on VSStoP4: # Written by James Strickland, April 1998 # Maintained by Robert Cowham, since 2000 # Updated to support StarTeam conversions: # Jeffery G. Smith, MedPlus, Inc. 2004-2005 # # This script sorts the metadata output (first step in phase II). require 5.0; use strict; use integer; use lib '.'; use convert; use Change; convert::openlog('open'); open(CHANGES, "<$convert::metadata_dir/changes.ns") or die "can't open for read: $!"; open(NEWCHANGES, ">$convert::metadata_dir/changes") or die "can't open for write: $!"; my ($index,$c,@timestamp_and_index); # read 'em in for($index=0;$c=get Change(\*CHANGES);$index++) { push(@timestamp_and_index, [ $c->timestamp, $index, $c ]); } # sort them by timestamp, then file location @timestamp_and_index = sort { ($$a[0] <=> $$b[0]) || ($$b[1] <=> $$a[1]) } @timestamp_and_index; # write 'em out my $ti; foreach $ti (@timestamp_and_index) { $$ti[2]->put(\*NEWCHANGES); } close(CHANGES); close(NEWCHANGES); unlink("$convert::metadata_dir/changes.ns"); # delete the "not sorted" version