#!/usr/local/bin/perl # # FileLog.pl # # Written by Steve Howell, NXT Corporation, # Bethesda, MD, US, 12/28/98. # # Use this script to find all the changes in a file, including # its history in other branches. Run "FileLog.pl " to see # something that looks like the output of a "p4 filelog -l " # command. The only difference is this utility will also show # the changes that happened in other branches, in a recursive sort # of fashion. # # You should alias/soft-link/rename this to be "fl," to save some typing. # # Note to public users: # --------------------- # This code is completely free, no restrictions on reuse. Please send # me an email (showell@nxt.com) if you use the program and like it (or # don't like it). I've never written free public software before, so I # will get a huge feeling of satisfaction if only one stranger sends me # an email. # # I would love to find out about bigger and better utilities that do this # same thing. Even better, I would love for this to be added as a feature # to other utilities. # use strict; my ($file) = @ARGV; die "Please supply a file name" if not @ARGV; &history($file,"",0,undef); sub history { my ($file, $indent, $min, $max) = @_; my $hist = `p4 filelog -l $file` or die; my @revs = split '\n', $hist; my $rev; my $divider = $indent . "-------------------\n"; print $divider; print $indent . $file . "\n"; print $divider; my $tab = " " x 8; foreach $rev (@revs) { if ($rev =~ /\.\.\. \#(\d+)/) { my $num = $1; if ($max) { next if $num > $max; $max = undef; } last if $num < $min; } else { next if $max; } if ($rev =~ /\.\.\. \.\.\. copy from (.*?)(\#.*)/) { # Let's dig a little deeper. my $file = $1; my ($min,$max) = range($2); print $indent . $tab . "COPY:\n"; history($file, $tab . $indent, $min, $max); } elsif ($rev =~ /\.\.\. \.\.\. branch from (.*?)(\#.*)/) { # Let's dig a little deeper. my $file = $1; my ($min,$max) = range($2); print $indent . $tab . "BRANCH:\n"; history($file, $tab . $indent, $min, $max); } elsif ($rev =~ /\.\.\. \.\.\. merge from (.*?)(\#.*)/) { # Let's dig a little deeper. my $file = $1; my ($min,$max) = range($2); print $indent . $tab . "MERGE:\n"; history($file, $tab . $indent, $min, $max); } elsif ($rev =~ /\.\.\. \.\.\. (branch|copy|merge) into/) { # do nothing } else { # just echo output print $indent . "$rev\n"; } } print $divider; } sub range { my ($range) = @_; if ($range =~ /\#(\d+)\,\#(\d+)/) { return ($1, $2); } elsif ($range =~ /\#(\d+)/) { return ($1, $1); } else { die "Bad range"; } }