2 * Release: "cancel" a checkout in the history log.
4 * - Enter a line in the history log indicating the "release". - If asked to,
5 * delete the local working directory.
12 static const char *const release_usage[] =
14 "Usage: %s %s [-d] directories...\n",
15 "\t-d\tDelete the given directory.\n",
16 "(Specify the --help global option for a list of other help options)\n",
21 static int release_server PROTO ((int argc, char **argv));
23 /* This is the server side of cvs release. */
25 release_server (argc, argv)
31 /* Note that we skip argv[0]. */
32 for (i = 1; i < argc; ++i)
33 history_write ('F', argv[i], "", argv[i], "");
37 #endif /* SERVER_SUPPORT */
39 /* There are various things to improve about this implementation:
41 1. Using run_popen to run "cvs update" could be replaced by a
42 fairly simple start_recursion/classify_file loop--a win for
43 portability, performance, and cleanliness. In particular, there is
44 no particularly good way to find the right "cvs".
46 2. The fact that "cvs update" contacts the server slows things down;
47 it undermines the case for using "cvs release" rather than "rm -rf".
48 However, for correctly printing "? foo" and correctly handling
49 CVSROOTADM_IGNORE, we currently need to contact the server. (One
50 idea for how to fix this is to stash a copy of CVSROOTADM_IGNORE in
51 the working directories; see comment at base_* in entries.c for a
52 few thoughts on that).
54 3. Would be nice to take processing things on the client side one step
55 further, and making it like edit/unedit in terms of working well if
56 disconnected from the network, and then sending a delayed
59 4. Having separate network turnarounds for the "Notify" request
60 which we do as part of unedit, and for the "release" itself, is slow
72 size_t line_allocated = 0;
77 short delete_flag = 0;
82 return release_server (argc, argv);
85 /* Everything from here on is client or local. */
87 usage (release_usage);
89 while ((c = getopt (argc, argv, "+Qdq")) != -1)
96 "-q or -Q must be specified before \"%s\"",
104 usage (release_usage);
111 /* We're going to run "cvs -n -q update" and check its output; if
112 * the output is sufficiently unalarming, then we release with no
113 * questions asked. Else we prompt, then maybe release.
114 * (Well, actually we ask no matter what. Our notion of "sufficiently
115 * unalarming" doesn't take into account "? foo.c" files, so it is
116 * up to the user to take note of them, at least currently
117 * (ignore-193 in testsuite)).
119 /* Construct the update command. Be sure to add authentication and
120 encryption if we are using them currently, else our child process may
121 not be able to communicate with the server. */
122 update_cmd = xmalloc (strlen (program_path)
123 + strlen (current_parsed_root->original)
124 + 1 + 3 + 3 + 16 + 1);
125 sprintf (update_cmd, "%s %s%s-n -q -d %s update",
127 cvsauthenticate ? "-a " : "",
128 cvsencrypt ? "-x " : "",
129 current_parsed_root->original);
131 #ifdef CLIENT_SUPPORT
132 /* Start the server; we'll close it after looping. */
133 if (current_parsed_root->isremote)
138 #endif /* CLIENT_SUPPORT */
140 /* Remember the directory where "cvs release" was invoked because
141 all args are relative to this directory and we chdir around.
148 for (i = arg_start_idx; i < argc; i++)
154 if (CVS_CHDIR (thisarg) < 0)
157 error (0, errno, "can't chdir to: %s", thisarg);
163 error (0, 0, "no repository directory: %s", thisarg);
164 if (restore_cwd (&cwd, NULL))
172 error (0, 0, "no such directory: %s", thisarg);
176 repository = Name_Repository ((char *) NULL, (char *) NULL);
182 /* The "release" command piggybacks on "update", which
183 does the real work of finding out if anything is not
184 up-to-date with the repository. Then "release" prompts
185 the user, telling her how many files have been
186 modified, and asking if she still wants to do the
188 fp = run_popen (update_cmd, "r");
190 error (1, 0, "cannot run command %s", update_cmd);
194 while ((line_length = getline (&line, &line_allocated, fp)) >= 0)
196 if (strchr ("MARCZ", *line))
198 (void) fputs (line, stdout);
200 if (line_length < 0 && !feof (fp))
201 error (0, errno, "cannot read from subprocess");
203 /* If the update exited with an error, then we just want to
204 complain and go on to the next arg. Especially, we do
205 not want to delete the local copy, since it's obviously
206 not what the user thinks it is. */
207 if ((pclose (fp)) != 0)
209 error (0, 0, "unable to release `%s'", thisarg);
211 if (restore_cwd (&cwd, NULL))
216 printf ("You have [%d] altered files in this repository.\n",
218 printf ("Are you sure you want to release %sdirectory `%s': ",
219 delete_flag ? "(and delete) " : "", thisarg);
223 (void) fprintf (stderr, "** `%s' aborted by user choice.\n",
226 if (restore_cwd (&cwd, NULL))
232 /* Note: client.c doesn't like to have other code
233 changing the current directory on it. So a fair amount
234 of effort is needed to make sure it doesn't get confused
235 about the directory and (for example) overwrite
236 CVS/Entries file in the wrong directory. See release-17
237 through release-23. */
240 if (restore_cwd (&cwd, NULL))
244 #ifdef CLIENT_SUPPORT
245 && !(current_parsed_root->isremote
246 && (!supported_request ("noop")
247 || !supported_request ("Notify")))
256 err += unedit (argc, argv);
257 if (restore_cwd (&cwd, NULL))
261 #ifdef CLIENT_SUPPORT
262 if (current_parsed_root->isremote)
264 send_to_server ("Argument ", 0);
265 send_to_server (thisarg, 0);
266 send_to_server ("\012", 1);
267 send_to_server ("release\012", 0);
270 #endif /* CLIENT_SUPPORT */
272 history_write ('F', thisarg, "", thisarg, ""); /* F == Free */
277 /* FIXME? Shouldn't this just delete the CVS-controlled
278 files and, perhaps, the files that would normally be
279 ignored and leave everything else? */
281 if (unlink_file_dir (thisarg) < 0)
282 error (0, errno, "deletion of directory %s failed", thisarg);
285 #ifdef CLIENT_SUPPORT
286 if (current_parsed_root->isremote)
289 * Is there a good reason why get_server_responses() isn't
290 * responsible for restoring its initial directory itself when
293 err += get_server_responses ();
295 if (restore_cwd (&cwd, NULL))
298 #endif /* CLIENT_SUPPORT */
301 if (restore_cwd (&cwd, NULL))
305 #ifdef CLIENT_SUPPORT
306 if (current_parsed_root->isremote)
308 /* Unfortunately, client.c doesn't offer a way to close
309 the connection without waiting for responses. The extra
310 network turnaround here is quite unnecessary other than
312 send_to_server ("noop\012", 0);
313 err += get_responses_and_close ();
315 #endif /* CLIENT_SUPPORT */