Platon Technologies
not logged in Login Registration
EnglishSlovak
open source software development celebrating 10 years of open source development! Thursday, October 15, 2026

Diff for scripts/php/parsecvs/parsecvs.php between version 1.24 and 1.25

version 1.24, 2002/06/17 07:48:49 version 1.25, 2003/01/11 13:47:21
Line 1 
Line 1 
 <?php  <?php
   
         // $Id$          // parsecvs.php - Platon SDG CVS commit reports prettyfier
           // Developed by Martin Karas <wolcano@pobox.sk>
           // Tag support by Ondrej Jombik <nepto@php.net> [11/1/2003]
           // Copyright (c) 2002-2003 Platon SDG, http://www.platon.sk/
           // Licensed under terms of GNU General Public License
   
           // $Platon: parsecvs.php,v 1.24 2002/06/17 07:48:49 karas9 Exp $
   
           #
           # CONSTANTS
           #
   
         // Specify input/output streams (ie. files, sockets or std's)          // Specify input/output streams (ie. files, sockets or std's)
   
         $input_file  = 'php://stdin';          $input_file  = 'php://stdin';
         $output_file = 'php://stdout';          $output_file = 'php://stdout';
   
         $begin_line = '----------------------------------------------';          // Made more liberal (20 compulsory dashes, others are arbitrary)
           // old: $begin_line = '----------------------------------------------';
           $begin_line = '--------------------[-]*';
         $msg_log_begin = '^Log Message:';          $msg_log_begin = '^Log Message:';
         $date_format = '^([A-Z][a-z]{2} *)?([A-Z][a-z]{2} *[0-9]+ *' .          $date_format = '^([A-Z][a-z]{2} *)?([A-Z][a-z]{2} *[0-9]+ *' .
                         '[0-9]{2}:[0-9]{2}:[0-9]{2}) *CES?T *([0-9]{4})';                          '[0-9]{2}:[0-9]{2}:[0-9]{2}) *CES?T *([0-9]{4})';
         $user_format = '^CVSUSER=([0-9a-zA-Z]*)';          $user_format = '^CVSUSER=([0-9a-zA-Z]*)';
         $directory_format = '^In directory';          $directory_format = '^In directory';
         $project_name_format = '^Update of /home/cvs/(.*)';          $project_name_format = '^Update of /home/cvs/(.*)';
           $tag_oper_begin  = '^Tag operation: (.*)$';
           $tag_name_begin  = '^Tag name: (.*)$';
         $add_files_begin = '^Added Files:';          $add_files_begin = '^Added Files:';
         $mod_files_begin = '^Modified Files:';          $mod_files_begin = '^Modified Files:';
         $del_files_begin = '^Removed Files:';          $del_files_begin = '^Removed Files:';
Line 22 
Line 35 
         $project_head_folding_char = '-';          $project_head_folding_char = '-';
         $sub_projects_separator = "----\n";          $sub_projects_separator = "----\n";
         $log_message_folding = '  ';          $log_message_folding = '  ';
           
           #
           # FUNCTIONS
           #
   
         function my_array_walk($x) {          function my_array_walk($x)
           {
                 // This will do array_unique() on third-level values of $x                  // This will do array_unique() on third-level values of $x
                 $ik = array_keys($x);                  $ik = array_keys($x);
                 for ($i = 0; $i < sizeof($ik); $i++) {                  for ($i = 0; $i < sizeof($ik); $i++) {
                         $jk = array_keys($x[$ik[$i]]);                          $jk = array_keys($x[$ik[$i]]);
                         for ($j = 0; $j < sizeof($jk); $j++)                          for ($j = 0; $j < sizeof($jk); $j++)
                                 if (is_array($x[$ik[$i]][$jk[$j]])) {                                  if (is_array($x[$ik[$i]][$jk[$j]])) {
                                         $x[$ik[$i]][$jk[$j]] = array_unique($x[$ik[$i]][$jk[$j]]);  
                                           /* To prevent merging [0] => array(), [1] => array(), ...
                                              into one [0] => array().  Note that merging algorithm
                                              in array_unique() is string-based, thus it saw
                                              [0] => 'Array', [1] => 'Array', ... and it logically
                                              merge it into one [0] => 'Array'. However, this is not
                                              desirable for us.
   
                                              -- Nepto [11/1/2003] */
   
                                           $all_values_are_arrays = true;
                                           foreach ($x[$ik[$i]][$jk[$j]] as $val) {
                                                   if (! is_array($val)) {
                                                           $all_values_are_arrays = false;
                                                           break;
                                                   }
                                           }
                                           // Skip merging process if all values are arrays
                                           if (! $all_values_are_arrays) {
                                                   $x[$ik[$i]][$jk[$j]] = array_unique($x[$ik[$i]][$jk[$j]]);
                                           }
                                 }                                  }
                 }                  }
                 return $x;                  return $x;
         } // my_array_walk()          } // my_array_walk()
   
         $in = file($input_file);          function write_out_file_set($op = '*', $file_ar, $tags)
           {
                   if (! is_array($file_ar) || count($file_ar) <= 0)
                           return;
   
                   $additional_file_infos = array();
                   if (is_array($tags)) {
                           foreach ($tags as $tag_ar) {
                                   foreach ($tag_ar['files'] as $file) {
                                           $additional_file_infos[$file][] =
                                                   $tag_ar['operation'].' '.$tag_ar['name'];
                                   }
                           }
                   }
   
         $i = 0;                  global $out, $indent_str;
         $j = -1;                  $prefix = "$indent_str$op ";
                   foreach ($file_ar as $filename) {
                           fwrite($out, $prefix);
                           if (is_array($additional_file_infos[$filename])) {
                                   for ($i = 0; $i < count($additional_file_infos[$filename]); $i++) {
                                           if ($i == 0) {
                                                   $filename2 = str_pad($filename, 35, ' ', STR_PAD_RIGHT);
                                           } else if ($i == 1) {
                                                   $filename2 = str_repeat(' ', 35 + strlen($prefix));
                                           }
                                           $add_info = $additional_file_infos[$filename][$i];
                                           fwrite($out, "$filename2 $add_info\n");
                                   }
                           } else {
                                   fwrite($out, "$filename\n");
                           }
                   }
           }
   
         $in_msg_log = false;          #
         $in_add_files = false;          # MAIN JOB
         $in_mod_files = false;          #
         $in_del_files = false;  
           $in = file($input_file);  // input split into array by lines
           $i  = 0;                  // starting line to parse
           $j  = -1;                 // current parsed report
   
           // Rewind to the beginning of the first commit. This will allow us
           // to parse commits with garbage texts on the top (ie. e-mails).
           for (; ! ereg($begin_line, $in[$i]); $i++);
   
         while ($i < sizeof($in)) {          while ($i < sizeof($in)) {
                 // BEGIN NEW COMMIT                  // BEGIN NEW COMMIT
                 if (ereg($begin_line, $in[$i])) {                  if (ereg($begin_line, $in[$i])) {
                           // increasing report index
                         $j++;                          $j++;
                           // reseting all flags
                           $in_msg_log   = false;
                           $in_add_files = false;
                           $in_mod_files = false;
                           $in_del_files = false;
                           // moving to the next line
                           $i++;
                           continue;
                 }                  }
   
                 // LOG MESSAGE                  // LOG MESSAGE
Line 148 
Line 232 
                         $reports[$j]['directory'] = trim($regs[1]);                          $reports[$j]['directory'] = trim($regs[1]);
                 }                  }
   
                   // TAG OPERATION
                   if (ereg($tag_oper_begin, $in[$i], $regs)) {
                           //$reports[$j]['tag_operation'][0] = trim($regs[1]);
                           $reports[$j]['tag'][0]['operation'] = trim($regs[1]);
                   }
                   
                   // TAG NAME
                   if (ereg($tag_name_begin, $in[$i], $regs)) {
                           //$reports[$j]['tag_name'][0] = trim($regs[1]);
                           $reports[$j]['tag'][0]['name'] = trim($regs[1]);
                   }
   
                 $i++;                  $i++;
         }          }
   
         $merged = array();          $merged = array();
         $i = 0;  
   
         // Merge recursively all reports into one array          // Merge recursively all reports into one array
         // eg. join reports in same directory          // eg. join reports in same directory
         while ($i < sizeof($reports)) {          for ($i = 0; $i < sizeof($reports); $i++) {
   
                   if (isset($reports[$i]['tag'][0]['name'])) {                    
                           $reports[$i]['tag'][0]['files'] =
                                   (array) $reports[$i]['added'] +
                                   (array) $reports[$i]['modified'] +
                                   (array) $reports[$i]['deleted'];
   
                           switch (@$reports[$i]['tag'][0]['operation']) {
                                   case 'add': $op = '+'; break;
                                   case 'del': $op = '-'; break;
                                   default:    $op = '?'; break;
                           }
                           $reports[$i]['tag'][0]['operation'] = $op;
                   }
                 unset($a);                  unset($a);
                 $a[$reports[$i]['directory']] = $reports[$i];                  $a[$reports[$i]['directory']] = $reports[$i];
                 $merged = array_merge_recursive($merged, $a);                  $merged = array_merge_recursive($merged, $a);
                 $i++;  
         }          }
         unset($i);          unset($i);
         unset($a);          unset($a);
Line 176 
Line 284 
         unset($reports);          unset($reports);
         unset($merged);          unset($merged);
   
         $out = fopen($output_file, 'w');          $out  = fopen($output_file, 'w');
   
         $keys = array_keys($merged_unique);          $keys = array_keys($merged_unique);
         $i = 0;          $i    = 0;
         $name = '';          $name = '';
   
         // OUTPUT:          // OUTPUT:
Line 236 
Line 343 
                 }                  }
                                                   
                 // mod = mod - add                  // mod = mod - add
                 if (is_array($m['added']) && is_array($m['modified']))                  if (is_array($m['added']) && is_array($m['modified'])) {
                         $m['modified'] = array_diff($m['modified'], $m['added']);                          $m['modified'] = array_diff($m['modified'], $m['added']);
                   }
                                   
                 // mod = mod - del                  // $indent_str is used as global in write_out_file_set()
                 /*  
                 if (is_array($m['modified']) && is_array($m['deleted']))  
                         $m['modified'] = array_diff($m['modified'], $m['deleted']);  
                 */  
   
                 $indent_str = str_repeat(' ', strlen('Files') + 2);                  $indent_str = str_repeat(' ', strlen('Files') + 2);
                 if (is_array($m['added']) && (sizeof($m['added']) > 0))  
                         fwrite($out, "$indent_str+ "                  write_out_file_set('+', $m['added'],    $m['tag']);
                                 . implode("\n$indent_str+ ", $m['added']) . "\n");                  write_out_file_set('*', $m['modified'], $m['tag']);
                 if (is_array($m['modified']) && (sizeof($m['modified']) > 0))                  write_out_file_set('-', $m['deleted'],  $m['tag']);
                         fwrite($out, "$indent_str* "  
                                 . implode("\n$indent_str* ", $m['modified']) . "\n");  
                 if (is_array($m['deleted'])  && (sizeof($m['deleted']) > 0))  
                         fwrite($out, "$indent_str- "  
                                 . implode("\n$indent_str- ", $m['deleted']) . "\n");  
   
                 // LOG MESSAGES                  // LOG MESSAGES
                 if (is_array($m['log_msg'])) {                  if (is_array($m['log_msg'])) {

Legend:
Removed from v.1.24  
changed lines
  Added in v.1.25

Platon Group <platon@platon.org> http://platon.org/
Copyright © 2002-2006 Platon Group
Site powered by Metafox CMS
Go to Top