Move to git-archive for zip support
Move to git-archive for zip support

<?php <?php
/* /*
* gitphp.conf.php * gitphp.conf.php
* gitphp: A PHP git repository browser * gitphp: A PHP git repository browser
* Component: Configuration * Component: Configuration
* *
* Copyright (C) 2006 Christopher Han <xiphux@gmail.com> * Copyright (C) 2006 Christopher Han <xiphux@gmail.com>
*/ */
   
/* /*
* stylesheet * stylesheet
* Path to page stylesheet * Path to page stylesheet
*/ */
$gitphp_conf['stylesheet'] = "gitphp.css"; $gitphp_conf['stylesheet'] = "gitphp.css";
   
/* /*
* projectroot * projectroot
* Absolute filesystem path prepended to project paths * Absolute filesystem path prepended to project paths
* (don't forget trailing slash!) * (don't forget trailing slash!)
*/ */
$gitphp_conf['projectroot'] = "/git/"; $gitphp_conf['projectroot'] = "/git/";
   
/* /*
* gitbin * gitbin
* Path to git binary * Path to git binary
* For example, /usr/bin/git on Linux * For example, /usr/bin/git on Linux
* or C:\\Program Files\\Git\\bin\\git.exe on Windows * or C:\\Program Files\\Git\\bin\\git.exe on Windows
* with msysgit. You can also omit the full path and just * with msysgit. You can also omit the full path and just
* use the executable name to search the user's $PATH. * use the executable name to search the user's $PATH.
* Note: Versions of PHP below 5.2 have buggy handling of spaces * Note: Versions of PHP below 5.2 have buggy handling of spaces
* in paths. Use the 8.3 version of the filename if you're * in paths. Use the 8.3 version of the filename if you're
* having trouble, e.g. C:\\Progra~1\\Git\\bin\\git.exe * having trouble, e.g. C:\\Progra~1\\Git\\bin\\git.exe
*/ */
$gitphp_conf['gitbin'] = "/usr/bin/git"; $gitphp_conf['gitbin'] = "/usr/bin/git";
   
/* /*
* diffbin * diffbin
* Path to diff binary * Path to diff binary
* Same rules as gitbin * Same rules as gitbin
* Windows (msysgit): C:\\Progra~1\\Git\\bin\\diff.exe * Windows (msysgit): C:\\Progra~1\\Git\\bin\\diff.exe
*/ */
$gitphp_conf['diffbin'] = "/usr/bin/diff"; $gitphp_conf['diffbin'] = "/usr/bin/diff";
   
/* /*
* gittmp * gittmp
* Location for temporary files for diffs * Location for temporary files for diffs
* (don't forget trailing slash!) * (don't forget trailing slash!)
*/ */
$gitphp_conf['gittmp'] = "/tmp/gitphp/"; $gitphp_conf['gittmp'] = "/tmp/gitphp/";
   
/* /*
* title * title
* The string that will be used as the page title * The string that will be used as the page title
* The variable '$gitphp_appstring' will expand to * The variable '$gitphp_appstring' will expand to
* the name (gitphp) and version * the name (gitphp) and version
* The variable '$gitphp_version' will expand to the * The variable '$gitphp_version' will expand to the
* version number only * version number only
*/ */
$gitphp_conf['title'] = "$gitphp_appstring"; $gitphp_conf['title'] = "$gitphp_appstring";
   
/* /*
* self * self
* This is the path to the script that will be inserted * This is the path to the script that will be inserted
* in urls. If you leave this blank/commented the script * in urls. If you leave this blank/commented the script
* will try to guess the correct URL, but you can override * will try to guess the correct URL, but you can override
* it here if it's not being guessed correctly. * it here if it's not being guessed correctly.
* *
* If only specifying the directory path (and omitting the * If only specifying the directory path (and omitting the
* index.php filename), make sure to include the trailing * index.php filename), make sure to include the trailing
* slash! * slash!
*/ */
//$gitphp_conf['self'] = "http://localhost/gitphp/"; //$gitphp_conf['self'] = "http://localhost/gitphp/";
   
/* /*
* smarty_prefix * smarty_prefix
* This is the prefix where smarty is installed. * This is the prefix where smarty is installed.
* (including trailing slash) * (including trailing slash)
* If an absolute (starts with /) path is given, * If an absolute (starts with /) path is given,
* Smarty.class.php will be searched for in that directory. * Smarty.class.php will be searched for in that directory.
* If a relative (doesn't start with /) path is given, * If a relative (doesn't start with /) path is given,
* that subdirectory inside the php include dirs will be * that subdirectory inside the php include dirs will be
* searched. So, for example, if you specify the path as * searched. So, for example, if you specify the path as
* "/usr/share/Smarty/" then the script will look for * "/usr/share/Smarty/" then the script will look for
* /usr/share/Smarty/Smarty.class.php. * /usr/share/Smarty/Smarty.class.php.
* If you specify the path as "smarty/" then it will search * If you specify the path as "smarty/" then it will search
* the include directories in php.ini's include_path directive, * the include directories in php.ini's include_path directive,
* so it would search in places like /usr/share/php and /usr/lib/php: * so it would search in places like /usr/share/php and /usr/lib/php:
* /usr/share/php/smarty/Smarty.class.php, * /usr/share/php/smarty/Smarty.class.php,
* /usr/lib/php/smarty/Smarty.class.php, etc. * /usr/lib/php/smarty/Smarty.class.php, etc.
* Leave blank to just search in the root of the php include directories * Leave blank to just search in the root of the php include directories
* like /usr/share/php/Smarty.class.php, /usr/lib/php/Smarty.class.php, etc. * like /usr/share/php/Smarty.class.php, /usr/lib/php/Smarty.class.php, etc.
*/ */
$gitphp_conf['smarty_prefix'] = "smarty/"; $gitphp_conf['smarty_prefix'] = "smarty/";
   
/* /*
* compressformat * compressformat
* Indicates what kind of compression will be done on the * Indicates what kind of compression will be done on the
* snapshot archive. Recognized settings are: * snapshot archive. Recognized settings are:
* *
* GITPHP_COMPRESS_BZ2 - create a tar.bz2 file (php must have bz2 support) * GITPHP_COMPRESS_BZ2 - create a tar.bz2 file (php must have bz2 support)
* GITPHP_COMPRESS_GZ - create a tar.gz file (php must have gzip support) * GITPHP_COMPRESS_GZ - create a tar.gz file (php must have gzip support)
  * GITPHP_COMPRESS_ZIP - create a zip file
* *
* Any other setting, or no setting, will create uncompressed tar archives * Any other setting, or no setting, will create uncompressed tar archives
* If you choose a compression format and your php does not support it, * If you choose a compression format and your php does not support it,
* gitphp will fall back to uncompressed tar archives * gitphp will fall back to uncompressed tar archives
*/ */
$gitphp_conf['compressformat'] = GITPHP_COMPRESS_BZ2; $gitphp_conf['compressformat'] = GITPHP_COMPRESS_BZ2;
   
/* /*
* compresslevel * compresslevel
* Sets the compression level for snapshots. Ranges from 1-9, with * Sets the compression level for snapshots. Ranges from 1-9, with
* 9 being the most compression but requiring the most processing * 9 being the most compression but requiring the most processing
* (bzip defaults to 4, gzip defaults to -1) * (bzip defaults to 4, gzip defaults to -1)
*/ */
$gitphp_conf['compresslevel'] = 9; $gitphp_conf['compresslevel'] = 9;
   
/* /*
* geshi * geshi
* Run blob output through geshi syntax highlighting * Run blob output through geshi syntax highlighting
* and line numbering * and line numbering
*/ */
$gitphp_conf['geshi'] = FALSE; $gitphp_conf['geshi'] = FALSE;
   
/* /*
* geshiroot * geshiroot
* Directory where geshi is installed * Directory where geshi is installed
* NOTE: this is the path to the base geshi.php file to include, * NOTE: this is the path to the base geshi.php file to include,
* NOT the various other geshi php source files! * NOT the various other geshi php source files!
* Leave blank if geshi.php is in the gitphp root * Leave blank if geshi.php is in the gitphp root
* (don't forget trailing slash!) * (don't forget trailing slash!)
*/ */
$gitphp_conf['geshiroot'] = "geshi/"; $gitphp_conf['geshiroot'] = "geshi/";
   
/* /*
* filemimetype * filemimetype
* Attempt to read the file's mimetype when displaying * Attempt to read the file's mimetype when displaying
* (for example, displaying an image as an actual image * (for example, displaying an image as an actual image
* in a browser) * in a browser)
* This requires either PHP >= 5.3.0, PECL fileinfo, or * This requires either PHP >= 5.3.0, PECL fileinfo, or
* Linux * Linux
*/ */
$gitphp_conf['filemimetype'] = TRUE; $gitphp_conf['filemimetype'] = TRUE;
   
/* /*
* magicdb * magicdb
* Path to the libmagic db used to read mimetype * Path to the libmagic db used to read mimetype
* You can leave this as null and let the system * You can leave this as null and let the system
* try to find the database for you, but that method * try to find the database for you, but that method
* is known to have issues * is known to have issues
* If the path is correct but it's still not working, * If the path is correct but it's still not working,
* try removing the file extension if you have it on, * try removing the file extension if you have it on,
* or vice versa * or vice versa
*/ */
$gitphp_conf['magicdb'] = "/usr/share/misc/magic.mgc"; $gitphp_conf['magicdb'] = "/usr/share/misc/magic.mgc";
//$gitphp_conf['magicdb'] = "C:\\wamp\\php\\extras\\magic"; // Windows //$gitphp_conf['magicdb'] = "C:\\wamp\\php\\extras\\magic"; // Windows
   
/* /*
* search * search
* Set this to false or comment it out to disable searching * Set this to false or comment it out to disable searching
*/ */
$gitphp_conf['search'] = TRUE; $gitphp_conf['search'] = TRUE;
   
/* /*
* filesearch * filesearch
* Set this to false to disable searching within files * Set this to false to disable searching within files
* (it can be resource intensive) * (it can be resource intensive)
*/ */
$gitphp_conf['filesearch'] = TRUE; $gitphp_conf['filesearch'] = TRUE;
   
/* /*
* git_projects * git_projects
* Two-dimensional array list of projects * Two-dimensional array list of projects
* First array index is the name of the category the projects * First array index is the name of the category the projects
* belong to, and the second array index is a human-readable * belong to, and the second array index is a human-readable
* name for the project (not used, just for organizational * name for the project (not used, just for organizational
* purposes), and the value is the path to the project * purposes), and the value is the path to the project
* (minus the projectroot). * (minus the projectroot).
* Any projects belonging to the special category "none" * Any projects belonging to the special category "none"
* will be listed without a category. * will be listed without a category.
* Comment out $git_projects (leave null) to attempt to read all * Comment out $git_projects (leave null) to attempt to read all
* projects in the projectroot. * projects in the projectroot.
*/ */
//$git_projects['Core']['FBX'] = "core/fbx.git"; //$git_projects['Core']['FBX'] = "core/fbx.git";
//$git_projects['PHP']['gitphp'] = "php/gitphp.git"; //$git_projects['PHP']['gitphp'] = "php/gitphp.git";
//$git_projects['PHP']['MDB'] = "php/mdb.git"; //$git_projects['PHP']['MDB'] = "php/mdb.git";
//$git_projects['PHP']['xxcache'] = "php/xxcache.git"; //$git_projects['PHP']['xxcache'] = "php/xxcache.git";
//$git_projects['Websites']['bth'] = "websites/bth.git"; //$git_projects['Websites']['bth'] = "websites/bth.git";
   
?> ?>
   
<?php <?php
/* /*
* defs.commands.php * defs.commands.php
* gitphp: A PHP git repository browser * gitphp: A PHP git repository browser
* Component: Definitions - commands * Component: Definitions - commands
* *
* Copyright (C) 2008 Christopher Han <xiphux@gmail.com> * Copyright (C) 2008 Christopher Han <xiphux@gmail.com>
*/ */
   
define('GIT_CAT_FILE','cat-file'); define('GIT_CAT_FILE','cat-file');
define('GIT_DIFF_TREE','diff-tree'); define('GIT_DIFF_TREE','diff-tree');
define('GIT_LS_TREE','ls-tree'); define('GIT_LS_TREE','ls-tree');
define('GIT_REV_LIST','rev-list'); define('GIT_REV_LIST','rev-list');
define('GIT_REV_PARSE','rev-parse'); define('GIT_REV_PARSE','rev-parse');
define('GIT_SHOW_REF','show-ref'); define('GIT_SHOW_REF','show-ref');
define('GIT_TAR_TREE','tar-tree'); define('GIT_ARCHIVE','archive');
define('GIT_GREP','grep'); define('GIT_GREP','grep');
   
?> ?>
   
<?php <?php
/* /*
* defs.constants.php * defs.constants.php
* gitphp: A PHP git repository browser * gitphp: A PHP git repository browser
* Component: Definitions - constants * Component: Definitions - constants
* *
* Copyright (C) 2009 Christopher Han <xiphux@gmail.com> * Copyright (C) 2009 Christopher Han <xiphux@gmail.com>
*/ */
   
define("GITPHP_TRIM_LENGTH", 50); define("GITPHP_TRIM_LENGTH", 50);
   
define("GITPHP_RSS_ITEMS", 150); define("GITPHP_RSS_ITEMS", 150);
   
define("GITPHP_COMPRESS_BZ2", 1); define("GITPHP_COMPRESS_BZ2", 1);
define("GITPHP_COMPRESS_GZ", 2); define("GITPHP_COMPRESS_GZ", 2);
  define("GITPHP_COMPRESS_ZIP", 3);
   
?> ?>
   
<?php <?php
/* /*
* display.git_snapshot.php * display.git_snapshot.php
* gitphp: A PHP git repository browser * gitphp: A PHP git repository browser
* Component: Display - snapshot * Component: Display - snapshot
* *
* Copyright (C) 2008 Christopher Han <xiphux@gmail.com> * Copyright (C) 2008 Christopher Han <xiphux@gmail.com>
*/ */
   
require_once('defs.constants.php'); require_once('defs.constants.php');
require_once('gitutil.git_tar_tree.php'); require_once('gitutil.git_archive.php');
   
function git_snapshot($projectroot,$project,$hash) function git_snapshot($projectroot,$project,$hash)
{ {
global $gitphp_conf; global $gitphp_conf;
if (!isset($hash)) if (!isset($hash))
$hash = "HEAD"; $hash = "HEAD";
$rname = str_replace(array("/",".git"),array("-",""),$project); $rname = str_replace(array("/",".git"),array("-",""),$project);
$tar = git_tar_tree($projectroot . $project, $hash, $rname); $arc = git_archive($projectroot . $project, $hash, $rname,
if (($gitphp_conf['compressformat'] == GITPHP_COMPRESS_BZ2) && function_exists("bzcompress")) { (($gitphp_conf['compressformat'] == GITPHP_COMPRESS_ZIP) ? "zip" : "tar"));
   
  if ($gitphp_conf['compressformat'] == GITPHP_COMPRESS_ZIP) {
  header("Content-Type: application/x-zip");
  header("Content-Disposition: attachment; filename=" . $rname . ".zip");
  echo $arc;
  return;
  } else if (($gitphp_conf['compressformat'] == GITPHP_COMPRESS_BZ2) && function_exists("bzcompress")) {
header("Content-Type: application/x-bzip2"); header("Content-Type: application/x-bzip2");
header("Content-Disposition: attachment; filename=" . $rname . ".tar.bz2"); header("Content-Disposition: attachment; filename=" . $rname . ".tar.bz2");
echo bzcompress($tar,(isset($gitphp_conf['compresslevel'])?$gitphp_conf['compresslevel']:4)); echo bzcompress($arc,(isset($gitphp_conf['compresslevel'])?$gitphp_conf['compresslevel']:4));
return; return;
} else if (($gitphp_conf['compressformat'] == GITPHP_COMPRESS_GZ) && function_exists("gzencode")) { } else if (($gitphp_conf['compressformat'] == GITPHP_COMPRESS_GZ) && function_exists("gzencode")) {
header("Content-Type: application/x-gzip"); header("Content-Type: application/x-gzip");
header("Content-Disposition: attachment; filename=" . $rname . ".tar.gz"); header("Content-Disposition: attachment; filename=" . $rname . ".tar.gz");
echo gzencode($tar,(isset($gitphp_conf['compresslevel'])?$gitphp_conf['compresslevel']:-1)); echo gzencode($arc,(isset($gitphp_conf['compresslevel'])?$gitphp_conf['compresslevel']:-1));
return; return;
} }
   
header("Content-Type: application/x-tar"); header("Content-Type: application/x-tar");
header("Content-Disposition: attachment; filename=" . $rname . ".tar"); header("Content-Disposition: attachment; filename=" . $rname . ".tar");
echo $tar; echo $arc;
} }
   
?> ?>
   
  <?php
  /*
  * gitutil.git_archive.php
  * gitphp: A PHP git repository browser
  * Component: Git utility - archive
  *
  * Copyright (C) 2009 Christopher Han <xiphux@gmail.com>
  */
 
  require_once('defs.commands.php');
  require_once('gitutil.git_exec.php');
 
  function git_archive($proj,$hash,$rname = NULL, $fmt = "tar")
  {
  $cmd = GIT_ARCHIVE . " --format=" . $fmt;
  if ($rname)
  $cmd .= " --prefix=" . $rname . "/";
  $cmd .= " " . $hash;
  return git_exec($proj, $cmd);
  }
 
  ?>
 
<?php  
/*  
* gitutil.git_tar_tree.php  
* gitphp: A PHP git repository browser  
* Component: Git utility - tar tree  
*  
* Copyright (C) 2008 Christopher Han <xiphux@gmail.com>  
*/  
 
require_once('defs.commands.php');  
require_once('gitutil.git_exec.php');  
 
function git_tar_tree($proj,$hash,$rname = NULL)  
{  
$cmd = GIT_TAR_TREE . " " . $hash;  
if ($rname)  
$cmd .= " " . $rname;  
return git_exec($proj, $cmd);  
}  
 
?>  
 
comments