This patch plugs in a new option --invoke-diff-cmd into the existing
diff command structure, but does leave the existing "diff-cmd" option
untouched.
This addition allows the user to define a complex diff command, to be
applied in place of the internal diff, for example:
svn diff --invoke-diff-cmd="kdiff3 -auto -o /home/g/log ---f1 ---f2 --L1
---l1 --L2 "MyLabel""
either on the command line(for example):
svn diff --invoke-diff-cmd="diff -y ---f1 ---f2"
which expands to "diff -y *from *to",
or, in the config file by adding
invoke-diff-cmd= diff -y ---f1 ---f2
where ---f1 ---f2 are file 1 and 2. and ---l1 ---l2 are labels.
What's missing:
--------------
* The merge part, --invoke-diff3-cmd.
* Tests. I will write them, but I have to spent some time reading
into the test suite first.
* This patch breaks the override --internal-diff for now, because
this part has to be revised anyway when the invoke-diff3-cmd part
gets added.
* I added the help blurb to subversion/svn/svn.c:340 but svn help is
not showing it. I will hunt for th reason over the weekend, I
didn't want to delay the patch any longer.
Thanks for looking!
Gabriela
[[[
Add new diff option "--invoke-diff-cmd" which allows the user to
define a custom command line or config file entry for an external
diff program.
* subversion/include/svn_client.h
(svn_client_diff7): Add new function.
(svn_client_diff6): Remove deprecated function.
* subversion/include/svn_config.h
(): Add new definition.
* subversion/include/svn_io.h
(svn_io_create_custom_diff_cmd): Add new function.
(svn_io_run_external_diff): Add new function.
* subversion/libsvn_client/deprecated.c
(svn_client_diff6): Add deprecated function.
* subversion/libsvn_client/diff.c
(struct diff_cmd_baton): Add new variable.
(diff_content_changed): Add new conditional function call.
(set_up_diff_cmd_and_options): Add new condition.
* subversion/libsvn_subr/config_file.c
(svn_config_ensure): Add help text.
* subversion/libsvn_subr/io.c
(svn_io_create_custom_diff_cmd): Add new function.
(svn_io_run_external_diff): Add new function.
* subversion/svn/cl.h
(struct svn_cl__opt_state_t): Add new variable.
(struct svn_cl__opt_state_t.diff): Add new variable.
* subversion/svn/diff-cmd.c
(svn_cl__diff): Modify call to deprecated function.
* subversion/svn/svn.c
(svn_cl__options[]): Add new variable and help info.
]]]
Index: subversion/include/svn_client.h
===================================================================
--- subversion/include/svn_client.h (revision 1466727)
+++ subversion/include/svn_client.h (working copy)
@@ -2978,6 +2978,9 @@ svn_client_blame(const char *path_or_url,
* The above two options are mutually exclusive. It is an error to set
* both to TRUE.
*
+ * If @a invoke_diff_cmd is non-null, invoke extermal diff command
+ * with the string it contains.
+ *
* Generated headers are encoded using @a header_encoding.
*
* Diff output will not be generated for binary files, unless @a
@@ -3007,9 +3010,39 @@ svn_client_blame(const char *path_or_url,
*
* @note @a relative_to_dir doesn't affect the path index generated by
* external diff programs.
+ *
+ * @since New in 1.8.
+ */
+svn_error_t *
+svn_client_diff7(const apr_array_header_t *options,
+ const char *path_or_url1,
+ const svn_opt_revision_t *revision1,
+ const char *path_or_url2,
+ const svn_opt_revision_t *revision2,
+ const char *relative_to_dir,
+ svn_depth_t depth,
+ svn_boolean_t ignore_ancestry,
+ svn_boolean_t no_diff_added,
+ svn_boolean_t no_diff_deleted,
+ svn_boolean_t show_copies_as_adds,
+ svn_boolean_t ignore_content_type,
+ svn_boolean_t ignore_properties,
+ svn_boolean_t properties_only,
+ svn_boolean_t use_git_diff_format,
+ const char *header_encoding,
+ svn_stream_t *outstream,
+ svn_stream_t *errstream,
+ const apr_array_header_t *changelists,
+ svn_client_ctx_t *ctx,
+ apr_pool_t *pool,
+ const char *invoke_diff_cmd);
+
+/** Similar to svn_client_diff7(), but with @a invoke_diff_cmd.
*
+ * @deprecated Provided for backward compatibility with the 1.8 API.
* @since New in 1.8.
*/
+SVN_DEPRECATED
svn_error_t *
svn_client_diff6(const apr_array_header_t *diff_options,
const char *path_or_url1,
Index: subversion/include/svn_config.h
===================================================================
--- subversion/include/svn_config.h (revision 1466727)
+++ subversion/include/svn_config.h (working copy)
@@ -112,6 +112,7 @@ typedef struct svn_config_t svn_config_t;
#define SVN_CONFIG_OPTION_DIFF_EXTENSIONS "diff-extensions"
#define SVN_CONFIG_OPTION_DIFF3_CMD "diff3-cmd"
#define SVN_CONFIG_OPTION_DIFF3_HAS_PROGRAM_ARG "diff3-has-program-arg"
+#define SVN_CONFIG_OPTION_INVOKE_DIFF_CMD "invoke-diff-cmd"
#define SVN_CONFIG_OPTION_MERGE_TOOL_CMD "merge-tool-cmd"
#define SVN_CONFIG_SECTION_MISCELLANY "miscellany"
#define SVN_CONFIG_OPTION_GLOBAL_IGNORES "global-ignores"
Index: subversion/include/svn_io.h
===================================================================
--- subversion/include/svn_io.h (revision 1466727)
+++ subversion/include/svn_io.h (working copy)
@@ -2260,8 +2260,40 @@ svn_io_file_readline(apr_file_t *file,
apr_pool_t *result_pool,
apr_pool_t *scratch_pool);
+/* Parse a user defined command to contain dynamically
+ * created labels and filenames.
+ *
+ ** @since New in 1.8. (?)
+ */
/** @} */
+const char **
+svn_io_create_custom_diff_cmd(const char *label1,
+ const char *label2,
+ const char *label3,
+ const char *tmpfile1,
+ const char *tmpfile2,
+ const char *base,
+ const char *cmd,
+ apr_pool_t *pool);
+/* Run the external diff command defined by the invoke-diff-cmd
+ * option.
+ *
+ ** @since New in 1.8.
+ */
+/** @} */
+svn_error_t *
+svn_io_run_external_diff(const char *dir,
+ const char *label1,
+ const char *label2,
+ const char *tmpfile1,
+ const char *tmpfile2,
+ int *pexitcode,
+ apr_file_t *outfile,
+ apr_file_t *errfile,
+ const char *external_diff_cmd,
+ apr_pool_t *pool);
+
#ifdef __cplusplus
}
#endif /* __cplusplus */
Index: subversion/libsvn_client/deprecated.c
===================================================================
--- subversion/libsvn_client/deprecated.c (revision 1466727)
+++ subversion/libsvn_client/deprecated.c (working copy)
@@ -914,6 +914,54 @@ svn_client_delete(svn_client_commit_info_t **commi
/*** From diff.c ***/
svn_error_t *
+svn_client_diff6(const apr_array_header_t *options,
+ const char *path_or_url1,
+ const svn_opt_revision_t *revision1,
+ const char *path_or_url2,
+ const svn_opt_revision_t *revision2,
+ const char *relative_to_dir,
+ svn_depth_t depth,
+ svn_boolean_t ignore_ancestry,
+ svn_boolean_t no_diff_added,
+ svn_boolean_t no_diff_deleted,
+ svn_boolean_t show_copies_as_adds,
+ svn_boolean_t ignore_content_type,
+ svn_boolean_t ignore_properties,
+ svn_boolean_t properties_only,
+ svn_boolean_t use_git_diff_format,
+ const char *header_encoding,
+ svn_stream_t *outstream,
+ svn_stream_t *errstream,
+ const apr_array_header_t *changelists,
+ svn_client_ctx_t *ctx,
+ apr_pool_t *pool)
+{
+
+ return svn_client_diff7(options,
+ path_or_url1,
+ revision1,
+ path_or_url2,
+ revision2,
+ relative_to_dir,
+ depth,
+ ignore_ancestry,
+ no_diff_added,
+ no_diff_deleted,
+ show_copies_as_adds,
+ ignore_content_type,
+ ignore_properties,
+ properties_only,
+ use_git_diff_format,
+ header_encoding,
+ outstream,
+ errstream,
+ changelists,
+ ctx,
+ pool,
+ "");
+}
+
+svn_error_t *
svn_client_diff5(const apr_array_header_t *diff_options,
const char *path1,
const svn_opt_revision_t *revision1,
Index: subversion/libsvn_client/diff.c
===================================================================
--- subversion/libsvn_client/diff.c (revision 1466727)
+++ subversion/libsvn_client/diff.c (working copy)
@@ -611,6 +611,10 @@ struct diff_cmd_baton {
/* Whether the local diff target of a repos->wc diff is a copy. */
svn_boolean_t repos_wc_diff_target_is_copy;
+
+ /* external custom diff command */
+ const char *invoke_diff_cmd;
+
};
/* An helper for diff_dir_props_changed, diff_file_changed and diff_file_added
@@ -786,7 +790,7 @@ diff_content_changed(svn_boolean_t *wrote_header,
}
- if (diff_cmd_baton->diff_cmd)
+ if (diff_cmd_baton->diff_cmd || diff_cmd_baton->invoke_diff_cmd)
{
apr_file_t *outfile;
apr_file_t *errfile;
@@ -815,15 +819,25 @@ diff_content_changed(svn_boolean_t *wrote_header,
SVN_ERR(svn_io_open_unique_file3(&errfile, &errfilename, NULL,
svn_io_file_del_on_pool_cleanup,
scratch_pool, scratch_pool));
-
- SVN_ERR(svn_io_run_diff2(".",
- diff_cmd_baton->options.for_external.argv,
- diff_cmd_baton->options.for_external.argc,
- label1, label2,
- tmpfile1, tmpfile2,
- &exitcode, outfile, errfile,
- diff_cmd_baton->diff_cmd, scratch_pool));
-
+
+ if (diff_cmd_baton->diff_cmd)
+ SVN_ERR(svn_io_run_diff2(".",
+ diff_cmd_baton->options.for_external.argv,
+ diff_cmd_baton->options.for_external.argc,
+ label1, label2,
+ tmpfile1, tmpfile2,
+ &exitcode, outfile, errfile,
+ diff_cmd_baton->diff_cmd, scratch_pool));
+ else
+ {
+ SVN_ERR(
+ svn_io_run_external_diff(".",
+ label1, label2,
+ tmpfile1, tmpfile2,
+ &exitcode, outfile, errfile,
+ diff_cmd_baton->invoke_diff_cmd,
+ scratch_pool));
+ }
SVN_ERR(svn_io_file_close(outfile, scratch_pool));
SVN_ERR(svn_io_file_close(errfile, scratch_pool));
@@ -2447,13 +2461,28 @@ set_up_diff_cmd_and_options(struct diff_cmd_baton
apr_hash_t *config, apr_pool_t *pool)
{
const char *diff_cmd = NULL;
-
- /* See if there is a diff command and/or diff arguments. */
+ svn_config_t *cfg;
+
if (config)
+ { /* command line must override config file */
+ if (!diff_cmd_baton->invoke_diff_cmd)
+ {
+ cfg = svn_hash_gets(config, SVN_CONFIG_CATEGORY_CONFIG);
+ svn_config_get(cfg, &diff_cmd, SVN_CONFIG_SECTION_HELPERS,
+ SVN_CONFIG_OPTION_INVOKE_DIFF_CMD, NULL);
+ if (diff_cmd)
+ {
+ SVN_ERR(svn_path_cstring_to_utf8(
+ &diff_cmd_baton->invoke_diff_cmd, diff_cmd, pool));
+ return SVN_NO_ERROR;
+ }
+ }
+ }
+ else /* check if there is a diff-cmd */
{
- svn_config_t *cfg = svn_hash_gets(config, SVN_CONFIG_CATEGORY_CONFIG);
+ cfg = svn_hash_gets(config, SVN_CONFIG_CATEGORY_CONFIG);
svn_config_get(cfg, &diff_cmd, SVN_CONFIG_SECTION_HELPERS,
- SVN_CONFIG_OPTION_DIFF_CMD, NULL);
+ SVN_CONFIG_OPTION_DIFF_CMD, NULL);
if (options == NULL)
{
const char *diff_extensions;
@@ -2463,9 +2492,8 @@ set_up_diff_cmd_and_options(struct diff_cmd_baton
options = svn_cstring_split(diff_extensions, " \t\n\r", TRUE, pool);
}
}
-
if (options == NULL)
- options = apr_array_make(pool, 0, sizeof(const char *));
+ options = apr_array_make(pool, 0, sizeof(const char *));
if (diff_cmd)
SVN_ERR(svn_path_cstring_to_utf8(&diff_cmd_baton->diff_cmd, diff_cmd,
@@ -2537,7 +2565,7 @@ set_up_diff_cmd_and_options(struct diff_cmd_baton
* These cases require server communication.
*/
svn_error_t *
-svn_client_diff6(const apr_array_header_t *options,
+svn_client_diff7(const apr_array_header_t *options,
const char *path_or_url1,
const svn_opt_revision_t *revision1,
const char *path_or_url2,
@@ -2557,7 +2585,8 @@ svn_error_t *
svn_stream_t *errstream,
const apr_array_header_t *changelists,
svn_client_ctx_t *ctx,
- apr_pool_t *pool)
+ apr_pool_t *pool,
+ const char *invoke_diff_cmd)
{
struct diff_cmd_baton diff_cmd_baton = { 0 };
svn_opt_revision_t peg_revision;
@@ -2573,6 +2602,7 @@ svn_error_t *
/* setup callback and baton */
diff_cmd_baton.orig_path_1 = path_or_url1;
diff_cmd_baton.orig_path_2 = path_or_url2;
+ diff_cmd_baton.invoke_diff_cmd = invoke_diff_cmd;
SVN_ERR(set_up_diff_cmd_and_options(&diff_cmd_baton, options,
ctx->config, pool));
@@ -2721,3 +2751,4 @@ svn_client_diff_summarize_dup(const svn_client_dif
return dup_diff;
}
+
Index: subversion/libsvn_subr/config_file.c
===================================================================
--- subversion/libsvn_subr/config_file.c (revision 1466727)
+++ subversion/libsvn_subr/config_file.c (working copy)
@@ -1084,6 +1084,19 @@ svn_config_ensure(const char *config_dir, apr_pool
"### Set diff3-has-program-arg to 'yes' if your 'diff3' program" NL
"### accepts the '--diff-program' option." NL
"# diff3-has-program-arg = [yes | no]" NL
+ "### Set invoke-diff-cmd to the absolute path of your difff'" NL
+ "### program." NL
+ "### This will override the compile-time default, which is to use" NL
+ "### Subversion's internal diff implementation." NL
+ "### invoke-diff-cmd = " NL
+ "### diff_program (diff, gdiff, etc.) <options> <substitutions>" NL
+ "### Substitutions: ---f1 ---f2 files to compare" NL
+ "### ---l1 ---l2 user defined labels" NL
+ "### If any substitutions are omitted, svn uses the default values." NL
+ "### Example: --invoke-diff-cmd= \"diff -y ---f1 ---f2\"" NL
+ "### --invoke-diff-cmd= \"kdiff3 -auto -o /home/u/log \\ " NL
+ "### ---f1 ---f2 --L1 ---l1 --L2 \"custom label\" " NL
+ "# --invoke-diff-cmd= diff -y ---f1 ---f2 " NL
"### Set merge-tool-cmd to the command used to invoke your external" NL
"### merging tool of choice. Subversion will pass 5 arguments to" NL
"### the specified command: base theirs mine merged wcfile" NL
Index: subversion/libsvn_subr/io.c
===================================================================
--- subversion/libsvn_subr/io.c (revision 1466727)
+++ subversion/libsvn_subr/io.c (working copy)
@@ -2832,7 +2832,6 @@ svn_io_run_cmd(const char *path,
return svn_io_wait_for_cmd(&cmd_proc, cmd, exitcode, exitwhy, pool);
}
-
svn_error_t *
svn_io_run_diff2(const char *dir,
const char *const *user_args,
@@ -2921,8 +2920,84 @@ svn_io_run_diff2(const char *dir,
return SVN_NO_ERROR;
}
+const char **
+svn_io_create_custom_diff_cmd(const char *label1,
+ const char *label2,
+ const char *label3,
+ const char *tmpfile1,
+ const char *tmpfile2,
+ const char *base,
+ const char *cmd,
+ apr_pool_t *pool)
+{
+ int i;
+ apr_array_header_t * external_diff_cmd;
+ const char ** ret;
+ external_diff_cmd = svn_cstring_split(cmd, " ", FALSE, pool);
+ i = external_diff_cmd->nelts;
+ ret = apr_palloc(pool, i > 2 ? i : 2);
+
+ for (i = 0; i < external_diff_cmd->nelts; i++)
+ {
+ const char * atom;
+ atom = APR_ARRAY_IDX(external_diff_cmd, i, char *);
+
+ if (!strcmp(atom, "---f1"))
+ ret[i] = svn_dirent_local_style(tmpfile1, pool);
+ else if(!strcmp(atom, "---f2"))
+ ret[i] = svn_dirent_local_style(tmpfile2, pool);
+ else if(!strcmp(atom, "---f3"))
+ ret[i] = svn_dirent_local_style(base, pool);
+ else if(!strcmp(atom, "---l1"))
+ ret[i] = label1;
+ else if(!strcmp(atom, "---l2"))
+ ret[i] = label2;
+ else if(!strcmp(atom, "---l3"))
+ ret[i] = label3;
+ else
+ ret[i] = atom;
+ }
+ ret[i] = NULL;
+ return ret;
+}
+
svn_error_t *
+svn_io_run_external_diff(const char *dir,
+ const char *label1,
+ const char *label2,
+ const char *tmpfile1,
+ const char *tmpfile2,
+ int *pexitcode,
+ apr_file_t *outfile,
+ apr_file_t *errfile,
+ const char *external_diff_cmd,
+ apr_pool_t *pool)
+{
+ int exitcode;
+ const char ** cmd;
+ apr_pool_t *subpool = svn_pool_create(pool);
+
+ cmd = svn_io_create_custom_diff_cmd(label1, label2, NULL, tmpfile1, tmpfile2,
+ NULL, external_diff_cmd, pool);
+ if (pexitcode == NULL)
+ pexitcode = &exitcode;
+
+ SVN_ERR(svn_io_run_cmd(dir, cmd[0], cmd, pexitcode, NULL, TRUE,
+ NULL, outfile, errfile, subpool));
+
+ if (*pexitcode != 0 && *pexitcode != 1)
+ return svn_error_createf(SVN_ERR_EXTERNAL_PROGRAM, NULL,
+ _("'%s' returned %d"),
+ svn_dirent_local_style(cmd[0], pool),
+ *pexitcode);
+
+ svn_pool_destroy(subpool);
+
+ return SVN_NO_ERROR;
+}
+
+svn_error_t *
svn_io_run_diff3_3(int *exitcode,
const char *dir,
const char *mine,
Index: subversion/svn/cl.h
===================================================================
--- subversion/svn/cl.h (revision 1466727)
+++ subversion/svn/cl.h (working copy)
@@ -181,6 +181,8 @@ typedef struct svn_cl__opt_state_t
struct
{
const char *diff_cmd; /* the external diff command to use */
+ const char *invoke_diff_cmd; /* the format string to specify args */
+ /* for the external diff cmd */
svn_boolean_t internal_diff; /* override diff_cmd in config file */
svn_boolean_t no_diff_added; /* do not show diffs for deleted files */
svn_boolean_t no_diff_deleted; /* do not show diffs for deleted files */
@@ -213,6 +215,7 @@ typedef struct svn_cl__opt_state_t
const char *changelist; /* operate on this changelist
THIS IS TEMPORARY (LAST OF CHANGELISTS) */
svn_boolean_t keep_changelists;/* don't remove changelists after commit */
+ const char *invoke_diff_cmd; /* external customizable diff command */
svn_boolean_t keep_local; /* delete path only from repository */
svn_boolean_t all_revprops; /* retrieve all revprops */
svn_boolean_t no_revprops; /* retrieve no revprops */
Index: subversion/svn/diff-cmd.c
===================================================================
--- subversion/svn/diff-cmd.c (revision 1466727)
+++ subversion/svn/diff-cmd.c (working copy)
@@ -387,7 +387,7 @@ svn_cl__diff(apr_getopt_t *os,
ctx, iterpool));
}
else
- SVN_ERR(svn_client_diff6(
+ SVN_ERR(svn_client_diff7(
options,
target1,
&(opt_state->start_revision),
@@ -407,7 +407,9 @@ svn_cl__diff(apr_getopt_t *os,
outstream,
errstream,
opt_state->changelists,
- ctx, iterpool));
+ ctx,
+ iterpool,
+ opt_state->diff.invoke_diff_cmd));
}
else
{
Index: subversion/svn/svn.c
===================================================================
--- subversion/svn/svn.c (revision 1466727)
+++ subversion/svn/svn.c (working copy)
@@ -84,6 +84,7 @@ typedef enum svn_cl__longopt_t {
opt_ignore_properties,
opt_properties_only,
opt_patch_compatible,
+ opt_invoke_diff_cmd,
/* end of diff options */
opt_dry_run,
opt_editor_cmd,
@@ -336,6 +337,22 @@ const apr_getopt_option_t svn_cl__options[] =
{"diff", opt_diff, 0, N_("produce diff output")}, /* maps to show_diff */
/* diff options */
{"diff-cmd", opt_diff_cmd, 1, N_("use ARG as diff command")},
+ {"invoke-diff-cmd", opt_invoke_diff_cmd, 1,
+ N_("use ARG as format string for external diff command\n"
+ "invocation. \n "
+ " "
+ "Substitutions: ---f1 ---f2 files to compare"
+ " "
+ " ---l1 ---l2 user defined labels"
+ " "
+ "If any substitutions are omitted, svn will use the default values."
+ " "
+ "Example: --invoke-diff-cmd=\"diff -y ---f1 ---f2 "
+ " "
+ " --invoke-diff-cmd=\"kdiff3 -auto -o /home/u/log \\ "
+ " "
+ " ---f1 ---f2 --L1 ---l1 --L2 \"Custom Label\""
+ )},
{"internal-diff", opt_internal_diff, 0,
N_("override diff-cmd specified in config file")},
{"no-diff-added", opt_no_diff_added, 0,
@@ -575,7 +592,8 @@ const svn_opt_subcommand_desc2_t svn_cl__cmd_table
opt_internal_diff, 'x', opt_no_diff_added, opt_no_diff_deleted,
opt_ignore_properties, opt_properties_only,
opt_show_copies_as_adds, opt_notice_ancestry, opt_summarize, opt_changelist,
- opt_force, opt_xml, opt_use_git_diff_format, opt_patch_compatible} },
+ opt_force, opt_xml, opt_use_git_diff_format, opt_patch_compatible,
+ opt_invoke_diff_cmd} },
{ "export", svn_cl__export, {0}, N_
("Create an unversioned copy of a tree.\n"
"usage: 1. export [-r REV] URL[@PEGREV] [PATH]\n"
@@ -2088,6 +2106,9 @@ sub_main(int argc, const char *argv[], apr_pool_t
case opt_diff_cmd:
opt_state.diff.diff_cmd = apr_pstrdup(pool, opt_arg);
break;
+ case opt_invoke_diff_cmd:
+ opt_state.diff.invoke_diff_cmd = apr_pstrdup(pool, opt_arg);
+ break;
case opt_merge_cmd:
opt_state.merge_cmd = apr_pstrdup(pool, opt_arg);
break;