View Issue Details

IDProjectCategoryView StatusLast Update
0009866mantisbtadministrationpublic2010-09-19 03:11
Reportermartyribs Assigned Todhx  
PrioritynormalSeveritymajorReproducibilityalways
Status closedResolutionwon't fix 
PlatformIntelOSLinuxOS Version2.6.17-1.2142_FC
Product Version1.1.4 
Summary0009866: CVS integration does not work
Description

I have all the pieces in place for CVS integration, but when ../core/checkin.php gets called, the STDIN stream does not contain anything. I have inserted fwrites in the checkin.php script and there is nothing coming in on STDIN, so the regex matching does not occur inside the loop.

However, when the script is called from the command line like so:

cat message.txt | php checkin.php

there is data on the standard IN stream as expected.

I'm still investigating how CVS passes parameters in the commitinfo mechanism on Linux, but I have not found the details on the topic yet.

Steps To Reproduce

Add to checkin.php

At the beginning

define(MYDEBUGFILE, fopen("/tmp/mymantistest.out", "a"));
fwrite(MYDEBUGFILE, "New invocation\n");

Inside the STDIN loop

fwrite(MYDEBUGFILE, "Read from STDIN: " . $t_line . "\n");

At the end

fclose(MYDEBUGFILE);

Do a CVS commit on a file and check MYDEBUGFILE for output.

Additional Information

I did see some references on-line about the fact that on Windows (which I'm not using), what used to be passed as parameters by CVS was at some point moved to STDIN. I doubt that checkin.php was written with just Windows in mind, so this is likely not the cause.

I also saw references to bugs in the STDIN handling by PHP a few versions back, but I have confirmed with my tests that that is not an issue. My PHP version is 5.0.4. checkin.php reads STDIN correctly when invoked from the command line.

TagsNo tags attached.

Relationships

related to 0011732 closeddhx Remove built-in source code integration support 

Activities

martyribs

martyribs

2008-11-21 17:00

reporter   ~0019976

I did an additional test. I modified ../core/checkin.php script. Here is the code.

=================================================================

#!/usr/local/bin/php -q
<?php

Mantis - a php based bugtracking system

Copyright (C) 2000 - 2002 Kenzaburo Ito - kenito@300baud.org

Copyright (C) 2002 - 2007 Mantis Team - mantisbt-dev@lists.sourceforge.net

Mantis is free software: you can redistribute it and/or modify

it under the terms of the GNU General Public License as published by

the Free Software Foundation, either version 2 of the License, or

(at your option) any later version.

#

Mantis is distributed in the hope that it will be useful,

but WITHOUT ANY WARRANTY; without even the implied warranty of

MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the

GNU General Public License for more details.

#

You should have received a copy of the GNU General Public License

along with Mantis. If not, see http://www.gnu.org/licenses/.

# See the README and LICENSE files for details

# --------------------------------------------------------
# $Id: checkin.php,v 1.5.2.1 2007-10-13 22:35:16 giallu Exp $
# --------------------------------------------------------

define (MYDEBUGFILE, fopen("/tmp/mantistest.out", "a"));
fwrite(MYDEBUGFILE, "\n\nNew invocation of checkin.php\n");

for ($i = 0; $i < $argc; $i++) {
    fwrite(MYDEBUGFILE, "Parm #".$i.": ".$argv[$i]."\n");   
}

global $g_bypass_headers;
$g_bypass_headers = 1;
require_once( dirname( dirname( __FILE__ ) ) . DIRECTORY_SEPARATOR . 'core.php' );

# Make sure this script doesn't run via the webserver
# @@@ This is a hack to detect php-cgi, there must be a better way.
if ( isset( $_SERVER['SERVER_PORT'] ) ) {
    echo "checkin.php is not allowed to run through the webserver.\n";
    exit( 1 );
}

# Check that the username is set and exists
$t_username = config_get( 'source_control_account' );
if ( is_blank( $t_username ) || ( user_get_id_by_name( $t_username ) === false ) ) {
    echo "Invalid source control account ('$t_username').\n";
    exit( 1 );
}

if ( !defined( "STDIN" ) ) {
        define("STDIN", fopen('php://stdin','r'));
}

# Detect references to issues + concat all lines to have the comment log.
$t_commit_regexp = config_get( 'source_control_regexp' );
    $t_commit_fixed_regexp = config_get( 'source_control_fixed_regexp' );

$t_comment = '';
$t_issues = array();
$t_fixed_issues = array();
while ( ( $t_line = fgets( STDIN, 1024 ) ) ) {
    $t_comment .= $t_line;
    fwrite(MYDEBUGFILE, "Line from STDIN: " . $t_line . "\n");
    if ( preg_match_all( $t_commit_regexp, $t_line, $t_matches ) ) {
        for ( $i = 0; $i < count( $t_matches[0] ); ++$i ) {
            $t_issues[] = $t_matches[1][$i];
        }
    }

    if ( preg_match_all( $t_commit_fixed_regexp, $t_line, $t_matches) ) {
        for ( $i = 0; $i < count( $t_matches[0] ); ++$i ) {
            $t_fixed_issues[] = $t_matches[1][$i];
        }
    }
}

# If no issues found, then no work to do.
if ( ( count( $t_issues ) == 0 ) && ( count( $t_fixed_issues ) == 0 ) ) {
    echo "Comment does not reference any issues.\n";
    exit(0);
}

# Login as source control user
if ( !auth_attempt_script_login( $t_username ) ) {
    echo "Unable to login\n";
    exit( 1 );
}

# history parameters are reserved for future use.
$t_history_old_value = '';
$t_history_new_value = '';

# add note to each bug only once
$t_issues = array_unique( $t_issues );
$t_fixed_issues = array_unique( $t_fixed_issues );

# Call the custom function to register the checkin on each issue.

foreach ( $t_issues as $t_issue_id ) {
    if ( !in_array( $t_issue_id, $t_fixed_issues ) ) {
        helper_call_custom_function( 'checkin', array( $t_issue_id, $t_comment, $t_history_old_value, $t_history_new_value, false ) );
    }
}

foreach ( $t_fixed_issues as $t_issue_id ) {
    helper_call_custom_function( 'checkin', array( $t_issue_id, $t_comment, $t_history_old_value, $t_history_new_value, true ) );
}

fwrite(MYDEBUGFILE, "Bye ... \n");
fclose(MYDEBUGFILE);

exit( 0 );

?>

======================================================

The output in /tmp/mantistest.out was as follows:

New invocation of checkin.php
Parm #0: /home/mantis/apache2.2.10/htdocs/mantis/core/checkin.php
Parm 0000001: /home/srcadmin/cvsroot/taosprd/src/ConfigTool/com/termalabs/configui
Parm 0000002: Main.java

============================================================

So there is no data on the STDIN stream.

anelsen

anelsen

2009-04-23 16:44

reporter   ~0021650

I'm seeing the same issue, STDIN is empty on my commits:
Kernel 2.6.23.17-88.fc7
Mantis 1.1.1
CVS 1.11.22

anelsen

anelsen

2009-04-24 09:36

reporter   ~0021658

I don't know if this is correct, but I got the result I wanted by putting the trigger in 'loginfo' instead of 'commitinfo':

DEFAULT (echo ""; id; echo %{sVv}; date; cat) | /usr/share/mantis/core/checkin.php

dhx

dhx

2010-03-31 03:38

reporter   ~0024949

Won't fix as this old source code integration support is being dropped in favour of using a more modern plugin approach with the SourceIntegration plugin.

Refer to 0011732 for more details and feedback.