2 * Copyright (C) 1986-2005 The Free Software Foundation, Inc.
4 * Portions Copyright (C) 1998-2005 Derek Price, Ximbiot <http://ximbiot.com>,
7 * Portions Copyright (C) 1992, Brian Berliner and Jeff Polk
8 * Portions Copyright (C) 1989-1992, Brian Berliner
10 * You may distribute under the terms of the GNU General Public License as
11 * specified in the README file that comes with the CVS source distribution.
15 * Removes entries from the present version. The entries will be removed from
16 * the RCS repository upon the next "commit".
18 * "remove" accepts no options, only file names that are to be removed. The
19 * file must not exist in the current directory for "remove" to work
26 static int remove_force_fileproc PROTO ((void *callerdat,
27 struct file_info *finfo));
29 static int remove_fileproc PROTO ((void *callerdat, struct file_info *finfo));
30 static Dtype remove_dirproc PROTO ((void *callerdat, const char *dir,
31 const char *repos, const char *update_dir,
36 static int removed_files;
37 static int existing_files;
39 static const char *const remove_usage[] =
41 "Usage: %s %s [-flR] [files...]\n",
42 "\t-f\tDelete the file before removing it.\n",
43 "\t-l\tProcess this directory only (not recursive).\n",
44 "\t-R\tProcess directories recursively.\n",
45 "(Specify the --help global option for a list of other help options)\n",
50 cvsremove (argc, argv)
60 while ((c = getopt (argc, argv, "+flR")) != -1)
85 if (current_parsed_root->isremote) {
86 /* Call expand_wild so that the local removal of files will
87 work. It's ok to do it always because we have to send the
88 file names expanded anyway. */
89 expand_wild (argc, argv, &argc, &argv);
95 start_recursion (remove_force_fileproc, (FILESDONEPROC) NULL,
96 (DIRENTPROC) NULL, (DIRLEAVEPROC) NULL,
97 (void *) NULL, argc, argv, local, W_LOCAL,
98 0, CVS_LOCK_NONE, (char *) NULL, 0,
101 /* else FIXME should probably act as if the file doesn't exist
102 in doing the following checks. */
110 /* FIXME: Can't we set SEND_NO_CONTENTS here? Needs investigation. */
111 send_files (argc, argv, local, 0, 0);
112 send_file_names (argc, argv, 0);
113 free_names (&argc, argv);
114 send_to_server ("remove\012", 0);
115 return get_responses_and_close ();
119 /* start the recursion processor */
120 err = start_recursion (remove_fileproc, (FILESDONEPROC) NULL,
121 remove_dirproc, (DIRLEAVEPROC) NULL, NULL,
123 local, W_LOCAL, 0, CVS_LOCK_READ, (char *) NULL, 1,
126 if (removed_files && !really_quiet)
127 error (0, 0, "use '%s commit' to remove %s permanently", program_name,
128 (removed_files == 1) ? "this file" : "these files");
132 ((existing_files == 1) ?
133 "%d file exists; remove it first" :
134 "%d files exist; remove them first"),
140 #ifdef CLIENT_SUPPORT
143 * This is called via start_recursion if we are running as the client
144 * and the -f option was used. We just physically remove the file.
149 remove_force_fileproc (callerdat, finfo)
151 struct file_info *finfo;
153 if (CVS_UNLINK (finfo->file) < 0 && ! existence_error (errno))
154 error (0, errno, "unable to remove %s", finfo->fullname);
161 * remove the file, only if it has already been physically removed
165 remove_fileproc (callerdat, finfo)
167 struct file_info *finfo;
175 if ( CVS_UNLINK (finfo->file) < 0 && ! existence_error (errno))
177 error (0, errno, "unable to remove %s", finfo->fullname);
180 /* else FIXME should probably act as if the file doesn't exist
181 in doing the following checks. */
184 vers = Version_TS (finfo, NULL, NULL, NULL, 0, 0);
186 if (vers->ts_user != NULL)
190 error (0, 0, "file `%s' still in working directory",
193 else if (vers->vn_user == NULL)
196 error (0, 0, "nothing known about `%s'", finfo->fullname);
198 else if (vers->vn_user[0] == '0' && vers->vn_user[1] == '\0')
203 * It's a file that has been added, but not commited yet. So,
204 * remove the ,t file for it and scratch it from the
206 Scratch_Entry (finfo->entries, finfo->file);
207 fname = xmalloc (strlen (finfo->file)
209 + sizeof (CVSEXT_LOG)
211 (void) sprintf (fname, "%s/%s%s", CVSADM, finfo->file, CVSEXT_LOG);
212 if (unlink_file (fname) < 0
213 && !existence_error (errno))
214 error (0, errno, "cannot remove %s", CVSEXT_LOG);
216 error (0, 0, "removed `%s'", finfo->fullname);
218 #ifdef SERVER_SUPPORT
220 server_checked_in (finfo->file, finfo->update_dir, finfo->repository);
224 else if (vers->vn_user[0] == '-')
227 error (0, 0, "file `%s' already scheduled for removal",
230 else if (vers->tag != NULL && isdigit ((unsigned char) *vers->tag))
232 /* Commit will just give an error, and so there seems to be
233 little reason to allow the remove. I mean, conflicts that
234 arise out of parallel development are one thing, but conflicts
235 that arise from sticky tags are quite another.
237 I would have thought that non-branch sticky tags should be the
238 same but at least now, removing a file with a non-branch sticky
239 tag means to delete the tag from the file. I'm not sure that
240 is a good behavior, but until it is changed, we need to allow
243 cannot remove file `%s' which has a numeric sticky tag of `%s'",
244 finfo->fullname, vers->tag);
246 else if (vers->date != NULL)
248 /* Commit will just give an error, and so there seems to be
249 little reason to allow the remove. */
251 cannot remove file `%s' which has a sticky date of `%s'",
252 finfo->fullname, vers->date);
258 /* Re-register it with a negative version number. */
259 fname = xmalloc (strlen (vers->vn_user) + 5);
260 (void) strcpy (fname, "-");
261 (void) strcat (fname, vers->vn_user);
262 Register (finfo->entries, finfo->file, fname, vers->ts_rcs, vers->options,
263 vers->tag, vers->date, vers->ts_conflict);
265 error (0, 0, "scheduling `%s' for removal", finfo->fullname);
268 #ifdef SERVER_SUPPORT
270 server_checked_in (finfo->file, finfo->update_dir, finfo->repository);
280 * Print a warm fuzzy message
284 remove_dirproc (callerdat, dir, repos, update_dir, entries)
288 const char *update_dir;
292 error (0, 0, "Removing %s", update_dir);