edi: Add Log to the SCM Tool.

Nice to remember what's been happening in the working tree.
master
Alastair Poole 2 years ago
parent 65b1330a47
commit 9ff3615165
  1. 13
      src/bin/edi_main.c
  2. 39
      src/bin/edi_scm_main.c
  3. 82
      src/bin/edi_scm_ui.c
  4. 6
      src/bin/edi_scm_ui.h
  5. 51
      src/lib/edi_scm.c
  6. 10
      src/lib/edi_scm.h

@ -48,7 +48,7 @@ static Evas_Object *_edi_filepanel, *_edi_filepanel_icon;
static Evas_Object *_edi_toolbar_save, *_edi_toolbar_undo, *_edi_toolbar_redo, *_edi_toolbar_build, *_edi_toolbar_test, *_edi_toolbar_clean;
static Evas_Object *_edi_toolbar_run, *_edi_toolbar_terminate, *_edi_toolbar_hbx, *_edi_toolbar_vbx, *_edi_toolbar_main_box;
static Evas_Object *_edi_menu_save, *_edi_menu_undo, *_edi_menu_redo, *_edi_menu_build, *_edi_menu_clean, *_edi_menu_test, *_edi_menu_run;
static Evas_Object *_edi_menu_save, *_edi_menu_undo, *_edi_menu_redo, *_edi_menu_build, *_edi_menu_clean, *_edi_menu_test, *_edi_menu_run, *_edi_menu_log;
static Evas_Object *_edi_menu_init, *_edi_menu_commit, *_edi_menu_push, *_edi_menu_pull, *_edi_menu_status, *_edi_menu_stash, *_edi_menu_terminate;
static Evas_Object *_edi_main_win, *_edi_main_box;
static Eina_Bool _edi_toolbar_is_horizontal, _edi_toolbar_text_visible;
@ -626,6 +626,7 @@ _edi_icon_update()
elm_object_item_disabled_set(_edi_menu_push, !can_remote);
elm_object_item_disabled_set(_edi_menu_pull, !can_remote);
elm_object_item_disabled_set(_edi_menu_status, !can_scm);
elm_object_item_disabled_set(_edi_menu_log, !can_scm);
elm_object_item_disabled_set(_edi_menu_commit, !can_scm);
elm_object_item_disabled_set(_edi_menu_stash, !can_scm);
}
@ -1240,6 +1241,13 @@ _edi_menu_scm_status_cb(void *data EINA_UNUSED, Evas_Object *obj EINA_UNUSED,
edi_scm_status();
}
static void
_edi_menu_scm_log_cb(void *data EINA_UNUSED, Evas_Object *obj EINA_UNUSED,
void *event_info EINA_UNUSED)
{
ecore_exe_run(eina_slstr_printf("edi_scm --log ."), NULL);
}
static void
_edi_menu_scm_pull_cb(void *data EINA_UNUSED, Evas_Object *obj EINA_UNUSED,
void *event_info EINA_UNUSED)
@ -1352,7 +1360,10 @@ _edi_menu_setup(Evas_Object *win)
_edi_menu_init = elm_menu_item_add(menu, menu_it, edi_theme_icon_path_get("media-playback-start"), _("Init"), _edi_menu_scm_init_cb, NULL);
_edi_menu_commit = elm_menu_item_add(menu, menu_it, edi_theme_icon_path_get("mail-send"), _("Commit"), _edi_menu_scm_commit_cb, NULL);
_edi_menu_stash = elm_menu_item_add(menu, menu_it, edi_theme_icon_path_get("edit-undo"), _("Stash"), _edi_menu_scm_stash_cb, NULL);
elm_menu_item_separator_add(menu, menu_it);
_edi_menu_status = elm_menu_item_add(menu, menu_it, edi_theme_icon_path_get("dialog-error"), _("Status"), _edi_menu_scm_status_cb, NULL);
_edi_menu_log = elm_menu_item_add(menu, menu_it, edi_theme_icon_path_get("dialog-information"), _("Log"), _edi_menu_scm_log_cb, NULL);
elm_menu_item_separator_add(menu, menu_it);
_edi_menu_push = elm_menu_item_add(menu, menu_it, edi_theme_icon_path_get("go-up"), _("Push"), _edi_menu_scm_push_cb, NULL);
_edi_menu_pull = elm_menu_item_add(menu, menu_it, edi_theme_icon_path_get("go-down"), _("Pull"), _edi_menu_scm_pull_cb, NULL);
}

@ -46,34 +46,45 @@ _win_add(Edi_Scm_Engine *engine)
return win;
}
static void
usage(void)
{
printf("Usage: edi_scm [directory]\n\n");
printf("The Enlightened IDE Source Control\n\n");
printf("Options:\n");
printf(" -c, --commit\t\topen with the commit screen.\n");
printf(" -l, --log\t\tshow scm log.\n");
printf(" -h, --help\t\tshow this message.\n");
exit(0);
}
int main(int argc, char **argv)
{
Evas_Object *win;
Edi_Scm_Engine *engine;
const char *arg, *root;
Edi_Scm_Ui_Opts options;
memset(&options,0, sizeof(Edi_Scm_Ui_Opts));
ecore_init();
elm_init(argc, argv);
root = NULL;
if (argc >= 2)
for (int i = 1; i < argc; i++)
{
arg = argv[1];
arg = argv[i];
if (!strcmp("-h", arg) || !strcmp("--help", arg))
{
printf("Usage: edi_scm [directory]\n\n");
printf("The Enlightened IDE Source Control\n\n");
printf("Options:\n");
printf(" -c, --commit\t\topen with the commit screen.\n");
printf(" -h, --help\t\tshow this message.\n");
return 0;
usage();
}
if (!strcmp("-c", arg) || !strcmp("--commit", arg))
else if (!strcmp("-c", arg) || !strcmp("--commit", arg))
{
}
else if (!strcmp("-l", arg) || !strcmp("--log", arg))
{
if (argc >= 3)
root = argv[2];
options.log = EINA_TRUE;
}
else
{
@ -99,7 +110,7 @@ int main(int argc, char **argv)
exit(1 << 2);
win = _win_add(engine);
edi_scm_ui_add(win);
edi_scm_ui_add(win, options);
elm_win_center(win, EINA_TRUE, EINA_TRUE);
evas_object_show(win);

@ -601,8 +601,82 @@ _avatar_effect(Evas_Object *avatar)
evas_map_free(map);
}
static void
_edi_scm_ui_close_cb(void *data EINA_UNUSED, Evas_Object *obj EINA_UNUSED,
void *event_info EINA_UNUSED)
{
ecore_main_loop_quit();
}
static Eina_Bool
_edi_scm_ui_log_fill_cb(void *data)
{
Edi_Scm_Engine *engine;
Evas_Object *entry;
Eina_List *log;
char *line;
entry = data;
engine = edi_scm_engine_get();
log = engine->log();
EINA_LIST_FREE(log, line)
{
elm_entry_entry_insert(entry, eina_slstr_printf("%s<br>", line));
free(line);
}
return ECORE_CALLBACK_CANCEL;
}
static void
_edi_scm_ui_log(Evas_Object *parent)
{
Evas_Object *bx, *hbx, *pad, *entry, *btn;
bx = elm_box_add(parent);
evas_object_size_hint_align_set(bx, EVAS_HINT_FILL, EVAS_HINT_FILL);
evas_object_size_hint_weight_set(bx, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
evas_object_show(bx);
elm_object_content_set(parent, bx);
entry = elm_entry_add(parent);
elm_entry_editable_set(entry, EINA_FALSE);
elm_entry_single_line_set(entry, EINA_FALSE);
elm_entry_scrollable_set(entry, EINA_TRUE);
elm_scroller_policy_set(entry, ELM_SCROLLER_POLICY_AUTO, ELM_SCROLLER_POLICY_AUTO);
evas_object_size_hint_weight_set(entry, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
evas_object_size_hint_align_set(entry, EVAS_HINT_FILL, EVAS_HINT_FILL);
evas_object_show(entry);
elm_box_pack_end(bx, entry);
hbx = elm_box_add(bx);
elm_box_horizontal_set(hbx, EINA_TRUE);
evas_object_size_hint_align_set(hbx, EVAS_HINT_FILL, EVAS_HINT_FILL);
evas_object_size_hint_weight_set(hbx, EVAS_HINT_EXPAND, 0.0);
evas_object_show(hbx);
elm_box_pack_end(bx, hbx);
pad = elm_box_add(hbx);
elm_box_horizontal_set(pad, EINA_TRUE);
evas_object_size_hint_align_set(pad, EVAS_HINT_FILL, EVAS_HINT_FILL);
evas_object_size_hint_weight_set(pad, EVAS_HINT_EXPAND, 0.0);
evas_object_show(pad);
elm_box_pack_end(hbx, pad);
btn = elm_button_add(hbx);
evas_object_size_hint_align_set(btn, EVAS_HINT_FILL, EVAS_HINT_FILL);
evas_object_size_hint_weight_set(btn, 0.25, EVAS_HINT_EXPAND);
elm_object_text_set(btn, _("Close"));
evas_object_smart_callback_add(btn, "clicked", _edi_scm_ui_close_cb, NULL);
ecore_timer_add(0.1, _edi_scm_ui_log_fill_cb, entry);
evas_object_show(btn);
elm_box_pack_end(hbx, btn);
}
void
edi_scm_ui_add(Evas_Object *parent)
edi_scm_ui_add(Evas_Object *parent, Edi_Scm_Ui_Opts options)
{
Evas_Object *layout, *frame, *hbox, *cbox, *label, *avatar, *input, *button;
Evas_Object *list, *pbox;
@ -618,6 +692,12 @@ edi_scm_ui_add(Evas_Object *parent)
if (!engine)
exit(1 << 1);
if (options.log)
{
_edi_scm_ui_log(parent);
return;
}
pd = calloc(1, sizeof(Edi_Scm_Ui_Data));
pd->workdir = engine->root_directory;
pd->monitor = eio_monitor_add(pd->workdir);

@ -12,6 +12,10 @@ extern "C" {
* @brief These routines used for managing Edi SCM UI actions.
*/
typedef struct _Edi_Scm_Ui_Opts {
Eina_Bool log;
} Edi_Scm_Ui_Opts;
/**
* @brief SCM management functions.
* @defgroup SCM
@ -28,7 +32,7 @@ extern "C" {
* @param parent Parent object to add the commit UI to.
* @ingroup SCM
*/
void edi_scm_ui_add(Evas_Object *parent);
void edi_scm_ui_add(Evas_Object *parent, Edi_Scm_Ui_Opts opts);
/**
* @}
*/

@ -220,6 +220,48 @@ _edi_scm_git_status(void)
return code;
}
static void
_chomp(char *s)
{
while (*s)
{
if (*s == '\r' || *s == '\n')
{
*s = 0;
return;
}
++s;
}
}
static Eina_List *
_edi_scm_git_log(void)
{
FILE *p;
Eina_Strbuf *command;
char buf[4096];
Eina_List *lines = NULL;
command = eina_strbuf_new();
eina_strbuf_append(command, "git log");
p = popen(eina_strbuf_string_get(command), "r");
if (!p) return NULL;
while ((fgets(buf, sizeof(buf), p)) != NULL)
{
_chomp(buf);
lines = eina_list_append(lines, strdup(buf));
}
eina_strbuf_free(command);
pclose(p);
return lines;
}
static Edi_Scm_Status *
_parse_line(char *line)
{
@ -769,6 +811,14 @@ edi_scm_diff(Eina_Bool cached)
return e->diff(cached);
}
EAPI Eina_List *
edi_scm_log(void)
{
Edi_Scm_Engine *e = edi_scm_engine_get();
return e->log();
}
EAPI void
edi_scm_stash(void)
{
@ -847,6 +897,7 @@ _edi_scm_git_init(const char *rootdir)
engine->file_undo = _edi_scm_git_file_undo;
engine->move = _edi_scm_git_file_move;
engine->status = _edi_scm_git_status;
engine->log = _edi_scm_git_log;
engine->diff = _edi_scm_git_diff;
engine->commit = _edi_scm_git_commit;
engine->pull = _edi_scm_git_pull;

@ -41,6 +41,7 @@ typedef int (scm_fn_del)(const char *path);
typedef int (scm_fn_move)(const char *src, const char *dest);
typedef int (scm_fn_commit)(const char *message);
typedef int (scm_fn_status)(void);
typedef Eina_List *(scm_fn_log)(void);
typedef char *(scm_fn_diff)(Eina_Bool);
typedef int (scm_fn_push)(void);
typedef int (scm_fn_pull)(void);
@ -70,6 +71,7 @@ typedef struct _Edi_Scm_Engine
scm_fn_move *move;
scm_fn_commit *commit;
scm_fn_status *status;
scm_fn_log *log;
scm_fn_diff *diff;
scm_fn_file_status *file_status;
scm_fn_push *push;
@ -217,6 +219,14 @@ void edi_scm_commit(const char *message);
void edi_scm_status(void);
/**
* Get log of repository.
*
* @ingroup Scm
*/
Eina_List *edi_scm_log(void);
/**
*
* Get file status within repository.
*
* @param path The file path.

Loading…
Cancel
Save