Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactor: break up nested ternaries into multiple lines #1158

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

krobelus
Copy link
Contributor

We have some places where multiple ternary operators are nested on a
single line. Break them up into multiple lines. I think this is much
easier to read because the indentation shows the nesting structure.
No functional change here.

Reading through format_append_arg(), I noticed that "echo %%(commit"
with the missing closing parenthesis is not supported. Probably
not worth spending too much time on that.

We have some places where multiple ternary operators are nested on a
single line.  Break them up into multiple lines. I think this is much
easier to read because the indentation shows the nesting structure.
No functional change here.

Reading through format_append_arg(), I noticed that "echo %%(commit"
with the missing closing parenthesis is not supported. Probably
not worth spending too much time on that.
@koutcher
Copy link
Collaborator

koutcher commented Nov 4, 2021

Not much time needed, I think this should do the job:

-               if (var && !closing)
+               if (var && !closing && !esc)

When doing 6134336, I took it as a challenge to do it in one line only, so I'll have hard time to let it go :-), but, agreed, as we have no plans to enter IOCCC with Tig, we should prioritize the readability.

@krobelus
Copy link
Contributor Author

if (var && !closing && !esc)

Problem is that %%(foo will become %%(foo, so there is no way to express %(foo.
So the rule should probably be: %%( becomes %(, and elsewhere % is not special.
That would mean %%%( becomes %%( which feels weird. Also it might be legit to want
%%(branch) to output %some-branch, which we don't support.
Anyway it's really not important, these are mostly theoretical issues.
But if we make more changes to the expansion code, we should probably reduce the number of special cases.

I took it as a challenge to do it in one line only

Haha yeah, I was mildly surprised when I came across this while trying to understand the formatting logic

@koutcher
Copy link
Collaborator

You're right, I missed that point. This is better but as you said, we cannot get %some-branch. As in Tig context there is very little reason to want %( without closing ) we may leave it as it is today.

-               if (var && !closing)
-                       return false;
+               if (var && !closing) {
+                       if (!esc)
+                               return false;
+                       else
+                               ++arg;
+               }

@krobelus
Copy link
Contributor Author

krobelus commented Jan 8, 2022

Ideally we can interpret each %% as % (like printf). This has a fairly low risk of breaking scripts.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants