2 * Copyright (c) 1992, Brian Berliner and Jeff Polk
3 * Copyright (c) 1989-1992, Brian Berliner
5 * You may distribute under the terms of the GNU General Public License as
6 * specified in the README file that comes with the CVS source distribution.
10 * Removes entries from the present version. The entries will be removed from
11 * the RCS repository upon the next "commit".
13 * "remove" accepts no options, only file names that are to be removed. The
14 * file must not exist in the current directory for "remove" to work
21 static int remove_force_fileproc PROTO ((void *callerdat,
22 struct file_info *finfo));
24 static int remove_fileproc PROTO ((void *callerdat, struct file_info *finfo));
25 static Dtype remove_dirproc PROTO ((void *callerdat, char *dir,
26 char *repos, char *update_dir,
31 static int removed_files;
32 static int existing_files;
34 static const char *const remove_usage[] =
36 "Usage: %s %s [-flR] [files...]\n",
37 "\t-f\tDelete the file before removing it.\n",
38 "\t-l\tProcess this directory only (not recursive).\n",
39 "\t-R\tProcess directories recursively.\n",
40 "(Specify the --help global option for a list of other help options)\n",
45 cvsremove (argc, argv)
55 while ((c = getopt (argc, argv, "+flR")) != -1)
81 /* Call expand_wild so that the local removal of files will
82 work. It's ok to do it always because we have to send the
83 file names expanded anyway. */
84 expand_wild (argc, argv, &argc, &argv);
90 start_recursion (remove_force_fileproc, (FILESDONEPROC) NULL,
91 (DIRENTPROC) NULL, (DIRLEAVEPROC) NULL,
92 (void *) NULL, argc, argv, local, W_LOCAL,
93 0, 0, (char *) NULL, 0);
95 /* else FIXME should probably act as if the file doesn't exist
96 in doing the following checks. */
103 send_file_names (argc, argv, 0);
104 /* FIXME: Can't we set SEND_NO_CONTENTS here? Needs investigation. */
105 send_files (argc, argv, local, 0, 0);
106 send_to_server ("remove\012", 0);
107 return get_responses_and_close ();
111 /* start the recursion processor */
112 err = start_recursion (remove_fileproc, (FILESDONEPROC) NULL,
113 remove_dirproc, (DIRLEAVEPROC) NULL, NULL,
115 local, W_LOCAL, 0, 1, (char *) NULL, 1);
118 error (0, 0, "use '%s commit' to remove %s permanently", program_name,
119 (removed_files == 1) ? "this file" : "these files");
123 ((existing_files == 1) ?
124 "%d file exists; remove it first" :
125 "%d files exist; remove them first"),
131 #ifdef CLIENT_SUPPORT
134 * This is called via start_recursion if we are running as the client
135 * and the -f option was used. We just physically remove the file.
140 remove_force_fileproc (callerdat, finfo)
142 struct file_info *finfo;
144 if (CVS_UNLINK (finfo->file) < 0 && ! existence_error (errno))
145 error (0, errno, "unable to remove %s", finfo->fullname);
152 * remove the file, only if it has already been physically removed
156 remove_fileproc (callerdat, finfo)
158 struct file_info *finfo;
166 if ( CVS_UNLINK (finfo->file) < 0 && ! existence_error (errno))
168 error (0, errno, "unable to remove %s", finfo->fullname);
171 /* else FIXME should probably act as if the file doesn't exist
172 in doing the following checks. */
175 vers = Version_TS (finfo, NULL, NULL, NULL, 0, 0);
177 if (vers->ts_user != NULL)
181 error (0, 0, "file `%s' still in working directory",
184 else if (vers->vn_user == NULL)
187 error (0, 0, "nothing known about `%s'", finfo->fullname);
189 else if (vers->vn_user[0] == '0' && vers->vn_user[1] == '\0')
194 * It's a file that has been added, but not commited yet. So,
195 * remove the ,t file for it and scratch it from the
197 Scratch_Entry (finfo->entries, finfo->file);
198 fname = xmalloc (strlen (finfo->file)
200 + sizeof (CVSEXT_LOG)
202 (void) sprintf (fname, "%s/%s%s", CVSADM, finfo->file, CVSEXT_LOG);
203 (void) unlink_file (fname);
205 error (0, 0, "removed `%s'", finfo->fullname);
207 #ifdef SERVER_SUPPORT
209 server_checked_in (finfo->file, finfo->update_dir, finfo->repository);
213 else if (vers->vn_user[0] == '-')
216 error (0, 0, "file `%s' already scheduled for removal",
219 else if (vers->tag != NULL && isdigit (*vers->tag))
221 /* Commit will just give an error, and so there seems to be
222 little reason to allow the remove. I mean, conflicts that
223 arise out of parallel development are one thing, but conflicts
224 that arise from sticky tags are quite another.
226 I would have thought that non-branch sticky tags should be the
227 same but at least now, removing a file with a non-branch sticky
228 tag means to delete the tag from the file. I'm not sure that
229 is a good behavior, but until it is changed, we need to allow
232 cannot remove file `%s' which has a numeric sticky tag of `%s'",
233 finfo->fullname, vers->tag);
239 /* Re-register it with a negative version number. */
240 fname = xmalloc (strlen (vers->vn_user) + 5);
241 (void) strcpy (fname, "-");
242 (void) strcat (fname, vers->vn_user);
243 Register (finfo->entries, finfo->file, fname, vers->ts_rcs, vers->options,
244 vers->tag, vers->date, vers->ts_conflict);
246 error (0, 0, "scheduling `%s' for removal", finfo->fullname);
249 #ifdef SERVER_SUPPORT
251 server_checked_in (finfo->file, finfo->update_dir, finfo->repository);
261 * Print a warm fuzzy message
265 remove_dirproc (callerdat, dir, repos, update_dir, entries)
273 error (0, 0, "Removing %s", update_dir);