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

Warning when function is not modified by the editor after calling `funced` #3961

Merged
merged 6 commits into from Apr 17, 2017

Conversation

Projects
None yet
3 participants
@adambyrtek
Contributor

adambyrtek commented Apr 17, 2017

Description

funced runs the editor command with a temporary file and quits silently once the process completes. However, in some cases the editor command might return immediately (see #1081). This change shows a warning if the file wasn't modified (according to the MD5 checksum) to make it easier to spot problems like that.

Fixes issue #1081

TODOs:

  • Changes to fish usage are reflected in user documentation/manpages.
  • Tests have been added for regressions fixed
  • User-visible changes noted in CHANGELOG.md
@adambyrtek

This comment has been minimized.

Show comment
Hide comment
@adambyrtek

adambyrtek Apr 17, 2017

Contributor

@krader1961 Review please. Not sure whether this is significant enough for a CHANGELOG entry.

Contributor

adambyrtek commented Apr 17, 2017

@krader1961 Review please. Not sure whether this is significant enough for a CHANGELOG entry.

@faho

This comment has been minimized.

Show comment
Hide comment
@faho

faho Apr 17, 2017

Member

@krader1961's comments are pretty much spot on:

  • set -l your variables before using them, or risk clobbering global ones

  • Check for existence of md5sum outside of the loop

Also, please don't use which.

Member

faho commented Apr 17, 2017

@krader1961's comments are pretty much spot on:

  • set -l your variables before using them, or risk clobbering global ones

  • Check for existence of md5sum outside of the loop

Also, please don't use which.

@adambyrtek

This comment has been minimized.

Show comment
Hide comment
@adambyrtek

adambyrtek Apr 17, 2017

Contributor

@krader1961 @faho Thanks for your review, I replied to most of your comments inline.

When it comes to the while loop, I put the checksum calculation inside the loop on purpose, so that we check for modifications against the previous version (the one sent to the last instance of the editor). This all happens interactively so I don't think there is a performance problem, but it's pretty much an edge case anyway, so I'll follow you advice as long as you understand my motivations for putting the check inside the loop.

Contributor

adambyrtek commented Apr 17, 2017

@krader1961 @faho Thanks for your review, I replied to most of your comments inline.

When it comes to the while loop, I put the checksum calculation inside the loop on purpose, so that we check for modifications against the previous version (the one sent to the last instance of the editor). This all happens interactively so I don't think there is a performance problem, but it's pretty much an edge case anyway, so I'll follow you advice as long as you understand my motivations for putting the check inside the loop.

@adambyrtek

This comment has been minimized.

Show comment
Hide comment
@adambyrtek

adambyrtek Apr 17, 2017

Contributor

@faho Please take another look. I've added a private MD5 function with support for both GNU and BSD to make this more portable. I kept the checksum calculation inside the loop (see comment above) but I'm happy to move it outside if that's still your preference.

Contributor

adambyrtek commented Apr 17, 2017

@faho Please take another look. I've added a private MD5 function with support for both GNU and BSD to make this more portable. I kept the checksum calculation inside the loop (see comment above) but I'm happy to move it outside if that's still your preference.

@@ -1,3 +1,17 @@
function __funced_md5

This comment has been minimized.

@faho

faho Apr 17, 2017

Member

This is a good idea!

@faho

faho Apr 17, 2017

Member

This is a good idea!

Show outdated Hide outdated share/functions/funced.fish
@adambyrtek

This comment has been minimized.

Show comment
Hide comment
@adambyrtek

adambyrtek Apr 17, 2017

Contributor

@faho Well spotted, I made the change you requested.

Contributor

adambyrtek commented Apr 17, 2017

@faho Well spotted, I made the change you requested.

@faho faho added the enhancement label Apr 17, 2017

@faho faho added this to the 2.6.0 milestone Apr 17, 2017

@faho

faho approved these changes Apr 17, 2017

Show outdated Hide outdated share/functions/funced.fish
@adambyrtek

This comment has been minimized.

Show comment
Hide comment
@adambyrtek

adambyrtek Apr 17, 2017

Contributor

@faho Changes made :)

Contributor

adambyrtek commented Apr 17, 2017

@faho Changes made :)

@faho faho merged commit dd69ca5 into fish-shell:master Apr 17, 2017

1 check passed

continuous-integration/travis-ci/pr The Travis CI build passed
Details
@faho

This comment has been minimized.

Show comment
Hide comment
@faho

faho Apr 17, 2017

Member

Merged, thanks!

Member

faho commented Apr 17, 2017

Merged, thanks!

@adambyrtek adambyrtek deleted the adambyrtek:funced-checksum branch Apr 17, 2017

develop7 added a commit to develop7/fish-shell that referenced this pull request Apr 17, 2017

Warn when function is not modified by the editor after calling `funce…
…d` (#3961)

* Check whether tmp file was modified in `funced`

* More idiomatic error messages

* Store the checksum in a local variable

* MD5 function supporting both GNU and BSD

* Use `else if` in MD5 function

* Use `string` builtin instead of `cut`
@krader1961

This comment has been minimized.

Show comment
Hide comment
@krader1961

krader1961 Apr 17, 2017

Contributor

Whether the initial calculation should be inside or outside the while loop depends on what we're trying to warn the user about. The original justification was to protect against a GUI editor automatically going into the background which could confuse the user into thinking that any change they make will be honored. That argues for doing the check once outside the loop. However, if we want to warn the user that they didn't make a change every time the editor returns control to the function then it belongs inside the loop. I'm fine with it being inside the loop.

Contributor

krader1961 commented Apr 17, 2017

Whether the initial calculation should be inside or outside the while loop depends on what we're trying to warn the user about. The original justification was to protect against a GUI editor automatically going into the background which could confuse the user into thinking that any change they make will be honored. That argues for doing the check once outside the loop. However, if we want to warn the user that they didn't make a change every time the editor returns control to the function then it belongs inside the loop. I'm fine with it being inside the loop.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment