Followup to r29625: fix getopt tests.
[svn.git] / subversion / svn / changelist-cmd.c
blob3a47d567a21c239fc237eeacdfef2844f5393e47
1 /*
2 * changelist-cmd.c -- Associate (or deassociate) a wc path with a changelist.
4 * ====================================================================
5 * Copyright (c) 2006-2007 CollabNet. All rights reserved.
7 * This software is licensed as described in the file COPYING, which
8 * you should have received as part of this distribution. The terms
9 * are also available at http://subversion.tigris.org/license-1.html.
10 * If newer versions of this license are posted there, you may use a
11 * newer version instead, at your option.
13 * This software consists of voluntary contributions made by many
14 * individuals. For exact contribution history, see the revision
15 * history and logs, available at http://subversion.tigris.org/.
16 * ====================================================================
19 /* ==================================================================== */
23 /*** Includes. ***/
25 #include "svn_client.h"
26 #include "svn_error_codes.h"
27 #include "svn_error.h"
28 #include "cl.h"
30 #include "svn_private_config.h"
33 /*** Code. ***/
36 /* This implements the `svn_opt_subcommand_t' interface. */
37 svn_error_t *
38 svn_cl__changelist(apr_getopt_t *os,
39 void *baton,
40 apr_pool_t *pool)
42 const char *changelist_name = NULL;
43 svn_cl__opt_state_t *opt_state = ((svn_cl__cmd_baton_t *) baton)->opt_state;
44 svn_client_ctx_t *ctx = ((svn_cl__cmd_baton_t *) baton)->ctx;
45 apr_array_header_t *targets;
46 svn_depth_t depth = opt_state->depth;
48 /* If we're not removing changelists, then our first argument should
49 be the name of a changelist. */
51 if (! opt_state->remove)
53 apr_array_header_t *args;
54 SVN_ERR(svn_opt_parse_num_args(&args, os, 1, pool));
55 changelist_name = APR_ARRAY_IDX(args, 0, const char *);
56 SVN_ERR(svn_utf_cstring_to_utf8(&changelist_name,
57 changelist_name, pool));
60 /* Parse the remaining arguments as paths. */
61 SVN_ERR(svn_cl__args_to_target_array_print_reserved(&targets, os,
62 opt_state->targets,
63 pool));
65 /* Changelist has no implicit dot-target `.', so don't you put that
66 code here! */
67 if (! targets->nelts)
68 return svn_error_create(SVN_ERR_CL_INSUFFICIENT_ARGS, 0, NULL);
70 if (! opt_state->quiet)
71 svn_cl__get_notifier(&ctx->notify_func2, &ctx->notify_baton2, FALSE,
72 FALSE, FALSE, pool);
73 else
74 /* FIXME: This is required because svn_client_create_context()
75 always initializes ctx->notify_func2 to a wrapper function
76 which calls ctx->notify_func() if it isn't NULL. In other
77 words, typically, ctx->notify_func2 is never NULL. This isn't
78 usually a problem, but the changelist logic generates
79 svn_error_t's as part of its notification.
81 So, svn_wc_set_changelist() checks its notify_func (our
82 ctx->notify_func2) for NULL-ness, and seeing non-NULL-ness,
83 generates a notificaton object and svn_error_t to describe some
84 problem. It passes that off to its notify_func (our
85 ctx->notify_func2) which drops the notification on the floor
86 (because it wraps a NULL ctx->notify_func). But svn_error_t's
87 dropped on the floor cause SEGFAULTs at pool cleanup time --
88 they need instead to be cleared.
90 SOOOooo... we set our ctx->notify_func2 to NULL so the WC code
91 doesn't even generate the errors. */
92 ctx->notify_func2 = NULL;
94 if (depth == svn_depth_unknown)
95 depth = svn_depth_empty;
97 if (changelist_name)
99 SVN_ERR(svn_cl__try
100 (svn_client_add_to_changelist(targets, changelist_name,
101 depth, opt_state->changelists,
102 ctx, pool),
103 NULL, opt_state->quiet,
104 SVN_ERR_UNVERSIONED_RESOURCE,
105 SVN_ERR_WC_PATH_NOT_FOUND,
106 SVN_NO_ERROR));
108 else
110 SVN_ERR(svn_cl__try
111 (svn_client_remove_from_changelists(targets, depth,
112 opt_state->changelists,
113 ctx, pool),
114 NULL, opt_state->quiet,
115 SVN_ERR_UNVERSIONED_RESOURCE,
116 SVN_ERR_WC_PATH_NOT_FOUND,
117 SVN_NO_ERROR));
121 return SVN_NO_ERROR;