Annotation of src/usr.bin/cvs/checkout.c, Revision 1.149
1.149 ! tobias 1: /* $OpenBSD: checkout.c,v 1.148 2008/06/10 20:30:17 joris Exp $ */
1.1 jfb 2: /*
1.53 joris 3: * Copyright (c) 2006 Joris Vink <joris@openbsd.org>
1.1 jfb 4: *
1.53 joris 5: * Permission to use, copy, modify, and distribute this software for any
6: * purpose with or without fee is hereby granted, provided that the above
7: * copyright notice and this permission notice appear in all copies.
1.1 jfb 8: *
1.53 joris 9: * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
10: * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
11: * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
12: * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
13: * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
14: * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
15: * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
1.1 jfb 16: */
17:
1.92 otto 18: #include <sys/param.h>
19: #include <sys/dirent.h>
20: #include <sys/stat.h>
1.117 tobias 21: #include <sys/time.h>
1.92 otto 22:
23: #include <errno.h>
24: #include <fcntl.h>
1.100 tobias 25: #include <libgen.h>
1.130 xsa 26: #include <stdlib.h>
1.92 otto 27: #include <string.h>
1.149 ! tobias 28: #include <time.h>
1.92 otto 29: #include <unistd.h>
1.1 jfb 30:
31: #include "cvs.h"
1.53 joris 32: #include "diff.h"
1.66 joris 33: #include "remote.h"
1.72 joris 34:
1.61 xsa 35: static void checkout_check_repository(int, char **);
1.113 tobias 36: static int checkout_classify(const char *, const char *);
1.53 joris 37: static void checkout_repository(const char *, const char *);
1.14 joris 38:
1.101 joris 39: extern int print_stdout;
1.54 joris 40: extern int prune_dirs;
1.57 joris 41: extern int build_dirs;
1.54 joris 42:
1.78 xsa 43: static int flags = CR_REPO | CR_RECURSE_DIRS;
1.132 tobias 44: static int Aflag = 0;
1.120 joris 45: static char *dflag = NULL;
1.125 tobias 46: static char *koptstr = NULL;
1.133 joris 47: static char *dateflag = NULL;
1.78 xsa 48:
1.127 joris 49: static int nflag = 0;
50:
1.133 joris 51: char *checkout_target_dir = NULL;
1.136 joris 52: time_t cvs_specified_date = -1;
1.131 tobias 53:
1.22 jfb 54: struct cvs_cmd cvs_cmd_checkout = {
1.112 tobias 55: CVS_OP_CHECKOUT, CVS_USE_WDIR, "checkout",
1.22 jfb 56: { "co", "get" },
1.53 joris 57: "Checkout a working copy of a repository",
1.33 xsa 58: "[-AcflNnPpRs] [-D date | -r tag] [-d dir] [-j rev] [-k mode] "
1.22 jfb 59: "[-t id] module ...",
1.77 xsa 60: "AcD:d:fj:k:lNnPpRr:st:",
1.59 joris 61: NULL,
62: cvs_checkout
63: };
64:
65: struct cvs_cmd cvs_cmd_export = {
1.112 tobias 66: CVS_OP_EXPORT, CVS_USE_WDIR, "export",
1.59 joris 67: { "exp", "ex" },
68: "Export sources from CVS, similar to checkout",
1.61 xsa 69: "[-flNnR] [-d dir] [-k mode] -D date | -r rev module ...",
70: "D:d:k:flNnRr:",
1.22 jfb 71: NULL,
1.61 xsa 72: cvs_export
1.33 xsa 73: };
74:
1.53 joris 75: int
76: cvs_checkout(int argc, char **argv)
1.1 jfb 77: {
1.78 xsa 78: int ch;
1.13 jfb 79:
1.53 joris 80: while ((ch = getopt(argc, argv, cvs_cmd_checkout.cmd_opts)) != -1) {
1.1 jfb 81: switch (ch) {
1.76 xsa 82: case 'A':
1.132 tobias 83: Aflag = 1;
84: if (koptstr == NULL)
85: reset_option = 1;
86: if (cvs_specified_tag == NULL)
87: reset_tag = 1;
1.76 xsa 88: break;
1.129 joris 89: case 'c':
90: cvs_modules_list();
91: exit(0);
1.131 tobias 92: case 'D':
1.133 joris 93: dateflag = optarg;
94: cvs_specified_date = cvs_date_parse(dateflag);
1.131 tobias 95: break;
1.120 joris 96: case 'd':
97: if (dflag != NULL)
98: fatal("-d specified two or more times");
99: dflag = optarg;
1.133 joris 100: checkout_target_dir = dflag;
1.120 joris 101: break;
1.142 joris 102: case 'j':
103: if (cvs_join_rev1 == NULL)
104: cvs_join_rev1 = optarg;
105: else if (cvs_join_rev2 == NULL)
106: cvs_join_rev2 = optarg;
107: else
108: fatal("too many -j options");
109: break;
1.125 tobias 110: case 'k':
1.132 tobias 111: reset_option = 0;
1.125 tobias 112: koptstr = optarg;
113: kflag = rcs_kflag_get(koptstr);
114: if (RCS_KWEXP_INVAL(kflag)) {
115: cvs_log(LP_ERR,
1.144 tobias 116: "invalid RCS keyword expansion mode");
1.125 tobias 117: fatal("%s", cvs_cmd_add.cmd_synopsis);
118: }
119: break;
1.77 xsa 120: case 'l':
121: flags &= ~CR_RECURSE_DIRS;
122: break;
1.104 joris 123: case 'N':
124: break;
1.127 joris 125: case 'n':
126: nflag = 1;
127: break;
1.54 joris 128: case 'P':
129: prune_dirs = 1;
1.77 xsa 130: break;
1.101 joris 131: case 'p':
1.112 tobias 132: cmdp->cmd_flags &= ~CVS_USE_WDIR;
1.101 joris 133: print_stdout = 1;
134: cvs_noexec = 1;
1.127 joris 135: nflag = 1;
1.101 joris 136: break;
1.77 xsa 137: case 'R':
1.110 tobias 138: flags |= CR_RECURSE_DIRS;
1.54 joris 139: break;
1.93 niallo 140: case 'r':
1.132 tobias 141: reset_tag = 0;
1.97 joris 142: cvs_specified_tag = optarg;
1.93 niallo 143: break;
1.1 jfb 144: default:
1.53 joris 145: fatal("%s", cvs_cmd_checkout.cmd_synopsis);
1.1 jfb 146: }
147: }
148:
149: argc -= optind;
150: argv += optind;
151:
1.53 joris 152: if (argc == 0)
153: fatal("%s", cvs_cmd_checkout.cmd_synopsis);
1.22 jfb 154:
1.61 xsa 155: checkout_check_repository(argc, argv);
156:
157: return (0);
158: }
159:
160: int
161: cvs_export(int argc, char **argv)
162: {
1.78 xsa 163: int ch;
1.61 xsa 164:
165: prune_dirs = 1;
166:
167: while ((ch = getopt(argc, argv, cvs_cmd_export.cmd_opts)) != -1) {
168: switch (ch) {
1.125 tobias 169: case 'k':
170: koptstr = optarg;
171: kflag = rcs_kflag_get(koptstr);
172: if (RCS_KWEXP_INVAL(kflag)) {
173: cvs_log(LP_ERR,
1.144 tobias 174: "invalid RCS keyword expansion mode");
1.125 tobias 175: fatal("%s", cvs_cmd_add.cmd_synopsis);
176: }
177: break;
1.61 xsa 178: case 'l':
179: flags &= ~CR_RECURSE_DIRS;
180: break;
181: case 'R':
1.110 tobias 182: flags |= CR_RECURSE_DIRS;
1.98 xsa 183: break;
184: case 'r':
185: cvs_specified_tag = optarg;
1.61 xsa 186: break;
187: default:
188: fatal("%s", cvs_cmd_export.cmd_synopsis);
189: }
190: }
191:
192: argc -= optind;
193: argv += optind;
194:
1.108 tobias 195: if (cvs_specified_tag == NULL)
196: fatal("must specify a tag or date");
197:
1.61 xsa 198: if (argc == 0)
199: fatal("%s", cvs_cmd_export.cmd_synopsis);
200:
201: checkout_check_repository(argc, argv);
202:
203: return (0);
204: }
205:
206: static void
207: checkout_check_repository(int argc, char **argv)
208: {
1.67 xsa 209: int i;
1.123 joris 210: char *wdir, *d;
1.79 joris 211: struct cvs_recursion cr;
1.119 joris 212: struct module_checkout *mc;
1.123 joris 213: struct cvs_ignpat *ip;
214: struct cvs_filelist *fl, *nxt;
215: char repo[MAXPATHLEN], fpath[MAXPATHLEN], *f[1];
1.79 joris 216:
1.102 tobias 217: build_dirs = print_stdout ? 0 : 1;
218:
1.79 joris 219: if (current_cvsroot->cr_method != CVS_METHOD_LOCAL) {
220: cvs_client_connect_to_server();
221:
1.97 joris 222: if (cvs_specified_tag != NULL)
223: cvs_client_send_request("Argument -r%s",
224: cvs_specified_tag);
1.132 tobias 225: if (Aflag)
1.79 joris 226: cvs_client_send_request("Argument -A");
1.133 joris 227:
228: if (dateflag != NULL)
229: cvs_client_send_request("Argument -D%s", dateflag);
1.122 joris 230:
1.125 tobias 231: if (kflag)
232: cvs_client_send_request("Argument -k%s", koptstr);
233:
1.122 joris 234: if (dflag != NULL)
235: cvs_client_send_request("Argument -d%s", dflag);
1.80 xsa 236:
237: if (!(flags & CR_RECURSE_DIRS))
238: cvs_client_send_request("Argument -l");
1.79 joris 239:
240: if (cvs_cmdop == CVS_OP_CHECKOUT && prune_dirs == 1)
241: cvs_client_send_request("Argument -P");
242:
1.101 joris 243: if (print_stdout == 1)
244: cvs_client_send_request("Argument -p");
245:
1.127 joris 246: if (nflag == 1)
247: cvs_client_send_request("Argument -n");
248:
1.79 joris 249: cr.enterdir = NULL;
250: cr.leavedir = NULL;
1.103 tobias 251: if (print_stdout)
252: cr.fileproc = NULL;
253: else
254: cr.fileproc = cvs_client_sendfile;
255:
256: flags &= ~CR_REPO;
1.79 joris 257: cr.flags = flags;
258:
1.108 tobias 259: if (cvs_cmdop != CVS_OP_EXPORT)
260: cvs_file_run(argc, argv, &cr);
1.79 joris 261:
262: cvs_client_send_files(argv, argc);
263: cvs_client_senddir(".");
264:
265: cvs_client_send_request("%s",
266: (cvs_cmdop == CVS_OP_CHECKOUT) ? "co" : "export");
267:
268: cvs_client_get_responses();
269:
270: return;
271: }
1.104 joris 272:
1.53 joris 273: for (i = 0; i < argc; i++) {
1.119 joris 274: mc = cvs_module_lookup(argv[i]);
275: current_module = mc;
1.116 joris 276:
1.123 joris 277: TAILQ_FOREACH(fl, &(mc->mc_ignores), flist)
278: cvs_file_ignore(fl->file_path, &checkout_ign_pats);
1.13 jfb 279:
1.123 joris 280: TAILQ_FOREACH(fl, &(mc->mc_modules), flist) {
1.139 tobias 281: module_repo_root = NULL;
282:
1.123 joris 283: (void)xsnprintf(repo, sizeof(repo), "%s/%s",
284: current_cvsroot->cr_dir, fl->file_path);
1.121 joris 285:
1.123 joris 286: if (!(mc->mc_flags & MODULE_ALIAS) || dflag != NULL)
1.139 tobias 287: module_repo_root = xstrdup(fl->file_path);
1.123 joris 288:
289: if (mc->mc_flags & MODULE_NORECURSE)
290: flags &= ~CR_RECURSE_DIRS;
291:
292: if (dflag != NULL)
293: wdir = dflag;
1.124 joris 294: else if (mc->mc_flags & MODULE_ALIAS)
295: wdir = fl->file_path;
1.123 joris 296: else
1.124 joris 297: wdir = mc->mc_name;
1.123 joris 298:
299: switch (checkout_classify(repo, fl->file_path)) {
300: case CVS_FILE:
301: cr.fileproc = cvs_update_local;
302: cr.flags = flags;
303:
304: if (!(mc->mc_flags & MODULE_ALIAS)) {
305: module_repo_root =
1.139 tobias 306: xstrdup(dirname(fl->file_path));
1.123 joris 307: d = wdir;
308: (void)xsnprintf(fpath, sizeof(fpath),
309: "%s/%s", d,
310: basename(fl->file_path));
311: } else {
312: d = dirname(wdir);
313: strlcpy(fpath, fl->file_path,
314: sizeof(fpath));
315: }
316:
317: if (build_dirs == 1)
318: cvs_mkpath(d, cvs_specified_tag);
319:
320: f[0] = fpath;
321: cvs_file_run(1, f, &cr);
322: break;
323: case CVS_DIR:
324: if (build_dirs == 1)
325: cvs_mkpath(wdir, cvs_specified_tag);
326: checkout_repository(repo, wdir);
327: break;
328: default:
329: break;
330: }
1.126 joris 331:
1.127 joris 332: if (nflag != 1 && mc->mc_prog != NULL &&
1.128 joris 333: mc->mc_flags & MODULE_RUN_ON_CHECKOUT)
1.147 joris 334: cvs_exec(mc->mc_prog, NULL, 0);
1.139 tobias 335:
336: if (module_repo_root != NULL)
337: xfree(module_repo_root);
1.123 joris 338: }
1.119 joris 339:
1.123 joris 340: if (mc->mc_canfree == 1) {
341: for (fl = TAILQ_FIRST(&(mc->mc_modules));
342: fl != TAILQ_END(&(mc->mc_modules)); fl = nxt) {
343: nxt = TAILQ_NEXT(fl, flist);
344: TAILQ_REMOVE(&(mc->mc_modules), fl, flist);
345: xfree(fl->file_path);
346: xfree(fl);
347: }
348: }
1.120 joris 349:
1.123 joris 350: while ((ip = TAILQ_FIRST(&checkout_ign_pats)) != NULL) {
351: TAILQ_REMOVE(&checkout_ign_pats, ip, ip_list);
352: xfree(ip);
1.113 tobias 353: }
1.119 joris 354:
355: xfree(mc);
1.113 tobias 356: }
357: }
1.100 tobias 358:
1.113 tobias 359: static int
360: checkout_classify(const char *repo, const char *arg)
361: {
362: char *d, *f, fpath[MAXPATHLEN];
363: struct stat sb;
364:
365: if (stat(repo, &sb) == 0) {
1.123 joris 366: if (S_ISDIR(sb.st_mode))
367: return CVS_DIR;
1.113 tobias 368: }
1.97 joris 369:
1.113 tobias 370: d = dirname(repo);
371: f = basename(repo);
372:
373: (void)xsnprintf(fpath, sizeof(fpath), "%s/%s%s", d, f, RCS_FILE_EXT);
374: if (stat(fpath, &sb) == 0) {
375: if (!S_ISREG(sb.st_mode)) {
376: cvs_log(LP_ERR, "ignoring %s: not a regular file", arg);
377: return 0;
378: }
379: return CVS_FILE;
1.33 xsa 380: }
1.113 tobias 381:
382: (void)xsnprintf(fpath, sizeof(fpath), "%s/%s/%s%s",
383: d, CVS_PATH_ATTIC, f, RCS_FILE_EXT);
384: if (stat(fpath, &sb) == 0) {
385: if (!S_ISREG(sb.st_mode)) {
386: cvs_log(LP_ERR, "ignoring %s: not a regular file", arg);
387: return 0;
388: }
389: return CVS_FILE;
390: }
391:
392: cvs_log(LP_ERR, "cannot find module `%s' - ignored", arg);
393: return 0;
1.14 joris 394: }
1.9 jfb 395:
1.53 joris 396: static void
397: checkout_repository(const char *repobase, const char *wdbase)
1.14 joris 398: {
1.53 joris 399: struct cvs_flisthead fl, dl;
400: struct cvs_recursion cr;
401:
402: TAILQ_INIT(&fl);
403: TAILQ_INIT(&dl);
1.94 joris 404:
1.99 xsa 405: cvs_history_add((cvs_cmdop == CVS_OP_CHECKOUT) ?
406: CVS_HISTORY_CHECKOUT : CVS_HISTORY_EXPORT, NULL, wdbase);
1.41 joris 407:
1.112 tobias 408: if (print_stdout) {
409: cr.enterdir = NULL;
410: cr.leavedir = NULL;
411: } else {
412: cr.enterdir = cvs_update_enterdir;
1.118 tobias 413: cr.leavedir = prune_dirs ? cvs_update_leavedir : NULL;
1.112 tobias 414: }
1.64 joris 415: cr.fileproc = cvs_update_local;
1.78 xsa 416: cr.flags = flags;
1.41 joris 417:
1.143 joris 418: cvs_repository_lock(repobase, 0);
1.111 tobias 419: cvs_repository_getdir(repobase, wdbase, &fl, &dl,
420: flags & CR_RECURSE_DIRS ? 1 : 0);
1.1 jfb 421:
1.53 joris 422: cvs_file_walklist(&fl, &cr);
423: cvs_file_freelist(&fl);
1.23 joris 424:
1.53 joris 425: cvs_repository_unlock(repobase);
1.23 joris 426:
1.53 joris 427: cvs_file_walklist(&dl, &cr);
428: cvs_file_freelist(&dl);
429: }
1.23 joris 430:
1.58 joris 431: void
1.105 joris 432: cvs_checkout_file(struct cvs_file *cf, RCSNUM *rnum, char *tag, int co_flags)
1.53 joris 433: {
1.148 joris 434: mode_t mode;
1.141 joris 435: int cf_kflag, exists, fd;
1.53 joris 436: time_t rcstime;
437: CVSENTRIES *ent;
438: struct timeval tv[2];
1.149 ! tobias 439: struct tm datetm;
1.87 joris 440: char *tosend;
1.135 xsa 441: char template[MAXPATHLEN], *entry;
1.115 xsa 442: char kbuf[8], sticky[CVS_REV_BUFSZ], rev[CVS_REV_BUFSZ];
1.96 xsa 443: char timebuf[CVS_TIME_BUFSZ], tbuf[CVS_TIME_BUFSZ];
1.22 jfb 444:
1.87 joris 445: exists = 0;
446: tosend = NULL;
1.104 joris 447:
448: if (!(co_flags & CO_REMOVE))
449: rcsnum_tostr(rnum, rev, sizeof(rev));
1.41 joris 450:
1.66 joris 451: cvs_log(LP_TRACE, "cvs_checkout_file(%s, %s, %d) -> %s",
1.78 xsa 452: cf->file_path, rev, co_flags,
1.66 joris 453: (cvs_server_active) ? "to client" : "to disk");
1.42 joris 454:
1.78 xsa 455: if (co_flags & CO_DUMP) {
1.106 tobias 456: rcs_rev_write_fd(cf->file_rcs, rnum, STDOUT_FILENO, 0);
1.65 reyk 457: return;
458: }
1.87 joris 459:
1.66 joris 460: if (cvs_server_active == 0) {
1.141 joris 461: (void)unlink(cf->file_path);
462:
1.87 joris 463: if (!(co_flags & CO_MERGE)) {
464: if (cf->fd != -1) {
465: exists = 1;
466: (void)close(cf->fd);
467: }
468:
1.141 joris 469: cf->fd = open(cf->file_path,
1.142 joris 470: O_CREAT | O_RDWR | O_TRUNC);
1.87 joris 471: if (cf->fd == -1)
472: fatal("cvs_checkout_file: open: %s",
473: strerror(errno));
474:
1.106 tobias 475: rcs_rev_write_fd(cf->file_rcs, rnum, cf->fd, 0);
1.87 joris 476: } else {
1.142 joris 477: cvs_merge_file(cf, (cvs_join_rev1 == NULL));
1.66 joris 478: }
479:
1.148 joris 480: mode = cf->file_rcs->rf_mode;
481: mode |= S_IWUSR;
482:
483: if (fchmod(cf->fd, mode) == -1)
1.66 joris 484: fatal("cvs_checkout_file: fchmod: %s", strerror(errno));
485:
1.87 joris 486: if ((exists == 0) && (cf->file_ent == NULL) &&
487: !(co_flags & CO_MERGE))
1.66 joris 488: rcstime = rcs_rev_getdate(cf->file_rcs, rnum);
1.84 joris 489: else
1.66 joris 490: time(&rcstime);
491:
492: tv[0].tv_sec = rcstime;
493: tv[0].tv_usec = 0;
494: tv[1] = tv[0];
495: if (futimes(cf->fd, tv) == -1)
496: fatal("cvs_checkout_file: futimes: %s",
497: strerror(errno));
1.53 joris 498: } else {
499: time(&rcstime);
1.41 joris 500: }
501:
1.149 ! tobias 502: gmtime_r(&rcstime, &datetm);
! 503: asctime_r(&datetm, tbuf);
1.107 tobias 504: tbuf[strcspn(tbuf, "\n")] = '\0';
1.58 joris 505:
1.78 xsa 506: if (co_flags & CO_MERGE) {
1.89 xsa 507: (void)xsnprintf(timebuf, sizeof(timebuf), "Result of merge+%s",
1.58 joris 508: tbuf);
509: } else {
510: strlcpy(timebuf, tbuf, sizeof(timebuf));
511: }
1.41 joris 512:
1.89 xsa 513: if (co_flags & CO_SETSTICKY)
1.105 joris 514: if (tag != NULL)
1.114 xsa 515: (void)xsnprintf(sticky, sizeof(sticky), "T%s", tag);
1.136 joris 516: else if (cvs_specified_date != -1) {
1.149 ! tobias 517: gmtime_r(&cvs_specified_date, &datetm);
1.138 xsa 518: (void)strftime(sticky, sizeof(sticky),
1.149 ! tobias 519: "D"CVS_DATE_FMT, &datetm);
1.134 tobias 520: } else
1.114 xsa 521: (void)xsnprintf(sticky, sizeof(sticky), "T%s", rev);
1.132 tobias 522: else if (!reset_tag && cf->file_ent != NULL &&
1.109 tobias 523: cf->file_ent->ce_tag != NULL)
1.114 xsa 524: (void)xsnprintf(sticky, sizeof(sticky), "T%s",
1.109 tobias 525: cf->file_ent->ce_tag);
1.89 xsa 526: else
1.114 xsa 527: sticky[0] = '\0';
1.60 joris 528:
1.85 xsa 529: kbuf[0] = '\0';
1.125 tobias 530: if (cf->file_rcs->rf_expand != NULL) {
531: cf_kflag = rcs_kflag_get(cf->file_rcs->rf_expand);
532: if (kflag || cf_kflag != RCS_KWEXP_DEFAULT)
533: (void)xsnprintf(kbuf, sizeof(kbuf),
534: "-k%s", cf->file_rcs->rf_expand);
1.132 tobias 535: } else if (!reset_option && cf->file_ent != NULL) {
1.85 xsa 536: if (cf->file_ent->ce_opts != NULL)
537: strlcpy(kbuf, cf->file_ent->ce_opts, sizeof(kbuf));
538: }
539:
1.135 xsa 540: entry = xmalloc(CVS_ENT_MAXLINELEN);
541: cvs_ent_line_str(cf->file_name, rev, timebuf, kbuf, sticky, 0, 0,
542: entry, CVS_ENT_MAXLINELEN);
1.41 joris 543:
1.66 joris 544: if (cvs_server_active == 0) {
1.108 tobias 545: if (!(co_flags & CO_REMOVE) && cvs_cmdop != CVS_OP_EXPORT) {
1.95 joris 546: ent = cvs_ent_open(cf->file_wd);
547: cvs_ent_add(ent, entry);
548: cvs_ent_close(ent, ENT_SYNC);
1.142 joris 549: cf->file_ent = cvs_ent_parse(entry);
1.135 xsa 550: xfree(entry);
1.95 joris 551: }
1.66 joris 552: } else {
1.87 joris 553: if (co_flags & CO_MERGE) {
1.141 joris 554: (void)unlink(cf->file_path);
1.142 joris 555: cvs_merge_file(cf, (cvs_join_rev1 == NULL));
1.87 joris 556: tosend = cf->file_path;
1.140 joris 557: fd = cf->fd;
1.87 joris 558: }
559:
1.78 xsa 560: if (co_flags & CO_COMMIT)
1.137 tobias 561: cvs_server_update_entry("Updated", cf);
1.87 joris 562: else if (co_flags & CO_MERGE)
563: cvs_server_update_entry("Merged", cf);
1.95 joris 564: else if (co_flags & CO_REMOVE)
565: cvs_server_update_entry("Removed", cf);
1.69 joris 566: else
567: cvs_server_update_entry("Updated", cf);
1.68 joris 568:
1.135 xsa 569: if (!(co_flags & CO_REMOVE)) {
1.95 joris 570: cvs_remote_output(entry);
1.135 xsa 571: xfree(entry);
1.66 joris 572:
1.87 joris 573: if (!(co_flags & CO_MERGE)) {
1.89 xsa 574: (void)xsnprintf(template, MAXPATHLEN,
1.87 joris 575: "%s/checkout.XXXXXXXXXX", cvs_tmpdir);
1.89 xsa 576:
1.140 joris 577: fd = rcs_rev_write_stmp(cf->file_rcs, rnum,
1.87 joris 578: template, 0);
1.148 joris 579:
580: mode = cf->file_rcs->rf_mode;
581: mode |= S_IWUSR;
582:
583: if (fchmod(fd, mode) == -1) {
584: cvs_log(LP_ERR,
585: "failed to set mode for %s",
586: cf->file_path);
587: }
588:
1.87 joris 589: tosend = template;
590: }
591:
1.140 joris 592: cvs_remote_send_file(tosend, fd);
1.87 joris 593:
594: if (!(co_flags & CO_MERGE)) {
1.140 joris 595: close(fd);
1.87 joris 596: (void)unlink(template);
597: cvs_worklist_run(&temp_files,
598: cvs_worklist_unlink);
599: }
1.68 joris 600: }
1.66 joris 601: }
1.1 jfb 602: }