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

Re: [PATCH] fix svn cat to skip unversioned items V3.

From: <kfogel_at_collab.net>
Date: 2005-05-30 22:39:16 CEST

<vivek@collab.net> writes:
> [[[
> Fix svn cat so that it skips unversioned items.
>
> * subversion/clients/cmdline/cat-cmd.c
> (svn_cl__cat): Added logic to skip unversioned items.
> Also skips directories.

A directory is an item, so that last line is unnecessary.

> * subversion/tests/clients/cmdline/cat_tests.py
> (cat_skip_unversioned_file): New function to
> verify skipping of unversioned items.

The test's name makes it clear what it does, so the description is
redundant. Just write something like this:

   * subversion/tests/clients/cmdline/cat_tests.py
     (cat_skip_unversioned_file): New test.
     (test_list): Run it.

> Index: subversion/clients/cmdline/cat-cmd.c
> ===================================================================
> --- subversion/clients/cmdline/cat-cmd.c (revision 14823)
> +++ subversion/clients/cmdline/cat-cmd.c (working copy)
> @@ -42,6 +42,7 @@
> int i;
> svn_stream_t *out;
> apr_pool_t *subpool = svn_pool_create (pool);
> + svn_error_t *err;
>
> SVN_ERR (svn_opt_args_to_target_array2 (&targets, os,
> opt_state->targets, pool));
> @@ -65,9 +66,22 @@
> SVN_ERR (svn_opt_parse_path (&peg_revision, &truepath, target,
> subpool));
>
> - SVN_ERR (svn_client_cat2 (out, truepath, &peg_revision,
> - &(opt_state->start_revision),
> - ctx, subpool));
> + err = svn_client_cat2 (out, truepath, &peg_revision,
> + &(opt_state->start_revision),
> + ctx, subpool);
> + if (err)
> + {
> + if ((err->apr_err == SVN_ERR_ENTRY_NOT_FOUND)
> + || (err->apr_err == SVN_ERR_UNVERSIONED_RESOURCE)
> + || (err->apr_err == SVN_ERR_CLIENT_IS_DIRECTORY))
> + {
> + svn_handle_warning (stderr, err);
> + svn_error_clear (err);
> + continue;
> + }
> + else
> + return err;
> + }
> }

It's a pity we can't use SVN_CL__TRY for this, but I guess the
SVN_ERR_CLIENT_IS_DIRECTORY error precludes it.

(If I could think of some way to make SVN_CL__TRY take an arbitrary
number of errors to test for, that would be perfect. But variadic
macros weren't added to C until C99, and even then they don't do quite
what we'd need. Oh well.)

Don't forget to check opt_state->quiet before calling
svn_handle_warning(). We don't want to emit warnings if the user
specified --quiet on the command line.

> Index: subversion/tests/clients/cmdline/cat_tests.py
> ===================================================================
> --- subversion/tests/clients/cmdline/cat_tests.py (revision 14823)
> +++ subversion/tests/clients/cmdline/cat_tests.py (working copy)
> @@ -84,6 +84,62 @@
> None, svntest.SVNAnyOutput, 'cat',
> bogus_path)
>
> +def cat_skip_unversioned_file(sbox):
> + "cat should skip an unversioned resource"
> + sbox.build()
> +
> + wc_dir = sbox.wc_dir
> + dir_path = os.path.join(wc_dir, 'A/D')
> + new_file_path = os.path.join(dir_path, 'new')
> + open(new_file_path, 'w')
> + file_list = os.listdir(dir_path)
> +
> +# file_list has all the files and directories under 'dir_path'
> +# including .svn. But cat'ing of .svn just gives the
> +# output of 'svn help cat'. So skip .svn directory

Indent comments with the local code level.

> + file_list = file_list[1:]

According to http://docs.python.org/lib/os-file-dir.html, the list
returned by os.listdir() is in arbitrary order. Therefore, you cannot
count on ".svn" being the first item in file_list.

Since file_list contains both files and directories, maybe it would be
better to call it entries_list or items_list or something?

> + for file in file_list :
> + file_to_cat = os.path.join(dir_path, file)
> + if file_to_cat == new_file_path:
> + expected_err = "svn: warning: '" + file_to_cat + "'" + \
> + " is not under version control or doesn't exist\n"
> + svntest.actions.run_and_verify_svn(None, None,
> + expected_err, 'cat', file_to_cat)
> + elif os.path.isdir(file_to_cat):
> + expected_err = "svn: warning: '" + file_to_cat + "'" + \
> + " refers to a directory\n"
> + svntest.actions.run_and_verify_svn(None, None,
> + expected_err, 'cat', file_to_cat)

Here, for example, the code

   os.path.isdir(file_to_cat)

is rather confusing. How can a file be a dir?? file_to_cat should be
item_to_cat, or something like that.

> + else:
> + svntest.actions.run_and_verify_svn(None,
> + ["This is the file '"+file+"'."],
> + None, 'cat', file_to_cat)
> +
> + G_path = os.path.join(dir_path,'G')
> + rho_path = os.path.join(G_path,'rho')
> +
> + expected_err1 = "svn: warning: '" + G_path + "'" + " refers to a directory\n"
> + expected_out = "This is the file 'rho'."
> + out, err = svntest.main.run_svn(expected_err1, 'cat', rho_path, G_path)
> + if out[0] != expected_out:
> + raise svntest.Failure ('Cat failed: expected "%s", but received "%s"' % \
> + (expected_out, out[0]))
> +
> + expected_err2 = "svn: warning: '" + new_file_path + "'" + \
> + " is not under version control or doesn't exist\n"
> + out, err = svntest.main.run_svn(expected_err2, 'cat', rho_path, new_file_path)
> + if out[0] != expected_out:
> + raise svntest.Failure ('Cat failed: expected "%s", but received "%s"' % \
> + (expected_out, out[0]))
> +
> + out, err = svntest.main.run_svn(expected_err1+expected_err2,
> + 'cat', rho_path, G_path, new_file_path)
> + if out[0] != expected_out:
> + raise svntest.Failure ('Cat failed: expected "%s", but received "%s"' % \
> + (expected_out, out[0]))
> +

Isn't there some way to do this with svntest.run_and_verify_svn(), so
that you can just pass in the expected output, instead of manually
checking it afterwards each time?

Looking forward to v4...

Best,
-Karl

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@subversion.tigris.org
For additional commands, e-mail: dev-help@subversion.tigris.org
Received on Mon May 30 23:18:32 2005

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.