<commit_before>
# this script expects repository as an arg
# and cvs log info on stdin

use strict;

my $CVSROOT             = $ENV{'CVSROOT'};
my $DIRT_DIR            = "$CVSROOT/dirt_active";
my $DIRT_PACKAGE_DEF    = "$DIRT_DIR/package.def";
my $DIRT_BRANCH_DEF     = "$DIRT_DIR/branch.def";
my $DIRT_TEMPLATE_DIR   = "$DIRT_DIR/templates";

# verify location of package and branch databases
(-d $DIRT_DIR)           || die("DiRT Error: Can't find DiRT dir at $DIRT_DIR!");
(-f $DIRT_PACKAGE_DEF)   || die("DiRT Error: Missing package defs at $DIRT_PACKAGE_DEF!");
(-f $DIRT_BRANCH_DEF)    || die("DiRT Error: Missing branch defs at $DIRT_BRANCH_DEF!");
(-d $DIRT_TEMPLATE_DIR)  || die("DiRT Error: Can't find template dir at $DIRT_TEMPLATE_DIR!");

# using RESPOSITORY and package db, find this package's root dir and template file
# if none can be found, we dont do anything for this package

open(PACKAGE_DEF, $DIRT_PACKAGE_DEF)
    || die("DiRT Error: could not open $DIRT_PACKAGE_DEF");

my $repository          = shift(@ARGV) || die("DiRT Error: Missing argument!");
my $package_loc;
my $template_filename;

while(!$package_loc && defined($_ = <PACKAGE_DEF>))
{
    # ignore comment lines
    if(!m/^#/)
    {   
        my @fields = split();
        if(@fields == 3)
        {
            if($repository =~ m/^$fields[1]/)
            {
                $package_loc = "$CVSROOT/$fields[1]";
                $template_filename = $fields[2];
            }
        }
        elsif(@fields)
        {
            print("DiRT Warning: Ignoring bad line in $DIRT_PACKAGE_DEF\n$_\n");
        }
    }
}

close(PACKAGE_DEF);

if(!$package_loc)
{
    exit(0);
}

my $template_file = "$DIRT_TEMPLATE_DIR/$template_filename";
(-f $template_file)
    || die("DiRT Error: Missing template file at $template_file\n");

# see if the RCS file exists. if not, its never been requested for
# any branches yet, so we dont need to do anything
# need to check Attic also
my $rcsfile = "$package_loc/$template_filename,v";
if(!-f $rcsfile) 
{
    $rcsfile = "$package_loc/Attic/$template_filename,v";
    (-f $rcsfile) 
        || print("DiRT Warning: Package defined for DiRT but no users\n") && exit(0);
}

# parse log message for the tags we need to update
# note: this rather complex parse is mostly to handle strange
# commits involving mutliple tags that is likely never to occur
# The worst case log might look something like:
# 
# Update of <absolute path to repository>
# In directory <machine>:<working dir path>
# 
# Modified Files:
#         globus_ftp_client.c 
#       Tag: globus-beta-branch-sub-versions
#         globus_ftp_client_state.c 
#       Tag: globus-beta-branch
#         globus_ftp_client_throughput_plugin.h 
# Added Files:
#       Tag: globus-beta-branch
#         new-a new-b new-c 
# Removed Files:
#       Tag: globus-beta-branch-sub-versions
#         globus_ftp_client.h 
#       Tag: globus-beta-branch
#         globus_ftp_client_attr.c 
#       No tag
#         globus_ftp_client_data.c 
# Log Message:
# hi

my %tags;
my $can_be_trunk = 0;
while(defined($_ = <STDIN>) && !m/^Log Message:$/)
{
    chomp();
    
    # see if its a '(Modified|Added|Removed) Files:' line
    if(m/^(Modified|Added|Removed) Files:$/)
    {
        $can_be_trunk = 1;
    }
    else
    {
        # check for tag line, otherwise this might be on the trunk
        if(s/^\s+Tag: (.*)$/$1/)
        {
            $tags{$_} = 0;
        }
        elsif($can_be_trunk || m/^\s+No tag$/)
        {
            $tags{'TRUNK'} = 1;
        }
        $can_be_trunk = 0;
    }
}

# consume rest of input
@_ = <STDIN>;

# now check to see what tags are actually defined AND NOT dead in
# rcsfile.  Those that are dead or not defined dont get updates
# if we end up removing all set tags, then we're done.
# this is made more difficult because we use tags that rcs doesnt like
# (those that contain '-') so we need to match symbols to a branch rev
# and query on the numeric revision
my %tag_version;
my $save_rlog;

$_ = `rlog -h $rcsfile 2>&1`;
$save_rlog = $_;
if(s/.*symbolic names:\s*(.*)keyword substitution:.*/$1/s)
{
    %tag_version = split(/[ \t\n:]+/);
    # the TRUNK doesn't end up as a symbolic name. 
    # so add it here; it has empty version
    $tag_version{'TRUNK'} = '';
    <commit_msg>add line to consume rest of stdin<commit_after>
# this script expects repository as an arg
# and cvs log info on stdin

use strict;

my $CVSROOT             = $ENV{'CVSROOT'};
my $DIRT_DIR            = "$CVSROOT/dirt_active";
my $DIRT_PACKAGE_DEF    = "$DIRT_DIR/package.def";
my $DIRT_BRANCH_DEF     = "$DIRT_DIR/branch.def";
my $DIRT_TEMPLATE_DIR   = "$DIRT_DIR/templates";

# verify location of package and branch databases
(-d $DIRT_DIR)           || die("DiRT Error: Can't find DiRT dir at $DIRT_DIR!");
(-f $DIRT_PACKAGE_DEF)   || die("DiRT Error: Missing package defs at $DIRT_PACKAGE_DEF!");
(-f $DIRT_BRANCH_DEF)    || die("DiRT Error: Missing branch defs at $DIRT_BRANCH_DEF!");
(-d $DIRT_TEMPLATE_DIR)  || die("DiRT Error: Can't find template dir at $DIRT_TEMPLATE_DIR!");

# using RESPOSITORY and package db, find this package's root dir and template file
# if none can be found, we dont do anything for this package

open(PACKAGE_DEF, $DIRT_PACKAGE_DEF)
    || die("DiRT Error: could not open $DIRT_PACKAGE_DEF");

my $repository          = shift(@ARGV) || die("DiRT Error: Missing argument!");
my $package_loc;
my $template_filename;

while(!$package_loc && defined($_ = <PACKAGE_DEF>))
{
    # ignore comment lines
    if(!m/^#/)
    {   
        my @fields = split();
        if(@fields == 3)
        {
            if($repository =~ m/^$fields[1]/)
            {
                $package_loc = "$CVSROOT/$fields[1]";
                $template_filename = $fields[2];
            }
        }
        elsif(@fields)
        {
            print("DiRT Warning: Ignoring bad line in $DIRT_PACKAGE_DEF\n$_\n");
        }
    }
}

close(PACKAGE_DEF);

if(!$package_loc)
{
    exit(0);
}

my $template_file = "$DIRT_TEMPLATE_DIR/$template_filename";
(-f $template_file)
    || die("DiRT Error: Missing template file at $template_file\n");

# see if the RCS file exists. if not, its never been requested for
# any branches yet, so we dont need to do anything
# need to check Attic also
my $rcsfile = "$package_loc/$template_filename,v";
if(!-f $rcsfile) 
{
    $rcsfile = "$package_loc/Attic/$template_filename,v";
    (-f $rcsfile) 
        || print("DiRT Warning: Package defined for DiRT but no users\n") && exit(0);
}

# parse log message for the tags we need to update
# note: this rather complex parse is mostly to handle strange
# commits involving mutliple tags that is likely never to occur
# The worst case log might look something like:
# 
# Update of <absolute path to repository>
# In directory <machine>:<working dir path>
# 
# Modified Files:
#         globus_ftp_client.c 
#       Tag: globus-beta-branch-sub-versions
#         globus_ftp_client_state.c 
#       Tag: globus-beta-branch
#         globus_ftp_client_throughput_plugin.h 
# Added Files:
#       Tag: globus-beta-branch
#         new-a new-b new-c 
# Removed Files:
#       Tag: globus-beta-branch-sub-versions
#         globus_ftp_client.h 
#       Tag: globus-beta-branch
#         globus_ftp_client_attr.c 
#       No tag
#         globus_ftp_client_data.c 
# Log Message:
# hi

my %tags;
my $can_be_trunk = 0;
while(defined($_ = <STDIN>) && !m/^Log Message:$/)
{
    chomp();
    
    # see if its a '(Modified|Added|Removed) Files:' line
    if(m/^(Modified|Added|Removed) Files:$/)
    {
        $can_be_trunk = 1;
    }
    else
    {
        # check for tag line, otherwise this might be on the trunk
        if(s/^\s+Tag: (.*)$/$1/)
        {
            $tags{$_} = 0;
        }
        elsif($can_be_trunk || m/^\s+No tag$/)
        {
            $tags{'TRUNK'} = 1;
        }
        $can_be_trunk = 0;
    }
}

# consume rest of input
while(defined(<STDIN>));

# now check to see what tags are actually defined AND NOT dead in
# rcsfile.  Those that are dead or not defined dont get updates
# if we end up removing all set tags, then we're done.
# this is made more difficult because we use tags that rcs doesnt like
# (those that contain '-') so we need to match symbols to a branch rev
# and query on the numeric revision
my %tag_version;
my $save_rlog;

$_ = `rlog -h $rcsfile 2>&1`;
$save_rlog = $_;
if(s/.*symbolic names:\s*(.*)keyword substitution:.*/$1/s)
{
    %tag_version = split(/[ \t\n:]+/);
    # the TRUNK doesn't end up as a symbolic name. 
    # so add it here; it has empty version
    $tag_version{'TRUNK'} = '';
    
{'fraction_non_alphanumeric': 0.128314997104806, 'fraction_numerical': 0.003474232773595831, 'mean_word_length': 2.7728265618173875, 'pattern_counts': {'":': 0, '<': 15, '<?xml version=': 0, '>': 17, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2855310', 'n_tokens_mistral': 3024, 'n_tokens_neox': 2950, 'n_words': 878}