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 * Does a very careful checkin of the file "user", and tries not to spoil its
11 * modification time (to avoid needless recompilations). When RCS ID keywords
12 * get expanded on checkout, however, the modification time is updated and
13 * there is no good way to get around this.
15 * Returns non-zero on error.
24 Checkin (type, finfo, rev, tag, options, message)
26 struct file_info *finfo;
34 char *tocvsPath = NULL;
36 /* Hmm. This message goes to stdout and the "foo,v <-- foo"
37 message from "ci" goes to stderr. This doesn't make a whole
38 lot of sense, but making everything go to stdout can only be
39 gracefully achieved once RCS_checkin is librarified. */
40 cvs_output ("Checking in ", 0);
41 cvs_output (finfo->fullname, 0);
42 cvs_output (";\n", 0);
44 tocvsPath = wrap_tocvs_process_file (finfo->file);
49 if (unlink_file_dir (finfo->file) < 0)
50 if (! existence_error (errno))
51 error (1, errno, "cannot remove %s", finfo->fullname);
52 rename_file (tocvsPath, finfo->file);
56 /* There use to be a check for finfo->rcs == NULL here and then a
57 * call to RCS_parse when necessary, but Checkin() isn't called
58 * if the RCS file hasn't already been parsed in one of the
61 assert (finfo->rcs != NULL);
63 switch (RCS_checkin (finfo->rcs, finfo->file, message, rev,
66 case 0: /* everything normal */
68 /* The checkin succeeded. If checking the file out again
69 would not cause any changes, we are done. Otherwise,
70 we need to check out the file, which will change the
71 modification time of the file.
73 The only way checking out the file could cause any
74 changes is if the file contains RCS keywords. So we if
75 we are not expanding RCS keywords, we are done. */
77 if (strcmp (options, "-V4") == 0) /* upgrade to V5 now */
80 /* FIXME: If PreservePermissions is on, RCS_cmp_file is
81 going to call RCS_checkout into a temporary file
82 anyhow. In that case, it would be more efficient to
83 call RCS_checkout here, compare the resulting files
84 using xcmp, and rename if necessary. I think this
85 should be fixed in RCS_cmp_file. */
86 if( ( ! preserve_perms
88 && ( strcmp( options, "-ko" ) == 0
89 || strcmp( options, "-kb" ) == 0 ) )
90 || RCS_cmp_file( finfo->rcs, rev, (char **)NULL, (char *)NULL,
91 options, finfo->file ) == 0 )
93 /* The existing file is correct. We don't have to do
99 /* The existing file is incorrect. We need to check
100 out the correct file contents. */
101 if (RCS_checkout (finfo->rcs, finfo->file, rev, (char *) NULL,
102 options, RUN_TTY, (RCSCHECKOUTPROC) NULL,
104 error (1, 0, "failed when checking out new copy of %s",
106 xchmod (finfo->file, 1);
110 wrap_fromcvs_process_file (finfo->file);
113 * If we want read-only files, muck the permissions here, before
114 * getting the file time-stamp.
116 if (!cvswrite || fileattr_get (finfo->file, "_watched"))
117 xchmod (finfo->file, 0);
119 /* Re-register with the new data. */
120 vers = Version_TS (finfo, NULL, tag, NULL, 1, set_time);
121 if (strcmp (vers->options, "-V4") == 0)
122 vers->options[0] = '\0';
123 Register (finfo->entries, finfo->file, vers->vn_rcs, vers->ts_user,
124 vers->options, vers->tag, vers->date, (char *) 0);
125 history_write (type, NULL, vers->vn_rcs,
126 finfo->file, finfo->repository);
129 if (unlink_file_dir (tocvsPath) < 0)
130 error (0, errno, "cannot remove %s", tocvsPath);
134 case -1: /* fork failed */
136 if (unlink_file_dir (tocvsPath) < 0)
137 error (0, errno, "cannot remove %s", tocvsPath);
140 error (1, errno, "could not check in %s -- fork failed",
144 default: /* ci failed */
146 /* The checkin failed, for some unknown reason, so we
147 print an error, and return an error. We assume that
148 the original file has not been touched. */
150 if (unlink_file_dir (tocvsPath) < 0)
151 error (0, errno, "cannot remove %s", tocvsPath);
154 error (0, 0, "could not check in %s", finfo->fullname);
159 * When checking in a specific revision, we may have locked the wrong
160 * branch, so to be sure, we do an extra unlock here before
165 (void) RCS_unlock (finfo->rcs, NULL, 1);
166 RCS_rewrite (finfo->rcs, NULL, NULL);
169 #ifdef SERVER_SUPPORT
173 /* Need to update the checked out file on the client side. */
174 server_updated (finfo, vers, SERVER_UPDATED,
175 (mode_t) -1, (unsigned char *) NULL,
176 (struct buffer *) NULL);
178 server_checked_in (finfo->file, finfo->update_dir, finfo->repository);
182 mark_up_to_date (finfo->file);