Exemple #1
0
 public function testDiffRemoveOneLine()
 {
     $diff_content = file_get_contents(dirname(__FILE__) . '/test-diff-remove-oneline.diff');
     $diff = new IDF_Diff($diff_content);
     $diff->parse();
     $this->assertEqual(2, count($diff->files));
     $this->assertEqual(array(280, 288, ''), $diff->files['src/IDF/Scm/Git.php']['chunks'][1][2]);
     $this->assertEqual(7, count($diff->files['src/IDF/Scm/Git.php']['chunks'][1]));
 }
Exemple #2
0
 public function clean_patch()
 {
     $diff = new IDF_Diff(file_get_contents(Pluf::f('upload_issue_path') . '/' . $this->cleaned_data['patch']));
     $diff->parse();
     if (count($diff->files) == 0) {
         throw new Pluf_Form_Invalid(__('We were not able to parse your patch. Please provide a valid patch.'));
     }
     return $this->cleaned_data['patch'];
 }
Exemple #3
0
 /**
  * Returns a HTML snippet with a line-by-line pre-rendered table
  * for the given source content
  *
  * @param array file information as returned by getMimeType or getMimeTypeFromContent
  * @param string the content of the file
  * @return string
  */
 public static function highLight($fileinfo, $content)
 {
     $pretty = '';
     if (self::isSupportedExtension($fileinfo[2])) {
         $pretty = ' prettyprint';
     }
     $table = array();
     $i = 1;
     foreach (preg_split("/\r\n|\r|\n/", $content) as $line) {
         $table[] = '<tr class="c-line"><td class="code-lc" id="L' . $i . '"><a href="#L' . $i . '">' . $i . '</a></td>' . '<td class="code mono' . $pretty . '">' . IDF_Diff::padLine(Pluf_esc($line)) . '</td></tr>';
         $i++;
     }
     return Pluf_Template::markSafe(implode("\n", $table));
 }
Exemple #4
0
 public function view($request, $match)
 {
     $prj = $request->project;
     $review = Pluf_Shortcuts_GetObjectOr404('IDF_Review', $match[2]);
     $prj->inOr404($review);
     $url = Pluf_HTTP_URL_urlForView('IDF_Views_Review::view', array($prj->shortname, $review->id));
     $title = Pluf_Template::markSafe(sprintf(__('Review <a href="%s">%d</a>: %s'), $url, $review->id, $review->summary));
     $patches = $review->get_patches_list();
     $patch = $patches[0];
     $diff = new IDF_Diff(file_get_contents(Pluf::f('upload_issue_path') . '/' . $patch->patch));
     $diff->parse();
     // The form to submit comments is based on the files in the
     // diff
     if ($request->method == 'POST' and !$request->user->isAnonymous()) {
         $form = new IDF_Form_ReviewFileComment($request->POST, array('files' => $diff->files, 'user' => $request->user, 'patch' => $patch, 'project' => $prj));
         if ($form->isValid()) {
             $review_comment = $form->save();
             $review = $patch->get_review();
             $urlr = Pluf_HTTP_URL_urlForView('IDF_Views_Review::view', array($prj->shortname, $review->id));
             $request->user->setMessage(sprintf(__('Your <a href="%s">code review %d</a> has been published.'), $urlr, $review->id));
             $url = Pluf_HTTP_URL_urlForView('IDF_Views_Review::index', array($prj->shortname));
             $review_comment->notify($request->conf);
             return new Pluf_HTTP_Response_Redirect($url);
         }
     } else {
         $form = new IDF_Form_ReviewFileComment(null, array('files' => $diff->files, 'user' => $request->user, 'project' => $prj, 'patch' => $patch));
     }
     $scm = IDF_Scm::get($request->project);
     $files = array();
     $reviewers = array();
     foreach ($diff->files as $filename => $def) {
         $fileinfo = $scm->getPathInfo($filename, $patch->get_commit()->scm_id);
         $sql = new Pluf_SQL('cfile=%s', array($filename));
         $cts = $patch->getFileComments(array('filter' => $sql->gen(), 'order' => 'creation_dtime ASC'));
         foreach ($cts as $ct) {
             $reviewers[] = $ct->get_comment()->get_submitter();
         }
         if (count($def['chunks'])) {
             $orig_file = $fileinfo ? $scm->getFile($fileinfo) : '';
             $files[$filename] = array($diff->fileCompare($orig_file, $def, $filename), $form->f->{md5($filename)}, $cts);
         } else {
             $files[$filename] = array('', $form->f->{md5($filename)}, $cts);
         }
     }
     $reviewers = Pluf_Model_RemoveDuplicates($reviewers);
     return Pluf_Shortcuts_RenderToResponse('idf/review/view.html', array_merge(array('page_title' => $title, 'review' => $review, 'files' => $files, 'diff' => $diff, 'patch' => $patch, 'comments' => $patch->get_comments_list(array('sort' => 'id ASC')), 'form' => $form, 'reviewers' => $reviewers), IDF_Views_Issue::autoCompleteArrays($prj)), $request);
 }
Exemple #5
0
 public function commit($request, $match)
 {
     $scm = IDF_Scm::get($request->project);
     $commit = $match[2];
     $large = $scm->isCommitLarge($commit);
     $cobject = $scm->getCommit($commit, !$large);
     if (!$cobject) {
         throw new Exception('could not retrieve commit object for ' . $commit);
     }
     $title = sprintf(__('%s Commit Details'), (string) $request->project);
     $page_title = sprintf(__('%s Commit Details - %s'), (string) $request->project, $commit);
     $rcommit = IDF_Commit::getOrAdd($cobject, $request->project);
     $diff = new IDF_Diff($cobject->diff);
     $diff->parse();
     $scmConf = $request->conf->getVal('scm', 'git');
     try {
         $changes = $scm->getChanges($commit);
     } catch (Exception $e) {
         // getChanges is not yes supported by this backend.
         $changes = array();
     }
     $branches = $scm->getBranches();
     $in_branches = $scm->inBranches($cobject->commit, '');
     $tags = $scm->getTags();
     $in_tags = $scm->inTags($cobject->commit, '');
     return Pluf_Shortcuts_RenderToResponse('idf/source/' . $scmConf . '/commit.html', array('page_title' => $page_title, 'title' => $title, 'diff' => $diff, 'cobject' => $cobject, 'commit' => $commit, 'changes' => $changes, 'branches' => $branches, 'tree_in' => $in_branches, 'tags' => $tags, 'tags_in' => $in_tags, 'scm' => $scmConf, 'rcommit' => $rcommit, 'large_commit' => $large), $request);
 }