调用URL http://<gitweburl>/gitweb.cgi?p=<repo>;a=tree;f=<subdir>;hb=HEAD将显示从<subdir>开始的<repo>树。
调用URL http://<gitweburl>/gitweb.cgi?p=<repo>;a=snapshot;f=<subdir>;hb=HEAD将产生一个404。
调用URL http://<gitweburl>/gitweb.cgi?p=<repo>.git;a=snapshot;h=HEAD将在头版提供<repo>的快照。
我找不到正确的语法来让Gitweb给出一个从子目录开始的快照。我指的是导致:$ git archive --format=tar --remote=<gituser>@<gitserver>:<repo> HEAD:<subdir>
我天真地尝试调用URL http://<gitweburl>/gitweb.cgi?p=<repo>;a=snapshot;h=HEAD;f=<subdir>,但是调用,从而生成包含整个存储库的快照存档。
单击Gitweb界面后,我发现,切换到“树”视图并移动到<subdir>,然后单击“快照”使用类似于此的URL:
http://<gitweburl>?p=<repo>;a=snapshot;h=42a6503da6aaedc92bb3543e0b0de9b2de0aaae9;sf=tgz
它提供了我想要的东西,但是我不知道这个散列参数h=...是什么。这不是提交身份证-我查过了。它必须以某种方式识别<subdir>。但是即使是这样--这仍然帮不了我,因为有人只想要一个从/只包含<subdir>的快照,通常不知道这个散列。
知道如何通过Gitweb获得子目录快照吗?提前感谢!
增添:
刚刚发现:h=42a6503da6aaedc92bb3543e0b0de9b2de0aaae9是与<subdir>相关联的哈希值,可由$ git ls-tree -r -t HEAD看到
所以这两个命令:
$ git archive --format=tar --remote=<gituser>@<gitserver>:<repo> HEAD:<subdir>
$ git archive --format=tar --remote=<gituser>@<gitserver>:<repo> 42a6503da6aaedc92bb3543e0b0de9b2de0aaae9
同样地,让我认为,HEAD:<subdir>和42a6503da6aaedc92bb3543e0b0de9b2de0aaae9是等价的。不过,我不能仅仅用http://<gitweburl>?p=<repo>;a=snapshot;h=42a6503da6aaedc92bb3543e0b0de9b2de0aaae9;sf=tgz中的散列替换HEAD:<subdir>。调用此URL将导致"400 -无效哈希参数“.所以这里没有真正的进展。
正如poke所建议的那样,一次使用URL http://<gitweburl>/gitweb.cgi?p=<repo>;a=snapshot;h=HEAD;f=<subdir>的快速肮脏攻击
$ diff -Naur gitweb.cgi.original gitweb.cgi.new
--- gitweb.cgi.original 2012-09-28 00:50:47.000000000 +0200
+++ gitweb.cgi.new 2013-01-22 11:04:29.870532502 +0100
@@ -7029,6 +7029,9 @@
my ($name, $prefix) = snapshot_name($project, $hash);
my $filename = "$name$known_snapshot_formats{$format}{'suffix'}";
+ if ($file_name) {
+ $hash="$hash:$file_name"
+ }
my $cmd = quote_command(
git_cmd(), 'archive',
"--format=$known_snapshot_formats{$format}{'format'}",发布于 2013-01-21 18:14:19
所讨论的h值是当前正在查看的树对象的id。提交只有一个根树对象,您可以在Gitweb的提交页面上看到它。每棵树都是指向blobs (如果是文件)或其他树对象的目录条目的列表。
因此,当您深入到树中时,h总是表示树id。另一方面,hb值是提交id。
不幸的是,Gitweb没有包含更好的获取子目录快照的方法,即不知道树散列,而只知道路径。但是,可能可以向其添加一些功能,将f参数考虑在内,并自动为您获取树哈希。
我刚刚检查了源代码,在修改这部分时,您可能会很幸运。我不太了解perl,无法告诉您到底要做什么,但是基本上可以检查$file_name变量是否设置了,如果是这样的话,只需获取$hash:$file_name的哈希。然后将其设置为新的哈希,一切都可以正常工作。
发布于 2015-07-02 12:55:18
我最近遇到了一个类似的问题--让gitweb生成一个包含列出对象名称的归档文件(只允许一个f= URL参数,但我们可以传递%20个空格字符来列出多个对象)。这是我针对gitweb.cgi的总体补丁,如OpenSuse 13.2“git-web-2.1.413.1.x86_64”版本。
请随意使用和享受:
--- gitweb.cgi.orig 2015-03-13 13:42:29.000000000 +0100
+++ gitweb.cgi.snapshot-filenames-withoutDebug 2015-07-02 14:50:46.196000000 +0200
@@ -20,6 +20,11 @@
use Time::HiRes qw(gettimeofday tv_interval);
binmode STDOUT, ':utf8';
+# http://www.spinics.net/lists/git/msg241958.html
+if (!defined($CGI::VERSION) || $CGI::VERSION < 4.08) {
+ eval 'sub CGI::multi_param { CGI::param(@_) }'
+}
+
our $t0 = [ gettimeofday() ];
our $number_of_git_cmds = 0;
@@ -871,7 +876,7 @@
while (my ($name, $symbol) = each %cgi_param_mapping) {
if ($symbol eq 'opt') {
- $input_params{$name} = [ map { decode_utf8($_) } $cgi->param($symbol) ];
+ $input_params{$name} = [ map { decode_utf8($_) } $cgi->multi_param($symbol) ];
} else {
$input_params{$name} = decode_utf8($cgi->param($symbol));
}
@@ -7324,6 +7329,15 @@
die_error(403, "Unsupported snapshot format");
}
+ if (!defined($hash)) {
+ $hash = "";
+ if ( $file_name && $file_name =~ /^([^:]*):(.*)$/ ) {
+ $hash = "$1";
+ $file_name = "$2";
+ }
+ if ( $hash eq "") { $hash = "HEAD"; }
+ printf STDERR "Defaulted hash to '$hash' ('h=' URL argument was missing)\n";
+ }
my $type = git_get_type("$hash^{}");
if (!$type) {
die_error(404, 'Object does not exist');
@@ -7341,6 +7354,14 @@
git_cmd(), 'archive',
"--format=$known_snapshot_formats{$format}{'format'}",
"--prefix=$prefix/", $hash);
+ if ($file_name) {
+ # To fetch several pathnames use space-separation, e.g.
+ # "...git-web?p=proj.git;a=snapshot;f=file1%20file2
+ # To fetch pathnames with spaces, escape them, e.g.
+ # "...git-web?p=proj.git;a=snapshot;f=file\%20name
+ $cmd .= " " . $file_name;
+ }
+
if (exists $known_snapshot_formats{$format}{'compressor'}) {
$cmd .= ' | ' . quote_command(@{$known_snapshot_formats{$format}{'compressor'}});
}更新:此代码删除已通过单元测试等进行了修改和扩展,并针对上游gitweb进行了PR‘.让我们看看它是如何进行的;)在这里看到更多:https://github.com/git/git/pull/206
希望这能帮上忙吉姆·克里莫夫
https://stackoverflow.com/questions/14444593
复制相似问题