subversion-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From julianf...@apache.org
Subject svn commit: r1811558 - in /subversion/branches/shelve/subversion: include/svn_client.h libsvn_client/shelve.c svn/shelve-cmd.c
Date Mon, 09 Oct 2017 12:18:26 GMT
Author: julianfoad
Date: Mon Oct  9 12:18:25 2017
New Revision: 1811558

URL: http://svn.apache.org/viewvc?rev=1811558&view=rev
Log:
On the 'shelve' branch: Improve the 'list' API.

* subversion/include/svn_client.h,
  subversion/libssvn_client/shelve.c
  (svn_client_shelved_patch_info_t): New.
  (read_logmsg_from_patch): Moved from 'shelve.cmd.c'.
  (svn_client_shelves_list): Return patch-info structs instead of dirents.

* subversion/svn/shelve-cmd.c
  (compare_dirents_by_mtime, list_sorted_by_date, shelves_list): Updated.

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

Modified: subversion/branches/shelve/subversion/include/svn_client.h
URL: http://svn.apache.org/viewvc/subversion/branches/shelve/subversion/include/svn_client.h?rev=1811558&r1=1811557&r2=1811558&view=diff
==============================================================================
--- subversion/branches/shelve/subversion/include/svn_client.h (original)
+++ subversion/branches/shelve/subversion/include/svn_client.h Mon Oct  9 12:18:25 2017
@@ -6762,8 +6762,21 @@ svn_client_shelves_delete(const char *na
  *
  * @since New in 1.11.
  */
+typedef struct svn_client_shelved_patch_info_t
+{
+  const char *message;
+  const char *patch_path;
+  svn_io_dirent2_t *dirent;
+  apr_time_t mtime;
+} svn_client_shelved_patch_info_t;
+
+/** Set *shelved_patches to a hash, keyed by patch name, of pointers to
+ * @c svn_client_shelved_patch_info_t structures.
+ *
+ * @since New in 1.11.
+ */
 svn_error_t *
-svn_client_shelves_list(apr_hash_t **dirents,
+svn_client_shelves_list(apr_hash_t **shelved_patch_infos,
                         const char *local_abspath,
                         svn_client_ctx_t *ctx,
                         apr_pool_t *result_pool,

Modified: subversion/branches/shelve/subversion/libsvn_client/shelve.c
URL: http://svn.apache.org/viewvc/subversion/branches/shelve/subversion/libsvn_client/shelve.c?rev=1811558&r1=1811557&r2=1811558&view=diff
==============================================================================
--- subversion/branches/shelve/subversion/libsvn_client/shelve.c (original)
+++ subversion/branches/shelve/subversion/libsvn_client/shelve.c Mon Oct  9 12:18:25 2017
@@ -341,30 +341,68 @@ svn_client_shelves_delete(const char *na
   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, result_pool));
+  SVN_ERR(svn_stream_close(stream));
+  *logmsg = line->data;
+  return SVN_NO_ERROR;
+}
+
 svn_error_t *
-svn_client_shelves_list(apr_hash_t **dirents,
+svn_client_shelves_list(apr_hash_t **shelved_patch_infos,
                         const char *local_abspath,
                         svn_client_ctx_t *ctx,
                         apr_pool_t *result_pool,
                         apr_pool_t *scratch_pool)
 {
   char *shelves_dir;
+  apr_hash_t *dirents;
   apr_hash_index_t *hi;
 
   SVN_ERR(svn_wc__get_shelves_dir(&shelves_dir, ctx->wc_ctx, local_abspath,
                                   scratch_pool, scratch_pool));
-  SVN_ERR(svn_io_get_dirents3(dirents, shelves_dir, FALSE /*only_check_type*/,
+  SVN_ERR(svn_io_get_dirents3(&dirents, shelves_dir, FALSE /*only_check_type*/,
                               result_pool, scratch_pool));
 
+  *shelved_patch_infos = apr_hash_make(result_pool);
+
   /* Remove non-shelves */
-  for (hi = apr_hash_first(scratch_pool, *dirents); hi; hi = apr_hash_next(hi))
+  for (hi = apr_hash_first(scratch_pool, dirents); hi; hi = apr_hash_next(hi))
     {
-      const char *name = apr_hash_this_key(hi);
-      int len = strlen(name);
+      const char *filename = apr_hash_this_key(hi);
+      int len = strlen(filename);
 
-      if (len < 6 || strcmp(name + len - 6, ".patch") != 0)
+      if (len > 6 && strcmp(filename + len - 6, ".patch") == 0)
         {
-          svn_hash_sets(*dirents, name, NULL);
+          const char *name = apr_pstrndup(result_pool, filename, len - 6);
+          svn_client_shelved_patch_info_t *info
+            = apr_palloc(result_pool, sizeof(*info));
+
+          info->dirent = apr_hash_this_val(hi);
+          info->mtime = info->dirent->mtime;
+          info->patch_path
+            = svn_dirent_join_many(result_pool,
+                                   local_abspath, ".svn", "shelves", filename,
+                                   SVN_VA_NULL);
+          SVN_ERR(read_logmsg_from_patch(&info->message, info->patch_path,
+                                         result_pool, scratch_pool));
+
+          svn_hash_sets(*shelved_patch_infos, name, info);
         }
     }
 

Modified: subversion/branches/shelve/subversion/svn/shelve-cmd.c
URL: http://svn.apache.org/viewvc/subversion/branches/shelve/subversion/svn/shelve-cmd.c?rev=1811558&r1=1811557&r2=1811558&view=diff
==============================================================================
--- subversion/branches/shelve/subversion/svn/shelve-cmd.c (original)
+++ subversion/branches/shelve/subversion/svn/shelve-cmd.c Mon Oct  9 12:18:25 2017
@@ -49,58 +49,36 @@ get_name(const char **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;
-}
-
 /*  */
 static int
 compare_dirents_by_mtime(const svn_sort__item_t *a,
                          const svn_sort__item_t *b)
 {
-  svn_io_dirent2_t *a_val = a->value;
-  svn_io_dirent2_t *b_val = b->value;
+  svn_client_shelved_patch_info_t *a_val = a->value;
+  svn_client_shelved_patch_info_t *b_val = b->value;
 
-  return (a_val->mtime < b_val->mtime)
-           ? -1 : (a_val->mtime > b_val->mtime) ? 1 : 0;
+  return (a_val->dirent->mtime < b_val->dirent->mtime)
+           ? -1 : (a_val->dirent->mtime > b_val->dirent->mtime) ? 1 : 0;
 }
 
-/* Return a list of shelves sorted by patch file mtime, oldest first.
+/* Return a list of shelved changes sorted by patch file mtime, oldest first.
  */
 static svn_error_t *
 list_sorted_by_date(apr_array_header_t **list,
                     const char *local_abspath,
-                    svn_boolean_t diffstat,
                     svn_client_ctx_t *ctx,
                     apr_pool_t *scratch_pool)
 {
-  apr_hash_t *dirents;
+  apr_hash_t *shelved_patch_infos;
 
-  SVN_ERR(svn_client_shelves_list(&dirents, local_abspath,
+  SVN_ERR(svn_client_shelves_list(&shelved_patch_infos, local_abspath,
                                   ctx, scratch_pool, scratch_pool));
-  *list = svn_sort__hash(dirents, compare_dirents_by_mtime, scratch_pool);
+  *list = svn_sort__hash(shelved_patch_infos, compare_dirents_by_mtime,
+                         scratch_pool);
   return SVN_NO_ERROR;
 }
 
-/* Display a list of shelves */
+/* Display a list of shelved changes */
 static svn_error_t *
 shelves_list(const char *local_abspath,
              svn_boolean_t diffstat,
@@ -111,37 +89,24 @@ shelves_list(const char *local_abspath,
   int i;
 
   SVN_ERR(list_sorted_by_date(&list,
-                              local_abspath, diffstat, ctx, scratch_pool));
+                              local_abspath, ctx, scratch_pool));
 
   for (i = 0; i < list->nelts; i++)
     {
       const svn_sort__item_t *item = &APR_ARRAY_IDX(list, i, svn_sort__item_t);
       const char *name = item->key;
-      svn_io_dirent2_t *dirent = item->value;
-      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));
+      svn_client_shelved_patch_info_t *info = item->value;
+      int age = (apr_time_now() - info->mtime) / 1000000 / 60;
+
       printf("%-30s %6d mins old %10ld bytes\n",
-             name, age, (long)dirent->filesize);
+             name, age, (long)info->dirent->filesize);
       printf(" %.50s\n",
-             logmsg);
+             info->message);
 
       if (diffstat)
         {
-          char *path = svn_path_join_many(scratch_pool,
-                                          local_abspath, ".svn/shelves", name,
-                                          SVN_VA_NULL);
-
-          system(apr_psprintf(scratch_pool, "diffstat %s 2> /dev/null", path));
+          system(apr_psprintf(scratch_pool, "diffstat %s 2> /dev/null",
+                              info->patch_path));
           printf("\n");
         }
     }



Mime
View raw message