diff --git a/apps/front/modules/default/actions/breadcrumbComponent.class.php b/apps/front/modules/default/actions/breadcrumbComponent.class.php index b24c21b..6832e03 100644 --- a/apps/front/modules/default/actions/breadcrumbComponent.class.php +++ b/apps/front/modules/default/actions/breadcrumbComponent.class.php @@ -31,7 +31,6 @@ public function execute($request) $fileBreadCrumbList = FileQuery::create() ->filterById($fileId, Criteria::NOT_EQUAL) ->filterByBranchId($this->currentBreadCrumbFile->getBranchId()) - ->filterByIsBinary(false) ->orderByFilename() ->find() ; diff --git a/apps/front/modules/default/actions/fileAction.class.php b/apps/front/modules/default/actions/fileAction.class.php index 07034ac..9c34593 100644 --- a/apps/front/modules/default/actions/fileAction.class.php +++ b/apps/front/modules/default/actions/fileAction.class.php @@ -35,7 +35,6 @@ public function execute($request) ->select(array('Id', 'Filename')) ->filterByBranchId($this->file->getBranchId()) ->filterByFilename($this->file->getFilename(), Criteria::LESS_THAN) - ->filterByIsBinary(false) ->orderByFilename(Criteria::DESC) ->find() ; @@ -44,12 +43,10 @@ public function execute($request) ->select(array('Id', 'Filename')) ->filterByBranchId($this->file->getBranchId()) ->filterByFilename($this->file->getFilename(), Criteria::GREATER_THAN) - ->filterByIsBinary(false) ->orderByFilename(Criteria::ASC) ->find() ; - $commitFrom = $request->getParameter('from', $this->branch->getCommitReference()); $commitTo = $request->getParameter('to', $this->branch->getLastCommit()); $this->commit_from = null; @@ -77,28 +74,53 @@ public function execute($request) $this->previousFileId = $this->findClosestFileId($previousFiles, $modifiedFiles); $this->nextFileId = $this->findClosestFileId($nextFiles, $modifiedFiles); - $this->fileContentLines = $this->gitCommand->getShowFileFromBranch( - $this->repository->getGitDir(), - $commitFrom, - $commitTo, - $this->file->getFilename(), - $options - ); + if ($this->file->getIsBinary()) + { + $oldBinaryContent = $this->gitCommand->getShowFile( + $this->repository->getGitDir(), + $commitFrom, + $this->file->getFilename() + ); - $fileLineCommentsModel = CommentQuery::create() - ->filterByFileId($this->file->getId()) - ->filterByCommit($this->file->getLastChangeCommit()) - ->filterByType(CommentPeer::TYPE_LINE) - ->find() - ; + $this->oldImageExists = !(strpos($oldBinaryContent, 'fatal: Path') === 0); + $this->oldImageType = ImageUtils::getImageTypeFromContent($oldBinaryContent); + $this->oldImageContent = base64_encode($oldBinaryContent); - $this->userId = $this->getUser()->getId(); + $newBinaryContent = $this->gitCommand->getShowFile( + $this->repository->getGitDir(), + $commitTo, + $this->file->getFilename() + ); - $this->fileLineComments = array(); - foreach ($fileLineCommentsModel as $fileLineCommentModel) + $this->newImageExists = !(strpos($newBinaryContent, 'fatal: Path') === 0); + $this->newImageType = ImageUtils::getImageTypeFromContent($newBinaryContent); + $this->newImageContent = base64_encode($newBinaryContent); + } + else { - $this->fileLineComments[$fileLineCommentModel->getPosition()][] = $fileLineCommentModel; + $this->fileContentLines = $this->gitCommand->getShowFileFromBranch( + $this->repository->getGitDir(), + $commitFrom, + $commitTo, + $this->file->getFilename(), + $options + ); + + $fileLineCommentsModel = CommentQuery::create() + ->filterByFileId($this->file->getId()) + ->filterByCommit($this->file->getLastChangeCommit()) + ->filterByType(CommentPeer::TYPE_LINE) + ->find() + ; + + $this->fileLineComments = array(); + foreach ($fileLineCommentsModel as $fileLineCommentModel) + { + $this->fileLineComments[$fileLineCommentModel->getPosition()][] = $fileLineCommentModel; + } } + + $this->userId = $this->getUser()->getId(); } /** diff --git a/apps/front/modules/default/templates/fileListSuccess.php b/apps/front/modules/default/templates/fileListSuccess.php index aae2efe..9db6836 100644 --- a/apps/front/modules/default/templates/fileListSuccess.php +++ b/apps/front/modules/default/templates/fileListSuccess.php @@ -47,15 +47,14 @@

i - - $file['Id'])))); ?>" - title=""> - - + $file['Id'])))); ?>" + title=""> + + - + Ñ

diff --git a/apps/front/modules/default/templates/fileSuccess.php b/apps/front/modules/default/templates/fileSuccess.php index 8c63beb..c021311 100644 --- a/apps/front/modules/default/templates/fileSuccess.php +++ b/apps/front/modules/default/templates/fileSuccess.php @@ -89,7 +89,20 @@ class="add_bubble -
This is a binary file.
+
+
+
No binary file in this revision.
+
This is an unknown type binary file.
+ + +
+
+
No binary file in this revision.
+
This is an unknown type binary file.
+ + +
+
diff --git a/lib/git/GitCommand.class.php b/lib/git/GitCommand.class.php index b8c7603..cd2cb35 100644 --- a/lib/git/GitCommand.class.php +++ b/lib/git/GitCommand.class.php @@ -73,12 +73,12 @@ public function getDiffFilesFromBranch($gitDir, $referenceCommit, $lastCommit, $ if($withDetails) { - $lineResults = $this->exec("git --git-dir=%s diff %s..%s --numstat | sed 's/\'$'\t''/ /g'", array($gitDir, $referenceCommit, $lastCommit)); + $lineResults = $this->exec("git --git-dir=%s diff %s..%s --numstat", array($gitDir, $referenceCommit, $lastCommit)); $linesInfos = array(); foreach($lineResults as $line) { - $infos = explode(' ', $line); + $infos = explode("\t", $line); if(count($infos) == 3) { $linesInfos[$infos[2]] = array($infos[0], $infos[1]); @@ -117,9 +117,7 @@ public function getShowFile($gitDir, $currentCommit, $filename) { $this->fetch($gitDir); - $fileContent = $this->exec('git --git-dir=%s show %s:%s', array($gitDir, $currentCommit, $filename)); - - return implode(PHP_EOL, $fileContent); + return $this->execReturnRaw('git --git-dir=%s show %s:%s', array($gitDir, $currentCommit, $filename)); } /** @@ -137,6 +135,7 @@ public function getShowFileFromBranch($gitDir, $referenceCommit, $currentCommit, $gitDiffOptions = array( '-U9999' ); + if (isset($options['ignore-all-space']) && $options['ignore-all-space']) { $gitDiffOptions[] = '-w'; @@ -144,20 +143,17 @@ public function getShowFileFromBranch($gitDir, $referenceCommit, $currentCommit, $currentContentLinesResults = $this->exec('git --git-dir=%s diff '.implode(' ', $gitDiffOptions).' %s..%s -- %s', array($gitDir, $referenceCommit, $currentCommit, $filename)); - $patternFinded = false; $fileLines = $currentContentLinesResults; foreach($currentContentLinesResults as $key => $currentContentLinesResult) { - if($patternFinded === false) + unset($fileLines[$key]); + if(substr($currentContentLinesResult, 0, 2) == "@@") { - unset($fileLines[$key]); - if(substr($currentContentLinesResult, 0, 2) == "@@") - { - break; - } + break; } } + return $fileLines; } @@ -233,4 +229,44 @@ public function exec($cmd, array $arguments = array(), &$status = null) return $internOutput; } + + /** + * Executes a command, and returns the raw output as a string + * Absolutely no operation is done on the command's output. + * + * @param string $cmd + * @param array $arguments + * @param int & $status + * + * @return string + */ + public function execReturnRaw($cmd, array $arguments = array(), &$status = null) + { + $arguments = array_map('escapeshellarg', $arguments); + + $cmd = vsprintf($cmd, $arguments); + $cmd.= ' 2>&1'; + + // exec() returns an array of strings, but quoting http://www.php.net/manual/en/function.exec.php : + // "Trailing whitespace, such as \n, is not included in this array." + // So, exec() will break the output -- especially when working with binary files. + // passthru() doesn't do that ; but writes on stdout ; which explains the need for output buffering. + ob_start(); + passthru($cmd, $internStatus); + $internOutput = ob_get_contents(); + ob_end_clean(); + + if($this->logger !== null) + { + $this->logger->log($cmd, $internStatus, $internOutput); + } + + if(!is_null($status)) + { + $status = $internStatus; + } + + return $internOutput; + } + } diff --git a/lib/utils/ImageUtils.class.php b/lib/utils/ImageUtils.class.php new file mode 100644 index 0000000..c354b39 --- /dev/null +++ b/lib/utils/ImageUtils.class.php @@ -0,0 +1,24 @@ + "\xFF\xD8\xFF", + 'gif' => 'GIF', + 'png' => "\x89\x50\x4e\x47\x0d\x0a", + 'bmp' => 'BM', + ); + + foreach ($supportedTypes as $supportedType => $header) + { + if (strpos($binaryContent, $header) === 0) + { + return $supportedType; + } + } + + return null; + } +} \ No newline at end of file diff --git a/web/css/less/_data.less b/web/css/less/_data.less index 5d6e51a..eb1ef1b 100644 --- a/web/css/less/_data.less +++ b/web/css/less/_data.less @@ -80,4 +80,15 @@ } } } + + .imageDiff { + float: left; + margin: 20px; + width: 46%; + + img { + border: 1px solid #f9a; + max-width: 100%; + } + } } diff --git a/web/css/less/_list.less b/web/css/less/_list.less index a0dced0..779a96d 100644 --- a/web/css/less/_list.less +++ b/web/css/less/_list.less @@ -280,6 +280,10 @@ color: #4a3; font-size: 21px; margin-right: 3px; + + &.binary { + color: @lightGrey; + } } } diff --git a/web/css/main.css b/web/css/main.css index 26b74ed..49d4c41 100755 --- a/web/css/main.css +++ b/web/css/main.css @@ -216,6 +216,7 @@ font-size:21px; margin-right:3px; } +.list .list_body table tr td.file_name .ricon.binary { color:#999999; } .list .list_body table tr td.branch_name { white-space:nowrap; } .list .list_body table tr td.branch_name .new { background-color:#4183c4; @@ -486,6 +487,15 @@ font-size:12px; } .list_body.data table .line_comment .clipper { width:925px; } +.list_body.data .imageDiff { + float:left; + margin:20px; + width:46%; +} +.list_body.data .imageDiff img { + border:1px solid #ff99aa; + max-width:100%; +} .form { display:inline-block; width:auto;