[svn.haxx.se] · SVN Dev · SVN Users · SVN Org · TSVN Dev · TSVN Users · Subclipse Dev · Subclipse Users · this month's index

[PATCH] Factor out the default log message code

From: Chris Foote <cfoote_at_v21.me.uk>
Date: 2003-12-09 23:14:15 CET

Scratch my own itch. This patch factors out from the cmdline client
the code that generates the list of commit files for the default
commit log message.
Not sure of the name (svn_client_get_default_log_message), suggestions
welcome.

Patch and log follows.

Regards,
Chris

Log:

Factor out the default log message code so that other clients can use
it.

* include\svn_client.h:
  (svn_client_get_default_log_message): New. Construct from the
  commit items.

* libsvn_client\commit.c:
  (svn_client_get_default_log_message): New. Move implementation from
  util.c

* clients\cmdline\util.c:
  (svn_cl__get_log_message): Use svn_client_get_default_log_message.

Index: subversion/include/svn_client.h
===================================================================
--- subversion/include/svn_client.h (revision 7944)
+++ subversion/include/svn_client.h (working copy)
@@ -1338,6 +1338,22 @@
                            svn_client_ctx_t *ctx,
                            apr_pool_t *pool);
 
+
+
+/* Log message creation. */
+
+/** Return a default log message constructed from @a commit_items, allocated
+ * in @a pool. If @a base_dir is given then subtract it from the path of the
+ * commit items. If @a prefix is given then use it at the start of the
+ * message. Used by svn_client_get_commit_log_t functions.
+ */
+const char *
+svn_client_get_default_log_message (apr_array_header_t *commit_items,
+ const char *base_dir,
+ const char *prefix,
+ apr_pool_t *pool);
+
+
 #ifdef __cplusplus
 }
 #endif /* __cplusplus */
Index: subversion/libsvn_client/commit.c
===================================================================
--- subversion/libsvn_client/commit.c (revision 7944)
+++ subversion/libsvn_client/commit.c (working copy)
@@ -1335,3 +1335,56 @@
 
   return reconcile_errors (cmt_err, unlock_err, bump_err, cleanup_err, pool);
 }
+
+
+const char *
+svn_client_get_default_log_message (apr_array_header_t *commit_items,
+ const char *base_dir,
+ const char *prefix,
+ apr_pool_t *pool)
+{
+ int i;
+ svn_stringbuf_t *tmp_message =
+ svn_stringbuf_create ((prefix ? prefix : ""), pool);
+
+ for (i = 0; i < commit_items->nelts; i++)
+ {
+ svn_client_commit_item_t *item =
+ APR_ARRAY_IDX (commit_items, i, svn_client_commit_item_t *);
+ const char *path = item->path;
+ char text_mod = '_', prop_mod = ' ';
+
+ if (! path)
+ path = item->url;
+ else if (! *path)
+ path = ".";
+
+ if (path && base_dir)
+ path = svn_path_is_child (base_dir, path, pool);
+
+ /* If still no path, then just use current directory. */
+ if (! path)
+ path = ".";
+
+ if ((item->state_flags & SVN_CLIENT_COMMIT_ITEM_DELETE)
+ && (item->state_flags & SVN_CLIENT_COMMIT_ITEM_ADD))
+ text_mod = 'R';
+ else if (item->state_flags & SVN_CLIENT_COMMIT_ITEM_ADD)
+ text_mod = 'A';
+ else if (item->state_flags & SVN_CLIENT_COMMIT_ITEM_DELETE)
+ text_mod = 'D';
+ else if (item->state_flags & SVN_CLIENT_COMMIT_ITEM_TEXT_MODS)
+ text_mod = 'M';
+
+ if (item->state_flags & SVN_CLIENT_COMMIT_ITEM_PROP_MODS)
+ prop_mod = 'M';
+
+ svn_stringbuf_appendbytes (tmp_message, &text_mod, 1);
+ svn_stringbuf_appendbytes (tmp_message, &prop_mod, 1);
+ svn_stringbuf_appendcstr (tmp_message, " ");
+ svn_stringbuf_appendcstr (tmp_message, path);
+ svn_stringbuf_appendcstr (tmp_message, APR_EOL_STR);
+ }
+
+ return tmp_message->data;
+}
Index: subversion/clients/cmdline/util.c
===================================================================
--- subversion/clients/cmdline/util.c (revision 7944)
+++ subversion/clients/cmdline/util.c (working copy)
@@ -417,8 +417,6 @@
                          void *baton,
                          apr_pool_t *pool)
 {
- const char *default_msg =
- APR_EOL_STR EDITOR_EOF_PREFIX APR_EOL_STR APR_EOL_STR;
   struct log_msg_baton *lmb = baton;
   svn_stringbuf_t *message = NULL;
   
@@ -453,54 +451,18 @@
       /* We still don't have a valid commit message. Use $EDITOR to
          get one. Note that svn_cl__edit_externally will still return
          a UTF-8'ized log message. */
- int i;
- svn_stringbuf_t *tmp_message = svn_stringbuf_create (default_msg, pool);
+ const char *default_prefix =
+ APR_EOL_STR EDITOR_EOF_PREFIX APR_EOL_STR APR_EOL_STR;
+ const char *default_msg =
+ svn_client_get_default_log_message (commit_items, lmb->base_dir,
+ default_prefix, pool);
       svn_error_t *err = SVN_NO_ERROR;
       const char *msg2 = NULL; /* ### shim for svn_cl__edit_externally */
 
- for (i = 0; i < commit_items->nelts; i++)
- {
- svn_client_commit_item_t *item
- = ((svn_client_commit_item_t **) commit_items->elts)[i];
- const char *path = item->path;
- char text_mod = '_', prop_mod = ' ';
-
- if (! path)
- path = item->url;
- else if (! *path)
- path = ".";
-
- if (path && lmb->base_dir)
- path = svn_path_is_child (lmb->base_dir, path, pool);
-
- /* If still no path, then just use current directory. */
- if (! path)
- path = ".";
-
- if ((item->state_flags & SVN_CLIENT_COMMIT_ITEM_DELETE)
- && (item->state_flags & SVN_CLIENT_COMMIT_ITEM_ADD))
- text_mod = 'R';
- else if (item->state_flags & SVN_CLIENT_COMMIT_ITEM_ADD)
- text_mod = 'A';
- else if (item->state_flags & SVN_CLIENT_COMMIT_ITEM_DELETE)
- text_mod = 'D';
- else if (item->state_flags & SVN_CLIENT_COMMIT_ITEM_TEXT_MODS)
- text_mod = 'M';
-
- if (item->state_flags & SVN_CLIENT_COMMIT_ITEM_PROP_MODS)
- prop_mod = 'M';
-
- svn_stringbuf_appendbytes (tmp_message, &text_mod, 1);
- svn_stringbuf_appendbytes (tmp_message, &prop_mod, 1);
- svn_stringbuf_appendcstr (tmp_message, " ");
- svn_stringbuf_appendcstr (tmp_message, path);
- svn_stringbuf_appendcstr (tmp_message, APR_EOL_STR);
- }
-
       /* Use the external edit to get a log message. */
       err = svn_cl__edit_externally (&msg2, &lmb->tmpfile_left,
                                      lmb->editor_cmd, lmb->base_dir,
- tmp_message->data, "svn-commit",
+ default_msg, "svn-commit",
                                      lmb->config, pool);
 
       /* Clean up the log message into UTF8/LF before giving it to

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@subversion.tigris.org
For additional commands, e-mail: dev-help@subversion.tigris.org
Received on Tue Dec 9 23:15:00 2003

This is an archived mail posted to the Subversion Dev mailing list.

This site is subject to the Apache Privacy Policy and the Apache Public Forum Archive Policy.