<commit_before>#!/usr/bin/perl

#
# Port Updater for FreshPorts
# takes output of LogMunger and updates the database
# written by <NAME>
# copyright 2000 DVL Software
#

use DBI;

#
# These are the files which require a port be refreshed from the raw Makefile
#
$FilesWhichPromptRefresh = "Makefile|pkg/DESCR|pkg/COMMENT";

#sub GetPortCategory($category, $dbh) {
sub GetPortCategory($;$) {
   my $category = shift;
   my $dbh = shift;

   $sql = "select id from categories where lower(name) = lower('" . $category . "')";

   $sth = $dbh->prepare($sql);

   $sth->execute ||
        die "Could not execute SQL statement ... maybe invalid?";


   @row=$sth->fetchrow_array;

   print "\nGetPortCategory = $sql which gives ", @row[0], "\n";


   return @row[0];
}

#PortUpdate ($committer, $timestamp, $action, $description, $category, $port, $entry, $dbh) {
sub PortUpdate($;$;$;$;$;$;$;$) {
   my $committer   = shift;
   my $timestamp   = shift;
   my $action      = shift;
   my $description = shift;
   my $category    = shift;
   my $port        = shift;
   my $entry       = shift;
   my $dbh         = shift;

   my $sql = "";
   my $refresh_needed = "N";

   $categoryid = GetPortCategory($category, $dbh);

   # update the port, creating it if necessary

   $sql = "select id from ports where lower(name) = lower('" . $port . "') and primary_category_id = $categoryid";
   print $sql, "\n";
   $sth = $dbh->prepare($sql);
   
   $sth->execute ||
      die "Could not execute SQL statement ... maybe invalid?";

   @row=$sth->fetchrow_array;

   if (@row) {
      print "something found\n";
   } else {
      print "nothing found\n";
   }

   #
   # depending on what has changed, we need to take action accordingly
   #

   if ($entry =~ /$FilesWhichPromptRefresh/) {
      $refresh_needed = "Y";
   }

   print @row[0];

   if (!@row) {
      # no such port.  create it.
      $sql = "insert into ports (name, description, last_update, primary_category_id, " .
             "last_update_description, committer, version, date_created, needs_refresh, " .
             "status, package_exists) values (";
      # we assume above that the package does not exist until we are told otherwise.

      # we don't get a version when inserting, so we must fake it by supplying a name.
      $sql .= "'$port', '*** no description ***', '$timestamp', $categoryid, '$description', " . 
              "'$committer', '$port', CurDate(), 'Y', 'N', 'N')";

      print "$sql\n";

      $sth = $dbh->prepare($sql);

      $sth->execute ||
         die "Could not execute SQL statement ... maybe invalid?";

      $sql = "insert into newports (name, primary_category_id) values ('$port', $categoryid)";

      $sth = $dbh->prepare($sql);

      $sth->execute ||
         die "Could not execute SQL statement ... maybe invalid?";

   } else {
      # update the time on the port
      $sql = "update ports set last_update = '$timestamp', committer = '$committer', " .
             "last_update_description = '$description' ";

      if ($refresh_needed eq "Y") {
         $sql .= ", needs_refresh = 'Y'";<commit_msg>for a new port, set short_description to '-- waiting for description --'. also, set date_created to a datetime value instead of a date.<commit_after>#!/usr/bin/perl

#
# Port Updater for FreshPorts
# takes output of LogMunger and updates the database
# written by <NAME>
# copyright 2000 DVL Software
#

use DBI;

#
# These are the files which require a port be refreshed from the raw Makefile
#
$FilesWhichPromptRefresh = "Makefile|pkg/DESCR|pkg/COMMENT";

#sub GetPortCategory($category, $dbh) {
sub GetPortCategory($;$) {
   my $category = shift;
   my $dbh = shift;

   $sql = "select id from categories where lower(name) = lower('" . $category . "')";

   $sth = $dbh->prepare($sql);

   $sth->execute ||
        die "Could not execute SQL statement ... maybe invalid?";


   @row=$sth->fetchrow_array;

   print "\nGetPortCategory = $sql which gives ", @row[0], "\n";


   return @row[0];
}

#PortUpdate ($committer, $timestamp, $action, $description, $category, $port, $entry, $dbh) {
sub PortUpdate($;$;$;$;$;$;$;$) {
   my $committer   = shift;
   my $timestamp   = shift;
   my $action      = shift;
   my $description = shift;
   my $category    = shift;
   my $port        = shift;
   my $entry       = shift;
   my $dbh         = shift;

   my $sql = "";
   my $refresh_needed = "N";

   $categoryid = GetPortCategory($category, $dbh);

   # update the port, creating it if necessary

   $sql = "select id from ports where lower(name) = lower('" . $port . "') and primary_category_id = $categoryid";
   print $sql, "\n";
   $sth = $dbh->prepare($sql);
   
   $sth->execute ||
      die "Could not execute SQL statement ... maybe invalid?";

   @row=$sth->fetchrow_array;

   if (@row) {
      print "something found\n";
   } else {
      print "nothing found\n";
   }

   #
   # depending on what has changed, we need to take action accordingly
   #

   if ($entry =~ /$FilesWhichPromptRefresh/) {
      $refresh_needed = "Y";
   }

   print @row[0];

   if (!@row) {
      # no such port.  create it.
      $sql = "insert into ports (name, last_update, primary_category_id, " .
             "last_update_description, committer, date_created, needs_refresh, " .
             "status, package_exists, short_description) values (";
      # we assume above that the package does not exist until we are told otherwise.

      # we don't get a version when inserting, so we must fake it by supplying a name.
      $sql .= "'$port', '$timestamp', $categoryid, '$description', " . 
              "'$committer', current_timestamp, 'Y', 'N', 'N', '-- waiting for description --')";

      print "$sql\n";

      $sth = $dbh->prepare($sql);

      $sth->execute ||
         die "Could not execute SQL statement ... maybe invalid?";

      $sql = "insert into newports (name, primary_category_id) values ('$port', $categoryid)";

      $sth = $dbh->prepare($sql);

      $sth->execute ||
         die "Could not execute SQL statement ... maybe invalid?";

   } else {
      # update the time on the port
      $sql = "update ports set last_update = '$timestamp', committer = '$committer', " .
             "last_update_description = '$description' ";

      if ($refresh_needed eq "Y") {
         $sql .= ", needs_refresh = 'Y'";
{'fraction_non_alphanumeric': 0.15007101151964652, 'fraction_numerical': 0.002209247277891747, 'mean_word_length': 2.7681331747919145, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 25, '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': '7562000', 'n_tokens_mistral': 2040, 'n_tokens_neox': 1957, 'n_words': 630}