From: Mark Rada <marada@uwaterloo.ca>
To: git@vger.kernel.org
Cc: Junio C Hamano <gitster@pobox.com>, Jakub Narebski <jnareb@gmail.com>
Subject: [RFC/PATCH v4 2/2] gitweb: append short hash ids to snapshot files
Date: Sat, 12 Sep 2009 19:04:55 -0400 [thread overview]
Message-ID: <4AAC2917.6000306@mailservices.uwaterloo.ca> (raw)
Teach gitweb how to produce nicer snapshot names by only using the
short hash id. If clients make requests using a tree-ish that is not a
partial or full SHA-1 hash, then the short hash will also be appended
to whatever they asked for.
This also includes tests cases for t9502-gitweb-standalone-parse-output.
Signed-off-by: Mark Rada <marada@uwaterloo.ca>
---
gitweb/gitweb.perl | 26 +++++++++++
t/t9502-gitweb-standalone-parse-output.sh | 67 +++++++++++++++++++++++++++++
2 files changed, 93 insertions(+), 0 deletions(-)
create mode 100644 t/t9502-gitweb-standalone-parse-output.sh
diff --git a/gitweb/gitweb.perl b/gitweb/gitweb.perl
index e1beca5..fdecc3d 100755
--- a/gitweb/gitweb.perl
+++ b/gitweb/gitweb.perl
@@ -2006,6 +2006,26 @@ sub git_get_full_hash {
return $retval;
}
+# try and get a shorter hash id
+sub git_get_short_hash {
+ my $project = shift;
+ my $hash = shift;
+ my $o_git_dir = $git_dir;
+ my $retval = undef;
+ $git_dir = "$projectroot/$project";
+ if (open my $fd, '-|', git_cmd(), 'rev-parse', '--short', $hash) {
+ $hash = <$fd>;
+ close $fd;
+ if (defined $hash && $hash =~ /^([0-9a-fA-F]{7,})$/) {
+ $retval = $1;
+ }
+ }
+ if (defined $o_git_dir) {
+ $git_dir = $o_git_dir;
+ }
+ return $retval;
+}
+
# get type of given object
sub git_get_type {
my $hash = shift;
@@ -5207,6 +5227,12 @@ sub git_snapshot {
die_error(404, 'Hash id was not valid');
}
+
+ if ($full_hash !~ /$hash/) {
+ $hash .= '-' . git_get_short_hash($project, $hash);
+ } else {
+ $hash = git_get_short_hash($project, $hash);
+ }
my $name = $project;
$name =~ s,([^/])/*\.git$,$1,;
$name = basename($name);
diff --git a/t/t9502-gitweb-standalone-parse-output.sh b/t/t9502-gitweb-standalone-parse-output.sh
new file mode 100644
index 0000000..1a2a27f
--- /dev/null
+++ b/t/t9502-gitweb-standalone-parse-output.sh
@@ -0,0 +1,67 @@
+#!/bin/sh
+#
+# Copyright (c) 2009 Mark Rada
+#
+
+test_description='gitweb as standalone script (parsing script output).
+
+This test runs gitweb (git web interface) as a CGI script from the
+commandline, and checks that it produces the correct output, either
+in the HTTP header or the actual script output.'
+
+
+. ./gitweb-lib.sh
+
+# ----------------------------------------------------------------------
+# snapshot file name
+
+test_commit \
+ 'SnapshotFileTests' \
+ 'i can has snapshot?'
+
+test_expect_success \
+ 'snapshots: give full hash' \
+ 'ID=`git rev-parse --verify HEAD` &&
+ gitweb_run "p=.git;a=snapshot;h=$ID;sf=tgz" &&
+ ID=`git rev-parse --short HEAD` &&
+ grep ".git-$ID.tar.gz" gitweb.output'
+test_debug 'cat gitweb.output'
+
+test_expect_success \
+ 'snapshots: give short hash' \
+ 'ID=`git rev-parse --short HEAD` &&
+ gitweb_run "p=.git;a=snapshot;h=$ID;sf=tgz" &&
+ grep ".git-$ID.tar.gz" gitweb.output'
+test_debug 'cat gitweb.output'
+
+test_expect_success \
+ 'snapshots: give almost full hash' \
+ 'ID=`git rev-parse --short=30 HEAD` &&
+ gitweb_run "p=.git;a=snapshot;h=$ID;sf=tgz" &&
+ ID=`git rev-parse --short HEAD` &&
+ grep ".git-$ID.tar.gz" gitweb.output'
+test_debug 'cat gitweb.output'
+
+test_expect_success \
+ 'snapshots: give HEAD tree-ish' \
+ 'gitweb_run "p=.git;a=snapshot;h=HEAD;sf=tgz" &&
+ ID=`git rev-parse --short HEAD` &&
+ grep ".git-HEAD-$ID.tar.gz" gitweb.output'
+test_debug 'cat gitweb.output'
+
+test_expect_success \
+ 'snapshots: give branch name tree-ish' \
+ 'gitweb_run "p=.git;a=snapshot;h=master;sf=tgz" &&
+ ID=`git rev-parse --short master` &&
+ grep ".git-master-$ID.tar.gz" gitweb.output'
+test_debug 'cat gitweb.output'
+
+test_expect_success \
+ 'snapshots: give tag tree-ish' \
+ 'gitweb_run "p=.git;a=snapshot;h=SnapshotFileTests;sf=tgz" &&
+ ID=`git rev-parse --short SnapshotFileTests` &&
+ grep ".git-SnapshotFileTests-$ID.tar.gz" gitweb.output'
+test_debug 'cat gitweb.output'
+
+
+test_done
--
1.6.4.2
next reply other threads:[~2009-09-12 23:05 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2009-09-12 23:04 Mark Rada [this message]
2009-09-13 3:35 ` [RFC/PATCH v4 2/2] gitweb: append short hash ids to snapshot files Junio C Hamano
2009-09-13 5:39 ` Mark Rada
2009-09-13 5:57 ` Junio C Hamano
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=4AAC2917.6000306@mailservices.uwaterloo.ca \
--to=marada@uwaterloo.ca \
--cc=git@vger.kernel.org \
--cc=gitster@pobox.com \
--cc=jnareb@gmail.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.