williamr/summarise_hg_status.pl
author William Roberts <williamr@symbian.org>
Fri, 17 Jul 2009 15:16:08 +0100
changeset 17 4ed8ba809509
child 19 54785ea4cd2e
permissions -rw-r--r--
Add utility to summarise the hg status output across multiple packages
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
17
4ed8ba809509 Add utility to summarise the hg status output across multiple packages
William Roberts <williamr@symbian.org>
parents:
diff changeset
     1
#! perl
4ed8ba809509 Add utility to summarise the hg status output across multiple packages
William Roberts <williamr@symbian.org>
parents:
diff changeset
     2
4ed8ba809509 Add utility to summarise the hg status output across multiple packages
William Roberts <williamr@symbian.org>
parents:
diff changeset
     3
# Copyright (c) 2009 Symbian Foundation Ltd
4ed8ba809509 Add utility to summarise the hg status output across multiple packages
William Roberts <williamr@symbian.org>
parents:
diff changeset
     4
# This component and the accompanying materials are made available
4ed8ba809509 Add utility to summarise the hg status output across multiple packages
William Roberts <williamr@symbian.org>
parents:
diff changeset
     5
# under the terms of the License "Eclipse Public License v1.0"
4ed8ba809509 Add utility to summarise the hg status output across multiple packages
William Roberts <williamr@symbian.org>
parents:
diff changeset
     6
# which accompanies this distribution, and is available
4ed8ba809509 Add utility to summarise the hg status output across multiple packages
William Roberts <williamr@symbian.org>
parents:
diff changeset
     7
# at the URL "http://www.eclipse.org/legal/epl-v10.html".
4ed8ba809509 Add utility to summarise the hg status output across multiple packages
William Roberts <williamr@symbian.org>
parents:
diff changeset
     8
#
4ed8ba809509 Add utility to summarise the hg status output across multiple packages
William Roberts <williamr@symbian.org>
parents:
diff changeset
     9
# Initial Contributors:
4ed8ba809509 Add utility to summarise the hg status output across multiple packages
William Roberts <williamr@symbian.org>
parents:
diff changeset
    10
# Symbian Foundation Ltd - initial contribution.
4ed8ba809509 Add utility to summarise the hg status output across multiple packages
William Roberts <williamr@symbian.org>
parents:
diff changeset
    11
# 
4ed8ba809509 Add utility to summarise the hg status output across multiple packages
William Roberts <williamr@symbian.org>
parents:
diff changeset
    12
# Contributors:
4ed8ba809509 Add utility to summarise the hg status output across multiple packages
William Roberts <williamr@symbian.org>
parents:
diff changeset
    13
#
4ed8ba809509 Add utility to summarise the hg status output across multiple packages
William Roberts <williamr@symbian.org>
parents:
diff changeset
    14
# Description:
4ed8ba809509 Add utility to summarise the hg status output across multiple packages
William Roberts <williamr@symbian.org>
parents:
diff changeset
    15
# Summarise the "clone_all_packages.pl -exec -- hg status --rev a --rev b" output
4ed8ba809509 Add utility to summarise the hg status output across multiple packages
William Roberts <williamr@symbian.org>
parents:
diff changeset
    16
4ed8ba809509 Add utility to summarise the hg status output across multiple packages
William Roberts <williamr@symbian.org>
parents:
diff changeset
    17
use strict;
4ed8ba809509 Add utility to summarise the hg status output across multiple packages
William Roberts <williamr@symbian.org>
parents:
diff changeset
    18
4ed8ba809509 Add utility to summarise the hg status output across multiple packages
William Roberts <williamr@symbian.org>
parents:
diff changeset
    19
my %listings;
4ed8ba809509 Add utility to summarise the hg status output across multiple packages
William Roberts <williamr@symbian.org>
parents:
diff changeset
    20
my $current_repo = "";
4ed8ba809509 Add utility to summarise the hg status output across multiple packages
William Roberts <williamr@symbian.org>
parents:
diff changeset
    21
my @filelist = ();
4ed8ba809509 Add utility to summarise the hg status output across multiple packages
William Roberts <williamr@symbian.org>
parents:
diff changeset
    22
4ed8ba809509 Add utility to summarise the hg status output across multiple packages
William Roberts <williamr@symbian.org>
parents:
diff changeset
    23
sub record_file($$)
4ed8ba809509 Add utility to summarise the hg status output across multiple packages
William Roberts <williamr@symbian.org>
parents:
diff changeset
    24
  {
4ed8ba809509 Add utility to summarise the hg status output across multiple packages
William Roberts <williamr@symbian.org>
parents:
diff changeset
    25
  my ($file, $change) = @_;
4ed8ba809509 Add utility to summarise the hg status output across multiple packages
William Roberts <williamr@symbian.org>
parents:
diff changeset
    26
  
4ed8ba809509 Add utility to summarise the hg status output across multiple packages
William Roberts <williamr@symbian.org>
parents:
diff changeset
    27
  next if ($file eq ".hgtags");
4ed8ba809509 Add utility to summarise the hg status output across multiple packages
William Roberts <williamr@symbian.org>
parents:
diff changeset
    28
  push @filelist, "$file$change";
4ed8ba809509 Add utility to summarise the hg status output across multiple packages
William Roberts <williamr@symbian.org>
parents:
diff changeset
    29
  return;
4ed8ba809509 Add utility to summarise the hg status output across multiple packages
William Roberts <williamr@symbian.org>
parents:
diff changeset
    30
  }
4ed8ba809509 Add utility to summarise the hg status output across multiple packages
William Roberts <williamr@symbian.org>
parents:
diff changeset
    31
4ed8ba809509 Add utility to summarise the hg status output across multiple packages
William Roberts <williamr@symbian.org>
parents:
diff changeset
    32
sub finished_repo()
4ed8ba809509 Add utility to summarise the hg status output across multiple packages
William Roberts <williamr@symbian.org>
parents:
diff changeset
    33
  {
4ed8ba809509 Add utility to summarise the hg status output across multiple packages
William Roberts <williamr@symbian.org>
parents:
diff changeset
    34
  if ($current_repo ne "" && scalar @filelist > 0)
4ed8ba809509 Add utility to summarise the hg status output across multiple packages
William Roberts <williamr@symbian.org>
parents:
diff changeset
    35
    {
4ed8ba809509 Add utility to summarise the hg status output across multiple packages
William Roberts <williamr@symbian.org>
parents:
diff changeset
    36
    $current_repo =~ s/^.*CL\/sf/sf/; # remove leading MCL or FCL stuff
4ed8ba809509 Add utility to summarise the hg status output across multiple packages
William Roberts <williamr@symbian.org>
parents:
diff changeset
    37
    @{$listings{$current_repo}} = sort @filelist;
4ed8ba809509 Add utility to summarise the hg status output across multiple packages
William Roberts <williamr@symbian.org>
parents:
diff changeset
    38
    # printf STDERR "* %s %d\n", $current_repo, scalar @filelist;
4ed8ba809509 Add utility to summarise the hg status output across multiple packages
William Roberts <williamr@symbian.org>
parents:
diff changeset
    39
    }
4ed8ba809509 Add utility to summarise the hg status output across multiple packages
William Roberts <williamr@symbian.org>
parents:
diff changeset
    40
  @filelist = ();
4ed8ba809509 Add utility to summarise the hg status output across multiple packages
William Roberts <williamr@symbian.org>
parents:
diff changeset
    41
  $current_repo = "";
4ed8ba809509 Add utility to summarise the hg status output across multiple packages
William Roberts <williamr@symbian.org>
parents:
diff changeset
    42
  }
4ed8ba809509 Add utility to summarise the hg status output across multiple packages
William Roberts <williamr@symbian.org>
parents:
diff changeset
    43
  
4ed8ba809509 Add utility to summarise the hg status output across multiple packages
William Roberts <williamr@symbian.org>
parents:
diff changeset
    44
my $line;
4ed8ba809509 Add utility to summarise the hg status output across multiple packages
William Roberts <williamr@symbian.org>
parents:
diff changeset
    45
while ($line = <>)
4ed8ba809509 Add utility to summarise the hg status output across multiple packages
William Roberts <williamr@symbian.org>
parents:
diff changeset
    46
  {
4ed8ba809509 Add utility to summarise the hg status output across multiple packages
William Roberts <williamr@symbian.org>
parents:
diff changeset
    47
  # Processing sfl/MCL/sf/app/imgvieweruis...
4ed8ba809509 Add utility to summarise the hg status output across multiple packages
William Roberts <williamr@symbian.org>
parents:
diff changeset
    48
  if ($line =~ /^Processing (.*)\.\.\./)
4ed8ba809509 Add utility to summarise the hg status output across multiple packages
William Roberts <williamr@symbian.org>
parents:
diff changeset
    49
    {
4ed8ba809509 Add utility to summarise the hg status output across multiple packages
William Roberts <williamr@symbian.org>
parents:
diff changeset
    50
    finished_repo();
4ed8ba809509 Add utility to summarise the hg status output across multiple packages
William Roberts <williamr@symbian.org>
parents:
diff changeset
    51
    $current_repo = $1;
4ed8ba809509 Add utility to summarise the hg status output across multiple packages
William Roberts <williamr@symbian.org>
parents:
diff changeset
    52
    next;
4ed8ba809509 Add utility to summarise the hg status output across multiple packages
William Roberts <williamr@symbian.org>
parents:
diff changeset
    53
    }
4ed8ba809509 Add utility to summarise the hg status output across multiple packages
William Roberts <williamr@symbian.org>
parents:
diff changeset
    54
  # abort: unknown revision 'PDK_2.0.c'!
4ed8ba809509 Add utility to summarise the hg status output across multiple packages
William Roberts <williamr@symbian.org>
parents:
diff changeset
    55
  if ($line =~ /^abort/)
4ed8ba809509 Add utility to summarise the hg status output across multiple packages
William Roberts <williamr@symbian.org>
parents:
diff changeset
    56
    {
4ed8ba809509 Add utility to summarise the hg status output across multiple packages
William Roberts <williamr@symbian.org>
parents:
diff changeset
    57
    # ignore the current repo, as it probably didn't have the right tag
4ed8ba809509 Add utility to summarise the hg status output across multiple packages
William Roberts <williamr@symbian.org>
parents:
diff changeset
    58
    $current_repo = "";
4ed8ba809509 Add utility to summarise the hg status output across multiple packages
William Roberts <williamr@symbian.org>
parents:
diff changeset
    59
    next;
4ed8ba809509 Add utility to summarise the hg status output across multiple packages
William Roberts <williamr@symbian.org>
parents:
diff changeset
    60
    }
4ed8ba809509 Add utility to summarise the hg status output across multiple packages
William Roberts <williamr@symbian.org>
parents:
diff changeset
    61
  if ($line =~ /^([MARC]) (\S.*\S)\s*$/)
4ed8ba809509 Add utility to summarise the hg status output across multiple packages
William Roberts <williamr@symbian.org>
parents:
diff changeset
    62
    {
4ed8ba809509 Add utility to summarise the hg status output across multiple packages
William Roberts <williamr@symbian.org>
parents:
diff changeset
    63
    my $change = $1;
4ed8ba809509 Add utility to summarise the hg status output across multiple packages
William Roberts <williamr@symbian.org>
parents:
diff changeset
    64
    my $file = $2;
4ed8ba809509 Add utility to summarise the hg status output across multiple packages
William Roberts <williamr@symbian.org>
parents:
diff changeset
    65
    record_file($file, $change);
4ed8ba809509 Add utility to summarise the hg status output across multiple packages
William Roberts <williamr@symbian.org>
parents:
diff changeset
    66
    next;
4ed8ba809509 Add utility to summarise the hg status output across multiple packages
William Roberts <williamr@symbian.org>
parents:
diff changeset
    67
    }
4ed8ba809509 Add utility to summarise the hg status output across multiple packages
William Roberts <williamr@symbian.org>
parents:
diff changeset
    68
  }
4ed8ba809509 Add utility to summarise the hg status output across multiple packages
William Roberts <williamr@symbian.org>
parents:
diff changeset
    69
4ed8ba809509 Add utility to summarise the hg status output across multiple packages
William Roberts <williamr@symbian.org>
parents:
diff changeset
    70
finished_repo();
4ed8ba809509 Add utility to summarise the hg status output across multiple packages
William Roberts <williamr@symbian.org>
parents:
diff changeset
    71
4ed8ba809509 Add utility to summarise the hg status output across multiple packages
William Roberts <williamr@symbian.org>
parents:
diff changeset
    72
print "Package\tChange\tComponent\tFilename\tCount\n";
4ed8ba809509 Add utility to summarise the hg status output across multiple packages
William Roberts <williamr@symbian.org>
parents:
diff changeset
    73
foreach my $repo (sort keys %listings)
4ed8ba809509 Add utility to summarise the hg status output across multiple packages
William Roberts <williamr@symbian.org>
parents:
diff changeset
    74
  {
4ed8ba809509 Add utility to summarise the hg status output across multiple packages
William Roberts <williamr@symbian.org>
parents:
diff changeset
    75
  my @filelist = @{$listings{$repo}};
4ed8ba809509 Add utility to summarise the hg status output across multiple packages
William Roberts <williamr@symbian.org>
parents:
diff changeset
    76
  
4ed8ba809509 Add utility to summarise the hg status output across multiple packages
William Roberts <williamr@symbian.org>
parents:
diff changeset
    77
  my $last_component = "";
4ed8ba809509 Add utility to summarise the hg status output across multiple packages
William Roberts <williamr@symbian.org>
parents:
diff changeset
    78
  my @component_files = ();
4ed8ba809509 Add utility to summarise the hg status output across multiple packages
William Roberts <williamr@symbian.org>
parents:
diff changeset
    79
  my @clean_files = ();
4ed8ba809509 Add utility to summarise the hg status output across multiple packages
William Roberts <williamr@symbian.org>
parents:
diff changeset
    80
  my $clean_count = 0;
4ed8ba809509 Add utility to summarise the hg status output across multiple packages
William Roberts <williamr@symbian.org>
parents:
diff changeset
    81
  my $component = "";
4ed8ba809509 Add utility to summarise the hg status output across multiple packages
William Roberts <williamr@symbian.org>
parents:
diff changeset
    82
  
4ed8ba809509 Add utility to summarise the hg status output across multiple packages
William Roberts <williamr@symbian.org>
parents:
diff changeset
    83
  foreach my $item (@filelist, ":boo:/:hoo:/:for:/:you:M")
4ed8ba809509 Add utility to summarise the hg status output across multiple packages
William Roberts <williamr@symbian.org>
parents:
diff changeset
    84
    {
4ed8ba809509 Add utility to summarise the hg status output across multiple packages
William Roberts <williamr@symbian.org>
parents:
diff changeset
    85
    my $change = substr($item,-1);
4ed8ba809509 Add utility to summarise the hg status output across multiple packages
William Roberts <williamr@symbian.org>
parents:
diff changeset
    86
    my $file = substr($item,0,-1);
4ed8ba809509 Add utility to summarise the hg status output across multiple packages
William Roberts <williamr@symbian.org>
parents:
diff changeset
    87
    my @names = split /\\/, $file;
4ed8ba809509 Add utility to summarise the hg status output across multiple packages
William Roberts <williamr@symbian.org>
parents:
diff changeset
    88
    $component = "";
4ed8ba809509 Add utility to summarise the hg status output across multiple packages
William Roberts <williamr@symbian.org>
parents:
diff changeset
    89
    if (scalar @names > 2)
4ed8ba809509 Add utility to summarise the hg status output across multiple packages
William Roberts <williamr@symbian.org>
parents:
diff changeset
    90
      {
4ed8ba809509 Add utility to summarise the hg status output across multiple packages
William Roberts <williamr@symbian.org>
parents:
diff changeset
    91
      my $collection = shift @names;
4ed8ba809509 Add utility to summarise the hg status output across multiple packages
William Roberts <williamr@symbian.org>
parents:
diff changeset
    92
      $component = shift @names;
4ed8ba809509 Add utility to summarise the hg status output across multiple packages
William Roberts <williamr@symbian.org>
parents:
diff changeset
    93
      $component = $collection . "/" . $component;
4ed8ba809509 Add utility to summarise the hg status output across multiple packages
William Roberts <williamr@symbian.org>
parents:
diff changeset
    94
      }
4ed8ba809509 Add utility to summarise the hg status output across multiple packages
William Roberts <williamr@symbian.org>
parents:
diff changeset
    95
    $file = join("/", @names);
4ed8ba809509 Add utility to summarise the hg status output across multiple packages
William Roberts <williamr@symbian.org>
parents:
diff changeset
    96
    
4ed8ba809509 Add utility to summarise the hg status output across multiple packages
William Roberts <williamr@symbian.org>
parents:
diff changeset
    97
    if ($component ne $last_component)
4ed8ba809509 Add utility to summarise the hg status output across multiple packages
William Roberts <williamr@symbian.org>
parents:
diff changeset
    98
      {
4ed8ba809509 Add utility to summarise the hg status output across multiple packages
William Roberts <williamr@symbian.org>
parents:
diff changeset
    99
      if (scalar @component_files > 0)
4ed8ba809509 Add utility to summarise the hg status output across multiple packages
William Roberts <williamr@symbian.org>
parents:
diff changeset
   100
        {
4ed8ba809509 Add utility to summarise the hg status output across multiple packages
William Roberts <williamr@symbian.org>
parents:
diff changeset
   101
        # previous component contained some A, M or R files
4ed8ba809509 Add utility to summarise the hg status output across multiple packages
William Roberts <williamr@symbian.org>
parents:
diff changeset
   102
        print @component_files;
4ed8ba809509 Add utility to summarise the hg status output across multiple packages
William Roberts <williamr@symbian.org>
parents:
diff changeset
   103
        } 
4ed8ba809509 Add utility to summarise the hg status output across multiple packages
William Roberts <williamr@symbian.org>
parents:
diff changeset
   104
      if ($clean_count > 0)
4ed8ba809509 Add utility to summarise the hg status output across multiple packages
William Roberts <williamr@symbian.org>
parents:
diff changeset
   105
        {
4ed8ba809509 Add utility to summarise the hg status output across multiple packages
William Roberts <williamr@symbian.org>
parents:
diff changeset
   106
        print "$repo\tsame\t$last_component\t...\t$clean_count\n";
4ed8ba809509 Add utility to summarise the hg status output across multiple packages
William Roberts <williamr@symbian.org>
parents:
diff changeset
   107
        }
4ed8ba809509 Add utility to summarise the hg status output across multiple packages
William Roberts <williamr@symbian.org>
parents:
diff changeset
   108
      # reset, ready for next component;
4ed8ba809509 Add utility to summarise the hg status output across multiple packages
William Roberts <williamr@symbian.org>
parents:
diff changeset
   109
      $last_component = $component;
4ed8ba809509 Add utility to summarise the hg status output across multiple packages
William Roberts <williamr@symbian.org>
parents:
diff changeset
   110
      $clean_count = 0;
4ed8ba809509 Add utility to summarise the hg status output across multiple packages
William Roberts <williamr@symbian.org>
parents:
diff changeset
   111
      @component_files = ();
4ed8ba809509 Add utility to summarise the hg status output across multiple packages
William Roberts <williamr@symbian.org>
parents:
diff changeset
   112
      @clean_files = ();
4ed8ba809509 Add utility to summarise the hg status output across multiple packages
William Roberts <williamr@symbian.org>
parents:
diff changeset
   113
      }
4ed8ba809509 Add utility to summarise the hg status output across multiple packages
William Roberts <williamr@symbian.org>
parents:
diff changeset
   114
    if ($change eq "C")
4ed8ba809509 Add utility to summarise the hg status output across multiple packages
William Roberts <williamr@symbian.org>
parents:
diff changeset
   115
      {
4ed8ba809509 Add utility to summarise the hg status output across multiple packages
William Roberts <williamr@symbian.org>
parents:
diff changeset
   116
      $clean_count += 1;
4ed8ba809509 Add utility to summarise the hg status output across multiple packages
William Roberts <williamr@symbian.org>
parents:
diff changeset
   117
      push @clean_files, "$repo\tsame\t$component\t$file\t1\n";
4ed8ba809509 Add utility to summarise the hg status output across multiple packages
William Roberts <williamr@symbian.org>
parents:
diff changeset
   118
      }
4ed8ba809509 Add utility to summarise the hg status output across multiple packages
William Roberts <williamr@symbian.org>
parents:
diff changeset
   119
    else
4ed8ba809509 Add utility to summarise the hg status output across multiple packages
William Roberts <williamr@symbian.org>
parents:
diff changeset
   120
      {
4ed8ba809509 Add utility to summarise the hg status output across multiple packages
William Roberts <williamr@symbian.org>
parents:
diff changeset
   121
      push @component_files, "$repo\t$change\t$component\t$file\t1\n";
4ed8ba809509 Add utility to summarise the hg status output across multiple packages
William Roberts <williamr@symbian.org>
parents:
diff changeset
   122
      }
4ed8ba809509 Add utility to summarise the hg status output across multiple packages
William Roberts <williamr@symbian.org>
parents:
diff changeset
   123
    } 
4ed8ba809509 Add utility to summarise the hg status output across multiple packages
William Roberts <williamr@symbian.org>
parents:
diff changeset
   124
  }