Deleted Added
full compact
checkin.c (32785) checkin.c (34461)
1/*
2 * Copyright (c) 1992, Brian Berliner and Jeff Polk
3 * Copyright (c) 1989-1992, Brian Berliner
4 *
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.
7 *
8 * Check In

--- 15 unchanged lines hidden (view full) ---

24 int type;
25 struct file_info *finfo;
26 char *rcs;
27 char *rev;
28 char *tag;
29 char *options;
30 char *message;
31{
1/*
2 * Copyright (c) 1992, Brian Berliner and Jeff Polk
3 * Copyright (c) 1989-1992, Brian Berliner
4 *
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.
7 *
8 * Check In

--- 15 unchanged lines hidden (view full) ---

24 int type;
25 struct file_info *finfo;
26 char *rcs;
27 char *rev;
28 char *tag;
29 char *options;
30 char *message;
31{
32 char *fname;
33 Vers_TS *vers;
34 int set_time;
35 char *tocvsPath = NULL;
36
37 /* Hmm. This message goes to stdout and the "foo,v <-- foo"
38 message from "ci" goes to stderr. This doesn't make a whole
39 lot of sense, but making everything go to stdout can only be
40 gracefully achieved once RCS_checkin is librarified. */
41 cvs_output ("Checking in ", 0);
42 cvs_output (finfo->fullname, 0);
43 cvs_output (";\n", 0);
44
32 Vers_TS *vers;
33 int set_time;
34 char *tocvsPath = NULL;
35
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);
43
45 fname = xmalloc (strlen (finfo->file) + 80);
46 (void) sprintf (fname, "%s/%s%s", CVSADM, CVSPREFIX, finfo->file);
47
48 /*
49 * Move the user file to a backup file, so as to preserve its
50 * modification times, then place a copy back in the original file name
51 * for the checkin and checkout.
52 */
53
54 tocvsPath = wrap_tocvs_process_file (finfo->file);
44 tocvsPath = wrap_tocvs_process_file (finfo->file);
55
56 if (!noexec)
57 {
58 if (tocvsPath)
59 {
45 if (!noexec)
46 {
47 if (tocvsPath)
48 {
60 copy_file (tocvsPath, fname);
61 if (unlink_file_dir (finfo->file) < 0)
62 if (! existence_error (errno))
63 error (1, errno, "cannot remove %s", finfo->fullname);
49 if (unlink_file_dir (finfo->file) < 0)
50 if (! existence_error (errno))
51 error (1, errno, "cannot remove %s", finfo->fullname);
64 copy_file (tocvsPath, finfo->file);
52 rename_file (tocvsPath, finfo->file);
65 }
53 }
66 else
67 {
68 copy_file (finfo->file, fname);
69 }
70 }
71
72 if (finfo->rcs == NULL)
73 finfo->rcs = RCS_parse (finfo->file, finfo->repository);
74
54 }
55
56 if (finfo->rcs == NULL)
57 finfo->rcs = RCS_parse (finfo->file, finfo->repository);
58
75 switch (RCS_checkin (finfo->rcs, NULL, message, rev, 0))
59 switch (RCS_checkin (finfo->rcs, NULL, message, rev, RCS_FLAGS_KEEPFILE))
76 {
77 case 0: /* everything normal */
78
60 {
61 case 0: /* everything normal */
62
79 /*
80 * The checkin succeeded, so now check the new file back out and
81 * see if it matches exactly with the one we checked in. If it
82 * does, just move the original user file back, thus preserving
83 * the modes; otherwise, we have no recourse but to leave the
84 * newly checkout file as the user file and remove the old
85 * original user file.
86 */
63 /* The checkin succeeded. If checking the file out again
64 would not cause any changes, we are done. Otherwise,
65 we need to check out the file, which will change the
66 modification time of the file.
87
67
68 The only way checking out the file could cause any
69 changes is if the file contains RCS keywords. So we if
70 we are not expanding RCS keywords, we are done. */
71
88 if (strcmp (options, "-V4") == 0) /* upgrade to V5 now */
89 options[0] = '\0';
90
72 if (strcmp (options, "-V4") == 0) /* upgrade to V5 now */
73 options[0] = '\0';
74
91 /* FIXME: should be checking for errors. */
92 (void) RCS_checkout (finfo->rcs, finfo->file, rev,
93 (char *) NULL, options, RUN_TTY,
94 (RCSCHECKOUTPROC) NULL, (void *) NULL);
95
96 xchmod (finfo->file, 1);
97 if (xcmp (finfo->file, fname) == 0)
75 /* FIXME: If PreservePermissions is on, RCS_cmp_file is
76 going to call RCS_checkout into a temporary file
77 anyhow. In that case, it would be more efficient to
78 call RCS_checkout here, compare the resulting files
79 using xcmp, and rename if necessary. I think this
80 should be fixed in RCS_cmp_file. */
81 if ((! preserve_perms
82 && options != NULL
83 && (strcmp (options, "-ko") == 0
84 || strcmp (options, "-kb") == 0))
85 || RCS_cmp_file (finfo->rcs, rev, options, finfo->file) == 0)
98 {
86 {
99 rename_file (fname, finfo->file);
100 /* the time was correct, so leave it alone */
87 /* The existing file is correct. We don't have to do
88 anything. */
101 set_time = 0;
102 }
103 else
104 {
89 set_time = 0;
90 }
91 else
92 {
105 if (unlink_file (fname) < 0)
106 error (0, errno, "cannot remove %s", fname);
107 /* sync up with the time from the RCS file */
93 /* The existing file is incorrect. We need to check
94 out the correct file contents. */
95 if (RCS_checkout (finfo->rcs, finfo->file, rev, (char *) NULL,
96 options, RUN_TTY, (RCSCHECKOUTPROC) NULL,
97 (void *) NULL) != 0)
98 error (1, 0, "failed when checking out new copy of %s",
99 finfo->fullname);
100 xchmod (finfo->file, 1);
108 set_time = 1;
109 }
110
111 wrap_fromcvs_process_file (finfo->file);
112
113 /*
114 * If we want read-only files, muck the permissions here, before
115 * getting the file time-stamp.

--- 19 unchanged lines hidden (view full) ---

135 case -1: /* fork failed */
136 if (tocvsPath)
137 if (unlink_file_dir (tocvsPath) < 0)
138 error (0, errno, "cannot remove %s", tocvsPath);
139
140 if (!noexec)
141 error (1, errno, "could not check in %s -- fork failed",
142 finfo->fullname);
101 set_time = 1;
102 }
103
104 wrap_fromcvs_process_file (finfo->file);
105
106 /*
107 * If we want read-only files, muck the permissions here, before
108 * getting the file time-stamp.

--- 19 unchanged lines hidden (view full) ---

128 case -1: /* fork failed */
129 if (tocvsPath)
130 if (unlink_file_dir (tocvsPath) < 0)
131 error (0, errno, "cannot remove %s", tocvsPath);
132
133 if (!noexec)
134 error (1, errno, "could not check in %s -- fork failed",
135 finfo->fullname);
143 free (fname);
144 return (1);
145
146 default: /* ci failed */
147
136 return (1);
137
138 default: /* ci failed */
139
148 /*
149 * The checkin failed, for some unknown reason, so we restore the
150 * original user file, print an error, and return an error
151 */
140 /* The checkin failed, for some unknown reason, so we
141 print an error, and return an error. We assume that
142 the original file has not been touched. */
152 if (tocvsPath)
153 if (unlink_file_dir (tocvsPath) < 0)
154 error (0, errno, "cannot remove %s", tocvsPath);
155
156 if (!noexec)
143 if (tocvsPath)
144 if (unlink_file_dir (tocvsPath) < 0)
145 error (0, errno, "cannot remove %s", tocvsPath);
146
147 if (!noexec)
157 {
158 rename_file (fname, finfo->file);
159 error (0, 0, "could not check in %s", finfo->fullname);
148 error (0, 0, "could not check in %s", finfo->fullname);
160 }
161 free (fname);
162 return (1);
163 }
164
165 /*
166 * When checking in a specific revision, we may have locked the wrong
167 * branch, so to be sure, we do an extra unlock here before
168 * returning.
169 */

--- 4 unchanged lines hidden (view full) ---

174 }
175
176#ifdef SERVER_SUPPORT
177 if (server_active)
178 {
179 if (set_time)
180 /* Need to update the checked out file on the client side. */
181 server_updated (finfo, vers, SERVER_UPDATED,
149 return (1);
150 }
151
152 /*
153 * When checking in a specific revision, we may have locked the wrong
154 * branch, so to be sure, we do an extra unlock here before
155 * returning.
156 */

--- 4 unchanged lines hidden (view full) ---

161 }
162
163#ifdef SERVER_SUPPORT
164 if (server_active)
165 {
166 if (set_time)
167 /* Need to update the checked out file on the client side. */
168 server_updated (finfo, vers, SERVER_UPDATED,
182 NULL, NULL);
169 (mode_t) -1, (unsigned char *) NULL,
170 (struct buffer *) NULL);
183 else
184 server_checked_in (finfo->file, finfo->update_dir, finfo->repository);
185 }
186 else
187#endif
188 mark_up_to_date (finfo->file);
189
190 freevers_ts (&vers);
171 else
172 server_checked_in (finfo->file, finfo->update_dir, finfo->repository);
173 }
174 else
175#endif
176 mark_up_to_date (finfo->file);
177
178 freevers_ts (&vers);
191 free (fname);
192 return (0);
193}
179 return (0);
180}