Junio C Hamano <gitster@xxxxxxxxx> 于2021年5月31日周一 上午8:44写道: > > "ZheNing Hu via GitGitGadget" <gitgitgadget@xxxxxxxxx> writes: > > > Beyond, `--format=%(raw)` cannot be used with `--python`, `--shell`, > > `--tcl`, `--perl` because if our binary raw data is passed to a variable > > in the host language, the host languages may cause escape errors. > > "may cause escape errors" just says you are not escaping correctly > in your code (implying that this patch is not good enough and with > more effort we should be able to fix it to allow binaries), but the > problem is the host languages may not support binaries > (specifically, anything with a NUL in it) at all, which is > fundamentally unfixable, in which case, rejecting is the only > sensible choice. > > ... because the host language may not support a NUL in the variables > of its string type. > I agree. But host language not only support NUL but also some Non-ASCII character and Non-UTF-8 code: $ git hash-object a.out -w | xargs git update-ref refs/myblobs/aoutblob $ git for-each-ref --format="name=%(raw)" refs/myblobs/aoutblob --python | python2 File "<stdin>", line 1 SyntaxError: Non-ASCII character '\x8b' in file <stdin> on line 2, but no encoding declared; see http://python.org/dev/peps/pep-0263/ for details $ git for-each-ref --format="name=%(raw)" refs/myblobs/aoutblob --python |python3 SyntaxError: Non-UTF-8 code starting with '\x8b' in file <stdin> on line 2, but no encoding declared; see http://python.org/dev/peps/pep-0263/ for details > > +The raw data in a object is `raw`, For commit and tag objects, `raw` contain > > s/contain/contains/, but more importantly, as we are not introducing > %(header), I do not see why we want to talk about its details. For > commits and tags, just like for trees and blobs, 'raw' is the raw > data in the object, so beyond "The raw data of a object is %(raw)", > I do not think there is anything to talk about. > Ok, I will delete this part. > > + const char *s = buf->buf; > > + size_t cur_len = 0; > > + > > + while ((cur_len != buf->len) && (isspace(*s) || *s == '\0')) { > > s++; > > + cur_len++; > > Is NUL treated the same as a whitespace letter for the purpose of > determining if a line is empty? WHY? > Well, there seems to be no correction here. But is it true that memory like "\0abc" is considered empty? Thanks. -- ZheNing Hu