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

add a Win32 askpass #371

Merged
merged 3 commits into from
Aug 14, 2021
Merged

add a Win32 askpass #371

merged 3 commits into from
Aug 14, 2021

Conversation

rimrul
Copy link
Member

@rimrul rimrul commented Aug 13, 2021

It's currently as bare-bones as it gets, but seems to be functional.

grafik

The prompt does get wrapped into multiple lines if it gets too long. The code is obviously heavily based on the sample code for line edits and slightly on git-askyesno.

I intend to add the Git for Windows icon on the right (similar to the GCM askpass) at some point in the near future, but that'll probably happen after v2.33.0 is out.

The name isn't set in stone yet, but I think shipping two significantly different git-askpass.exe that are more or less intended for the same purpose might lead to confusion.

Changes since v1:

  • rename to git-askpass
  • includ the changes to the Makefile that I forgot to add
  • switch from DialogBoxW() to DialogBoxParamW(). This allows passing the prompt directly and gives us easier access to the result of the Dialog
  • return non-zero on cancel (alligns behaviour closer with OpenSSH ssh-askpass)
  • drop the changing of the default button from the sample code (alligns behaviour closer with OpenSSH ssh-askpass)
  • pass prompt directly
  • prefer %ls over %S
  • also show single arg prompts
  • fixed checksums that where off due to wrong EOLs
  • prepared env.sh to also handle MSYSTEM=ARM64
  • added the new askpass to env.sh

@rimrul rimrul requested a review from dscho August 13, 2021 20:43
Copy link
Member

@dscho dscho left a comment

Choose a reason for hiding this comment

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

Very nice!

@@ -52,7 +52,10 @@ source=('inputrc'
'update-via-pacman.bat'
'git-credential-helper-selector.c'
'git-credential-helper-selector.manifest'
'git-credential-helper-selector.rc')
'git-credential-helper-selector.rc'
'git-win32-askpass.c'
Copy link
Member

Choose a reason for hiding this comment

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

I intend to stop shipping GCM soon (and only retain GCM Core, its official successor). At that point at the latest, using the name git-askpass would actually bring a benefit.

Copy link
Member Author

Choose a reason for hiding this comment

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

Would that cause a new name conflict with git-ecosystem/git-credential-manager#385 or obsolete that issue?

Copy link
Member

Choose a reason for hiding this comment

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

I think it will obsolete git-ecosystem/git-credential-manager#385

git-extra/git-win32-askpass.c Outdated Show resolved Hide resolved
git-extra/git-win32-askpass.c Outdated Show resolved Hide resolved
git-extra/git-win32-askpass.c Outdated Show resolved Hide resolved
@rimrul rimrul force-pushed the win32-askpass branch 4 times, most recently from b9184fd to 350810e Compare August 14, 2021 08:42
@rimrul rimrul marked this pull request as ready for review August 14, 2021 08:46
@rimrul rimrul changed the title WIP: add a Win32 askpass add a Win32 askpass Aug 14, 2021
@rimrul
Copy link
Member Author

rimrul commented Aug 14, 2021

I think I've addressed all concerns. I've also added the new askpass to env.sh and prepared env.sh to handle ARM64.

rimrul added 3 commits August 14, 2021 11:38
This is a drop-in replacement for `git gui--askpass`. Since we added an
option to use an external `ssh` found on the `PATH` (git-for-windows#367) we'll need an
`askpass` implementation that can be called by any windows application even
without understanding shebang lines. `git gui--askpass` probably also has
the same problems with screenreaders that `git gui--askyesno` had(git-for-windows#234), so
we'll likely get improved accessibility as a positive side-effect.

Signed-off-by: Matthias Aßhauer <mha1993@live.de>
Signed-off-by: Matthias Aßhauer <mha1993@live.de>
The new `git-askpass.exe` doesn't use shebang lines and thus works with
non-msys2 OpenSSH. It's also likely to interact more nicely with screen
readers.

Signed-off-by: Matthias Aßhauer <mha1993@live.de>
@dscho
Copy link
Member

dscho commented Aug 14, 2021

I modified this a little, locally. This is the range-diff:

1:  7e0a028098 ! 1:  da9ba5d86b git-extra: include an simple Win32 `git askpass`
    @@ Commit message
         Signed-off-by: Matthias Aßhauer <mha1993@live.de>
     
      ## git-extra/Makefile ##
    +@@ git-extra/Makefile: CXXFLAGS ?= -Wall
    + all: $(BUILDDIR)/create-shortcut.exe $(BUILDDIR)/WhoUses.exe \
    + 	$(BUILDDIR)/blocked-file-util.exe $(BUILDDIR)/proxy-lookup.exe \
    + 	$(BUILDDIR)/git-askyesno.exe \
    ++	$(BUILDDIR)/git-askpass.exe \
    + 	$(BUILDDIR)/git-credential-helper-selector.exe
    + 
    + $(BUILDDIR)/create-shortcut.exe: $(BUILDDIR)/create-shortcut.o
     @@ git-extra/Makefile: $(BUILDDIR)/git-credential-helper-selector.exe: \
      	$(BUILDDIR)/git-credential-helper-selector.o \
      	$(BUILDDIR)/git-credential-helper-selector.res
    @@ git-extra/git-askpass.c (new)
     +		case WM_INITDIALOG:
     +			/* Display the prompt */
     +			SetDlgItemTextW(hDlg, IDC_PROMPT, (wchar_t *) lParam);
    -+			return TRUE; 
    ++			if (GetDlgCtrlID((HWND) wParam) != IDE_PASSWORDEDIT) {
    ++				SetFocus(GetDlgItem(hDlg, IDE_PASSWORDEDIT));
    ++				return FALSE;
    ++			}
    ++			return TRUE;
     +		case WM_COMMAND:
     +			switch(wParam)
     +			{
     +				case IDOK:
     +					/* Get number of characters. */
     +					cchPassword = (WORD) SendDlgItemMessage(hDlg,
    -+															IDE_PASSWORDEDIT,
    -+															EM_LINELENGTH,
    -+															(WPARAM) 0,
    -+															(LPARAM) 0);
    ++										IDE_PASSWORDEDIT,
    ++										EM_LINELENGTH,
    ++										(WPARAM) 0,
    ++										(LPARAM) 0);
     +
     +					lpszPassword = (wchar_t *) malloc(sizeof(wchar_t) * (cchPassword + 1));
     +					if (!lpszPassword) {
    @@ git-extra/git-askpass.c (new)
     +
     +					/* Get the characters. */
     +					SendDlgItemMessageW(hDlg,
    -+									   IDE_PASSWORDEDIT,
    -+									   EM_GETLINE,
    -+									   (WPARAM) 0,       /* line 0 */
    -+									   (LPARAM) lpszPassword);
    ++							    IDE_PASSWORDEDIT,
    ++							    EM_GETLINE,
    ++							    (WPARAM) 0,       /* line 0 */
    ++							    (LPARAM) lpszPassword);
     +
     +					/* Null-terminate the string. */
     +					lpszPassword[cchPassword] = 0;
    @@ git-extra/git-askpass.c (new)
     +{
     +	INT_PTR res;
     +	wchar_t *prompt = NULL;
    -+	
    ++
     +	if (argc < 2) {
     +		MessageBoxW(NULL, L"Usage: git askpass <prompt>", L"Error!", MB_OK);
     +		return 1;
    @@ git-extra/git-askpass.c (new)
     +	free(prompt);
     +	return !res;
     +}
    - \ No newline at end of file
     
      ## git-extra/git-askpass.h (new) ##
     @@
2:  1976019925 = 2:  dc55377e79 git-extra: set `DISPLAY` and `SSH_ASKPASS` for ARM64
3:  350810e4a9 = 3:  c292bffd28 env.sh: prefer git-askpass.exe over git-gui--askpass

Summary:

  1. git-askpass.exe is now built upon make
  2. The edit box gets the focus
  3. Whitespace issues were fixed via git rebase --whitespace=fix
  4. I fixed some indentation manually

@dscho dscho merged commit b818f12 into git-for-windows:main Aug 14, 2021
@dscho
Copy link
Member

dscho commented Aug 14, 2021

git-extra is being built and uploaded here: https://dev.azure.com/Git-for-Windows/git/_build/results?buildId=82787&view=results

@dscho
Copy link
Member

dscho commented Aug 14, 2021

Thank you so much @rimrul!!!

@dscho
Copy link
Member

dscho commented Aug 14, 2021

Oh, and once this is built, we will have to fix mingit/release.sh, I think: it would probably see a conflict otherwise because libexec/git-core/* is moved to bin/ in MinGit.

@rimrul rimrul deleted the win32-askpass branch August 14, 2021 09:54
@rimrul
Copy link
Member Author

rimrul commented Aug 14, 2021

libexec/git-core/* is moved to bin/ in MinGit.

Is it? I'm looking at the contents of MinGit-2.32.0.2-64-bit.zip and git-askpass.exe (and about 46 other files) is in libexec/git-core not bin/

@dscho
Copy link
Member

dscho commented Aug 14, 2021

Hrm. I thought I had moved them all into bin/. It's actually quite important.

@dscho
Copy link
Member

dscho commented Aug 14, 2021

Hrm. I thought I had moved them all into bin/. It's actually quite important.

Turns out that I only moved the .exe files from libexec/git-core/ to bin/ that originate from the mingw-w64-git package:

pacman -Ql mingw-w64-$ARCH-git |
sed 's|^[^ ]* /||' |
grep "^mingw$BITNESS/libexec/git-core/.*\.exe$" |
sort >"$SCRIPT_PATH"/sorted-libexec-exes &&
MOVED_FILE=etc/libexec-moved.txt &&
comm -12 "$SCRIPT_PATH"/sorted-all "$SCRIPT_PATH"/sorted-libexec-exes \
>"$SCRIPT_PATH"/root/$MOVED_FILE &&
if test ! -s "$SCRIPT_PATH"/root/$MOVED_FILE
then
die "Could not find any .exe files in libexec/git-core/"
fi &&
BIN_DIR=mingw$BITNESS/bin &&
mkdir -p "$SCRIPT_PATH"/root/$BIN_DIR &&
(cd / &&
cp $(cat "$SCRIPT_PATH"/root/$MOVED_FILE) "$SCRIPT_PATH"/root/$BIN_DIR/) &&

So I think we're actually good here.

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