Move to git-archive for zip support
[gitphp.git] / include / display.git_snapshot.php
blob:a/include/display.git_snapshot.php -> blob:b/include/display.git_snapshot.php
<?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;
} }
   
?> ?>
   
comments