Collection of themes/skins for the Fossil SCM. Public write access, just make an account.

⌈⌋ branch:  Fossil Skins Extra


Check-in [6a899c4640]

Many hyperlinks are disabled.
Use anonymous login to enable hyperlinks.

Overview
Comment:Repurpose `ignore-glob` to also exclude file type from statistics.
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA1:6a899c464006cba406ccbaaa7012dd277b805ca5
User & Date: mario 2015-04-30 06:17:01
Context
2016-09-04
12:28
Update json-prettifier URL to gitraw CDN. check-in: c102d240bc user: mario tags: trunk
2015-04-30
06:17
Repurpose `ignore-glob` to also exclude file type from statistics. check-in: 6a899c4640 user: mario tags: trunk
2015-02-24
20:45
Use HEX() in query, and hex2bin() in PHP for safer CSV export and binary extraction. Add .erb file type alias. check-in: 6d24f6c61f user: mario tags: trunk
Changes

Changes to features/fossil-stats-table.php.

96
97
98
99
100
101
102



103

104
105
106
107
108
109
110
111
112
...
124
125
126
127
128
129
130







131
132
133

134







135
136
137
138
139
140
141
142
143
144
...
179
180
181
182
183
184
185






186
187
188
189
190
191
192


   #-- open fossil.db
   $db = new PDO("sqlite:$repo");
   $db->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_WARNING);
   $db->sqliteCreateFunction("regexp", function($r, $s) { return preg_match("\1$r\1i", $s); }, 2);






   #-- setup table
   $db->query("DROP TABLE IF EXISTS fx_search"); // obsolete


   #-- loop through files
   $sql = escapeshellarg("
      SELECT 'file' AS type,   name AS name,    uuid,    HEX(CONTENT(uuid)) AS content
         FROM (SELECT  filename.name, bf.uuid, filename.fnid 
               FROM filename  JOIN mlink ON mlink.fnid=filename.fnid JOIN blob bf ON bf.rid=mlink.fid
................................................................................
      if (count($row) != 4) { continue; }
      list($type, $name, $uuid, $content) = $row;
      $content = hex2bin($content);
      echo "→ ", $name, " ", strlen($content), "\n";

      #-- statistics
      if (FX_STATS and $type == "file") {







          if ($lang = language_type($name, $content) or FX_STATS_BIN and $lang = "bin") {

              // add

              $comments = (FX_STATS_DOC && $type != "bin") ? extr_comments($content, $lang) : 0;







              @$stats["lang"][$lang] += strlen($content) - strlen($comments);
              @$stats["lang"]["comments"] += strlen($comments);
              @$total_size += strlen($content);
          }
      }
   }


   #-- `fx_stats` population
   $db->query("CREATE TABLE IF NOT EXISTS fx_stats (name TEXT, type TEXT, value TEXT)");
................................................................................
      "name,text" => "SELECT value FROM config WHERE name='project-name'",
      "description,html" => "SELECT value FROM config WHERE name='project-description'",
   );
   foreach ($other as $key=>$sql) {
       list($key, $typ, ) = explode(",", "$key,int");
       $db->query("INSERT INTO fx_stats (`name`, `type`, `value`) VALUES ('stats_$key', '$typ', ($sql))");
   }








}











>
>
>

>

|







 







>
>
>
>
>
>
>


<
>
|
>
>
>
>
>
>
>


|







 







>
>
>
>
>
>







96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
...
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143

144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
...
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216


   #-- open fossil.db
   $db = new PDO("sqlite:$repo");
   $db->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_WARNING);
   $db->sqliteCreateFunction("regexp", function($r, $s) { return preg_match("\1$r\1i", $s); }, 2);

   // settings
   $cfg = array_column($db->query("SELECT name,value FROM config")->fetchAll(), "value", "name");
   $ignore_glob = @($cfg["ignore-glob"]);  // just a single *.ext used here


   #-- setup table
   //$db->query("DROP TABLE IF EXISTS fx_search"); // obsolete


   #-- loop through files
   $sql = escapeshellarg("
      SELECT 'file' AS type,   name AS name,    uuid,    HEX(CONTENT(uuid)) AS content
         FROM (SELECT  filename.name, bf.uuid, filename.fnid 
               FROM filename  JOIN mlink ON mlink.fnid=filename.fnid JOIN blob bf ON bf.rid=mlink.fid
................................................................................
      if (count($row) != 4) { continue; }
      list($type, $name, $uuid, $content) = $row;
      $content = hex2bin($content);
      echo "→ ", $name, " ", strlen($content), "\n";

      #-- statistics
      if (FX_STATS and $type == "file") {

          // ignore-glob (e.g. *.html)
          if (fnmatch($ignore_glob, $name)) {
              continue;
          }

          // add if matched language, not binary, etc.
          if ($lang = language_type($name, $content) or FX_STATS_BIN and $lang = "bin") {


              // strip comments from code
              if (FX_STATS_DOC && $type != "bin") {
                  $comments = extr_comments($content, $lang);
              }
              else {
                  $comments = "";
              }
              
              // add to language statistics
              @$stats["lang"][$lang] += strlen($content) - strlen($comments);
              @$stats["lang"]["comments"] += strlen($comments);
              $total_size += strlen($content);
          }
      }
   }


   #-- `fx_stats` population
   $db->query("CREATE TABLE IF NOT EXISTS fx_stats (name TEXT, type TEXT, value TEXT)");
................................................................................
      "name,text" => "SELECT value FROM config WHERE name='project-name'",
      "description,html" => "SELECT value FROM config WHERE name='project-description'",
   );
   foreach ($other as $key=>$sql) {
       list($key, $typ, ) = explode(",", "$key,int");
       $db->query("INSERT INTO fx_stats (`name`, `type`, `value`) VALUES ('stats_$key', '$typ', ($sql))");
   }
   // latest_version
   $qv = $db->query("SELECT tagname FROM tag WHERE tagname REGEXP '^sym[-a-z0-9_.]+\d+\.\d+' ORDER BY tagid DESC LIMIT 1");
   if ($qv->execute() and preg_match("/(\d+\.\d+.*)$/", $qv->fetch()["tagname"], $m)) {
       $db->prepare("INSERT INTO fx_stats (`name`, `type`, `value`) VALUES ('stats_latest_version', 'text', ?)")
          ->execute([$m[1]]);
   }


}