Page MenuHomeFreeBSD

git-arc: Do not echo unescaped literals to jq
ClosedPublic

Authored by jlduran on Sep 24 2024, 12:39 AM.
Tags
None
Referenced Files
Unknown Object (File)
Tue, Nov 5, 10:54 PM
Unknown Object (File)
Sat, Nov 2, 10:02 PM
Unknown Object (File)
Fri, Oct 25, 1:30 PM
Unknown Object (File)
Wed, Oct 23, 7:10 PM
Unknown Object (File)
Oct 9 2024, 12:05 PM
Unknown Object (File)
Oct 8 2024, 9:50 PM
Unknown Object (File)
Oct 2 2024, 12:37 PM
Unknown Object (File)
Oct 1 2024, 2:00 PM
Subscribers

Details

Summary

Store the json blobs in temporary files instead of variables, and feed
them to jq for parsing.

When echoing "\n", the new line will become a literal new line, and
therefore, invalid json input:

jq: parse error: Invalid string: control characters from U+0000 through U+001F must be escaped ...

To reproduce:

% git arc patch -c D12345

Diff Detail

Repository
rG FreeBSD src repository
Lint
Lint Not Applicable
Unit
Tests Not Applicable

Event Timeline

I'm not a big fan of making temporary files, but I don't know how else to fix it.

I think this looks good

This revision is now accepted and ready to land.Sep 24 2024, 12:41 AM

Thank you.. Hmm I am pretty sure I included @emaste in the review. Well, still learning git-arc.

Looks ok to me, thank you.

I think I know how to achieve the same result using printf, and escaping literals with %s.
Regardless, I only have one more patch for git-arc (git arc list) that may benefit of review_data being in a file. If it turns out otherwise, I can "revert" to using variables.
I'm done trying out this great article on the topic.
Thank you for the reviews!

In D46767#1066872, @jlduran_gmail.com wrote:

I think I know how to achieve the same result using printf, and escaping literals with %s.
Regardless, I only have one more patch for git-arc (git arc list) that may benefit of review_data being in a file. If it turns out otherwise, I can "revert" to using variables.
I'm done trying out this great article on the topic.
Thank you for the reviews!

I think using files is fine. We don't care about the cost of creating a few extra temporary files here.

0mp added a subscriber: 0mp.
0mp added inline comments.
tools/tools/git/git-arc.sh
552

Note: backslashes are not necessary after a pipe. However, this style bit is already inconsistent in this file, so it's just a note and not a request for changes :)

This revision was automatically updated to reflect the committed changes.
des added inline comments.
tools/tools/git/git-arc.sh
584

whenever you create a temporary file, you should set a trap to delete it on exit, e.g.

trap 'rc=$?; rm -f "$review_data" "$user_data" "$diff_data" "$tmp"; trap - 0; exit $rc' 0 1 2 3 5 10 15

this is easier if you use a temporary directory instead, as you can just rm -rf the directory.

tools/tools/git/git-arc.sh
584

Great suggestion. Since it is already committed, I'll add the trap on a separate commit. Thank you!

jlduran added inline comments.
tools/tools/git/git-arc.sh
584

Done in D47289