Index: subversion/include/svn_error_codes.h
===================================================================
--- subversion/include/svn_error_codes.h	(revision 26908)
+++ subversion/include/svn_error_codes.h	(working copy)
@@ -1128,6 +1128,10 @@
   SVN_ERRDEF(SVN_ERR_CL_UNNECESSARY_LOG_MESSAGE,
              SVN_ERR_CL_CATEGORY_START + 9,
              "A log message was given where none was necessary")
+  
+  SVN_ERRDEF(SVN_ERR_CL_NO_EXTERNAL_MERGE_TOOL,
+             SVN_ERR_CL_CATEGORY_START + 10,
+             "No external merge tool available")
 
 SVN_ERROR_END
 
Index: subversion/include/svn_config.h
===================================================================
--- subversion/include/svn_config.h	(revision 26908)
+++ subversion/include/svn_config.h	(working copy)
@@ -83,6 +83,7 @@
 #define SVN_CONFIG_OPTION_DIFF_CMD                  "diff-cmd"
 #define SVN_CONFIG_OPTION_DIFF3_CMD                 "diff3-cmd"
 #define SVN_CONFIG_OPTION_DIFF3_HAS_PROGRAM_ARG     "diff3-has-program-arg"
+#define SVN_CONFIG_OPTION_MERGE_TOOL_CMD            "merge-tool-cmd"
 #define SVN_CONFIG_SECTION_MISCELLANY           "miscellany"
 #define SVN_CONFIG_OPTION_GLOBAL_IGNORES            "global-ignores"
 #define SVN_CONFIG_OPTION_LOG_ENCODING              "log-encoding"
Index: subversion/libsvn_subr/config_file.c
===================================================================
--- subversion/libsvn_subr/config_file.c	(revision 26908)
+++ subversion/libsvn_subr/config_file.c	(working copy)
@@ -929,6 +929,10 @@
         "### Set diff3-has-program-arg to 'true' or 'yes' if your 'diff3'"   NL
         "###   program accepts the '--diff-program' option."                 NL
         "# diff3-has-program-arg = [true | false]"                           NL
+        "### Set merge-tool-cmd to the command used to invoke your external" NL
+        "### merging tool of choice. Subversion will pass 4 arguments to"    NL
+        "### the specified command: base theirs mine merged"                 NL
+        "# merge-tool-cmd = merge_command"                                   NL
         ""                                                                   NL
         "### Section for configuring tunnel agents."                         NL
         "[tunnels]"                                                          NL
Index: subversion/svn/cl.h
===================================================================
--- subversion/svn/cl.h	(revision 26908)
+++ subversion/svn/cl.h	(working copy)
@@ -409,8 +409,21 @@
                              apr_hash_t *config,
                              apr_pool_t *pool);
 
+/* Search for a merge tool command in environment variables,
+   and use it to perform the merge of the four given files.
+   Use POOL for all allocations. 
+   
+   CONFIG is a hash of svn_config_t * items keyed on a configuration
+   category (SVN_CONFIG_CATEGORY_CONFIG et al), and may be NULL.
+   */
+svn_error_t *
+svn_cl__merge_file_externally(const char *base_path,
+                              const char *repos_path,
+                              const char *user_path,
+                              const char *merged_path,
+                              apr_hash_t *config,
+                              apr_pool_t *pool);
 
-
 
 /*** Notification functions to display results on the terminal. */
 
Index: subversion/svn/util.c
===================================================================
--- subversion/svn/util.c	(revision 26908)
+++ subversion/svn/util.c	(working copy)
@@ -193,8 +193,59 @@
   return SVN_NO_ERROR;
 }
 
+svn_error_t *
+svn_cl__merge_file_externally(const char *base_path,
+                              const char *repos_path,
+                              const char *user_path,
+                              const char *merged_path,
+                              apr_hash_t *config,
+                              apr_pool_t *pool)
+{
+  const char *merge_tool;
+  /* Error if there is no editor specified */
+  if (apr_env_get(&merge_tool, "SVN_MERGE", pool) != APR_SUCCESS)
+    {
+      struct svn_config_t *cfg;
+      merge_tool = NULL;
+      cfg = config ? apr_hash_get(config, SVN_CONFIG_CATEGORY_CONFIG,
+                                  APR_HASH_KEY_STRING) : NULL;
+      svn_config_get(cfg, &merge_tool, SVN_CONFIG_SECTION_HELPERS,
+                     SVN_CONFIG_OPTION_MERGE_TOOL_CMD, NULL);
+    }
 
+  if ( merge_tool) 
+    {
+      const char *c;
 
+      for (c = merge_tool; *c; c++)
+        if (!svn_ctype_isspace(*c))
+          break;
+
+      if (! *c)
+        return svn_error_create
+          (SVN_ERR_CL_NO_EXTERNAL_MERGE_TOOL, NULL,
+           _("The SVN_MERGE environment variable is empty or "
+             "consists solely of whitespace. Expected a shell command.\n"));
+    }
+  else
+      return svn_error_create
+        (SVN_ERR_CL_NO_EXTERNAL_MERGE_TOOL, NULL,
+         _("The environment variable SVN_MERGE and the merge-tool-cmd run-time "
+           "configuration option were not set.\n"));
+
+  {
+    const char *arguments[] = { merge_tool, base_path, repos_path, 
+                                user_path, merged_path, NULL};
+    char *cwd;
+    apr_status_t status = apr_filepath_get(&cwd, APR_FILEPATH_NATIVE, pool);
+    if (status != 0)
+      return svn_error_wrap_apr(status, NULL);
+    return svn_io_run_cmd(svn_path_internal_style(cwd, pool), merge_tool, 
+                          arguments, NULL, NULL, TRUE, NULL, NULL, NULL, 
+                          pool);
+  }
+}
+
 svn_error_t *
 svn_cl__edit_string_externally(svn_string_t **edited_contents /* UTF-8! */,
                                const char **tmpfile_left /* UTF-8! */,
Index: subversion/svn/conflict-callbacks.c
===================================================================
--- subversion/svn/conflict-callbacks.c	(revision 26908)
+++ subversion/svn/conflict-callbacks.c	(working copy)
@@ -258,12 +258,39 @@
             }
           if (strcmp(answer, "l") == 0)
             {
-              if (desc->base_file && desc->repos_file && desc->user_file)
+              if (desc->base_file && desc->repos_file && 
+                  desc->user_file && desc->merged_file)
                 {
-                  /* ### TODO: launch $SVNMERGE tool here with 3 fulltexts. */
-                  SVN_ERR(svn_cmdline_fprintf(stderr, subpool,
-                                       _("Feature not yet implemented.\n\n")));
-                  performed_edit = TRUE;
+                  svn_error_t *merge_err;
+                  merge_err = svn_cl__merge_file_externally(desc->base_file, 
+                                                            desc->repos_file, 
+                                                            desc->user_file, 
+                                                            desc->merged_file,
+                                                            NULL,
+                                                            pool);
+                  if (merge_err && 
+                      merge_err->apr_err == SVN_ERR_CL_NO_EXTERNAL_MERGE_TOOL)
+                    {
+                      SVN_ERR(svn_cmdline_fprintf(stderr, subpool, 
+                                                 merge_err->message ? 
+                                                 merge_err->message :
+                                                 _("No merge tool found.\n")));
+                      
+                      svn_error_clear(merge_err);
+                    }
+                  else if (merge_err && 
+                           merge_err->apr_err == SVN_ERR_EXTERNAL_PROGRAM)
+                    {
+                      SVN_ERR(svn_cmdline_fprintf(stderr, subpool, "%s\n",
+                                                 merge_err->message ?
+                                                 merge_err->message :
+                                             _("Error running merge tool.")));
+                      svn_error_clear(merge_err);
+                    }
+                  else if (merge_err)
+                    return merge_err;
+                  else
+                    performed_edit = TRUE;
                 }
               else
                 SVN_ERR(svn_cmdline_fprintf(stderr, subpool,

