php中对比svn两个不同分支目录的文件的实例分析
<?php /** * 对比svn两个不同分支目录的文件 */ class DiffDir {/*{{{*/ public function run($dir1,$dir2,$dirResult = '/tmp/') {/*{{{*/ $hash1 = $this->getFileInfo($dir1); $hash2 = $this->getFileInfo($dir2); $this->diff($dir1,$hash1,$dir2,$hash2,$dirResult); }/*}}}*/ //查找文件信息 public function getFileInfo($dir) {/*{{{*/ if(false == is_dir($dir)) { return array(); } $cmd = "find {$dir} -type f -name '*.php' | sort | xargs md5sum | awk '{print $2,$1}'"; $ret = exec($cmd, $out, $status); if(is_array($out) && count($out) > 0) { return $this->formart($dir,$out); } return array(); }/*}}}*/ //格式化文件 public function formart($dir,array $data) {/*{{{*/ $hash = array(); foreach($data as $line) { $line = str_replace($dir,'',$line); $arr = explode(" ",$line); $hash[$arr[0]] = $arr[1]; } return $hash; }/*}}}*/ //对比文件 public function diff($dir1,array $hash1,$dir2,array $hash2,$dirResult) {/*{{{*/ foreach($hash1 as $key1 => $va11) { $fileName1 = $this->getRetFileName($dir1,$key1); if(false == isset($hash2[$key1])) { $cmd = "cp -f {$dir1}{$key1} {$dirResult}/{$fileName1}\n"; exec($cmd, $out, $status); continue; } $fileName2 = $this->getRetFileName($dir2,$key1); if($va11 != $hash2[$key1]) { $cmd = "cp -f {$dir1}{$key1} {$dirResult}/{$fileName1}\n"; exec($cmd, $out, $status); $cmd = "cp -f {$dir2}{$key1} {$dirResult}/{$fileName2}\n"; exec($cmd, $out, $status); continue; } } foreach($hash2 as $key2 => $va12) { $fileName2 = $this->getRetFileName($dir2,$key2); if(false == isset($hash1[$key2])) { $cmd = "cp -f {$dir2}{$key2} {$dirResult}/{$fileName2}\n"; exec($cmd, $out, $status); continue; } } }/*}}}*/ public function getRetFileName($dir,$file) { return basename($file).str_replace("/",'_',dirname($dir.$file)); } }/*}}}*/ $diffDir = new DiffDir(); $diffDir->run('/tmp/diffDir/v6.1.0','/tmp/diffDir/v6.2.0','/tmp/diffDir/result'); ?>
Das obige ist der detaillierte Inhalt vonBeispielanalyse des Vergleichs von Dateien in zwei verschiedenen Zweigverzeichnissen von SVN in PHP. Für weitere Informationen folgen Sie bitte anderen verwandten Artikeln auf der PHP chinesischen Website!