This is an archive of the discontinued Mercurial Phabricator instance.

debugcommands: print out the editor that was searched for (post shlexsplit)
ClosedPublic

Authored by spectral on Jan 4 2018, 7:04 PM.

Details

Summary

A user was in #mercurial and had the following settings in their hgrc:

[ui]
editor = C:\home\npp\notepad++.exe -multiInst -nosession

After shlexsplit, the first argument was mangled into C:homenppnotepad++.exe,
which was quite unlikely to exist. It took many back-and-forths to identify
that adding " characters around the exe would fix the issue; we were thinking
that it's because something was incorrectly *not* splitting and adding/moving
the " characters fixed the split boundaries, but when testing afterward it
appears that it's just mangled.

I considered adding an informational if pycompat.iswindows and \ in the string
about this issue, but was worried that might have too many false positives and
did not do so at this time.

Diff Detail

Repository
rHG Mercurial
Lint
Lint Skipped
Unit
Unit Tests Skipped

Event Timeline

spectral created this revision.Jan 4 2018, 7:04 PM
spectral updated this revision to Diff 4694.Jan 4 2018, 7:29 PM
spectral updated this revision to Diff 4695.Jan 4 2018, 7:31 PM
krbullock requested changes to this revision.Jan 4 2018, 10:22 PM
krbullock added a subscriber: krbullock.
krbullock added inline comments.
mercurial/debugcommands.py
1212–1213

In this patch, we end up printing something potentially different in the "checking" line than in the "can't find editor" line. That seems wrong. I think I'd rather we do the shlexsplit before writing the "checking commit editor..." message and print the fully-interpreted path there.

This revision now requires changes to proceed.Jan 4 2018, 10:22 PM
spectral updated this revision to Diff 4714.Jan 5 2018, 2:38 PM
spectral added inline comments.Jan 5 2018, 2:39 PM
mercurial/debugcommands.py
1212–1213

I'm not sure I agree, but I'm not sure I disagree either :)

Anything using this output (it shouldn't afaik, but the user report in #mercurial said that this broke Eclipse, maybe it was only looking at debuginstall to see if there were problems and not actually parsing these values...?) might end up with incorrect results.

  • If we limit both of them to [0], it will end up with just the executable and miss the flags. Maybe this is fine? I don't know what Eclipse is doing with this command, basically, but I don't think we have BC guarantees on debug* commands.
  • If either or both of them are not limited to just [0], then they have to be output as something like "c:\foo\bar.exe" "-arg1" "-arg2" to show where the actual word boundaries are; we can't do something like:

    ' '.join(shlexed_editor)

We have to output it like that to avoid a similar problem, where instead of:

[ui]
editor = c:\foo\bar.exe -arg1 -arg2

the user wrote:

[ui]
editor = "c:\foo\bar.exe -arg1 -arg2"

(Currently, that problem is slightly more obvious, since the output is checking commit editor... ("c:\foo\bar.exe -arg1 -arg2")).

Basically... if we're ok with the rather mild BC break, I think it's probably fine to list only the editor, post-shlexsplit. I don't know what the guarantees are here. Anticipating that we're going to be OK with the output difference, since I can't see how things can actually correctly rely on the non-shlexsplit, non-findexe'd value we emit here (and thus have to assume that either nothing does, or they're already broken), I've made the change.

spectral marked an inline comment as done.Feb 6 2018, 1:23 PM

Sorry, I forgot about this, can you take another look? I believe I addressed your most recent comment.

krbullock accepted this revision as: krbullock.Feb 6 2018, 2:00 PM

This LGTM now. I think the executable as interpreted by shlex, but without the added flags, gives enough signal for the user to figure out what might be wrong without confusing things.

This looks good to me - @krbullock should I queue it?

This revision was automatically updated to reflect the committed changes.