git@vger.kernel.org mailing list mirror (one of many)
 help / color / mirror / code / Atom feed
From: Junio C Hamano <gitster@pobox.com>
To: "Ævar Arnfjörð Bjarmason" <avarab@gmail.com>
Cc: "SZEDER Gábor" <szeder.dev@gmail.com>,
	git@vger.kernel.org,
	"brian m. carlson" <sandals@crustytoothpaste.net>
Subject: Re: [PATCH] tests: make 'test_oid' print trailing newline
Date: Tue, 20 Dec 2022 08:58:53 +0900	[thread overview]
Message-ID: <xmqqfsdb2beq.fsf@gitster.g> (raw)
In-Reply-To: <221219.864jtrz9yf.gmgdl@evledraar.gmail.com> ("Ævar Arnfjörð Bjarmason"'s message of "Mon, 19 Dec 2022 16:27:12 +0100")

Ævar Arnfjörð Bjarmason <avarab@gmail.com> writes:

>> @@ -826,7 +827,7 @@ test_expect_success 'test_oid can look up data for SHA-1' '
>>  	grep "^00*\$" actual &&
> ...
> I also vaguely recall (although probably nobody worries about such a
> platform anymore) that POSIX utilities left themselves room to not work
> on things that weren't \n-terminated.

[jc: totally irrelevant curiosity-hunt]

I think you have in mind the combination of these.

 * "3.195 Incomplete Line" defines an incomple line as "A sequence
   of one or more non-<newline> characters at the end of the file."

 * "3.403 Text File" defines a text file to be "A file that contains
   characters organized into zero or more lines. ... many utilities
   only produce predictable or meaningful output when operating on
   text files".

 * "INPUT FILES" section of "grep" for example says "The input files
   shall be text files".

It may look unclear if "an incomplete line" is supposed to be a
"line", and if it is not, then the output from "test_oid zero" we
are grepping in in the above snippet is not a "text file".

The "INPUT FILES" section of "sort" states something interesting.

    The input files shall be text files, except that the sort
    utility shall add a <newline> to the end of a file ending with
    an incomplete last line.

Why is this interesting?  Because it smells like it is clarifying
whether it makes file a text to end in an incomplete line, but it
does not do any such thing ;-)  You can read it in two ways:

 * You must feed text files to "sort", but if you did feed a file
   that ends with an incomplete line, the utility adds <newline> at
   the end, which makes it a text, so the inputs to the utilities
   all becomes "text".

   Under this reading, you can as an exception feed a non-text file
   to the utility, as long as its non-text-ness is limited to ending
   with an incomplete line.  So, a file that ends with an incomplete
   line is *not* text.

 * You must feed text files to "sort", and an text file that ends
   with an incomplete line gains terminating <newline> at the end of
   that last line, so a hit on that line will be shown, terminated
   with <newline>, just like a hit on any other line.

   Under this reading, a text file may or may not end with an
   incomplete line, so a file that ends with an incomplete line is
   text.

https://pubs.opengroup.org/onlinepubs/9699919799/basedefs/V1_chap03.html
https://pubs.opengroup.org/onlinepubs/9699919799/utilities/grep.html
https://pubs.opengroup.org/onlinepubs/9699919799/utilities/sort.html

So I dunno.

In any case, I think it is a good practice to avoid having to worry
about how the standard utilities would behave by making sure our
lines are complete.


      reply	other threads:[~2022-12-19 23:59 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-12-18 16:29 [PATCH] tests: make 'test_oid' print trailing newline SZEDER Gábor
2022-12-19  0:48 ` Junio C Hamano
2022-12-22 18:58   ` SZEDER Gábor
2022-12-23  0:56     ` Junio C Hamano
2022-12-19 14:03 ` brian m. carlson
2022-12-19 15:27 ` Ævar Arnfjörð Bjarmason
2022-12-19 23:58   ` Junio C Hamano [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: http://vger.kernel.org/majordomo-info.html

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=xmqqfsdb2beq.fsf@gitster.g \
    --to=gitster@pobox.com \
    --cc=avarab@gmail.com \
    --cc=git@vger.kernel.org \
    --cc=sandals@crustytoothpaste.net \
    --cc=szeder.dev@gmail.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://80x24.org/mirrors/git.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).