Indefero

Indefero Commit Details


Date:2009-04-21 10:45:35 (15 years 8 months ago)
Author:Loic d'Anterroches
Branch:dev, develop, feature-issue_links, feature.better-home, feature.content-md5, feature.diff-whitespace, feature.download-md5, feature.issue-links, feature.issue-of-others, feature.issue-summary, feature.search-filter, feature.webrepos, feature.wiki-default-page, master, release-1.1, release-1.2, release-1.3
Commit:aab8720cac801e21672f9372881624c4b8bedaf3
Parents: 86da0c0eed9f249fb083741a150e17266f4a84c6
Message:Added a DB backend for the Git blob info.

Changes:

File differences

src/IDF/Migrations/11GitCache.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
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
<?php
/* -*- tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
/*
# ***** BEGIN LICENSE BLOCK *****
# This file is part of InDefero, an open source project management application.
# Copyright (C) 2008 Céondo Ltd and contributors.
#
# InDefero is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# InDefero is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
#
# ***** END LICENSE BLOCK ***** */
/**
* Add the DB based Git cache.
*/
function IDF_Migrations_11GitCache_up($params=null)
{
$models = array(
'IDF_Scm_Cache_Git',
);
$db = Pluf::db();
$schema = new Pluf_DB_Schema($db);
foreach ($models as $model) {
$schema->model = new $model();
$schema->createTables();
}
}
function IDF_Migrations_11GitCache_down($params=null)
{
$models = array(
'IDF_Scm_Cache_Git',
);
$db = Pluf::db();
$schema = new Pluf_DB_Schema($db);
foreach ($models as $model) {
$schema->model = new $model();
$schema->dropTables();
}
}
src/IDF/Scm.php
5656
5757
5858
59
60
61
62
63
5964
6065
6166
......
6570
6671
6772
73
74
75
76
77
78
79
80
81
6882
6983
7084
public $repo = '';
/**
* Corresponding project object.
*/
public $project = null;
/**
* Cache storage.
*
* It must only be used to store data for the lifetime of the
protected $cache = array();
/**
* Default constructor.
*/
public function __construct($repo, $project=null)
{
$this->repo = $repo;
$this->project = $project;
}
/**
* Returns an instance of the correct scm backend object.
*
* @param IDF_Project
src/IDF/Scm/Cache/Git.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
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
<?php
/* -*- tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
/*
# ***** BEGIN LICENSE BLOCK *****
# This file is part of InDefero, an open source project management application.
# Copyright (C) 2008 Céondo Ltd and contributors.
#
# InDefero is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# InDefero is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
#
# ***** END LICENSE BLOCK ***** */
/**
* This class implements the cache storage for the Git commits.
*
* The storage is simple. Each commit is linked to a project to drop
* the cache when the project is dropped. The key is the commit hash
* and the data is the date, author and one line title of information.
*
* A clean interface is available to bulk set/get a series of commit
* info with the minimum of SQL queries. The goal is to be fast.
*/
class IDF_Scm_Cache_Git extends Pluf_Model
{
public $_model = __CLASS__;
/**
* The current project to limit the search to.
*/
public $_project = null;
/**
* Store in the cache blob infos.
*
* The info is an array of stdClasses, with hash, date, title and
* author properties.
*
* @param array Blob infos
*/
public function store($infos)
{
foreach ($infos as $blob) {
$cache = new IDF_Scm_Cache_Git();
$cache->project = $this->_project;
$cache->githash = $blob->hash;
$cache->content = $blob->date.chr(31).$blob->author.chr(31).$blob->title;
$sql = new Pluf_SQL('project=%s AND githash=%s',
array($this->_project->id, $blob->hash));
if (0 == Pluf::factory(__CLASS__)->getCount(array('filter' => $sql->gen()))) {
$cache->create();
}
}
}
/**
* Get for the given hashes the corresponding date, title and
* author.
*
* It returns an hash indexed array with the info. If an hash is
* not in the db, the key is not set.
*
* Note that the hashes must always come from internal tools.
*
* @param array Hashes to get info
* @return array Blob infos
*/
public function retrieve($hashes)
{
$res = array();
$db = $this->getDbConnection();
$hashes = array_map(array($db, 'esc'), $hashes);
$sql = new Pluf_SQL('project=%s AND githash IN ('.implode(', ', $hashes).')',
array($this->_project->id));
foreach (Pluf::factory(__CLASS__)->getList(array('filter' => $sql->gen())) as $blob) {
$tmp = split(chr(31), $blob->content, 3);
$res[$blob->githash] = (object) array(
'hash' => $blob->githash,
'date' => $tmp[0],
'title' => $tmp[2],
'author' => $tmp[1],
);
}
return $res;
}
/**
* The storage is composed of 4 columns, id, project, hash and the
* raw data.
*/
function init()
{
$this->_a['table'] = 'idf_scm_cache_git';
$this->_a['model'] = __CLASS__;
$this->_a['cols'] = array(
// It is mandatory to have an "id" column.
'id' =>
array(
'type' => 'Pluf_DB_Field_Sequence',
'blank' => true,
),
'project' =>
array(
'type' => 'Pluf_DB_Field_Foreignkey',
'model' => 'IDF_Project',
'blank' => false,
),
'githash' =>
array(
'type' => 'Pluf_DB_Field_Varchar',
'blank' => false,
'size' => 40,
'index' => true,
),
'content' =>
array(
'type' => 'Pluf_DB_Field_Text',
'blank' => false,
),
);
}
}
src/IDF/Scm/Git.php
2929
3030
3131
32
33
34
35
36
37
3832
3933
4034
......
190184
191185
192186
193
187
194188
195189
196190
......
633627
634628
635629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
636652
637653
638654
......
645661
646662
647663
648
649664
650665
651666
......
658673
659674
660675
661
676
662677
663678
664679
665680
666681
667682
668
683
669684
670685
671686
672687
673
674688
675689
676690
{
public $mediumtree_fmt = 'commit %H%nAuthor: %an <%ae>%nTree: %T%nDate: %ai%n%n%s%n%n%b';
public function __construct($repo)
{
$this->repo = $repo;
}
/* ============================================== *
* *
* Common Methods Implemented By All The SCMs *
public static function factory($project)
{
$rep = sprintf(Pluf::f('git_repositories'), $project->shortname);
return new IDF_Scm_Git($rep);
return new IDF_Scm_Git($rep, $project);
}
/**
*/
public function getCachedBlobInfo($hashes)
{
$cache = new IDF_Scm_Cache_Git();
$cache->_project = $this->project;
return $cache->retrieve(array_keys($hashes));
}
/**
* Cache blob info.
*
* Given a series of blob info, cache them.
*
* @param array Blob info
* @return bool Success
*/
public function cacheBlobInfo($info)
{
$cache = new IDF_Scm_Cache_Git();
$cache->_project = $this->project;
return $cache->store($info);
}
public function getFileCachedBlobInfo($hashes)
{
$res = array();
$cache = Pluf::f('tmp_folder').'/IDF_Scm_Git-'.md5($this->repo).'.cache.db';
if (!file_exists($cache)) {
$data = split(chr(30), $data);
foreach ($data as $rec) {
if (isset($hashes[substr($rec, 0, 40)])) {
//$tmp = split(chr(31), gzinflate(substr($rec, 40)), 3);
$tmp = split(chr(31), substr($rec, 40), 3);
$res[substr($rec, 0, 40)] =
(object) array('hash' => substr($rec, 0, 40),
}
/**
* Cache blob info.
* File cache blob info.
*
* Given a series of blob info, cache them.
*
* @param array Blob info
* @return bool Success
*/
public function cacheBlobInfo($info)
public function fileCacheBlobInfo($info)
{
// Prepare the data
$data = array();
foreach ($info as $file) {
//$data[] = $file->hash.gzdeflate($file->date.chr(31).$file->author.chr(31).$file->title, 9);
$data[] = $file->hash.$file->date.chr(31).$file->author.chr(31).$file->title;
}
$data = implode(chr(30), $data).chr(30);

Archive Download the corresponding diff file

Page rendered in 0.08716s using 13 queries.