You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@subversion.apache.org by ju...@apache.org on 2017/08/23 13:17:39 UTC

svn commit: r1805895 - in /subversion/branches/shelve/subversion: include/svn_client.h libsvn_client/shelve.c svn/shelve-cmd.c svn/svn.c

Author: julianfoad
Date: Wed Aug 23 13:17:38 2017
New Revision: 1805895

URL: http://svn.apache.org/viewvc?rev=1805895&view=rev
Log:
On the 'shelve' branch: Support a description (log message).

* subversion/svn/svn.c
  (svn_cl__cmd_table,
   sub_main): Add log message options.

* subversion/svn/shelve-cmd.c
  (read_logmsg_from_patch): New.
  (shelves_list): Display the log message found in the patch file.
  (svn_cl__shelve): Initialize the standard log message callback.

* subversion/include/svn_client.h,
  subversion/libsvn_client/shelve.c
  (svn_client_shelf_write_patch): Add 'message' parameter.
    Print it at the start of the patch, followed by some separator lines.
  (svn_client_shelve): Fetch log message from the callback.

Modified:
    subversion/branches/shelve/subversion/include/svn_client.h
    subversion/branches/shelve/subversion/libsvn_client/shelve.c
    subversion/branches/shelve/subversion/svn/shelve-cmd.c
    subversion/branches/shelve/subversion/svn/svn.c

Modified: subversion/branches/shelve/subversion/include/svn_client.h
URL: http://svn.apache.org/viewvc/subversion/branches/shelve/subversion/include/svn_client.h?rev=1805895&r1=1805894&r2=1805895&view=diff
==============================================================================
--- subversion/branches/shelve/subversion/include/svn_client.h (original)
+++ subversion/branches/shelve/subversion/include/svn_client.h Wed Aug 23 13:17:38 2017
@@ -6777,6 +6777,7 @@ svn_client_shelves_list(apr_hash_t **dir
  */
 svn_error_t *
 svn_client_shelf_write_patch(const char *shelf_name,
+                             const char *message,
                              const char *wc_root_abspath,
                              svn_boolean_t overwrite_existing,
                              const apr_array_header_t *paths,

Modified: subversion/branches/shelve/subversion/libsvn_client/shelve.c
URL: http://svn.apache.org/viewvc/subversion/branches/shelve/subversion/libsvn_client/shelve.c?rev=1805895&r1=1805894&r2=1805895&view=diff
==============================================================================
--- subversion/branches/shelve/subversion/libsvn_client/shelve.c (original)
+++ subversion/branches/shelve/subversion/libsvn_client/shelve.c Wed Aug 23 13:17:38 2017
@@ -73,6 +73,7 @@ get_patch_abspath(char **patch_abspath,
 
 svn_error_t *
 svn_client_shelf_write_patch(const char *shelf_name,
+                             const char *message,
                              const char *wc_root_abspath,
                              svn_boolean_t overwrite_existing,
                              const apr_array_header_t *paths,
@@ -99,14 +100,25 @@ svn_client_shelf_write_patch(const char
   /* ### svn_stream_open_writable() doesn't work here: the buffering
          goes wrong so that diff headers appear after their hunks.
          For now, fix by opening the file without APR_BUFFERED. */
-  flag = APR_WRITE | APR_CREATE;
+  flag = APR_FOPEN_WRITE | APR_FOPEN_CREATE;
   if (! overwrite_existing)
-    flag |= APR_EXCL;
+    flag |= APR_FOPEN_EXCL;
   SVN_ERR(svn_io_file_open(&outfile, patch_abspath,
                            flag, APR_FPROT_OS_DEFAULT, scratch_pool));
   outstream = svn_stream_from_aprfile2(outfile, FALSE /*disown*/, scratch_pool);
   SVN_ERR(svn_stream_for_stderr(&errstream, scratch_pool));
 
+  /* Write the patch file header (log message, etc.) */
+  if (message)
+    {
+      SVN_ERR(svn_stream_printf(outstream, scratch_pool, "%s\n",
+                                message));
+    }
+  SVN_ERR(svn_stream_printf(outstream, scratch_pool,
+                            "--This line, and those below, will be ignored--\n\n"));
+  SVN_ERR(svn_stream_printf(outstream, scratch_pool,
+                            "--This patch was generated by 'svn shelve'--\n\n"));
+
   for (i = 0; i < paths->nelts; i++)
     {
       const char *path = APR_ARRAY_IDX(paths, i, const char *);
@@ -191,6 +203,7 @@ svn_client_shelve(const char *shelf_name
 {
   const char *local_abspath;
   const char *wc_root_abspath;
+  const char *message = "";
   svn_error_t *err;
 
   SVN_ERR(validate_shelf_name(shelf_name, pool));
@@ -201,7 +214,19 @@ svn_client_shelve(const char *shelf_name
   SVN_ERR(svn_client_get_wc_root(&wc_root_abspath,
                                  local_abspath, ctx, pool, pool));
 
-  err = svn_client_shelf_write_patch(shelf_name, wc_root_abspath,
+  /* Fetch the log message and any other revprops */
+  if (SVN_CLIENT__HAS_LOG_MSG_FUNC(ctx))
+    {
+      const char *tmp_file;
+      apr_array_header_t *commit_items = apr_array_make(pool, 1, sizeof(void *));
+
+      SVN_ERR(svn_client__get_log_msg(&message, &tmp_file, commit_items,
+                                      ctx, pool));
+      if (! message)
+        return SVN_NO_ERROR;
+    }
+
+  err = svn_client_shelf_write_patch(shelf_name, message, wc_root_abspath,
                                      FALSE /*overwrite_existing*/,
                                      paths, depth, changelists,
                                      ctx, pool);

Modified: subversion/branches/shelve/subversion/svn/shelve-cmd.c
URL: http://svn.apache.org/viewvc/subversion/branches/shelve/subversion/svn/shelve-cmd.c?rev=1805895&r1=1805894&r2=1805895&view=diff
==============================================================================
--- subversion/branches/shelve/subversion/svn/shelve-cmd.c (original)
+++ subversion/branches/shelve/subversion/svn/shelve-cmd.c Wed Aug 23 13:17:38 2017
@@ -48,6 +48,28 @@ get_shelf_name(const char **shelf_name,
   return SVN_NO_ERROR;
 }
 
+/* ### Currently just reads the first line.
+ */
+static svn_error_t *
+read_logmsg_from_patch(const char **logmsg,
+                       const char *patch_abspath,
+                       apr_pool_t *result_pool,
+                       apr_pool_t *scratch_pool)
+{
+  apr_file_t *file;
+  svn_stream_t *stream;
+  svn_boolean_t eof;
+  svn_stringbuf_t *line;
+
+  SVN_ERR(svn_io_file_open(&file, patch_abspath,
+                           APR_FOPEN_READ, APR_FPROT_OS_DEFAULT, scratch_pool));
+  stream = svn_stream_from_aprfile2(file, FALSE /*disown*/, scratch_pool);
+  SVN_ERR(svn_stream_readline(stream, &line, "\n", &eof, scratch_pool));
+  SVN_ERR(svn_stream_close(stream));
+  *logmsg = line->data;
+  return SVN_NO_ERROR;
+}
+
 /* Display a list of shelves */
 static svn_error_t *
 shelves_list(const char *local_abspath,
@@ -66,12 +88,21 @@ shelves_list(const char *local_abspath,
       const char *name = apr_hash_this_key(hi);
       svn_io_dirent2_t *dirent = apr_hash_this_val(hi);
       int age = (apr_time_now() - dirent->mtime) / 1000000 / 60;
+      const char *patch_abspath;
+      const char *logmsg;
 
       if (! strstr(name, ".patch"))
         continue;
 
+      patch_abspath = svn_dirent_join_many(scratch_pool,
+                                           local_abspath, ".svn", "shelves", name,
+                                           SVN_VA_NULL);
+      SVN_ERR(read_logmsg_from_patch(&logmsg, patch_abspath,
+                                     scratch_pool, scratch_pool));
       printf("%-30s %6d mins old %10ld bytes\n",
              name, age, (long)dirent->filesize);
+      printf(" %.50s\n",
+             logmsg);
 
       if (diffstat)
         {
@@ -137,6 +168,7 @@ svn_cl__shelve(apr_getopt_t *os,
 
   {
       svn_depth_t depth = opt_state->depth;
+      svn_error_t *err;
 
       /* shelve has no implicit dot-target `.', so don't you put that
          code here! */
@@ -150,10 +182,20 @@ svn_cl__shelve(apr_getopt_t *os,
 
       SVN_ERR(svn_cl__eat_peg_revisions(&targets, targets, pool));
 
-      SVN_ERR(svn_client_shelve(shelf_name,
-                                targets, depth, opt_state->changelists,
-                                opt_state->dry_run,
-                                ctx, pool));
+      if (ctx->log_msg_func3)
+        SVN_ERR(svn_cl__make_log_msg_baton(&ctx->log_msg_baton3,
+                                           opt_state, NULL, ctx->config,
+                                           pool));
+      err = svn_client_shelve(shelf_name,
+                              targets, depth, opt_state->changelists,
+                              opt_state->dry_run,
+                              ctx, pool);
+      if (ctx->log_msg_func3)
+        SVN_ERR(svn_cl__cleanup_log_msg(ctx->log_msg_baton3,
+                                        err, pool));
+      else
+        SVN_ERR(err);
+
       if (! opt_state->quiet)
         SVN_ERR(svn_cmdline_printf(pool, "shelved '%s'\n", shelf_name));
   }

Modified: subversion/branches/shelve/subversion/svn/svn.c
URL: http://svn.apache.org/viewvc/subversion/branches/shelve/subversion/svn/svn.c?rev=1805895&r1=1805894&r2=1805895&view=diff
==============================================================================
--- subversion/branches/shelve/subversion/svn/svn.c (original)
+++ subversion/branches/shelve/subversion/svn/svn.c Wed Aug 23 13:17:38 2017
@@ -1648,7 +1648,8 @@ const svn_opt_subcommand_desc2_t svn_cl_
      "  2. Delete the shelved patch NAME.\n"
      "  3. List shelved patches.\n"),
     {opt_delete, opt_list, 'q', opt_dry_run,
-     'N', opt_depth, opt_targets, opt_changelist} },
+     'N', opt_depth, opt_targets, opt_changelist,
+     SVN_CL__LOG_MSG_OPTIONS} },
 
   { "unshelve", svn_cl__unshelve, {0}, N_
     ("Unshelve changes.\n"
@@ -2912,7 +2913,8 @@ sub_main(int *exit_code, int argc, const
           || subcommand->cmd_func == svn_cl__mkdir
           || subcommand->cmd_func == svn_cl__move
           || subcommand->cmd_func == svn_cl__lock
-          || subcommand->cmd_func == svn_cl__propedit))
+          || subcommand->cmd_func == svn_cl__propedit
+          || subcommand->cmd_func == svn_cl__shelve))
     {
       /* If the -F argument is a file that's under revision control,
          that's probably not what the user intended. */