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 <krzesimir@endocode.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Krzesimir Nowak committed
Dec 11, 2013 at 12:54 UTC
e374747f51736a08d048d3e227053d02b0d28735
1 file changed
+29
-5
gitweb/gitweb.perl
+29
-5
@@ -3730,8 +3730,14 @@ sub git_get_heads_list {
3730
$ref_item{'fullname'} = $name;
3731
my $strip_refs = join '|', map { quotemeta } get_branch_refs();
3732
$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
+ }
3740
3734
- $ref_item{'name'} = $name;
3741
$ref_item{'id'} = $hash;
3742
$ref_item{'title'} = $title || '(no commit message)';
3743
$ref_item{'epoch'} = $epoch;
@@ -7223,6 +7229,15 @@ sub git_tree {
7229
git_footer_html();
7230
}
7231
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
+
7241
sub snapshot_name {
7242
my ($project, $hash) = @_;
7243
@@ -7230,9 +7245,7 @@ sub snapshot_name {
7245
# path/to/project/.git -> project
7246
my $name = to_utf8($project);
7247
$name =~ s,([^/])/*\.git$,$1,;
7233
- $name = basename($name);
7234
- # sanitize name
7235
- $name =~ s/[[:cntrl:]]/?/g;
7248
+ $name = sanitize_for_filename(basename($name));
7249
7250
my $ver = $hash;
7251
if ($hash =~ /^[0-9a-fA-F]+$/) {
@@ -7248,12 +7261,23 @@ sub snapshot_name {
7261
# branches and other need shortened SHA-1 hash
7262
my $strip_refs = join '|', map { quotemeta } get_branch_refs();
7263
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
+ }
7273
}
7274
$ver .= '-' . git_get_short_hash($project, $hash);
7275
}
7276
+ # special case of sanitization for filename - we change
7277
+ # slashes to dots instead of dashes
7278
# in case of hierarchical branch names
7279
$ver =~ s!/!.!g;
7280
+ $ver =~ s/[^[:alnum:]_.-]//g;
7281
7282
# name = project-version_string
7283
$name = "$name-$ver";