Hi,

On Fri, 8 Feb 2008, Kirill wrote:

> As Johannes Schindelin suggested, it verifies that the selected item is
> a valid Git repository and add different menu items accordingly.
> This version is for preview purposes only.

I'd say "This version puts the basic infrastructure in place, and does not 
necessarily provide a full-grown menu structure yet."

> It implements the suggestion in a way that the text of the item is 
> context-sensitive, but the action is always the same.
> 
> TODO: think about making LONGEST_MENU_ITEM and MAX_PROCESSING_TIME
>       dynamic/configurable.
> TODO: decide on a structure and actions of added menu items.
> ---
>  exec.c |   49 +++++++++++++++++++++++++++++-------
>  exec.h |    7 +++-
>  ext.c  |    4 +++
>  menu.c |   86 ++++++++++++++++++++++++++++++++++++++++++---------------------
>  4 files changed, 105 insertions(+), 41 deletions(-)
> 
> diff --git a/exec.c b/exec.c
> index 4d519cc..950a527 100644
> --- a/exec.c
> +++ b/exec.c
> @@ -51,26 +54,52 @@ char *env_for_git()
>       return environment;
>  }
> 
> -void exec_gui(char *command, const char *wd)
> +int exec_git(int mode, char *command, const char *wd)

Out of habit, I would have expected the mode to be the last argument...

>  {
>       STARTUPINFO si = { sizeof(si) };
>       PROCESS_INFORMATION pi;
> +     DWORD status = -1;
> +     char cmd[1024];
> +
> +     if (!msys_path()) {
> +             debug_git("[ERROR] Could not find msysPath");
> +             return -1;
> +     }
> +
> +     sprintf(cmd, "\"%s\\bin\\git.exe\" %s", msys_path(), command);
> 
>       si.dwFlags = STARTF_USESHOWWINDOW;
>       si.wShowWindow = SW_HIDE;
> 
> -     debug_git("Trying to spawn '%s' in working directory '%s'\n",
> +     debug_git("Trying to spawn 'git %s' in working directory '%s'\n",
>               command, wd);
> -     if (CreateProcess(NULL, command, NULL, NULL, FALSE, 0,
> -                     env_for_git(), wd, &si, &pi))
> -     {
> -             CloseHandle(pi.hProcess);
> -             CloseHandle(pi.hThread);
> -     }
> -     else
> -             debug_git("[ERROR] Could not create process (%d)"
> +     if (! CreateProcess(NULL, cmd, NULL, NULL, FALSE, 0,

Please lose the space after the "!".

> +                     env_for_git(), wd, &si, &pi)) {
> +             debug_git("[ERROR] Could not create process (%d); "
>                       "wd: %s; cmd: %s",
>                       GetLastError(), wd, command);
> 
> +             return -1;
> +     }
> +
> +     if (P_WAIT == mode) {
> +             if (WAIT_OBJECT_0 == WaitForSingleObject(pi.hProcess,
> +                             MAX_PROCESSING_TIME)) {
> +
> +                     if (! GetExitCodeProcess(pi.hProcess, &status))
> +                             debug_git("[ERROR] GetExitCode failed (%d); "
> +                                     "wd: %s; cmd: %s",
> +                                     GetLastError(), wd, command);
> +
> +             } else
> +                     debug_git("[ERROR] process timed out; "
> +                             "wd: %s; cmd: %s",
> +                             wd, command);
> +     }
> +
> +     CloseHandle(pi.hProcess);
> +     CloseHandle(pi.hThread);
> +
> +     return status;
>  }
> 
> diff --git a/menu.c b/menu.c
> index 97811fa..55f17d4 100644
> --- a/menu.c
> +++ b/menu.c
> @@ -1,13 +1,15 @@
>  #include <shlobj.h>
> -#include <stdarg.h>
>  #include <tchar.h>
>  #include <stdio.h>
> +#include <process.h>
>  #include "menu.h"
>  #include "ext.h"
>  #include "debug.h"
>  #include "systeminfo.h"
>  #include "exec.h"
> 
> +#define LONGEST_MENU_ITEM 40

I imagine a menu with entries longer than 40 characters would be 
unreadable anyway.

> @@ -18,16 +20,55 @@ static STDMETHODIMP query_context_menu(void *p, HMENU 
> menu,
>  {
>       struct git_menu *this_menu = p;
>       struct git_data *this_ = this_menu->git_data;
> +     char *wd;
> +     BOOL bDirSelected = TRUE;
> +
> +     UINT original_first = first_command;
> +     char menu_item[LONGEST_MENU_ITEM];
> +
> +     int status;
> 
>       if (flags & CMF_DEFAULTONLY)
>               return MAKE_HRESULT(SEVERITY_SUCCESS, FACILITY_NULL, 0);
> 
> +     /* figure out the directory */
> +     wd = strdup(this_->name);
> +     if (!(FILE_ATTRIBUTE_DIRECTORY & GetFileAttributes(wd))) {
> +             char *c = strrchr(wd, '\\');
> +             *c = 0;

Can you be sure that there is a "\\"?  (I made it a habit to guard code 
like this with "if (c)".)

> +             bDirSelected = FALSE;
> +     }
> +
> +     status = exec_git(P_WAIT, "rev-parse --show-cdup", wd);
> +     free (wd);

Doesn't this pop up a window (even if hidden)?

Thanks,
Dscho

Reply via email to