Skip to content

Commit e374747

Browse files
krnowakgitster
authored andcommitted
gitweb: Denote non-heads, non-remotes branches
Given two branches residing in refs/heads/master and refs/wip/feature the list-of-branches view will present them in following way: master feature (wip) When getting a snapshot of a 'feature' branch, the tarball is going to have name like 'project-wip-feature-<short hash>.tgz'. Signed-off-by: Krzesimir Nowak <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 8d646a9 commit e374747

File tree

1 file changed

+29
-5
lines changed

1 file changed

+29
-5
lines changed

gitweb/gitweb.perl

Lines changed: 29 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3730,8 +3730,14 @@ sub git_get_heads_list {
37303730
$ref_item{'fullname'} = $name;
37313731
my $strip_refs = join '|', map { quotemeta } get_branch_refs();
37323732
$name =~ s!^refs/($strip_refs|remotes)/!!;
3733+
$ref_item{'name'} = $name;
3734+
# for refs neither in 'heads' nor 'remotes' we want to
3735+
# show their ref dir
3736+
my $ref_dir = (defined $1) ? $1 : '';
3737+
if ($ref_dir ne '' and $ref_dir ne 'heads' and $ref_dir ne 'remotes') {
3738+
$ref_item{'name'} .= ' (' . $ref_dir . ')';
3739+
}
37333740

3734-
$ref_item{'name'} = $name;
37353741
$ref_item{'id'} = $hash;
37363742
$ref_item{'title'} = $title || '(no commit message)';
37373743
$ref_item{'epoch'} = $epoch;
@@ -7223,16 +7229,23 @@ sub git_tree {
72237229
git_footer_html();
72247230
}
72257231

7232+
sub sanitize_for_filename {
7233+
my $name = shift;
7234+
7235+
$name =~ s!/!-!g;
7236+
$name =~ s/[^[:alnum:]_.-]//g;
7237+
7238+
return $name;
7239+
}
7240+
72267241
sub snapshot_name {
72277242
my ($project, $hash) = @_;
72287243

72297244
# path/to/project.git -> project
72307245
# path/to/project/.git -> project
72317246
my $name = to_utf8($project);
72327247
$name =~ s,([^/])/*\.git$,$1,;
7233-
$name = basename($name);
7234-
# sanitize name
7235-
$name =~ s/[[:cntrl:]]/?/g;
7248+
$name = sanitize_for_filename(basename($name));
72367249

72377250
my $ver = $hash;
72387251
if ($hash =~ /^[0-9a-fA-F]+$/) {
@@ -7248,12 +7261,23 @@ sub snapshot_name {
72487261
# branches and other need shortened SHA-1 hash
72497262
my $strip_refs = join '|', map { quotemeta } get_branch_refs();
72507263
if ($hash =~ m!^refs/($strip_refs|remotes)/(.*)$!) {
7251-
$ver = $1;
7264+
my $ref_dir = (defined $1) ? $1 : '';
7265+
$ver = $2;
7266+
7267+
$ref_dir = sanitize_for_filename($ref_dir);
7268+
# for refs neither in heads nor remotes we want to
7269+
# add a ref dir to archive name
7270+
if ($ref_dir ne '' and $ref_dir ne 'heads' and $ref_dir ne 'remotes') {
7271+
$ver = $ref_dir . '-' . $ver;
7272+
}
72527273
}
72537274
$ver .= '-' . git_get_short_hash($project, $hash);
72547275
}
7276+
# special case of sanitization for filename - we change
7277+
# slashes to dots instead of dashes
72557278
# in case of hierarchical branch names
72567279
$ver =~ s!/!.!g;
7280+
$ver =~ s/[^[:alnum:]_.-]//g;
72577281

72587282
# name = project-version_string
72597283
$name = "$name-$ver";

0 commit comments

Comments
 (0)