* [PATCH 0/2] naming consistency cleanups
@ 2019-04-16 1:10 Eric Wong
2019-04-16 1:10 ` [PATCH 1/2] cleanup: use '$ibx' consistently when referring to Inbox refs Eric Wong
2019-04-16 1:10 ` [PATCH 2/2] import: prefix 'inbox' with '-' to denote Inbox ref Eric Wong
0 siblings, 2 replies; 3+ messages in thread
From: Eric Wong @ 2019-04-16 1:10 UTC (permalink / raw)
To: meta
Since we (and most Perl5 codebases) don't declare types with "my",
naming things consistently should reduce confusion and make the code
easier-to-follow/learn.
More to come...
Eric Wong (2):
cleanup: use '$ibx' consistently when referring to Inbox refs
import: prefix 'inbox' with '-' to denote Inbox ref
lib/PublicInbox/AltId.pm | 8 ++++----
lib/PublicInbox/Config.pm | 4 ++--
lib/PublicInbox/Import.pm | 6 +++---
lib/PublicInbox/NewsWWW.pm | 6 +++---
lib/PublicInbox/SearchView.pm | 4 ++--
lib/PublicInbox/Unsubscribe.pm | 4 ++--
lib/PublicInbox/View.pm | 16 ++++++++--------
lib/PublicInbox/WWW.pm | 14 +++++++-------
lib/PublicInbox/WwwStream.pm | 24 ++++++++++++------------
t/altid.t | 6 +++---
10 files changed, 46 insertions(+), 46 deletions(-)
--
EW
^ permalink raw reply [flat|nested] 3+ messages in thread
* [PATCH 1/2] cleanup: use '$ibx' consistently when referring to Inbox refs
2019-04-16 1:10 [PATCH 0/2] naming consistency cleanups Eric Wong
@ 2019-04-16 1:10 ` Eric Wong
2019-04-16 1:10 ` [PATCH 2/2] import: prefix 'inbox' with '-' to denote Inbox ref Eric Wong
1 sibling, 0 replies; 3+ messages in thread
From: Eric Wong @ 2019-04-16 1:10 UTC (permalink / raw)
To: meta
'$inbox' is more human-readable, so that is for the more
human-readable name in most cases. Making our variable naming
more consistent should make the code easier-to-review and
harder to screw up.
---
lib/PublicInbox/AltId.pm | 8 ++++----
lib/PublicInbox/Config.pm | 4 ++--
lib/PublicInbox/Import.pm | 4 ++--
lib/PublicInbox/NewsWWW.pm | 6 +++---
lib/PublicInbox/SearchView.pm | 4 ++--
lib/PublicInbox/Unsubscribe.pm | 4 ++--
lib/PublicInbox/View.pm | 16 ++++++++--------
lib/PublicInbox/WWW.pm | 14 +++++++-------
lib/PublicInbox/WwwStream.pm | 24 ++++++++++++------------
t/altid.t | 6 +++---
10 files changed, 45 insertions(+), 45 deletions(-)
diff --git a/lib/PublicInbox/AltId.pm b/lib/PublicInbox/AltId.pm
index 300bdc0..c22b959 100644
--- a/lib/PublicInbox/AltId.pm
+++ b/lib/PublicInbox/AltId.pm
@@ -18,7 +18,7 @@ use URI::Escape qw(uri_unescape);
# The PREFIX will be a searchable boolean prefix in Xapian
# Example: serial:gmane:file=/path/to/altmsgmap.sqlite3
sub new {
- my ($class, $inbox, $spec, $writable) = @_;
+ my ($class, $ibx, $spec, $writable) = @_;
my ($type, $prefix, $query) = split(/:/, $spec, 3);
$type eq 'serial' or die "non-serial not supported, yet\n";
@@ -31,10 +31,10 @@ sub new {
} split(/[&;]/, $query);
my $f = $params{file} or die "file: required for $type spec $spec\n";
unless (index($f, '/') == 0) {
- if (($inbox->{version} || 1) == 1) {
- $f = "$inbox->{mainrepo}/public-inbox/$f";
+ if (($ibx->{version} || 1) == 1) {
+ $f = "$ibx->{mainrepo}/public-inbox/$f";
} else {
- $f = "$inbox->{mainrepo}/$f";
+ $f = "$ibx->{mainrepo}/$f";
}
}
bless {
diff --git a/lib/PublicInbox/Config.pm b/lib/PublicInbox/Config.pm
index cdc939a..27222c0 100644
--- a/lib/PublicInbox/Config.pm
+++ b/lib/PublicInbox/Config.pm
@@ -60,8 +60,8 @@ sub new {
sub lookup {
my ($self, $recipient) = @_;
my $addr = lc($recipient);
- my $inbox = $self->{-by_addr}->{$addr};
- return $inbox if $inbox;
+ my $ibx = $self->{-by_addr}->{$addr};
+ return $ibx if $ibx;
my $pfx;
diff --git a/lib/PublicInbox/Import.pm b/lib/PublicInbox/Import.pm
index 7e596ab..fc4e72d 100644
--- a/lib/PublicInbox/Import.pm
+++ b/lib/PublicInbox/Import.pm
@@ -178,8 +178,8 @@ sub _update_git_info ($$) {
run_die([@cmd, 'update-server-info'], undef);
($self->{path_type} eq '2/38') and eval {
require PublicInbox::SearchIdx;
- my $inbox = $self->{inbox} || $git_dir;
- my $s = PublicInbox::SearchIdx->new($inbox);
+ my $ibx = $self->{inbox} || $git_dir;
+ my $s = PublicInbox::SearchIdx->new($ibx);
$s->index_sync({ ref => $self->{ref} });
};
eval { run_die([@cmd, qw(gc --auto)], undef) } if $do_gc;
diff --git a/lib/PublicInbox/NewsWWW.pm b/lib/PublicInbox/NewsWWW.pm
index d7fcb0d..8626cf9 100644
--- a/lib/PublicInbox/NewsWWW.pm
+++ b/lib/PublicInbox/NewsWWW.pm
@@ -44,11 +44,11 @@ sub call {
my (undef, @parts) = split(m!/!, $env->{PATH_INFO});
my ($ng, $article) = @parts;
my $pi_config = $self->{pi_config};
- if (my $inbox = $pi_config->lookup_newsgroup($ng)) {
- my $url = PublicInbox::Hval::prurl($env, $inbox->{url});
+ if (my $ibx = $pi_config->lookup_newsgroup($ng)) {
+ my $url = PublicInbox::Hval::prurl($env, $ibx->{url});
my $code = 301;
if (defined $article && $article =~ /\A\d+\z/) {
- my $mid = eval { $inbox->mm->mid_for($article) };
+ my $mid = eval { $ibx->mm->mid_for($article) };
if (defined $mid) {
# article IDs are not stable across clones,
# do not encourage caching/bookmarking them
diff --git a/lib/PublicInbox/SearchView.pm b/lib/PublicInbox/SearchView.pm
index c33caec..7ef6b07 100644
--- a/lib/PublicInbox/SearchView.pm
+++ b/lib/PublicInbox/SearchView.pm
@@ -231,7 +231,7 @@ sub mset_thread {
$r ? sort_relevance(\%pct) : *PublicInbox::View::sort_ds,
$ctx);
my $skel = search_nav_bot($mset, $q). "<pre>";
- my $inbox = $ctx->{-inbox};
+ my $ibx = $ctx->{-inbox};
$ctx->{-upfx} = '';
$ctx->{anchor_idx} = 1;
$ctx->{cur_level} = 0;
@@ -252,7 +252,7 @@ sub mset_thread {
return unless $msgs;
my $smsg;
while (my $m = pop @$msgs) {
- $smsg = $inbox->smsg_mime($m) and last;
+ $smsg = $ibx->smsg_mime($m) and last;
}
if ($smsg) {
return PublicInbox::View::index_entry($smsg, $ctx,
diff --git a/lib/PublicInbox/Unsubscribe.pm b/lib/PublicInbox/Unsubscribe.pm
index 2644f7a..11a347e 100644
--- a/lib/PublicInbox/Unsubscribe.pm
+++ b/lib/PublicInbox/Unsubscribe.pm
@@ -151,9 +151,9 @@ sub archive_info {
unless ($archive_url) {
if (my $config = $self->{pi_config}) {
# PublicInbox::Config::lookup
- my $inbox = $config->lookup($list_addr);
+ my $ibx = $config->lookup($list_addr);
# PublicInbox::Inbox::base_url
- $archive_url = $inbox->base_url if $inbox;
+ $archive_url = $ibx->base_url if $ibx;
}
}
diff --git a/lib/PublicInbox/View.pm b/lib/PublicInbox/View.pm
index 429eba8..f94daaf 100644
--- a/lib/PublicInbox/View.pm
+++ b/lib/PublicInbox/View.pm
@@ -399,7 +399,7 @@ sub thread_index_entry {
sub stream_thread ($$) {
my ($rootset, $ctx) = @_;
- my $inbox = $ctx->{-inbox};
+ my $ibx = $ctx->{-inbox};
my @q = map { (0, $_) } @$rootset;
my $level;
my $smsg;
@@ -408,11 +408,11 @@ sub stream_thread ($$) {
my $node = shift @q or next;
my $cl = $level + 1;
unshift @q, map { ($cl, $_) } @{$node->{children}};
- $smsg = $inbox->smsg_mime($node->{smsg}) and last;
+ $smsg = $ibx->smsg_mime($node->{smsg}) and last;
}
return missing_thread($ctx) unless $smsg;
- $ctx->{-obfs_ibx} = $inbox->{obfuscate} ? $inbox : undef;
+ $ctx->{-obfs_ibx} = $ibx->{obfuscate} ? $ibx : undef;
$ctx->{-title_html} = ascii_html($smsg->subject);
$ctx->{-html_tip} = thread_index_entry($ctx, $level, $smsg);
$smsg = undef;
@@ -423,7 +423,7 @@ sub stream_thread ($$) {
my $node = shift @q or next;
my $cl = $level + 1;
unshift @q, map { ($cl, $_) } @{$node->{children}};
- if ($smsg = $inbox->smsg_mime($node->{smsg})) {
+ if ($smsg = $ibx->smsg_mime($node->{smsg})) {
return thread_index_entry($ctx, $level, $smsg);
} else {
return ghost_index_entry($ctx, $level, $node);
@@ -462,8 +462,8 @@ sub thread_html {
my $rootset = thread_results($ctx, $msgs);
# reduce hash lookups in pre_thread->skel_dump
- my $inbox = $ctx->{-inbox};
- $ctx->{-obfs_ibx} = $inbox->{obfuscate} ? $inbox : undef;
+ my $ibx = $ctx->{-inbox};
+ $ctx->{-obfs_ibx} = $ibx->{obfuscate} ? $ibx : undef;
walk_thread($rootset, $ctx, *pre_thread);
$skel .= '</pre>';
@@ -472,7 +472,7 @@ sub thread_html {
# flat display: lazy load the full message from smsg
my $smsg;
while (my $m = shift @$msgs) {
- $smsg = $inbox->smsg_mime($m) and last;
+ $smsg = $ibx->smsg_mime($m) and last;
}
return missing_thread($ctx) unless $smsg;
$ctx->{-title_html} = ascii_html($smsg->subject);
@@ -482,7 +482,7 @@ sub thread_html {
return unless $msgs;
$smsg = undef;
while (my $m = shift @$msgs) {
- $smsg = $inbox->smsg_mime($m) and last;
+ $smsg = $ibx->smsg_mime($m) and last;
}
return index_entry($smsg, $ctx, scalar @$msgs) if $smsg;
$msgs = undef;
diff --git a/lib/PublicInbox/WWW.pm b/lib/PublicInbox/WWW.pm
index c24cde5..d3dfa74 100644
--- a/lib/PublicInbox/WWW.pm
+++ b/lib/PublicInbox/WWW.pm
@@ -187,9 +187,9 @@ sub news_cgit_fallback ($) {
# returns undef if valid, array ref response if invalid
sub invalid_inbox ($$) {
my ($ctx, $inbox) = @_;
- my $obj = $ctx->{www}->{pi_config}->lookup_name($inbox);
- if (defined $obj) {
- $ctx->{-inbox} = $obj;
+ my $ibx = $ctx->{www}->{pi_config}->lookup_name($inbox);
+ if (defined $ibx) {
+ $ctx->{-inbox} = $ibx;
return;
}
@@ -403,13 +403,13 @@ sub legacy_redirects {
sub r301 {
my ($ctx, $inbox, $mid_ue, $suffix) = @_;
- my $obj = $ctx->{-inbox};
- unless ($obj) {
+ my $ibx = $ctx->{-inbox};
+ unless ($ibx) {
my $r404 = invalid_inbox($ctx, $inbox);
return $r404 if $r404;
- $obj = $ctx->{-inbox};
+ $ibx = $ctx->{-inbox};
}
- my $url = $obj->base_url($ctx->{env});
+ my $url = $ibx->base_url($ctx->{env});
my $qs = $ctx->{env}->{QUERY_STRING};
if (defined $mid_ue) {
# common, and much nicer as '@' than '%40':
diff --git a/lib/PublicInbox/WwwStream.pm b/lib/PublicInbox/WwwStream.pm
index 8ae35c7..8b79923 100644
--- a/lib/PublicInbox/WwwStream.pm
+++ b/lib/PublicInbox/WwwStream.pm
@@ -33,8 +33,8 @@ sub response {
sub _html_top ($) {
my ($self) = @_;
my $ctx = $self->{ctx};
- my $obj = $ctx->{-inbox};
- my $desc = ascii_html($obj->description);
+ my $ibx = $ctx->{-inbox};
+ my $desc = ascii_html($ibx->description);
my $title = $ctx->{-title_html} || $desc;
my $upfx = $ctx->{-upfx} || '';
my $help = $upfx.'_/text/help';
@@ -45,7 +45,7 @@ sub _html_top ($) {
my $links = "<a\nhref=\"$help\">help</a> / ".
"<a\nhref=\"$color\">color</a> / ".
"<a\nhref=\"$atom\">Atom feed</a>";
- if ($obj->search) {
+ if ($ibx->search) {
my $q_val = $ctx->{-q_value_html};
if (defined $q_val && $q_val ne '') {
$q_val = qq(\nvalue="$q_val");
@@ -75,19 +75,19 @@ sub _html_end {
my ($self) = @_;
my $urls = 'Archives are clonable:';
my $ctx = $self->{ctx};
- my $obj = $ctx->{-inbox};
- my $desc = ascii_html($obj->description);
+ my $ibx = $ctx->{-inbox};
+ my $desc = ascii_html($ibx->description);
my (%seen, @urls);
- my $http = $obj->base_url($ctx->{env});
+ my $http = $ibx->base_url($ctx->{env});
chop $http; # no trailing slash for clone
- my $part = $obj->max_git_part;
+ my $part = $ibx->max_git_part;
my $dir = (split(m!/!, $http))[-1];
if (defined($part)) { # v2
$seen{$http} = 1;
for my $i (0..$part) {
# old parts my be deleted:
- -d "$obj->{mainrepo}/git/$i.git" or next;
+ -d "$ibx->{mainrepo}/git/$i.git" or next;
my $url = "$http/$i";
$seen{$url} = 1;
push @urls, "$url $dir/git/$i.git";
@@ -99,7 +99,7 @@ sub _html_end {
# FIXME: partitioning in can be different in other repositories,
# use the "cloneurl" file as-is for now:
- foreach my $u (@{$obj->cloneurl}) {
+ foreach my $u (@{$ibx->cloneurl}) {
next if $seen{$u};
$seen{$u} = 1;
push @urls, $u =~ /\Ahttps?:/ ? qq(<a\nhref="$u">$u</a>) : $u;
@@ -112,19 +112,19 @@ sub _html_end {
$urls .= " git clone --mirror $urls[0]";
}
if (defined $part) {
- my $addrs = $obj->{address};
+ my $addrs = $ibx->{address};
$addrs = join(' ', @$addrs) if ref($addrs) eq 'ARRAY';
$urls .= <<EOF
# If you have public-inbox 1.1+ installed, you may
# initialize and index your mirror using the following commands:
- public-inbox-init -V2 $obj->{name} $dir/ $http \\
+ public-inbox-init -V2 $ibx->{name} $dir/ $http \\
$addrs
public-inbox-index $dir
EOF
}
- my @nntp = map { qq(<a\nhref="$_">$_</a>) } @{$obj->nntp_url};
+ my @nntp = map { qq(<a\nhref="$_">$_</a>) } @{$ibx->nntp_url};
if (@nntp) {
$urls .= "\n\n";
$urls .= @nntp == 1 ? 'Newsgroup' : 'Newsgroups are';
diff --git a/t/altid.t b/t/altid.t
index d4f6152..13a44a3 100644
--- a/t/altid.t
+++ b/t/altid.t
@@ -42,9 +42,9 @@ my $altid = [ "serial:gmane:file=$alt_file" ];
$im->done;
}
{
- my $inbox = PublicInbox::Inbox->new({mainrepo=>$git_dir});
- $inbox->{altid} = $altid;
- my $rw = PublicInbox::SearchIdx->new($inbox, 1);
+ my $ibx = PublicInbox::Inbox->new({mainrepo => $git_dir});
+ $ibx->{altid} = $altid;
+ my $rw = PublicInbox::SearchIdx->new($ibx, 1);
$rw->index_sync;
}
--
EW
^ permalink raw reply related [flat|nested] 3+ messages in thread
* [PATCH 2/2] import: prefix 'inbox' with '-' to denote Inbox ref
2019-04-16 1:10 [PATCH 0/2] naming consistency cleanups Eric Wong
2019-04-16 1:10 ` [PATCH 1/2] cleanup: use '$ibx' consistently when referring to Inbox refs Eric Wong
@ 2019-04-16 1:10 ` Eric Wong
1 sibling, 0 replies; 3+ messages in thread
From: Eric Wong @ 2019-04-16 1:10 UTC (permalink / raw)
To: meta
This is for consistency with other fields which follow
this pattern w.r.t. field-naming when referring to internal
fields.
---
lib/PublicInbox/Import.pm | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/lib/PublicInbox/Import.pm b/lib/PublicInbox/Import.pm
index fc4e72d..c775575 100644
--- a/lib/PublicInbox/Import.pm
+++ b/lib/PublicInbox/Import.pm
@@ -30,7 +30,7 @@ sub new {
ident => "$name <$email>",
mark => 1,
ref => $ref,
- inbox => $ibx,
+ -inbox => $ibx,
path_type => '2/38', # or 'v2'
lock_path => "$git->{git_dir}/ssoma.lock", # v2 changes this
bytes_added => 0,
@@ -178,7 +178,7 @@ sub _update_git_info ($$) {
run_die([@cmd, 'update-server-info'], undef);
($self->{path_type} eq '2/38') and eval {
require PublicInbox::SearchIdx;
- my $ibx = $self->{inbox} || $git_dir;
+ my $ibx = $self->{-inbox} || $git_dir;
my $s = PublicInbox::SearchIdx->new($ibx);
$s->index_sync({ ref => $self->{ref} });
};
--
EW
^ permalink raw reply related [flat|nested] 3+ messages in thread
end of thread, other threads:[~2019-04-16 1:10 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2019-04-16 1:10 [PATCH 0/2] naming consistency cleanups Eric Wong
2019-04-16 1:10 ` [PATCH 1/2] cleanup: use '$ibx' consistently when referring to Inbox refs Eric Wong
2019-04-16 1:10 ` [PATCH 2/2] import: prefix 'inbox' with '-' to denote Inbox ref Eric Wong
Code repositories for project(s) associated with this public inbox
https://80x24.org/public-inbox.git
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).