git/builtin
Jeff King 819b929d33 pkt-line: teach packet_read_line to chomp newlines
The packets sent during ref negotiation are all terminated
by newline; even though the code to chomp these newlines is
short, we end up doing it in a lot of places.

This patch teaches packet_read_line to auto-chomp the
trailing newline; this lets us get rid of a lot of inline
chomping code.

As a result, some call-sites which are not reading
line-oriented data (e.g., when reading chunks of packfiles
alongside sideband) transition away from packet_read_line to
the generic packet_read interface. This patch converts all
of the existing callsites.

Since the function signature of packet_read_line does not
change (but its behavior does), there is a possibility of
new callsites being introduced in later commits, silently
introducing an incompatibility.  However, since a later
patch in this series will change the signature, such a
commit would have to be merged directly into this commit,
not to the tip of the series; we can therefore ignore the
issue.

This is an internal cleanup and should produce no change of
behavior in the normal case. However, there is one corner
case to note. Callers of packet_read_line have never been
able to tell the difference between a flush packet ("0000")
and an empty packet ("0004"), as both cause packet_read_line
to return a length of 0. Readers treat them identically,
even though Documentation/technical/protocol-common.txt says
we must not; it also says that implementations should not
send an empty pkt-line.

By stripping out the newline before the result gets to the
caller, we will now treat the newline-only packet ("0005\n")
the same as an empty packet, which in turn gets treated like
a flush packet. In practice this doesn't matter, as neither
empty nor newline-only packets are part of git's protocols
(at least not for the line-oriented bits, and readers who
are not expecting line-oriented packets will be calling
packet_read directly, anyway). But even if we do decide to
care about the distinction later, it is orthogonal to this
patch.  The right place to tighten would be to stop treating
empty packets as flush packets, and this change does not
make doing so any harder.

Signed-off-by: Jeff King <peff@peff.net>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2013-02-20 13:42:21 -08:00
..
add.c Merge branch 'maint' 2013-02-12 12:23:12 -08:00
annotate.c
apply.c Merge branch 'jc/extended-fake-ancestor-for-gitlink' 2013-02-14 10:28:48 -08:00
archive.c pkt-line: teach packet_read_line to chomp newlines 2013-02-20 13:42:21 -08:00
bisect--helper.c i18n: bisect--helper: mark parseopt strings for translation 2012-08-20 12:23:15 -07:00
blame.c logmsg_reencode: lazily load missing commit buffers 2013-01-26 13:28:22 -08:00
branch.c Merge branch 'nd/branch-error-cases' 2013-02-07 14:41:38 -08:00
bundle.c
cat-file.c Merge branch 'maint-1.7.11' into maint 2012-09-10 15:31:06 -07:00
check-attr.c Merge branch 'maint' 2012-09-17 15:59:34 -07:00
check-ignore.c add git-check-ignore sub-command 2013-01-06 14:26:38 -08:00
check-ref-format.c
checkout-index.c Use imperative form in help usage to describe an action 2012-08-22 12:02:28 -07:00
checkout.c checkout: print a message when switching unborn branches 2012-11-15 17:36:26 -08:00
clean.c Merge branch 'as/check-ignore' 2013-01-23 21:19:10 -08:00
clone.c Merge branch 'jc/no-git-config-in-clone' 2013-02-01 12:39:37 -08:00
column.c i18n: column: mark parseopt strings for translation 2012-08-20 12:23:16 -07:00
commit-tree.c Merge branch 'kk/maint-commit-tree' 2012-07-23 20:55:54 -07:00
commit.c Merge branch 'maint' 2013-02-12 12:23:12 -08:00
config.c Merge branch 'cn/config-missing-path' into maint 2012-11-25 18:35:46 -08:00
count-objects.c i18n: count-objects: mark parseopt strings for translation 2012-08-20 12:23:16 -07:00
credential.c git credential fill: output the whole 'struct credential' 2012-06-25 11:56:24 -07:00
describe.c Merge branch 'jk/peel-ref' 2012-10-25 06:42:27 -04:00
diff-files.c
diff-index.c update-index/diff-index: use core.preloadindex to improve performance 2012-11-02 11:38:29 -04:00
diff-tree.c
diff.c Merge branch 'kb/preload-index-more' 2012-11-20 10:32:10 -08:00
fast-export.c fast-export: make sure updated refs get updated 2012-12-03 09:57:16 -08:00
fetch-pack.c pkt-line: teach packet_read_line to chomp newlines 2013-02-20 13:42:21 -08:00
fetch.c Merge branch 'jk/gc-auto-after-fetch' 2013-02-01 12:40:16 -08:00
fmt-merge-msg.c Merge branch 'jc/custom-comment-char' 2013-02-04 10:23:49 -08:00
for-each-ref.c Merge branch 'nd/i18n-parseopt-help' 2012-09-07 11:09:09 -07:00
fsck.c i18n: fsck: mark parseopt strings for translation 2012-08-20 12:23:17 -07:00
gc.c silence git gc --auto --quiet output 2012-09-27 17:57:26 -07:00
grep.c grep: avoid accepting ambiguous revision 2013-01-21 16:57:38 -08:00
hash-object.c i18n: hash-object: mark parseopt strings for translation 2012-08-20 12:23:17 -07:00
help.c Merge branch 'jk/config-parsing-cleanup' 2013-02-04 10:24:50 -08:00
index-pack.c i18n: mark more index-pack strings for translation 2012-08-31 13:05:05 -07:00
init-db.c i18n: init-db: mark parseopt strings for translation 2012-08-20 12:23:17 -07:00
log.c Merge branch 'ap/log-mailmap' 2013-01-20 17:06:53 -08:00
ls-files.c Merge branch 'as/check-ignore' 2013-01-23 21:19:10 -08:00
ls-remote.c ls-remote: document the '--get-url' option 2012-09-07 10:58:35 -07:00
ls-tree.c pathspec: save the non-wildcard length part 2012-11-19 13:08:28 -08:00
mailinfo.c Merge branch 'jc/same-encoding' into maint 2012-12-07 14:10:56 -08:00
mailsplit.c
merge-base.c Merge branch 'jc/merge-bases' 2012-09-11 11:36:05 -07:00
merge-file.c i18n: merge-file: mark parseopt strings for translation 2012-08-20 12:23:18 -07:00
merge-index.c Which merge_file() function do you mean? 2012-12-09 23:05:27 -08:00
merge-ours.c
merge-recursive.c
merge-tree.c merge-tree: fix d/f conflicts 2012-12-26 14:46:15 -08:00
merge.c Merge branch 'jc/custom-comment-char' 2013-02-04 10:23:49 -08:00
mktag.c
mktree.c i18n: mktree: mark parseopt strings for translation 2012-08-20 12:23:18 -07:00
mv.c i18n: mv: mark parseopt strings for translation 2012-08-20 12:23:18 -07:00
name-rev.c i18n: name-rev: mark parseopt strings for translation 2012-08-20 12:23:18 -07:00
notes.c Allow custom "comment char" 2013-01-16 12:48:22 -08:00
pack-objects.c Merge branch 'jk/peel-ref' 2012-10-25 06:42:27 -04:00
pack-redundant.c Fix sizeof usage in get_permutations 2012-12-13 11:13:44 -08:00
pack-refs.c i18n: pack-refs: mark parseopt strings for translation 2012-08-20 12:23:19 -07:00
patch-id.c
prune-packed.c i18n: prune-packed: mark parseopt strings for translation 2012-08-20 12:23:19 -07:00
prune.c Merge branch 'rj/path-cleanup' 2012-09-14 11:53:53 -07:00
push.c Merge branch 'jc/push-reject-reasons' 2013-02-04 10:25:04 -08:00
read-tree.c i18n: read-tree: mark parseopt strings for translation 2012-08-20 12:23:19 -07:00
receive-pack.c pkt-line: teach packet_read_line to chomp newlines 2013-02-20 13:42:21 -08:00
reflog.c reflog: use parse_config_key in config callback 2013-01-23 12:58:33 -08:00
remote-ext.c
remote-fd.c
remote.c Fix typo in remote set-head usage 2012-11-26 13:27:45 -08:00
replace.c replace: parse revision argument for -d 2012-11-13 08:34:14 -05:00
rerere.c i18n: rerere: mark parseopt strings for translation 2012-08-20 12:23:19 -07:00
reset.c reset: update documentation to require only tree-ish with paths 2013-01-16 12:50:23 -08:00
rev-list.c Move print_commit_list to libgit.a 2012-10-29 03:08:30 -04:00
rev-parse.c Merge branch 'maint-1.7.11' into maint 2012-09-12 14:08:05 -07:00
revert.c Merge branch 'mz/cherry-pick-cmdline-order' 2012-09-10 15:42:55 -07:00
rm.c Merge branch 'jl/submodule-rm' 2012-11-29 12:52:30 -08:00
send-pack.c pkt-line: drop safe_write function 2013-02-20 13:42:21 -08:00
shortlog.c Merge branch 'ap/log-mailmap' 2013-01-20 17:06:53 -08:00
show-branch.c i18n: show-branch: mark parseopt strings for translation 2012-08-22 10:58:28 -07:00
show-ref.c Merge branch 'jk/peel-ref' 2012-10-25 06:42:27 -04:00
stripspace.c Allow custom "comment char" 2013-01-16 12:48:22 -08:00
symbolic-ref.c git symbolic-ref --delete $symref 2012-10-21 12:17:38 -07:00
tag.c Allow custom "comment char" 2013-01-16 12:48:22 -08:00
tar-tree.c
unpack-file.c
unpack-objects.c remove superfluous newlines in error messages 2012-04-30 15:45:51 -07:00
update-index.c Merge branch 'kb/preload-index-more' 2012-11-20 10:32:10 -08:00
update-ref.c Use imperative form in help usage to describe an action 2012-08-22 12:02:28 -07:00
update-server-info.c i18n: update-server-info: mark parseopt strings for translation 2012-08-22 10:58:29 -07:00
upload-archive.c pkt-line: teach packet_read_line to chomp newlines 2013-02-20 13:42:21 -08:00
var.c ident: rename IDENT_ERROR_ON_NO_NAME to IDENT_STRICT 2012-05-24 17:16:41 -07:00
verify-pack.c i18n: verify-pack: mark parseopt strings for translation 2012-08-22 10:58:29 -07:00
verify-tag.c i18n: verify-tag: mark parseopt strings for translation 2012-08-22 10:58:29 -07:00
write-tree.c i18n: write-tree: mark parseopt strings for translation 2012-08-22 10:58:29 -07:00