Skip to content

Fix and enforce BIP 2 & 3 field ordering #1893

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 3 commits into
base: master
Choose a base branch
from

Conversation

nothingmuch
Copy link
Contributor

@nothingmuch nothingmuch commented Jul 10, 2025

The first commit is a scripted diff that corrects field ordering in a number of BIPs which are not consistent with the specified in BIP 2.

The second commit enforces that fields are ordered consistently with both BIP 2 and BIP 3. It does not strictly depend on #1820.

@nothingmuch nothingmuch changed the title Field ordering [WIP] Correct and enforce field ordering Jul 10, 2025
-BEGIN VERIFY SCRIPT-
set -e
perl <<'-END PERL-'
use strict;
use warnings;

my $topbip = 9999;

my @FieldOrder = qw(
	BIP
	Layer
	Title
	Author
	Authors
	Editor
	Deputies
	Discussions-To
	Comments-Summary
	Comments-URI
	Status
	Type
	Created
	License
	License-Code
	Discussion
	Post-History
	Version
	Requires
	Replaces
	Proposed-Replacement
	Superseded-By
);

my $bipnum = 0;
while (++$bipnum <= $topbip) {
	my $fn = sprintf "bip-%04d.mediawiki", $bipnum;
	my $is_markdown = 0;
	if (!-e $fn) {
		$fn = sprintf "bip-%04d.md", $bipnum;
		$is_markdown = 1;
	}
	-e $fn || next;
	open my $F, "<", $fn or die "$!";

	my (@before, %preamble, @after);

	if ($is_markdown) {
		while (<$F>) {
			push @before, $_;
			last if m[^(?:\xef\xbb\xbf)?```$]
		}
		die "No ``` in $fn" if eof $F;
	} else {
		while (<$F>) {
			push @before, $_;
			last if m[^(?:\xef\xbb\xbf)?<pre>$];
		}
		die "No <pre> in $fn" if eof $F;
	}
	my %found;
	my ($title, $author, $status, $type, $layer);
	my ($field, $val, @field_order);
	while (<$F>) {
		push @after, $_ and last if ($is_markdown && m[^```$]);
		push @after, $_ and last if (!$is_markdown && m[^</pre>$]);

		if (m[^  ([\w-]+)\: (.*\S)$]) {
			$field = $1;
			$val = $2;
		} elsif (m[^  ( +)(.*\S)$]) {
			$val = $2;
		} else {
			die "Bad line in $fn preamble";
		}

		push @{$preamble{$field} ||= []}, $_;
	}
	push @after, <$F>;
	close $F or die $!;

	open my $W, ">", "$fn" or die "$!";

	print $W @before;
	print $W map { @$_ } grep { defined } delete @Preamble{@FieldOrder};
	die "Unknown fields: @{[ keys %preamble ]}" if %preamble;
	print $W @after;

	close $W or die $!;
}
-END PERL-
-END VERIFY SCRIPT-
@nothingmuch nothingmuch changed the title [WIP] Correct and enforce field ordering Fix and enforce BIP 2 & 3 field ordering Jul 10, 2025
The specified field order is consistent with both BIPs 2 and 3. The
ordering of fields which are only present in one or the other is
ambiguous, e.g. as in `Proposed-Replacement` and `Superseded-By` but
only one of these applies to a given BIP.

The `Editor` field is spurious, only being used in BIP 69, and appears
after Author.
@nothingmuch nothingmuch marked this pull request as ready for review July 10, 2025 01:47
@nothingmuch
Copy link
Contributor Author

@murchandamus murchandamus requested a review from jonatack July 16, 2025 20:26
@murchandamus murchandamus added the Process Trying to update process or stuck due to disagreement about Process label Jul 16, 2025
Copy link
Member

@jonatack jonatack left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM modulo comment

@@ -182,13 +206,18 @@
die "Unknown field $field in $fn";
}
++$found{$field};
push @field_order, $field if $field_order[-1] ne $field;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Running ./scripts/buildtable.pl on this branch, I am seeing the following messages on each iteration that were not present on master:

Use of uninitialized value in string ne at ./scripts/buildtable.pl line 209, <$F> line 2.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

$ ./scripts/buildtable.pl
Use of uninitialized value in string ne at ./scripts/buildtable.pl line 209, <$F> line 2.
|- style="background-color: #ffcfcf"
| [[bip-0001.mediawiki|1]]
|
| BIP Purpose and Guidelines
| Amir Taaki
| Process
| Replaced
Use of uninitialized value in string ne at ./scripts/buildtable.pl line 209, <$F> line 2.
|- style="background-color: #cfffcf"
| [[bip-0002.mediawiki|2]]
|
| BIP process, revised
| Luke Dashjr
| Process
| Active
Use of uninitialized value in string ne at ./scripts/buildtable.pl line 209, <$F> line 2.
|- style="background-color: #ffffcf"
| [[bip-0003.md|3]]
|
| Updated BIP Process
| Murch
| Process
| Proposed
Use of uninitialized value in string ne at ./scripts/buildtable.pl line 209, <$F> line 2.

.../...

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

sorry, that was sloppy... i pushed a fixup commit, should i squash it already or would reviewing that on its own be easier?

@jonatack jonatack added the PR Author action required Needs updates, has unaddressed review comments, or is otherwise waiting for PR author label Jul 18, 2025
@jonatack jonatack removed the PR Author action required Needs updates, has unaddressed review comments, or is otherwise waiting for PR author label Jul 19, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Process Trying to update process or stuck due to disagreement about Process
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants