php中對比svn兩個不同分支目錄的檔案的執行個體分析

來源:互聯網
上載者:User
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');?>

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.