Author: danielsh
Date: Fri Nov 8 17:36:05 2019
New Revision: 1869578
URL: http://svn.apache.org/viewvc?rev=1869578&view=rev
Log:
'info': Support multiple items in --show-item, as tab-separated values (TSV).
Suggested by: brane
Thread:
.
https://mail-archives.apache.org/mod_mbox/subversion-dev/201911.mbox/%3Cf6dc88d3-8227-4f22-768c-2cf6ce70fcb7%40apache.org%3E
Date: Thu, 7 Nov 2019 17:28:35 +0100
From: Branko Čibej <[email protected]>
To: [email protected]
Subject: svn status tabbed output [was: Re: svn status should not show
unmodified files in changelists]
Message-ID: <[email protected]>
* subversion/svn/info-cmd.c
(print_info_baton_t::print_what): Rename to..
(print_info_baton_t::print_whats): .. this.
(find_print_what): Rename argument and parse it as a list.
(print_info_item): Track changes to the baton.
(svn_cl__info): Track changes to the baton.
* subversion/svn/svn.c
(svn_cl__options."show_item"): Update docstring.
* subversion/tests/cmdline/info_tests.py
(info_item_simple): Extend existing test case to unit test this feature.
Blocks that haven't been reindented in this commit will be reindented in the
next commit.
Modified:
subversion/trunk/CHANGES
subversion/trunk/subversion/svn/info-cmd.c
subversion/trunk/subversion/svn/svn.c
subversion/trunk/subversion/tests/cmdline/info_tests.py
Modified: subversion/trunk/CHANGES
URL:
http://svn.apache.org/viewvc/subversion/trunk/CHANGES?rev=1869578&r1=1869577&r2=1869578&view=diff
==============================================================================
--- subversion/trunk/CHANGES (original)
+++ subversion/trunk/CHANGES Fri Nov 8 17:36:05 2019
@@ -11,6 +11,7 @@ https://svn.apache.org/repos/asf/subvers
User-visible changes:
- Minor new features and improvements:
* Add 'svn info --show-item=changelist' (r1869481)
+ * Add multiple item arguments to 'svn info --show-item=...' (r1869578)
Version 1.13.0
Modified: subversion/trunk/subversion/svn/info-cmd.c
URL:
http://svn.apache.org/viewvc/subversion/trunk/subversion/svn/info-cmd.c?rev=1869578&r1=1869577&r2=1869578&view=diff
==============================================================================
--- subversion/trunk/subversion/svn/info-cmd.c (original)
+++ subversion/trunk/subversion/svn/info-cmd.c Fri Nov 8 17:36:05 2019
@@ -411,8 +411,8 @@ typedef struct print_info_baton_t
* The following fields are used by print_info_item().
*/
- /* Which item to print. */
- info_item_t print_what;
+ /* Which items to print. */
+ apr_array_header_t *print_whats;
/* Do we expect to show info for multiple targets? */
svn_boolean_t multiple_targets;
@@ -431,12 +431,12 @@ typedef struct print_info_baton_t
} print_info_baton_t;
-/* Find the appropriate info_item_t for KEYWORD and initialize
+/* Find the appropriate info_item_t for KEYWORDS_FROM_ARGV and initialize
* RECEIVER_BATON for print_info_item(). Use SCRATCH_POOL for
* temporary allocation.
*/
static svn_error_t *
-find_print_what(const char *keyword,
+find_print_what(const char *keywords_from_argv,
print_info_baton_t *receiver_baton,
apr_pool_t *scratch_pool)
{
@@ -445,7 +445,9 @@ find_print_what(const char *keyword,
svn_cl__simcheck_t *kwbuf = apr_palloc(
scratch_pool, info_item_map_len * sizeof(svn_cl__simcheck_t));
apr_size_t i;
-
+ apr_array_header_t *whats;
+
+ /* Initialize KEYWORDS and KWBUF. */
for (i = 0; i < info_item_map_len; ++i)
{
keywords[i] = &kwbuf[i];
@@ -454,8 +456,13 @@ find_print_what(const char *keyword,
kwbuf[i].data = &info_item_map[i];
}
- switch (svn_cl__similarity_check(keyword, keywords,
- info_item_map_len, scratch_pool))
+ whats = svn_cstring_split(keywords_from_argv, ",", TRUE, scratch_pool);
+ for (i = 0; i < whats->nelts; i++)
+ {
+ const char *keyword = APR_ARRAY_IDX(whats, i, const char *);
+ switch (svn_cl__similarity_check(keyword, keywords,
+ info_item_map_len, scratch_pool))
+ /* TODO: indent this block */
{
const info_item_map_t *kw0;
const info_item_map_t *kw1;
@@ -463,8 +470,9 @@ find_print_what(const char *keyword,
case 0: /* Exact match. */
kw0 = keywords[0]->data;
- receiver_baton->print_what = kw0->print_what;
- return SVN_NO_ERROR;
+ APR_ARRAY_PUSH(receiver_baton->print_whats, info_item_t) =
+ kw0->print_what;
+ break;
case 1:
/* The best alternative isn't good enough */
@@ -503,6 +511,13 @@ find_print_what(const char *keyword,
" did you mean '%s', '%s' or '%s'?"),
keyword, kw0->keyword.data, kw1->keyword.data, kw2->keyword.data);
}
+ }
+
+ if (whats->nelts == 0)
+ return svn_error_create(SVN_ERR_CL_ARG_PARSING_ERROR, NULL,
+ _("--show-item requires a non-empty argument"));
+
+ return SVN_NO_ERROR;
}
/* A callback of type svn_client_info_receiver2_t.
@@ -1125,11 +1140,17 @@ print_info_item(void *baton,
receiver_baton->path_prefix, target, pool));
const char *const target_path =
(receiver_baton->multiple_targets ? actual_target_path : NULL);
+ int i;
if (receiver_baton->start_new_line)
SVN_ERR(svn_cmdline_fputs("\n", stdout, pool));
- switch (receiver_baton->print_what)
+ for (i = 0; i < receiver_baton->print_whats->nelts; i++)
+ {
+ if (i > 0)
+ SVN_ERR(svn_cmdline_fputs("\t", stdout, pool));
+ switch (APR_ARRAY_IDX(receiver_baton->print_whats, i, info_item_t))
+ /* TODO: indent this block */
{
case info_item_kind:
SVN_ERR(print_info_item_string(svn_node_kind_to_word(info->kind),
@@ -1235,6 +1256,7 @@ print_info_item(void *baton,
default:
SVN_ERR_MALFUNCTION();
}
+ }
receiver_baton->start_new_line = TRUE;
return SVN_NO_ERROR;
@@ -1300,6 +1322,7 @@ svn_cl__info(apr_getopt_t *os,
else if (opt_state->show_item)
{
receiver = print_info_item;
+ receiver_baton.print_whats = apr_array_make(pool, 5,
sizeof(info_item_t));
if (opt_state->incremental)
return svn_error_create(
Modified: subversion/trunk/subversion/svn/svn.c
URL:
http://svn.apache.org/viewvc/subversion/trunk/subversion/svn/svn.c?rev=1869578&r1=1869577&r2=1869578&view=diff
==============================================================================
--- subversion/trunk/subversion/svn/svn.c (original)
+++ subversion/trunk/subversion/svn/svn.c Fri Nov 8 17:36:05 2019
@@ -431,7 +431,9 @@ const apr_getopt_option_t svn_cl__option
" "
"current revision (recommended when tagging)")},
{"show-item", opt_show_item, 1,
- N_("print only the item identified by ARG:\n"
+ N_("print only the items identified by ARG, which is\n"
+ " "
+ "a comma-separated list of:\n"
" "
" 'kind' node kind of TARGET\n"
" "
Modified: subversion/trunk/subversion/tests/cmdline/info_tests.py
URL:
http://svn.apache.org/viewvc/subversion/trunk/subversion/tests/cmdline/info_tests.py?rev=1869578&r1=1869577&r2=1869578&view=diff
==============================================================================
--- subversion/trunk/subversion/tests/cmdline/info_tests.py (original)
+++ subversion/trunk/subversion/tests/cmdline/info_tests.py Fri Nov 8 17:36:05
2019
@@ -644,6 +644,10 @@ def info_item_simple(sbox):
['1'], [],
'info', '--show-item=revision', '--no-newline',
sbox.ospath(''))
+ svntest.actions.run_and_verify_svn(
+ ['1\tdir'], [],
+ 'info', '--show-item=revision,kind', '--no-newline',
+ sbox.ospath(''))
def info_item_simple_multiple(sbox):