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 1.4 kit.
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.
23 Checkin (type, file, update_dir, repository,
24 rcs, rev, tag, options, message, entries)
41 char *tocvsPath = NULL;
43 fullname = xmalloc (strlen (update_dir) + strlen (file) + 10);
44 if (update_dir[0] == '\0')
45 strcpy (fullname, file);
47 sprintf (fullname, "%s/%s", update_dir, file);
49 (void) printf ("Checking in %s;\n", fullname);
50 (void) sprintf (fname, "%s/%s%s", CVSADM, CVSPREFIX, file);
53 * Move the user file to a backup file, so as to preserve its
54 * modification times, then place a copy back in the original file name
55 * for the checkin and checkout.
58 tocvsPath = wrap_tocvs_process_file (fullname);
64 copy_file (tocvsPath, fname);
65 if (unlink_file_dir (file) < 0)
66 if (! existence_error (errno))
67 error (1, errno, "cannot remove %s", file);
68 copy_file (tocvsPath, file);
72 copy_file (file, fname);
76 switch (RCS_checkin (rcs, NULL, message, rev, 0, 0))
78 case 0: /* everything normal */
81 * The checkin succeeded, so now check the new file back out and
82 * see if it matches exactly with the one we checked in. If it
83 * does, just move the original user file back, thus preserving
84 * the modes; otherwise, we have no recourse but to leave the
85 * newly checkout file as the user file and remove the old
89 if (strcmp (options, "-V4") == 0) /* upgrade to V5 now */
92 /* FIXME: should be checking for errors. */
93 (void) RCS_checkout (rcs, "", rev, options, RUN_TTY, 0, 0);
96 if (xcmp (file, fname) == 0)
98 rename_file (fname, file);
99 /* the time was correct, so leave it alone */
104 if (unlink_file (fname) < 0)
105 error (0, errno, "cannot remove %s", fname);
106 /* sync up with the time from the RCS file */
110 wrap_fromcvs_process_file (file);
113 * If we want read-only files, muck the permissions here, before
114 * getting the file time-stamp.
116 if (cvswrite == FALSE || fileattr_get (file, "_watched"))
119 /* re-register with the new data */
120 vers = Version_TS (repository, (char *) NULL, tag, (char *) NULL,
121 file, 1, set_time, entries, (RCSNode *) NULL);
122 if (strcmp (vers->options, "-V4") == 0)
123 vers->options[0] = '\0';
124 Register (entries, file, vers->vn_rcs, vers->ts_user,
125 vers->options, vers->tag, vers->date, (char *) 0);
126 history_write (type, (char *) 0, vers->vn_rcs, file, repository);
130 if (unlink_file_dir (tocvsPath) < 0)
131 error (0, errno, "cannot remove %s", tocvsPath);
135 case -1: /* fork failed */
137 if (unlink_file_dir (tocvsPath) < 0)
138 error (0, errno, "cannot remove %s", tocvsPath);
141 error (1, errno, "could not check in %s -- fork failed",
145 default: /* ci failed */
148 * The checkin failed, for some unknown reason, so we restore the
149 * original user file, print an error, and return an error
152 if (unlink_file_dir (tocvsPath) < 0)
153 error (0, errno, "cannot remove %s", tocvsPath);
157 rename_file (fname, file);
158 error (0, 0, "could not check in %s", fullname);
164 * When checking in a specific revision, we may have locked the wrong
165 * branch, so to be sure, we do an extra unlock here before
170 (void) RCS_unlock (rcs, NULL, 1);
173 #ifdef SERVER_SUPPORT
177 /* Need to update the checked out file on the client side. */
178 server_updated (file, update_dir, repository, SERVER_UPDATED,
181 server_checked_in (file, update_dir, repository);
185 mark_up_to_date (file);