From: Emily Shaffer <emilyshaffer@google.com>
To: git@vger.kernel.org
Cc: jrnieder@gmail.com, Emily Shaffer <emilyshaffer@google.com>
Subject: [PATCH] revision: remove stray whitespace when name empty
Date: Fri, 7 Jun 2019 15:59:00 -0700 [thread overview]
Message-ID: <20190607225900.89299-1-emilyshaffer@google.com> (raw)
Teach show_object_with_name() to avoid writing a space before a name
which is empty. Also teach tests for rev-list --objects --filter to not
require a space between the object ID and name.
show_object_with_name() inserts a space between an object's OID and name
regardless of whether the name is empty or not. This causes 'git
cat-file (--batch | --batch-check)' to fail to discover the type of root
directories:
git rev-list --objects --filter=tree:1 --max-count=1 HEAD \
| git cat-file --batch-check
git rev-parse HEAD: | xargs -I% git cat-file -t %
git rev-list --objects --filter=tree:1 --max-count=1 HEAD \
| xargs -I% echo "AA%AA"
git rev-list --objects --filter=tree:1 --max-count=1 HEAD \
| cut -f 1 -d ' ' | git cat-file --batch-check
The extra space provided by 'show_object_with_name()' sticks to the
output of 'git rev-list' even if it's piped into a file.
Signed-off-by: Emily Shaffer <emilyshaffer@google.com>
---
I don't see any reason _not_ to remove this stray whitespace at the end,
since it seems like it just gets in the way of easy scripting. I also
think this case will only present itself for root trees.
Not sure if making the whitespace optional is the right solution for the
test, although I couldn't come up with a cleaner approach. Maybe
something like this would be better, even though handling it in the
regex is shorter?
if [[ -z "$name" ]] then
grep "^$hash" actual
else
grep "^$hash $name" actual
fi
- Emily
revision.c | 3 ++-
t/t6112-rev-list-filters-objects.sh | 2 +-
2 files changed, 3 insertions(+), 2 deletions(-)
diff --git a/revision.c b/revision.c
index d4aaf0ef25..260258b371 100644
--- a/revision.c
+++ b/revision.c
@@ -40,7 +40,8 @@ void show_object_with_name(FILE *out, struct object *obj, const char *name)
{
const char *p;
- fprintf(out, "%s ", oid_to_hex(&obj->oid));
+ fprintf(out, "%s%s", oid_to_hex(&obj->oid),
+ strcmp(name, "") == 0 ? "" : " ");
for (p = name; *p && *p != '\n'; p++)
fputc(*p, out);
fputc('\n', out);
diff --git a/t/t6112-rev-list-filters-objects.sh b/t/t6112-rev-list-filters-objects.sh
index acd7f5ab80..e05faa7a67 100755
--- a/t/t6112-rev-list-filters-objects.sh
+++ b/t/t6112-rev-list-filters-objects.sh
@@ -288,7 +288,7 @@ expect_has () {
name=$2 &&
hash=$(git -C r3 rev-parse $commit:$name) &&
- grep "^$hash $name$" actual
+ grep "^$hash \?$name$" actual
}
test_expect_success 'verify tree:1 includes root trees' '
--
2.22.0.rc2.383.gf4fbbf30c2-goog
next reply other threads:[~2019-06-07 22:59 UTC|newest]
Thread overview: 22+ messages / expand[flat|nested] mbox.gz Atom feed top
2019-06-07 22:59 Emily Shaffer [this message]
2019-06-08 0:42 ` [PATCH] revision: remove stray whitespace when name empty Eric Sunshine
2019-06-12 19:23 ` Emily Shaffer
2019-06-09 13:00 ` Jeff King
2019-06-10 16:29 ` Junio C Hamano
2019-06-12 19:37 ` Emily Shaffer
2019-06-13 15:20 ` Jeff King
2019-06-13 21:51 ` [PATCH v2] rev-list: teach --oid-only to enable piping Emily Shaffer
2019-06-14 16:07 ` Jeff King
2019-06-14 20:25 ` Junio C Hamano
2019-06-14 23:18 ` Emily Shaffer
2019-06-14 23:29 ` Emily Shaffer
2019-06-19 21:24 ` Jeff King
2019-06-14 23:48 ` [PATCH v3] rev-list: teach --no-object-names " Emily Shaffer
2019-06-17 22:32 ` Junio C Hamano
2019-06-18 22:08 ` Emily Shaffer
2019-06-18 22:29 ` [PATCH v4] " Emily Shaffer
2019-06-19 14:08 ` Junio C Hamano
2019-06-19 19:31 ` Emily Shaffer
2019-06-19 21:30 ` Jeff King
2019-06-19 20:56 ` [PATCH v5] " Emily Shaffer
2019-06-19 21:38 ` Jeff King
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=20190607225900.89299-1-emilyshaffer@google.com \
--to=emilyshaffer@google.com \
--cc=git@vger.kernel.org \
--cc=jrnieder@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).