Shut up linker
[git-cheetah.git] / cheetahmenu.c
bloba3a6a50574de281fb4a62cb9d91c10235556fbf2
2 #include "cache.h"
3 #include "exec.h"
4 #include "menuengine.h"
5 #include "cheetahmenu.h"
7 char *wd_from_path(const char *path, BOOL *is_path_dir)
9 BOOL is_directory = TRUE;
10 char *cheetah_wd = strdup(path);
11 if (!(FILE_ATTRIBUTE_DIRECTORY & GetFileAttributes(cheetah_wd))) {
12 char *c = strrchr(cheetah_wd, '\\');
13 if (c) /* sanity check in case it's a weird directory */
14 *c = 0;
16 is_directory = FALSE;
19 if (is_path_dir)
20 *is_path_dir = is_directory;
22 return cheetah_wd;
26 * Cheetah-specific menu
29 static void menu_gui(struct git_data *this_, UINT id)
31 char *wd = wd_from_path(this_->name, NULL);
32 exec_program(wd, NULL, NULL, HIDDENMODE, "git", "gui", NULL);
33 free(wd);
36 static void menu_init(struct git_data *this_, UINT id)
38 char *wd = wd_from_path(this_->name, NULL);
39 exec_program(wd, NULL, NULL, HIDDENMODE, "git", "init", NULL);
40 free(wd);
43 static void menu_history(struct git_data *this_, unsigned int id)
45 BOOL is_directory;
46 char *wd = wd_from_path(this_->name, &is_directory);
47 char *name = "";
49 if (!is_directory)
50 name = this_->name + strlen(wd) + 1;
52 exec_program(wd, NULL, NULL, HIDDENMODE, "sh", "--login", "-i",
53 "/bin/gitk", "HEAD", "--", name, NULL);
54 free(wd);
57 static void menu_bash(struct git_data *this_, UINT id)
59 char *wd = wd_from_path(this_->name, NULL);
60 /* start is required because exec_program does not create a window */
61 exec_program(wd, NULL, NULL, NORMALMODE,
62 "start", "sh", "--login", "-i", NULL);
63 free(wd);
66 static void menu_blame(struct git_data *this_, UINT id)
68 BOOL is_directory;
69 char *wd = wd_from_path(this_->name, &is_directory);
70 char *name = "";
72 if (!is_directory) {
73 name = this_->name + strlen(wd) + 1;
74 exec_program(wd, NULL, NULL, HIDDENMODE,
75 "git", "gui", "blame", name, NULL);
78 free(wd);
81 static void menu_citool(struct git_data *this_, UINT id)
83 char *wd = wd_from_path(this_->name, NULL);
84 exec_program(wd, NULL, NULL, HIDDENMODE, "git", "citool", NULL);
85 free(wd);
88 static void menu_addall(struct git_data *this_, UINT id)
90 char *wd = wd_from_path(this_->name, NULL);
91 exec_program(wd, NULL, NULL, HIDDENMODE, "git", "add", "--all", NULL);
92 free(wd);
95 UINT cheetah_menu_mask(struct git_data *this_)
97 BOOL is_directory;
98 char *wd = wd_from_path(this_->name, &is_directory);
99 UINT selection = is_directory ? MENU_ITEM_DIR : MENU_ITEM_FILE;
100 int status;
102 struct strbuf output;
103 char *eol;
104 strbuf_init(&output, 0);
106 status = exec_program(wd, &output, NULL, WAITMODE,
107 "git", "rev-parse", "--show-prefix", NULL);
108 eol = strchr(output.buf, '\n');
109 if (eol)
110 *eol = 0;
112 if (status < 0) /* something went terribly wrong */
113 selection = MENU_ITEM_LAST;
114 else if (status)
115 selection |= MENU_ITEM_NOREPO;
116 else {
117 char head_path[MAX_PATH] = "HEAD";
118 if (!is_directory)
119 sprintf(head_path, "HEAD:%s%s",
120 output.buf,
121 this_->name + strlen(wd) + 1);
123 status = exec_program(wd, NULL, NULL, WAITMODE,
124 "git", "rev-parse", "--verify", head_path, NULL);
125 if (status < 0) /* something went terribly wrong */
126 selection = MENU_ITEM_LAST;
127 else
128 selection |= MENU_ITEM_REPO |
129 (status ?
130 MENU_ITEM_NOTRACK : MENU_ITEM_TRACK);
133 strbuf_release(&output);
134 free(wd);
135 return selection;
138 const struct menu_item cheetah_menu[] = {
139 { MENU_ITEM_ALWAYS, NULL, NULL, build_separator, NULL },
141 { MENU_ITEM_REPO, "Git &Add all files now",
142 "Add all files from this folder now",
143 build_item, menu_addall },
144 { MENU_ITEM_REPO, "Git &Commit Tool",
145 "Launch the GIT commit tool in the local or chosen directory.",
146 build_item, menu_citool },
147 { MENU_ITEM_TRACK, "Git &History",
148 "Show GIT history of the chosen file or directory.",
149 build_item,
150 menu_history },
151 { MENU_ITEM_TRACK | MENU_ITEM_FILE, "Git &Blame",
152 "Start a blame viewer on the specified file.",
153 build_item, menu_blame },
155 { MENU_ITEM_REPO, "Git &Gui",
156 "Launch the GIT Gui in the local or chosen directory.",
157 build_item, menu_gui },
159 { MENU_ITEM_NOREPO, "Git I&nit Here",
160 "Initialize GIT repo in the local directory.",
161 build_item, menu_init },
162 { MENU_ITEM_NOREPO | MENU_ITEM_DIR, "Git &Gui",
163 "Launch the GIT Gui in the local or chosen directory.",
164 build_item, menu_gui },
166 { MENU_ITEM_ALWAYS, "Git Ba&sh",
167 "Start GIT shell in the local or chosen directory",
168 build_item, menu_bash },
169 { MENU_ITEM_ALWAYS, NULL, NULL, build_separator, NULL },
172 void build_cheetah_menu(struct git_data *data, void *platform_data)
174 reset_platform(platform_data);
175 build_menu_items(data, cheetah_menu_mask,
176 cheetah_menu,
177 sizeof(cheetah_menu) / sizeof(cheetah_menu[0]),
178 platform_data);