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

--- a/config/gitphp.conf.php.example
+++ b/config/gitphp.conf.php.example
@@ -99,6 +99,7 @@
  *
  * 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_ZIP - create a zip file
  *
  * Any other setting, or no setting, will create uncompressed tar archives
  * If you choose a compression format and your php does not support it,

--- a/include/defs.commands.php
+++ b/include/defs.commands.php
@@ -13,7 +13,7 @@
 define('GIT_REV_LIST','rev-list');
 define('GIT_REV_PARSE','rev-parse');
 define('GIT_SHOW_REF','show-ref');
-define('GIT_TAR_TREE','tar-tree');
+define('GIT_ARCHIVE','archive');
 define('GIT_GREP','grep');
 
 ?>

--- a/include/defs.constants.php
+++ b/include/defs.constants.php
@@ -13,6 +13,7 @@
 
 define("GITPHP_COMPRESS_BZ2", 1);
 define("GITPHP_COMPRESS_GZ", 2);
+define("GITPHP_COMPRESS_ZIP", 3);
 
 ?>
 

--- a/include/display.git_snapshot.php
+++ b/include/display.git_snapshot.php
@@ -8,7 +8,7 @@
  */
 
 require_once('defs.constants.php');
- require_once('gitutil.git_tar_tree.php');
+ require_once('gitutil.git_archive.php');
 
 function git_snapshot($projectroot,$project,$hash)
 {
@@ -16,22 +16,29 @@
 	if (!isset($hash))
 		$hash = "HEAD";
 	$rname = str_replace(array("/",".git"),array("-",""),$project);
-	$tar = git_tar_tree($projectroot . $project, $hash, $rname);
-	if (($gitphp_conf['compressformat'] == GITPHP_COMPRESS_BZ2) && function_exists("bzcompress")) {
+	$arc = git_archive($projectroot . $project, $hash, $rname,
+		(($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-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;
 	} else if (($gitphp_conf['compressformat'] == GITPHP_COMPRESS_GZ) && function_exists("gzencode")) {
 		header("Content-Type: application/x-gzip");
 		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;
 	}
 
 	header("Content-Type: application/x-tar");
 	header("Content-Disposition: attachment; filename=" . $rname . ".tar");
-	echo $tar;
+	echo $arc;
 }
 
 ?>

--- /dev/null
+++ b/include/gitutil.git_archive.php
@@ -1,1 +1,23 @@
+<?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);
+}
+
+?>
+

--- a/include/gitutil.git_tar_tree.php
+++ /dev/null
@@ -1,22 +1,1 @@
-<?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