Esempio n. 1
0
function get_diff($lines)
{
    $diffObjList = array();
    $max_idx = -1;
    $add_lines_cnt = 0;
    $del_lines_cnt = 0;
    $c1_index = 0;
    $c2_index = 0;
    // remove lines NOT belong to diff result
    $lines = get_valid_diff_lines($lines);
    if (count($lines) == 0) {
        echo "<b><font color='blue'>Info: No Diff</font></b>";
        exit(1);
    }
    array_push($lines, "_EOF_");
    // add a flag line
    foreach ($lines as $line) {
        // if (strstr($line, "No newline at end of file")) continue;
        $line03 = substr($line, 0, 3);
        $line04 = substr($line, 0, 4);
        $line05 = substr($line, 0, 5);
        $line07 = substr($line, 0, 7);
        // make diff count the same
        if ($line07 == "Index: " || $line05 == "_EOF_" || $line03 == "@@ ") {
            $delta = $add_lines_cnt - $del_lines_cnt;
            if ($delta > 0) {
                for ($i = 0; $i < $delta; $i++) {
                    if ($del_lines_cnt == 0) {
                        array_push($diffObjList[$max_idx]["c1_list"], "__add__");
                    } else {
                        array_push($diffObjList[$max_idx]["c1_list"], "__update__");
                    }
                    array_push($diffObjList[$max_idx]["c1_idx_list"], "");
                }
            } else {
                for ($i = 0; $i < abs($delta); $i++) {
                    if ($add_lines_cnt == 0) {
                        array_push($diffObjList[$max_idx]["c2_list"], "__del__");
                    } else {
                        array_push($diffObjList[$max_idx]["c2_list"], "__update__");
                    }
                    array_push($diffObjList[$max_idx]["c2_idx_list"], "");
                }
            }
            $add_lines_cnt = 0;
            $del_lines_cnt = 0;
        }
        // check for each condition
        if ($line07 == "Index: ") {
            $diffObj = array("file" => substr($line, 7), "ver1" => null, "ver2" => null, "c1_list" => array(), "c2_list" => array(), "c1_idx_list" => array(), "c2_idx_list" => array());
            array_push($diffObjList, $diffObj);
            $max_idx++;
        } elseif ($line04 == "--- ") {
            // get version for old file
            preg_match("/.*\\(revision (\\d+)\\)/", $line, $matches);
            $diffObjList[$max_idx]["ver1"] = $matches[1];
        } elseif ($line04 == "+++ ") {
            // get version for new file
            preg_match("/.*\\(revision (\\d+)\\)/", $line, $matches);
            $diffObjList[$max_idx]["ver2"] = $matches[1];
        } else {
            if (substr($line, 0, 1) == "-") {
                // lines removed
                array_push($diffObjList[$max_idx]["c1_list"], substr($line, 1));
                array_push($diffObjList[$max_idx]["c1_idx_list"], $c1_index);
                $del_lines_cnt++;
                $c1_index++;
            } else {
                if (substr($line, 0, 1) == "+") {
                    // lines added
                    array_push($diffObjList[$max_idx]["c2_list"], substr($line, 1));
                    $add_lines_cnt++;
                    array_push($diffObjList[$max_idx]["c2_idx_list"], $c2_index);
                    $c2_index++;
                } else {
                    if ($line03 == "===") {
                        // find split line "==================================================================="
                        // just need to do nothing
                    } else {
                        if ($line03 == "@@ ") {
                            // find line no info, like @@ -1,26 +0,0 @@
                            preg_match("/^@@ -(\\d+),(\\d+) \\+(\\d+),(\\d+) @@\$/", $line, $matches) or preg_match("/^@@ -(\\d+),(\\d+) \\+(\\d+) @@\$/", $line, $matches) or preg_match("/^@@ -(\\d+) \\+(\\d+) @@\$/", $line, $matches2);
                            if ($matches) {
                                $c1_index = $matches[1];
                                $c2_index = $matches[3];
                            } else {
                                // find line no info, like @@ -0,0 +1 @@
                                $c1_index = $matches2[1];
                                $c2_index = $matches2[2];
                            }
                        } else {
                            if ($line05 == "_EOF_") {
                                break;
                            } else {
                                $delta = $add_lines_cnt - $del_lines_cnt;
                                if ($delta > 0) {
                                    for ($i = 0; $i < $delta; $i++) {
                                        if ($del_lines_cnt == 0) {
                                            array_push($diffObjList[$max_idx]["c1_list"], "__add__");
                                        } else {
                                            array_push($diffObjList[$max_idx]["c1_list"], "__update__");
                                        }
                                        array_push($diffObjList[$max_idx]["c1_idx_list"], "");
                                    }
                                } else {
                                    for ($i = 0; $i < abs($delta); $i++) {
                                        if ($add_lines_cnt == 0) {
                                            array_push($diffObjList[$max_idx]["c2_list"], "__del__");
                                        } else {
                                            array_push($diffObjList[$max_idx]["c2_list"], "__update__");
                                        }
                                        array_push($diffObjList[$max_idx]["c2_idx_list"], "");
                                    }
                                }
                                $add_lines_cnt = 0;
                                $del_lines_cnt = 0;
                                // find not updated lines
                                array_push($diffObjList[$max_idx]["c1_list"], substr($line, 1));
                                array_push($diffObjList[$max_idx]["c1_idx_list"], $c1_index);
                                $c1_index++;
                                array_push($diffObjList[$max_idx]["c2_list"], substr($line, 1));
                                array_push($diffObjList[$max_idx]["c2_idx_list"], $c2_index);
                                $c2_index++;
                            }
                        }
                    }
                }
            }
        }
    }
    # end of foreach
    return $diffObjList;
}
Esempio n. 2
0
    $version = null;
    $user = null;
    $time = null;
    $comment = null;
    $retArray = array();
    foreach ($lines as $line) {
        $line1 = substr($line, 0, 1);
        $line5 = substr($line, 0, 5);
        if (preg_match("/r(\\d+) \\| (\\w+) \\| (\\d{4}-\\d{2}-\\d{2} \\d{2}:\\d{2}:\\d{2})/", $line, $matches)) {
            // revision line
            $version = $matches[1];
            $user = $matches[2];
            $time = $matches[3];
        } else {
            if ($line5 == "-----") {
                $tr_line = "<tr><td><input type=checkbox class='choice'></td><td class='version'>{$version}</td><td class='user'>{$user}</td><td class='time'>{$time}</td><td class='comment'><span><pre>{$comment}</span></pre></td></tr>";
                array_push($retArray, $tr_line);
                $comment = "";
            } else {
                $comment .= $line;
            }
        }
    }
    echo implode("\n", $retArray);
}
save_log($ldap, $svn_url);
$expect_file = build_expect_file($ldap, $passwd, $svn_url);
$cmd = "chmod 700 {$expect_file}; {$expect_file}";
exec($cmd, $lines, $ret);
$lines = get_valid_diff_lines($lines);
output_svn_log($lines);