public-inbox.git  about / heads / tags
an "archives first" approach to mailing lists
blob 114eb656a4343ad9976aef6356b47390578ce181 1560 bytes (raw)
$ git show repobrowse:lib/PublicInbox/RepoGit.pm	# shows this blob on the CLI

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
 
# Copyright (C) 2015 all contributors <meta@public-inbox.org>
# License: AGPL-3.0+ (https://www.gnu.org/licenses/agpl-3.0.txt)

# common functions used by other RepoGit* modules
package PublicInbox::RepoGit;
use strict;
use warnings;
use base qw(Exporter);
our @EXPORT_OK = qw(git_unquote git_commit_title git_dec_links);
use PublicInbox::Hval qw(utf8_html);

my %GIT_ESC = (
	a => "\a",
	b => "\b",
	f => "\f",
	n => "\n",
	r => "\r",
	t => "\t",
	v => "\013",
);

sub git_unquote ($) {
	my ($s) = @_;
	return $s unless ($s =~ /\A"(.*)"\z/);
	$s = $1;
	$s =~ s/\\([abfnrtv])/$GIT_ESC{$1}/g;
	$s =~ s/\\([0-7]{1,3})/chr(oct($1))/ge;
	$s;
}

# Remove, hilariously slow
sub git_commit_title ($$) {
	my ($git, $obj) = @_; # PublicInbox::Git, $sha1hex
	my $rv;
	eval {
		my $buf = $git->cat_file($obj);
		($rv) = ($$buf =~ /\r?\n\r?\n([^\r\n]+)\r?\n?/);
	};
	$rv;
}

# example inputs: "HEAD -> master", "tag: v1.0.0",
sub git_dec_links ($$) {
	my ($rel, $D) = @_;
	my @l;
	foreach (split /, /, $D) {
		if (/\A(\S+) -> (\S+)/) { # 'HEAD -> master'
			my ($s, $h) = ($1, $2);
			$s = utf8_html($s);
			$h = PublicInbox::Hval->utf8($h);
			my $r = $h->as_href;
			$h = $h->as_html;
			push @l, qq($s -&gt; <a\nhref="${rel}log/$r">$h</a>);
		} elsif (s/\Atag: //) {
			my $h = PublicInbox::Hval->utf8($_);
			my $r = $h->as_href;
			$h = $h->as_html;
			push @l, qq(<a\nhref="${rel}tag/$r"><b>$h</b></a>);
		} else {
			my $h = PublicInbox::Hval->utf8($_);
			my $r = $h->as_href;
			$h = $h->as_html;
			push @l, qq(<a\nhref="${rel}log/$r">$h</a>);
		}
	}
	@l;
}

1;

git clone https://public-inbox.org/public-inbox.git
git clone http://7fh6tueqddpjyxjmgtdiueylzoqt6pt7hec3pukyptlmohoowvhde4yd.onion/public-inbox.git