/** * Check if directory has any CVS information. * * This is actually sort of a recursive problem. If any subdirectory has * CVS information it can be imported. */ function is_cvs_dir($dir) { $files = @scandir($dir); // If there are no files, fail early. if (!$files) { return FALSE; } foreach ($files as $file) { $absolute = $dir . '/' . $file; // Skip POSIX aliases if ($file == '.' || $file == '..') { continue; } if (is_dir($absolute) && $file == 'Attic') { return TRUE; } elseif (strpos($file, ',v') !== FALSE) { return TRUE; } elseif (is_dir($absolute) && is_cvs_dir($absolute)) { return TRUE; } } return FALSE; }
<?php // Load shared functions. require_once dirname(__FILE__) . '/shared.php'; $config_template = realpath($argv[1]); $repository_root = realpath($argv[2]); $source_dir = $argv[3]; $absolute_source_dir = $repository_root . '/' . $source_dir; $elements = explode('/', $source_dir); $project = array_pop($elements); $destination_dir = $argv[4]; // If the source_dir is an empty directory, skip it; cvs2git barfs on these. if (is_empty_dir($absolute_source_dir)) { git_log("Skipping empty source directory '{$absolute_source_dir}'."); exit; } if (!is_cvs_dir($absolute_source_dir)) { git_log("Skipping non CVS source directory '{$absolute_source_dir}'."); exit; } // If the target destination dir exists already, remove it. if (file_exists($destination_dir) && is_dir($destination_dir)) { passthru('rm -Rf ' . escapeshellarg($destination_dir)); } // Create the destination directory. $ret = 0; passthru('mkdir -p ' . escapeshellarg($destination_dir), $ret); if (!empty($ret)) { git_log("Failed to create output directory at {$destination_dir}, project import will not procede.", 'WARN', $project); exit; } $destination_dir = realpath($destination_dir);