summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAlastair Poole <netstar@gmail.com>2020-08-13 17:33:35 +0100
committerAlastair Poole <netstar@gmail.com>2020-08-13 17:33:35 +0100
commit9ff36151651b1c1f13b3f0cffd415239fe683194 (patch)
tree62b7cfc52b9e003e31facc3d47e97ee3d2b26378
parent65b1330a47e00eac46e00968900d4608eac5cfe2 (diff)
edi: Add Log to the SCM Tool.
Nice to remember what's been happening in the working tree.
-rw-r--r--src/bin/edi_main.c13
-rw-r--r--src/bin/edi_scm_main.c39
-rw-r--r--src/bin/edi_scm_ui.c82
-rw-r--r--src/bin/edi_scm_ui.h6
-rw-r--r--src/lib/edi_scm.c51
-rw-r--r--src/lib/edi_scm.h10
6 files changed, 184 insertions, 17 deletions
diff --git a/src/bin/edi_main.c b/src/bin/edi_main.c
index ad5fbbc..9843363 100644
--- a/src/bin/edi_main.c
+++ b/src/bin/edi_main.c
@@ -48,7 +48,7 @@ static Evas_Object *_edi_filepanel, *_edi_filepanel_icon;
48 48
49static Evas_Object *_edi_toolbar_save, *_edi_toolbar_undo, *_edi_toolbar_redo, *_edi_toolbar_build, *_edi_toolbar_test, *_edi_toolbar_clean; 49static Evas_Object *_edi_toolbar_save, *_edi_toolbar_undo, *_edi_toolbar_redo, *_edi_toolbar_build, *_edi_toolbar_test, *_edi_toolbar_clean;
50static Evas_Object *_edi_toolbar_run, *_edi_toolbar_terminate, *_edi_toolbar_hbx, *_edi_toolbar_vbx, *_edi_toolbar_main_box; 50static Evas_Object *_edi_toolbar_run, *_edi_toolbar_terminate, *_edi_toolbar_hbx, *_edi_toolbar_vbx, *_edi_toolbar_main_box;
51static Evas_Object *_edi_menu_save, *_edi_menu_undo, *_edi_menu_redo, *_edi_menu_build, *_edi_menu_clean, *_edi_menu_test, *_edi_menu_run; 51static 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;
52static Evas_Object *_edi_menu_init, *_edi_menu_commit, *_edi_menu_push, *_edi_menu_pull, *_edi_menu_status, *_edi_menu_stash, *_edi_menu_terminate; 52static Evas_Object *_edi_menu_init, *_edi_menu_commit, *_edi_menu_push, *_edi_menu_pull, *_edi_menu_status, *_edi_menu_stash, *_edi_menu_terminate;
53static Evas_Object *_edi_main_win, *_edi_main_box; 53static Evas_Object *_edi_main_win, *_edi_main_box;
54static Eina_Bool _edi_toolbar_is_horizontal, _edi_toolbar_text_visible; 54static Eina_Bool _edi_toolbar_is_horizontal, _edi_toolbar_text_visible;
@@ -626,6 +626,7 @@ _edi_icon_update()
626 elm_object_item_disabled_set(_edi_menu_push, !can_remote); 626 elm_object_item_disabled_set(_edi_menu_push, !can_remote);
627 elm_object_item_disabled_set(_edi_menu_pull, !can_remote); 627 elm_object_item_disabled_set(_edi_menu_pull, !can_remote);
628 elm_object_item_disabled_set(_edi_menu_status, !can_scm); 628 elm_object_item_disabled_set(_edi_menu_status, !can_scm);
629 elm_object_item_disabled_set(_edi_menu_log, !can_scm);
629 elm_object_item_disabled_set(_edi_menu_commit, !can_scm); 630 elm_object_item_disabled_set(_edi_menu_commit, !can_scm);
630 elm_object_item_disabled_set(_edi_menu_stash, !can_scm); 631 elm_object_item_disabled_set(_edi_menu_stash, !can_scm);
631 } 632 }
@@ -1241,6 +1242,13 @@ _edi_menu_scm_status_cb(void *data EINA_UNUSED, Evas_Object *obj EINA_UNUSED,
1241} 1242}
1242 1243
1243static void 1244static void
1245_edi_menu_scm_log_cb(void *data EINA_UNUSED, Evas_Object *obj EINA_UNUSED,
1246 void *event_info EINA_UNUSED)
1247{
1248 ecore_exe_run(eina_slstr_printf("edi_scm --log ."), NULL);
1249}
1250
1251static void
1244_edi_menu_scm_pull_cb(void *data EINA_UNUSED, Evas_Object *obj EINA_UNUSED, 1252_edi_menu_scm_pull_cb(void *data EINA_UNUSED, Evas_Object *obj EINA_UNUSED,
1245 void *event_info EINA_UNUSED) 1253 void *event_info EINA_UNUSED)
1246{ 1254{
@@ -1352,7 +1360,10 @@ _edi_menu_setup(Evas_Object *win)
1352 _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); 1360 _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);
1353 _edi_menu_commit = elm_menu_item_add(menu, menu_it, edi_theme_icon_path_get("mail-send"), _("Commit"), _edi_menu_scm_commit_cb, NULL); 1361 _edi_menu_commit = elm_menu_item_add(menu, menu_it, edi_theme_icon_path_get("mail-send"), _("Commit"), _edi_menu_scm_commit_cb, NULL);
1354 _edi_menu_stash = elm_menu_item_add(menu, menu_it, edi_theme_icon_path_get("edit-undo"), _("Stash"), _edi_menu_scm_stash_cb, NULL); 1362 _edi_menu_stash = elm_menu_item_add(menu, menu_it, edi_theme_icon_path_get("edit-undo"), _("Stash"), _edi_menu_scm_stash_cb, NULL);
1363 elm_menu_item_separator_add(menu, menu_it);
1355 _edi_menu_status = elm_menu_item_add(menu, menu_it, edi_theme_icon_path_get("dialog-error"), _("Status"), _edi_menu_scm_status_cb, NULL); 1364 _edi_menu_status = elm_menu_item_add(menu, menu_it, edi_theme_icon_path_get("dialog-error"), _("Status"), _edi_menu_scm_status_cb, NULL);
1365 _edi_menu_log = elm_menu_item_add(menu, menu_it, edi_theme_icon_path_get("dialog-information"), _("Log"), _edi_menu_scm_log_cb, NULL);
1366 elm_menu_item_separator_add(menu, menu_it);
1356 _edi_menu_push = elm_menu_item_add(menu, menu_it, edi_theme_icon_path_get("go-up"), _("Push"), _edi_menu_scm_push_cb, NULL); 1367 _edi_menu_push = elm_menu_item_add(menu, menu_it, edi_theme_icon_path_get("go-up"), _("Push"), _edi_menu_scm_push_cb, NULL);
1357 _edi_menu_pull = elm_menu_item_add(menu, menu_it, edi_theme_icon_path_get("go-down"), _("Pull"), _edi_menu_scm_pull_cb, NULL); 1368 _edi_menu_pull = elm_menu_item_add(menu, menu_it, edi_theme_icon_path_get("go-down"), _("Pull"), _edi_menu_scm_pull_cb, NULL);
1358 } 1369 }
diff --git a/src/bin/edi_scm_main.c b/src/bin/edi_scm_main.c
index a1dd0e8..24a76d9 100644
--- a/src/bin/edi_scm_main.c
+++ b/src/bin/edi_scm_main.c
@@ -46,34 +46,45 @@ _win_add(Edi_Scm_Engine *engine)
46 return win; 46 return win;
47} 47}
48 48
49static void
50usage(void)
51{
52 printf("Usage: edi_scm [directory]\n\n");
53 printf("The Enlightened IDE Source Control\n\n");
54
55 printf("Options:\n");
56 printf(" -c, --commit\t\topen with the commit screen.\n");
57 printf(" -l, --log\t\tshow scm log.\n");
58 printf(" -h, --help\t\tshow this message.\n");
59 exit(0);
60}
61
49int main(int argc, char **argv) 62int main(int argc, char **argv)
50{ 63{
51 Evas_Object *win; 64 Evas_Object *win;
52 Edi_Scm_Engine *engine; 65 Edi_Scm_Engine *engine;
53 const char *arg, *root; 66 const char *arg, *root;
67 Edi_Scm_Ui_Opts options;
68
69 memset(&options,0, sizeof(Edi_Scm_Ui_Opts));
54 70
55 ecore_init(); 71 ecore_init();
56 elm_init(argc, argv); 72 elm_init(argc, argv);
57 root = NULL; 73 root = NULL;
58 74
59 if (argc >= 2) 75 for (int i = 1; i < argc; i++)
60 { 76 {
61 arg = argv[1]; 77 arg = argv[i];
62 if (!strcmp("-h", arg) || !strcmp("--help", arg)) 78 if (!strcmp("-h", arg) || !strcmp("--help", arg))
63 { 79 {
64 printf("Usage: edi_scm [directory]\n\n"); 80 usage();
65 printf("The Enlightened IDE Source Control\n\n");
66
67 printf("Options:\n");
68 printf(" -c, --commit\t\topen with the commit screen.\n");
69 printf(" -h, --help\t\tshow this message.\n");
70 return 0;
71 } 81 }
72 82 else if (!strcmp("-c", arg) || !strcmp("--commit", arg))
73 if (!strcmp("-c", arg) || !strcmp("--commit", arg)) 83 {
84 }
85 else if (!strcmp("-l", arg) || !strcmp("--log", arg))
74 { 86 {
75 if (argc >= 3) 87 options.log = EINA_TRUE;
76 root = argv[2];
77 } 88 }
78 else 89 else
79 { 90 {
@@ -99,7 +110,7 @@ int main(int argc, char **argv)
99 exit(1 << 2); 110 exit(1 << 2);
100 111
101 win = _win_add(engine); 112 win = _win_add(engine);
102 edi_scm_ui_add(win); 113 edi_scm_ui_add(win, options);
103 elm_win_center(win, EINA_TRUE, EINA_TRUE); 114 elm_win_center(win, EINA_TRUE, EINA_TRUE);
104 evas_object_show(win); 115 evas_object_show(win);
105 116
diff --git a/src/bin/edi_scm_ui.c b/src/bin/edi_scm_ui.c
index 73ec55e..2888b64 100644
--- a/src/bin/edi_scm_ui.c
+++ b/src/bin/edi_scm_ui.c
@@ -601,8 +601,82 @@ _avatar_effect(Evas_Object *avatar)
601 evas_map_free(map); 601 evas_map_free(map);
602} 602}
603 603
604static void
605_edi_scm_ui_close_cb(void *data EINA_UNUSED, Evas_Object *obj EINA_UNUSED,
606 void *event_info EINA_UNUSED)
607{
608 ecore_main_loop_quit();
609}
610
611static Eina_Bool
612_edi_scm_ui_log_fill_cb(void *data)
613{
614 Edi_Scm_Engine *engine;
615 Evas_Object *entry;
616 Eina_List *log;
617 char *line;
618
619 entry = data;
620
621 engine = edi_scm_engine_get();
622 log = engine->log();
623 EINA_LIST_FREE(log, line)
624 {
625 elm_entry_entry_insert(entry, eina_slstr_printf("%s<br>", line));
626 free(line);
627 }
628
629 return ECORE_CALLBACK_CANCEL;
630}
631
632static void
633_edi_scm_ui_log(Evas_Object *parent)
634{
635 Evas_Object *bx, *hbx, *pad, *entry, *btn;
636
637 bx = elm_box_add(parent);
638 evas_object_size_hint_align_set(bx, EVAS_HINT_FILL, EVAS_HINT_FILL);
639 evas_object_size_hint_weight_set(bx, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
640 evas_object_show(bx);
641 elm_object_content_set(parent, bx);
642
643 entry = elm_entry_add(parent);
644 elm_entry_editable_set(entry, EINA_FALSE);
645 elm_entry_single_line_set(entry, EINA_FALSE);
646 elm_entry_scrollable_set(entry, EINA_TRUE);
647 elm_scroller_policy_set(entry, ELM_SCROLLER_POLICY_AUTO, ELM_SCROLLER_POLICY_AUTO);
648 evas_object_size_hint_weight_set(entry, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
649 evas_object_size_hint_align_set(entry, EVAS_HINT_FILL, EVAS_HINT_FILL);
650 evas_object_show(entry);
651 elm_box_pack_end(bx, entry);
652
653 hbx = elm_box_add(bx);
654 elm_box_horizontal_set(hbx, EINA_TRUE);
655 evas_object_size_hint_align_set(hbx, EVAS_HINT_FILL, EVAS_HINT_FILL);
656 evas_object_size_hint_weight_set(hbx, EVAS_HINT_EXPAND, 0.0);
657 evas_object_show(hbx);
658 elm_box_pack_end(bx, hbx);
659
660 pad = elm_box_add(hbx);
661 elm_box_horizontal_set(pad, EINA_TRUE);
662 evas_object_size_hint_align_set(pad, EVAS_HINT_FILL, EVAS_HINT_FILL);
663 evas_object_size_hint_weight_set(pad, EVAS_HINT_EXPAND, 0.0);
664 evas_object_show(pad);
665 elm_box_pack_end(hbx, pad);
666
667 btn = elm_button_add(hbx);
668 evas_object_size_hint_align_set(btn, EVAS_HINT_FILL, EVAS_HINT_FILL);
669 evas_object_size_hint_weight_set(btn, 0.25, EVAS_HINT_EXPAND);
670 elm_object_text_set(btn, _("Close"));
671 evas_object_smart_callback_add(btn, "clicked", _edi_scm_ui_close_cb, NULL);
672
673 ecore_timer_add(0.1, _edi_scm_ui_log_fill_cb, entry);
674 evas_object_show(btn);
675 elm_box_pack_end(hbx, btn);
676}
677
604void 678void
605edi_scm_ui_add(Evas_Object *parent) 679edi_scm_ui_add(Evas_Object *parent, Edi_Scm_Ui_Opts options)
606{ 680{
607 Evas_Object *layout, *frame, *hbox, *cbox, *label, *avatar, *input, *button; 681 Evas_Object *layout, *frame, *hbox, *cbox, *label, *avatar, *input, *button;
608 Evas_Object *list, *pbox; 682 Evas_Object *list, *pbox;
@@ -618,6 +692,12 @@ edi_scm_ui_add(Evas_Object *parent)
618 if (!engine) 692 if (!engine)
619 exit(1 << 1); 693 exit(1 << 1);
620 694
695 if (options.log)
696 {
697 _edi_scm_ui_log(parent);
698 return;
699 }
700
621 pd = calloc(1, sizeof(Edi_Scm_Ui_Data)); 701 pd = calloc(1, sizeof(Edi_Scm_Ui_Data));
622 pd->workdir = engine->root_directory; 702 pd->workdir = engine->root_directory;
623 pd->monitor = eio_monitor_add(pd->workdir); 703 pd->monitor = eio_monitor_add(pd->workdir);
diff --git a/src/bin/edi_scm_ui.h b/src/bin/edi_scm_ui.h
index 5f6256d..5c26fc7 100644
--- a/src/bin/edi_scm_ui.h
+++ b/src/bin/edi_scm_ui.h
@@ -12,6 +12,10 @@ extern "C" {
12 * @brief These routines used for managing Edi SCM UI actions. 12 * @brief These routines used for managing Edi SCM UI actions.
13 */ 13 */
14 14
15typedef struct _Edi_Scm_Ui_Opts {
16 Eina_Bool log;
17} Edi_Scm_Ui_Opts;
18
15/** 19/**
16 * @brief SCM management functions. 20 * @brief SCM management functions.
17 * @defgroup SCM 21 * @defgroup SCM
@@ -28,7 +32,7 @@ extern "C" {
28 * @param parent Parent object to add the commit UI to. 32 * @param parent Parent object to add the commit UI to.
29 * @ingroup SCM 33 * @ingroup SCM
30 */ 34 */
31void edi_scm_ui_add(Evas_Object *parent); 35void edi_scm_ui_add(Evas_Object *parent, Edi_Scm_Ui_Opts opts);
32/** 36/**
33 * @} 37 * @}
34 */ 38 */
diff --git a/src/lib/edi_scm.c b/src/lib/edi_scm.c
index c5c97b6..b4542c9 100644
--- a/src/lib/edi_scm.c
+++ b/src/lib/edi_scm.c
@@ -220,6 +220,48 @@ _edi_scm_git_status(void)
220 return code; 220 return code;
221} 221}
222 222
223static void
224_chomp(char *s)
225{
226 while (*s)
227 {
228 if (*s == '\r' || *s == '\n')
229 {
230 *s = 0;
231 return;
232 }
233 ++s;
234 }
235}
236
237static Eina_List *
238_edi_scm_git_log(void)
239{
240 FILE *p;
241 Eina_Strbuf *command;
242 char buf[4096];
243 Eina_List *lines = NULL;
244
245 command = eina_strbuf_new();
246
247 eina_strbuf_append(command, "git log");
248
249 p = popen(eina_strbuf_string_get(command), "r");
250 if (!p) return NULL;
251
252 while ((fgets(buf, sizeof(buf), p)) != NULL)
253 {
254 _chomp(buf);
255 lines = eina_list_append(lines, strdup(buf));
256 }
257
258 eina_strbuf_free(command);
259
260 pclose(p);
261
262 return lines;
263}
264
223static Edi_Scm_Status * 265static Edi_Scm_Status *
224_parse_line(char *line) 266_parse_line(char *line)
225{ 267{
@@ -769,6 +811,14 @@ edi_scm_diff(Eina_Bool cached)
769 return e->diff(cached); 811 return e->diff(cached);
770} 812}
771 813
814EAPI Eina_List *
815edi_scm_log(void)
816{
817 Edi_Scm_Engine *e = edi_scm_engine_get();
818
819 return e->log();
820}
821
772EAPI void 822EAPI void
773edi_scm_stash(void) 823edi_scm_stash(void)
774{ 824{
@@ -847,6 +897,7 @@ _edi_scm_git_init(const char *rootdir)
847 engine->file_undo = _edi_scm_git_file_undo; 897 engine->file_undo = _edi_scm_git_file_undo;
848 engine->move = _edi_scm_git_file_move; 898 engine->move = _edi_scm_git_file_move;
849 engine->status = _edi_scm_git_status; 899 engine->status = _edi_scm_git_status;
900 engine->log = _edi_scm_git_log;
850 engine->diff = _edi_scm_git_diff; 901 engine->diff = _edi_scm_git_diff;
851 engine->commit = _edi_scm_git_commit; 902 engine->commit = _edi_scm_git_commit;
852 engine->pull = _edi_scm_git_pull; 903 engine->pull = _edi_scm_git_pull;
diff --git a/src/lib/edi_scm.h b/src/lib/edi_scm.h
index dac6ffb..bbaee36 100644
--- a/src/lib/edi_scm.h
+++ b/src/lib/edi_scm.h
@@ -41,6 +41,7 @@ typedef int (scm_fn_del)(const char *path);
41typedef int (scm_fn_move)(const char *src, const char *dest); 41typedef int (scm_fn_move)(const char *src, const char *dest);
42typedef int (scm_fn_commit)(const char *message); 42typedef int (scm_fn_commit)(const char *message);
43typedef int (scm_fn_status)(void); 43typedef int (scm_fn_status)(void);
44typedef Eina_List *(scm_fn_log)(void);
44typedef char *(scm_fn_diff)(Eina_Bool); 45typedef char *(scm_fn_diff)(Eina_Bool);
45typedef int (scm_fn_push)(void); 46typedef int (scm_fn_push)(void);
46typedef int (scm_fn_pull)(void); 47typedef int (scm_fn_pull)(void);
@@ -70,6 +71,7 @@ typedef struct _Edi_Scm_Engine
70 scm_fn_move *move; 71 scm_fn_move *move;
71 scm_fn_commit *commit; 72 scm_fn_commit *commit;
72 scm_fn_status *status; 73 scm_fn_status *status;
74 scm_fn_log *log;
73 scm_fn_diff *diff; 75 scm_fn_diff *diff;
74 scm_fn_file_status *file_status; 76 scm_fn_file_status *file_status;
75 scm_fn_push *push; 77 scm_fn_push *push;
@@ -217,6 +219,14 @@ void edi_scm_commit(const char *message);
217void edi_scm_status(void); 219void edi_scm_status(void);
218 220
219/** 221/**
222 * Get log of repository.
223 *
224 * @ingroup Scm
225 */
226Eina_List *edi_scm_log(void);
227
228/**
229 *
220 * Get file status within repository. 230 * Get file status within repository.
221 * 231 *
222 * @param path The file path. 232 * @param path The file path.