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

Compare snapshots: Don't use "false" as fallback diff command #1662

Closed
buhtz opened this issue Mar 8, 2024 · 2 comments · Fixed by #1682
Closed

Compare snapshots: Don't use "false" as fallback diff command #1662

buhtz opened this issue Mar 8, 2024 · 2 comments · Fixed by #1682

Comments

@buhtz
Copy link
Member

buhtz commented Mar 8, 2024

if tools.checkCommand('meld'):
DIFF_CMD = 'meld'
DIFF_PARAMS = '%1 %2'
elif tools.checkCommand('kompare'):
DIFF_CMD = 'kompare'
DIFF_PARAMS = '%1 %2'
else:
DIFF_CMD = 'false'
DIFF_PARAMS = '%1 %2'

Based on report on bit-dev mailing list.

Problem

An extern application is used to compare snapshots. If meld and kompare as such tools are not installed BIT is falling back to false. Be aware that false is not False and that false is a valid command in a *nix shell (see $ manpage false). This makes no sense from users perspective. The "Compare" button just does nothing in this case. No reaction. No response to the user.

BIT doesn't check for false but just checks for availability of the configured diff command.

if not tools.checkCommand(diffCmd):
messagebox.critical(
self, '{}: {}'.format(_('Command not found'), diffCmd)
)
return

image

Solution

The diff command should be empty (or None) if meld or kompare are not available. And the Compare button should check for emptiness.
Also the error message could be improved. A simple "Command not found" is not user friendly and to technical.

@stcksmsh
Copy link
Contributor

stcksmsh commented Apr 7, 2024

if tools.checkCommand('meld'):
    DIFF_CMD = 'meld'
    DIFF_PARAMS = '%1 %2'
elif tools.checkCommand('kompare'):
    DIFF_CMD = 'kompare'
    DIFF_PARAMS = '%1 %2'
else:
    DIFF_CMD = ''
    DIFF_PARAMS = '%1 %2'
        if not diffCmd:
            messagebox.critical(
                self, ('No diff command found. Please install meld or kompare.'))
            return

This is my idea of the fix, but I have a question (which probably does not make too much sense):
Based on the mailing list report we can see users want to be able to use non gui compare tools, an example of diff is given in the email. Right now if someone were to set the command to diff and the parameters to -r %1 %2 which should be a valid diff command, it will simply do nothing. Maybe just show a messagebox.info with the output (if there is anything to show, as kompare and meld do not seem to 'give' anything to stdout)?

@buhtz
Copy link
Member Author

buhtz commented Apr 8, 2024

Hello Kosta,
thanks for jumping in here.

Your approach seems correct to me. I would suggest a slightly refactoring like this:

if tools.checkCommand('meld'):
    DIFF_CMD = 'meld'
elif tools.checkCommand('kompare'):
    DIFF_CMD = 'kompare'
else:
    DIFF_CMD = None

if DIFF_CMD is None:
    DIFF_PARAMS = None
else:
    DIFF_PARAMS = '%1 %2'

And the dialog:

    if diffCmd is None:
        messagebox.critical(
            self, ('No tool found to compare snapshots. It is suggested to install "meld", "kompare", or a similar tool.'))
        return

Based on the mailing list report we can see users want to be able to use non gui compare tools
[..]
if someone were to set the command to diff and the parameters to -r %1 %2 which should be a valid diff command, it will simply do nothing.

I would treat this as an edge case. The users are responsible for this them self. When they want a terminal based diff output they have to use the correct commands (some bash/sh, termemu magic). Just ignore this case.

Maybe just show a messagebox.info with the output (if there is anything to show, as kompare and meld do not seem to 'give' anything to stdout)?

We could check the output on stdout when using subprocess.run(). But this is to much code and complexity for an edge case (1 user in 100.000 maybe). My intention is to simplify the the old BIT code where ever it is possible to improve its maintainablity. 😄

stcksmsh added a commit to stcksmsh/backintime that referenced this issue Apr 8, 2024
stcksmsh added a commit to stcksmsh/backintime that referenced this issue Apr 8, 2024
Changed initial `DIFF_CMD` and `DIFF_PARAMS` creation, changed `diffCmd` checking mechanism and added better error description
buhtz added a commit that referenced this issue Apr 15, 2024
… dialog

- Select default diff command (meld, kompare) if none is setup but only if present on the system
- Compare snapshots dialog reflect diff command settings via disabled/enabled compare button.
- Improved and more clear messages to the user about problems with diff command setup.

Fix #1662

Contributed by @stcksmsh (Kosta Vukicevic)

---------

Co-authored-by: Christian Buhtz <c.buhtz@posteo.jp>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants