1
0
mirror of https://github.com/weechat/weechat.git synced 2026-07-02 18:25:43 +02:00

script: add diff between current script and version in repository

New options:
- script.look.diff_command
- script.look.diff_color

Key alt-d has been changed to alt-v on script buffer (view script).
Key alt-d is now used on detail of script to jump to diff (if diff is displayed).
This commit is contained in:
Sebastien Helleu
2012-08-30 08:50:22 +02:00
parent 186053f90c
commit 80e740b72f
29 changed files with 599 additions and 88 deletions
File diff suppressed because it is too large Load Diff
+24 -20
View File
@@ -36,7 +36,8 @@
struct t_gui_buffer *script_buffer = NULL;
int script_buffer_selected_line = 0;
struct t_repo_script *script_buffer_detail_script = NULL;
int script_buffer_detail_script_line_source = 0;
int script_buffer_detail_script_last_line = 0;
int script_buffer_detail_script_line_diff = -1;
/*
@@ -475,7 +476,8 @@ script_buffer_display_detail_script (struct t_repo_script *script)
(script->max_weechat) ? script->max_weechat : "-");
line++;
script_buffer_detail_script_line_source = line + 2;
script_buffer_detail_script_last_line = line + 2;
script_buffer_detail_script_line_diff = -1;
}
/*
@@ -502,14 +504,14 @@ script_buffer_refresh (int clear)
{
snprintf (str_title, sizeof (str_title),
"%s",
_("alt+d=back to list"));
_("Alt+key/input: v=back to list d=jump to diff"));
}
else
{
snprintf (str_title, sizeof (str_title),
_("%d/%d scripts (filter: %s) | Sort: %s | "
"Alt+key/input: i=install r=remove l=load L=reload "
"u=unload h=(un)hold d=show detail | Input: q=close "
"u=unload h=(un)hold v=view script | Input: q=close "
"$=refresh s:x,y=sort words=filter *=reset filter | "
"Mouse: left=select right=install/remove"),
script_repo_count_displayed,
@@ -704,14 +706,15 @@ int
script_buffer_input_cb (void *data, struct t_gui_buffer *buffer,
const char *input_data)
{
char *actions[][2] = { { "l", "load" },
{ "u", "unload" },
{ "L", "reload" },
{ "i", "install" },
{ "r", "remove" },
{ "h", "hold" },
{ "d", "show" },
{ NULL, NULL } };
char *actions[][2] = { { "l", "load" },
{ "u", "unload" },
{ "L", "reload" },
{ "i", "install" },
{ "r", "remove" },
{ "h", "hold" },
{ "v", "show" },
{ "d", "showdiff" },
{ NULL, NULL } };
char str_command[64];
int i;
@@ -811,14 +814,15 @@ script_buffer_set_callbacks ()
void
script_buffer_set_keys ()
{
char *keys[][2] = { { "meta-l", "load" },
{ "meta-u", "unload" },
{ "meta-L", "reload" },
{ "meta-i", "install" },
{ "meta-r", "remove" },
{ "meta-h", "hold" },
{ "meta-d", "show" },
{ NULL, NULL } };
char *keys[][2] = { { "meta-l", "load" },
{ "meta-u", "unload" },
{ "meta-L", "reload" },
{ "meta-i", "install" },
{ "meta-r", "remove" },
{ "meta-h", "hold" },
{ "meta-v", "show" },
{ "meta-d", "showdiff" },
{ NULL, NULL } };
char str_key[64], str_command[64];
int i;
+4 -1
View File
@@ -27,11 +27,14 @@ struct t_repo_script;
extern struct t_gui_buffer *script_buffer;
extern int script_buffer_selected_line;
extern struct t_repo_script *script_buffer_detail_script;
extern int script_buffer_detail_script_line_source;
extern int script_buffer_detail_script_last_line;
extern int script_buffer_detail_script_line_diff;
extern void script_buffer_refresh (int clear);
extern void script_buffer_set_current_line (int line);
extern void script_buffer_show_detail_script (struct t_repo_script *script);
extern void script_buffer_get_window_info (struct t_gui_window *window,
int *start_line_y, int *chat_height);
extern void script_buffer_check_line_outside_window ();
extern int script_buffer_window_scrolled_cb (void *data, const char *signal,
const char *type_data,
+7 -4
View File
@@ -89,8 +89,9 @@ script_command_action (struct t_gui_buffer *buffer, const char *action,
else if (script_buffer && (buffer == script_buffer))
{
/* action on current line of script buffer */
if ((weechat_strcasecmp (action, "show") == 0)
&& script_buffer_detail_script)
if (script_buffer_detail_script
&& ((weechat_strcasecmp (action, "show") == 0)
|| (weechat_strcasecmp (action, "showdiff") == 0)))
{
/* if detail on script is displayed, back to list */
snprintf (str_action, sizeof (str_action),
@@ -183,7 +184,8 @@ script_command_script (void *data, struct t_gui_buffer *buffer, int argc,
|| (weechat_strcasecmp (argv[1], "remove") == 0)
|| (weechat_strcasecmp (argv[1], "installremove") == 0)
|| (weechat_strcasecmp (argv[1], "hold") == 0)
|| (weechat_strcasecmp (argv[1], "show") == 0))
|| (weechat_strcasecmp (argv[1], "show") == 0)
|| (weechat_strcasecmp (argv[1], "showdiff") == 0))
{
script_command_action (buffer,
argv[1],
@@ -318,7 +320,8 @@ script_command_init ()
" alt+l load script\n"
" alt+L reload script\n"
" alt+u unload script\n"
" alt+h (un)hold script\n\n"
" alt+h (un)hold script\n"
" alt+v view script\n\n"
"Input allowed on script buffer:\n"
" i/r/l/L/u/h action on script (same as keys above)\n"
" q close buffer\n"
+73
View File
@@ -22,8 +22,11 @@
*/
#include <stdlib.h>
#include <unistd.h>
#include <stdio.h>
#include <string.h>
#include <sys/types.h>
#include <sys/stat.h>
#include "../weechat-plugin.h"
#include "script.h"
@@ -40,6 +43,8 @@ struct t_config_section *script_config_section_scripts = NULL;
/* script config, look section */
struct t_config_option *script_config_look_columns;
struct t_config_option *script_config_look_diff_color;
struct t_config_option *script_config_look_diff_command;
struct t_config_option *script_config_look_display_source;
struct t_config_option *script_config_look_quiet_actions;
struct t_config_option *script_config_look_sort;
@@ -83,6 +88,59 @@ struct t_config_option *script_config_scripts_hold;
struct t_config_option *script_config_scripts_url;
/*
* script_config_get_diff_command: get diff command
* if option is "auto", try to find git, and
* fallbacks on "diff" if not found
* return NULL if no diff command is set
*/
const char *
script_config_get_diff_command ()
{
const char *diff_command, *dir_separator;
static char result[64];
struct stat st;
char *path, **paths, bin[4096];
int num_paths, i, rc;
diff_command = weechat_config_string (script_config_look_diff_command);
if (!diff_command || !diff_command[0])
return NULL;
if (strcmp (diff_command, "auto") == 0)
{
dir_separator = weechat_info_get ("dir_separator", "");
path = getenv ("PATH");
result[0] = '\0';
if (dir_separator && path)
{
paths = weechat_string_split (path, ":", 0, 0, &num_paths);
if (paths)
{
for (i = 0; i < num_paths; i++)
{
snprintf (bin, sizeof (bin), "%s%s%s",
paths[i], dir_separator, "git");
rc = stat (bin, &st);
if ((rc == 0) && (S_ISREG(st.st_mode)))
{
snprintf (result, sizeof (result),
"git diff --no-index");
break;
}
}
weechat_string_free_split (paths);
}
}
if (!result[0])
snprintf (result, sizeof (result), "diff");
return result;
}
return diff_command;
}
/*
* script_config_get_dir: get local directory for script
* Note: result must be freed after use
@@ -370,6 +428,21 @@ script_config_init ()
"%W=max_weechat)"),
NULL, 0, 0, "%s %n %V %v %u | %d | %t", NULL, 0,
NULL, NULL, &script_config_refresh_cb, NULL, NULL, NULL);
script_config_look_diff_color = weechat_config_new_option (
script_config_file, ptr_section,
"diff_color", "boolean",
N_("colorize output of diff"),
NULL, 0, 0, "on", NULL, 0,
NULL, NULL, NULL, NULL, NULL, NULL);
script_config_look_diff_command = weechat_config_new_option (
script_config_file, ptr_section,
"diff_command", "string",
N_("command used to show differences between script installed and the "
"new version in repository (\"auto\" = auto detect diff command (git "
"or diff), empty value = disable diff, other string = name of "
"command, for example \"diff\")"),
NULL, 0, 0, "auto", NULL, 0,
NULL, NULL, NULL, NULL, NULL, NULL);
script_config_look_display_source = weechat_config_new_option (
script_config_file, ptr_section,
"display_source", "boolean",
+3
View File
@@ -25,6 +25,8 @@
struct t_repo_script;
extern struct t_config_option *script_config_look_columns;
extern struct t_config_option *script_config_look_diff_color;
extern struct t_config_option *script_config_look_diff_command;
extern struct t_config_option *script_config_look_display_source;
extern struct t_config_option *script_config_look_quiet_actions;
extern struct t_config_option *script_config_look_sort;
@@ -63,6 +65,7 @@ extern struct t_config_option *script_config_scripts_dir;
extern struct t_config_option *script_config_scripts_hold;
extern struct t_config_option *script_config_scripts_url;
extern const char *script_config_get_diff_command ();
extern char *script_config_get_dir ();
extern char *script_config_get_xml_filename ();
extern char *script_config_get_script_download_filename (struct t_repo_script *script,
+56
View File
@@ -23,6 +23,7 @@
#define _XOPEN_SOURCE 700
#include <limits.h>
#include <stdlib.h>
#include <unistd.h>
#include <sys/types.h>
@@ -146,6 +147,61 @@ script_repo_search_by_name_ext (const char *name_with_extension)
return NULL;
}
/*
* script_repo_get_filename_loaded: get filename of a loaded script
* (it returns name of file and not the link,
* if there is a symbolic to file)
* Note: result has to be free() after use
*/
char *
script_repo_get_filename_loaded (struct t_repo_script *script)
{
const char *weechat_home;
char *filename, resolved_path[PATH_MAX];
int length;
struct stat st;
weechat_home = weechat_info_get ("weechat_dir", NULL);
length = strlen (weechat_home) + strlen (script->name_with_extension) + 64;
filename = malloc (length);
if (filename)
{
snprintf (filename, length, "%s/%s/autoload/%s",
weechat_home,
script_language[script->language],
script->name_with_extension);
if (stat (filename, &st) != 0)
{
snprintf (filename, length, "%s/%s/%s",
weechat_home,
script_language[script->language],
script->name_with_extension);
if (stat (filename, &st) != 0)
{
filename[0] = '\0';
}
}
}
if (!filename[0])
{
free (filename);
return NULL;
}
if (realpath (filename, resolved_path))
{
if (strcmp (filename, resolved_path) != 0)
{
free (filename);
return strdup (resolved_path);
}
}
return filename;
}
/*
* script_repo_get_status_for_display: get status for display
* list is the codes of status to display
+1
View File
@@ -64,6 +64,7 @@ extern int script_repo_script_valid (struct t_repo_script *script);
extern struct t_repo_script *script_repo_search_displayed_by_number (int number);
extern struct t_repo_script *script_repo_search_by_name (const char *name);
extern struct t_repo_script *script_repo_search_by_name_ext (const char *name_with_extension);
extern char *script_repo_get_filename_loaded (struct t_repo_script *script);
extern const char *script_repo_get_status_for_display (struct t_repo_script *script,
const char *list,
int collapse);