Index: status-cmd.c =================================================================== --- status-cmd.c (revision 6484) +++ status-cmd.c (working copy) @@ -34,6 +34,96 @@ /*** Code. ***/ +/* This function will determine if the repository is empty. + * Empty, here, means no files or directories are in the + * root of the repository (So, it may have had 1000 revisions, + * if the last revision all files were deleted, the repos is + * empty. If it finds this isn't the case, it does next to nothing. + * If it finds that the repos is not empty it will + * print a message to stout mentioning the emptyness of + * the repository (and maybe taking away some confusion + * from new users). */ +svn_error_t * +svn_cl__repos_empty (svn_cl__opt_state_t *opt_state, + svn_client_ctx_t *ctx, + apr_array_header_t *targets, + apr_pool_t *pool) +{ + apr_hash_t *ls_dirents; + apr_array_header_t *ls_targets; + char *ls_target; + int item_count_current_dir = 0; + int item_count_parent_dir = 0; + svn_error_t *err; + apr_pool_t *subpool; + + ls_targets = targets; + subpool = svn_pool_create (pool); + + /* Count the number of files in the current directory, + * if thats > 0, we know the repos is not empty. Otherwise, + * count the number of files in the parent directory + * (if there is a parent directory). For an empty repos + * that should generate an error. */ + svn_opt_push_implicit_dot_target(ls_targets, subpool); + ls_target = ((char **) (ls_targets->elts))[0]; + + err = ( svn_client_ls (&ls_dirents, + ls_target, + &(opt_state->start_revision), + 0, + ctx, + subpool)); + + if (err) + { + /* Doing an 'ls' on the current dir did generate + * an error. But because this functionality is not + * *that* important, just skip the error and + * return */ + svn_error_clear(err); + item_count_parent_dir = 0; + } + else + { + item_count_current_dir = apr_hash_count(ls_dirents); + + if (item_count_current_dir == 0) + { + /* 2nd pass */ + ls_target = ".."; + err = ( svn_client_ls (&ls_dirents, + ls_target, + &(opt_state->start_revision), + 0, + ctx, + subpool)); + if (err) + { + /* Fetching an 'ls' about the parent directory + * did not work out (maybe we're allready in the + * root directory). Clear the error and report + * the item_count as if it's 0 */ + svn_error_clear(err); + item_count_parent_dir = 0; + } + else + { + item_count_parent_dir = apr_hash_count(ls_dirents); + } + if ((item_count_current_dir == 0) + && (item_count_parent_dir == 0)) + { + printf("The repository is empty.\n"); + } + } + } + + svn_pool_clear (subpool); + svn_pool_destroy (subpool); + return SVN_NO_ERROR; +} + /* This implements the `svn_opt_subcommand_t' interface. */ svn_error_t * svn_cl__status (apr_getopt_t *os, @@ -90,6 +180,15 @@ opt_state->quiet, subpool); + if (opt_state->verbose) + { /* Only show helpfull messages if asked to be + verbose. */ + SVN_ERR (svn_cl__repos_empty (opt_state, + ctx, + targets, + subpool)); + } + SVN_ERR (svn_cl__check_cancel (ctx->cancel_baton)); svn_pool_clear (subpool); }