srchub

srchub Commit Details


Date:2016-04-23 12:01:09 (8 years 7 months ago)
Author:Natalie Adams
Branch:master
Commit:3f699e0afddab7f35cf88b8be446cddbeaa0c013
Parents: 1fdddf2501a61b8e02fe3567a9b2d3430ccbe296
Message:Issue 112: Missing git information for some files (final fix)

Changes:

File differences

indefero/src/IDF/Migrations/33GitCache.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
<?php
function IDF_Migrations_32ExternalFile_up()
{
$table = Pluf::factory('IDF_Scm_Cache_Git')->getSqlTable();
$sql = array();
$sql["MySQL"] = "ALTER TABLE " . $table . " CHANGE COLUMN `githash` TEXT NOT NULL DEFAULT '' AFTER `project`;";
$db = Pluf::db();
$engine = Pluf::f('db_engine');
$db->execute($sql[$engine]);
}
function IDF_Migrations_32ExternalFile_down()
{
$table = Pluf::factory('IDF_Scm_Cache_Git')->getSqlTable();
$sql = array();
$sql["MySQL"] = "ALTER TABLE " . $table . " CHANGE COLUMN `githash` VARCHAR(40) NOT NULL AFTER `project`;";
$db = Pluf::db();
$engine = Pluf::f('db_engine');
$db->execute($sql[$engine]);
}
indefero/src/IDF/Scm/Cache/Git.php
5050
5151
5252
53
53
5454
5555
56
56
5757
5858
5959
......
123123
124124
125125
126
126
127127
128
129128
130129
131130
*/
public function store($infos)
{
foreach ($infos as $blob) {
foreach ($infos as $key => $blob) {
$cache = new IDF_Scm_Cache_Git();
$cache->project = $this->_project;
$cache->githash = $blob->hash;
$cache->githash = $key;
$blob->title = IDF_Commit::toUTF8($blob->title);
$cache->content = IDF_Commit::toUTF8($blob->date) . chr(31)
. IDF_Commit::toUTF8($blob->author) . chr(31)
),
'githash' =>
array(
'type' => 'Pluf_DB_Field_Varchar',
'type' => 'Pluf_DB_Field_Text',
'blank' => false,
'size' => 40,
'index' => true,
),
'content' =>
indefero/src/IDF/Scm/Git.php
343343
344344
345345
346
346
347347
348348
349349
......
718718
719719
720720
721
721
722722
723723
724724
725725
726726
727
727
728728
729729
730730
......
742742
743743
744744
745
745
746746
747747
748748
......
766766
767767
768768
769
769
770770
771771
772772
773
774
773
774
775775
776776
777777
778778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
795816
796
797
798
799
800
801
802
817
818
819
820
821
822
823
824
825
826
827
828
803829
804
830
805831
806832
807
808
809
810
811
812
813
814
815
816
817
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
818849
819
820850
821
822
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
823870
824
871
872
825873
826874
827875
$res[] = $file;
}
// Grab the details for each blob and return the list.
return $this->getTreeDetails($res);
return $this->getTreeDetails($res, $commit);
}
/**
* @param array Tree information
* @return array Updated tree information
*/
public function getTreeDetails($tree)
public function getTreeDetails($tree, $commit)
{
$n = count($tree);
$details = array();
for ($i=0;$i<$n;$i++) {
if ($tree[$i]->type == 'blob') {
$details[sha1($tree[$i]->hash . $tree[$i]->fullpath)] = $i;
$details[sha1($tree[$i]->hash . $tree[$i]->fullpath) . ":" . $tree[$i]->hash . ":" . $tree[$i]->fullpath] = $i;
}
}
if (!count($details)) {
}
}
if (count($toapp)) {
$res = $this->appendBlobInfoCache($toapp);
$res = $this->appendBlobInfoCache($toapp, $commit);
foreach ($details as $blob => $idx) {
if (isset($res[$blob])) {
$tree[$idx]->date = $res[$blob]->date;
* @param array The blob for which we need the information
* @return array The information
*/
public function appendBlobInfoCache($blobs)
public function appendBlobInfoCache($blobs, $commit)
{
$rawlog = array();
$cmd = Pluf::f('idf_exec_cmd_prefix', '')
.sprintf('GIT_DIR=%s '.Pluf::f('git_path', 'git').' log --raw --abbrev=40 --pretty=oneline -5000 --skip=%%s',
escapeshellarg($this->repo));
.sprintf('GIT_DIR=%s '.Pluf::f('git_path', 'git').' log --raw --abbrev=40 --pretty=oneline -5000 --skip=%%s %s',
escapeshellarg($this->repo), $commit);
$skip = 0;
$res = array();
self::exec('IDF_Scm_Git::appendBlobInfoCache',
sprintf($cmd, $skip), $rawlog);
while (count($rawlog) and count($blobs)) {
$rawlog = implode("\n", array_reverse($rawlog));
$tmpRes = [];
foreach(explode("\n", $rawlog) as $line) {
if ($line[0] != ":") { //This is the commit number line
$commit = explode(" ", $line)[0];
$fc = $this->getCommit($commit);
foreach($tmpRes as $r) {
$res[$r["hash"]] = (object) [
"hash" => $r["hash"],
"date" => $fc->date,
"title" => $fc->title,
"author" => $fc->author
];
}
$tmpRes = [];
$fileinfoarr = [];
$lookup = [];
$cache = [];
$currentcommit = null;
$rawlog = implode("\n", array_reverse($rawlog));
foreach(explode("\n", $rawlog) as $line) {
if ($line[0] == ":") {
$matches = preg_split('/\s/', $line);
$currentFileHash = $matches[3];
$file = $matches[5];
$fileinfoarr[] = [
"filehash" => $currentFileHash,
"file" => $file
];
} else {
$matches = preg_split('/\s/', $line);
$currentcommit = $matches[0];
if ($fileinfoarr) {
$lookup[$currentcommit] = $fileinfoarr;
$fileinfoarr = [];
}
}
}
$commitData = $this->getCommit($commit);
foreach($blobs as $blobKey => $blobVal) {
list($newhash, $hash, $file) = explode(":", $blobKey);
if (isset($lookup[$commitData->commit])) {
$test = $lookup[$commitData->commit];
} else {
if (isset($lookup[$commitData->parents[0]])) { //tag?
$test = $lookup[$commitData->parents[0]];
} else {
$sides = explode("\t", $line);
$leftSide = trim($sides[0]);
$rightSide = trim($sides[1]);
$leftSideSplit = explode(" ", $leftSide);
$newHash = sha1($leftSideSplit[3] . $rightSide);
$tmpRes[$newHash] = [
"hash" => $newHash
$test = [];
}
}
$found = false;
foreach($test as $fileinfo) {
if ($fileinfo["filehash"] == $hash && $fileinfo["file"] == $file) {
$found = true;
$res[$blobKey] = (object) [
"hash" => $newhash,
"date" => $commitData->date,
"title" => $commitData->title,
"author" => $commitData->author
];
unset($blobs[$newHash]);
$cache[$blobKey] = $res[$blobKey];
}
}
$rawlog = array();
$skip += 5000;
if ($skip > 20000) {
// We are in the case of the import of a big old
// repository, we can store as unknown the commit info
// not to try to retrieve them each time.
foreach ($blobs as $blob => $idx) {
$res[$blob] = (object) array('hash' => $blob,
'date' => '0',
'title' => '----',
'author' => 'Unknown');
if (!$found) {
foreach ($lookup as $key=>$val) {
foreach($val as $fileinfo) {
if ($fileinfo["filehash"] == $hash && $fileinfo["file"] == $file) {
$commitTempData = $this->getCommit($key);
$res[$blobKey] = (object) [
"hash" => $newhash,
"date" => $commitTempData->date,
"title" => $commitTempData->title,
"author" => $commitTempData->author
];
$cache[$blobKey] = $res[$blobKey];
$found = true;
break;
}
}
}
break;
}
self::exec('IDF_Scm_Git::appendBlobInfoCache',
sprintf($cmd, $skip), $rawlog);
// If it's still not found - find the first commit where it's modified and use that
if (!$found) {
foreach ($lookup as $key=>$val) {
foreach($val as $fileinfo) {
if ($fileinfo["file"] == $file) {
$commitTempData = $this->getCommit($key);
$res[$blobKey] = (object) [
"hash" => $newhash,
"date" => $commitTempData->date,
"title" => $commitTempData->title,
"author" => $commitTempData->author
];
$cache[$blobKey] = $res[$blobKey];
break;
}
}
}
}
}
$this->cacheBlobInfo($res);
$this->cacheBlobInfo($cache);
return $res;
}

Archive Download the corresponding diff file

Branches

Number of commits:
Page rendered in 0.07915s using 20 queries.