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

Fix computed values to be computed after all set_options #690

Merged
merged 5 commits into from Aug 20, 2021
Merged

Fix computed values to be computed after all set_options #690

merged 5 commits into from Aug 20, 2021

Conversation

ghost
Copy link

@ghost ghost commented Aug 15, 2021

What this pr does

  • Make "true-color = ***" from gitconfig works

How it was

It was not working from original source.

ss 0003-08-15 at 21 38 49

So I make it works.

ss 0003-08-15 at 21 43 56

This still give prior to the config from cli. Also 24-bit-color can still work.

ss 0003-08-15 at 21 44 11

Motivaiton

I'm trying to integrate delta inside tig.

#689

However, if you allow user to use RGB, it's almost impossible inside tig since it uses ncurses. So I'm trying to limit only 8bit colors. Then I found this bug.

@dandavison
Copy link
Owner

Hi again @ulwlu! Great, thanks for this. I've pushed one commit to your branch adding a test that is intended to reproduce the bug that you are fixing. But there's one thing I'm confused about:

My test fails on master and passes on your branch. However my test tests true-color = never whereas the new code you've added is inside a if opt.true_color == "auto" statement. I haven't had time yet to figure out why my test passes on your branch. Would you be able to look at the test, and check everything makes sense, and add any further test cases you think are needed?

@ghost
Copy link
Author

ghost commented Aug 16, 2021

Hi @dandavison thank you for your review.

This is bacause cli.rs set opt.true-color to 'auto' if '--true-color' option is not given. That is the default value given by struct-opt.

I think it's little bit confusing, maybe we can remove the default value and change match condition inside set_true_color function.

arg_matches,
option_names,
false
);
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

true_color is present in the main call to set_options! on l.182. I think we need to know why that call is not working -- it feels wrong to make two set_options! calls for true_color.

Copy link
Author

@ghost ghost Aug 17, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh I see, and sorry. I missed that and found opt.true_color is set correctly (not exact correct because it's not computed into bool) from gitconfig after set_options. I'm maybe going to fix.

@dandavison
Copy link
Owner

This is bacause cli.rs set opt.true-color to 'auto' if '--true-color' option is not given. That is the default value given by struct-opt.

Thanks for explaining that!

@ghost
Copy link
Author

ghost commented Aug 17, 2021

Thanks to your pointing out, I found some configurations which is to be computed depends on opt.*** value must be after set_options which gets value from gitconfig. It is because gitconfig value will never be computed.

I'm going to think what way is good.

@ghost ghost changed the title Make true-color option honorable from gitconfig Fix computed values to be computed after all set_options Aug 17, 2021
@ghost
Copy link
Author

ghost commented Aug 17, 2021

@dandavison

Hi I fixed and change this PR's purpose.

  • Change ComputedValues's computing place after all set_options
    • It is because some of them depends on opt.** value but they have chance to miss gitconfig values
  • The ComputedValues which have a default value and computed before set_options were going wrong.
    • The ComputedValues which have a default value: paging-mode, inspect-raw-lines, and true-color
    • The ComputedValues which computed before set_options: true-color
    • So, only true-color was going wrong

I move set_width after set_options as well, so this func now doesn't need to set_options inside it.

  • I added a test for these computed values are setting correctly into config.
  • I removed an unused ComputedValue.

@dandavison dandavison merged commit 9fa449e into dandavison:master Aug 20, 2021
@dandavison
Copy link
Owner

Awesome, thanks very much for these fixes @ulwlu. I did some manual testing to check that width worked when set as a command-line option, and in gitconfig, and via git -c delta.width=xxx ....

@ghost
Copy link
Author

ghost commented Aug 20, 2021

@dandavison thanks!

Btw, integrating tig with delta is almost finished. Now I'm fixing little bugs.

jonas/tig#1140

@dandavison
Copy link
Owner

Btw, integrating with delta is almost finished. Now I'm fixing little bugs.

Awesome. Those screenshots look really nice. (I just tried compiling but got an error

src/line.c:245:3: error: implicit declaration of function 'init_extended_pair' is invalid in C99 [-Werror,-Wimplicit-function-declaration]
                init_extended_pair(++cnt, fg, bg);

)

@ghost
Copy link
Author

ghost commented Aug 20, 2021

Umm, init_expanded_pair is only available with ncurse upper than version 6.1, so compiling option may get wrong (such as linking with different path).

I also strrugled at that building. If this get merged jonas will release the new binary anyway, so maybe trying after that is easier...

@dandavison
Copy link
Owner

OK thanks (my Mac has 5.4, but I saw your instructions for building and linking against ncurses).

Kr1ss-XD added a commit to Kr1ss-XD/delta that referenced this pull request Aug 22, 2021
* upstream/master:
  Refactor: use Option to model sometimes-null highlighter (dandavison#698)
  Add some test coverage for truncate_str with a multibyte unicode character
  Use "syntax theme" terminology in show-syntax-themes output (dandavison#697)
  Fix deadlock in `git diff` mode (dandavison#695)
  Fix empty line highlighting (dandavison#642)
  Revert "Add failing test that gitconfig insteadOf is honored"
  Add failing test that gitconfig insteadOf is honored
  Support `insteadOf` replacements in git remote URLs
  Hold GitConfig in main Config struct
  Revert "Support `insteadOf` replacements in git remote URLs"
  Support `insteadOf` replacements in git remote URLs
  Refactoring for dandavison#693 (dandavison#696)
  Make it possible to jump between files when navigate is active (dandavison#684)
  Bump dev version number
  Compile delta from source in dockerfile
  Fix computed values to be computed after all set_options (dandavison#690)
  Remove unnecessary borrows (dandavison#692)
  Bump bitflags from 1.3.1 to 1.3.2 (dandavison#691)
  Bump git2 from 0.13.20 to 0.13.21 (dandavison#687)
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.

None yet

1 participant