Annotation of src/usr.bin/cvs/checkout.c, Revision 1.167
1.167 ! ray 1: /* $OpenBSD: checkout.c,v 1.166 2010/07/23 21:46:05 ray 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.160 joris 51: static char lastwd[MAXPATHLEN];
1.133 joris 52: char *checkout_target_dir = NULL;
1.151 joris 53:
1.136 joris 54: time_t cvs_specified_date = -1;
1.154 tobias 55: time_t cvs_directory_date = -1;
1.151 joris 56: int disable_fast_checkout = 0;
1.131 tobias 57:
1.22 jfb 58: struct cvs_cmd cvs_cmd_checkout = {
1.112 tobias 59: CVS_OP_CHECKOUT, CVS_USE_WDIR, "checkout",
1.22 jfb 60: { "co", "get" },
1.53 joris 61: "Checkout a working copy of a repository",
1.33 xsa 62: "[-AcflNnPpRs] [-D date | -r tag] [-d dir] [-j rev] [-k mode] "
1.22 jfb 63: "[-t id] module ...",
1.77 xsa 64: "AcD:d:fj:k:lNnPpRr:st:",
1.59 joris 65: NULL,
66: cvs_checkout
67: };
68:
69: struct cvs_cmd cvs_cmd_export = {
1.112 tobias 70: CVS_OP_EXPORT, CVS_USE_WDIR, "export",
1.59 joris 71: { "exp", "ex" },
72: "Export sources from CVS, similar to checkout",
1.61 xsa 73: "[-flNnR] [-d dir] [-k mode] -D date | -r rev module ...",
74: "D:d:k:flNnRr:",
1.22 jfb 75: NULL,
1.61 xsa 76: cvs_export
1.33 xsa 77: };
78:
1.53 joris 79: int
80: cvs_checkout(int argc, char **argv)
1.1 jfb 81: {
1.78 xsa 82: int ch;
1.13 jfb 83:
1.53 joris 84: while ((ch = getopt(argc, argv, cvs_cmd_checkout.cmd_opts)) != -1) {
1.1 jfb 85: switch (ch) {
1.76 xsa 86: case 'A':
1.132 tobias 87: Aflag = 1;
88: if (koptstr == NULL)
89: reset_option = 1;
90: if (cvs_specified_tag == NULL)
91: reset_tag = 1;
1.76 xsa 92: break;
1.129 joris 93: case 'c':
94: cvs_modules_list();
95: exit(0);
1.131 tobias 96: case 'D':
1.133 joris 97: dateflag = optarg;
1.167 ! ray 98: if ((cvs_specified_date = date_parse(dateflag)) == -1)
! 99: fatal("invalid date: %s", dateflag);
1.154 tobias 100: reset_tag = 0;
1.131 tobias 101: break;
1.120 joris 102: case 'd':
103: if (dflag != NULL)
104: fatal("-d specified two or more times");
105: dflag = optarg;
1.133 joris 106: checkout_target_dir = dflag;
1.151 joris 107:
108: if (cvs_server_active == 1)
109: disable_fast_checkout = 1;
1.120 joris 110: break;
1.142 joris 111: case 'j':
112: if (cvs_join_rev1 == NULL)
113: cvs_join_rev1 = optarg;
114: else if (cvs_join_rev2 == NULL)
115: cvs_join_rev2 = optarg;
116: else
117: fatal("too many -j options");
118: break;
1.125 tobias 119: case 'k':
1.132 tobias 120: reset_option = 0;
1.125 tobias 121: koptstr = optarg;
122: kflag = rcs_kflag_get(koptstr);
123: if (RCS_KWEXP_INVAL(kflag)) {
124: cvs_log(LP_ERR,
1.144 tobias 125: "invalid RCS keyword expansion mode");
1.165 sthen 126: fatal("%s", cvs_cmd_checkout.cmd_synopsis);
1.125 tobias 127: }
128: break;
1.77 xsa 129: case 'l':
130: flags &= ~CR_RECURSE_DIRS;
131: break;
1.104 joris 132: case 'N':
133: break;
1.127 joris 134: case 'n':
135: nflag = 1;
136: break;
1.54 joris 137: case 'P':
138: prune_dirs = 1;
1.77 xsa 139: break;
1.101 joris 140: case 'p':
1.112 tobias 141: cmdp->cmd_flags &= ~CVS_USE_WDIR;
1.101 joris 142: print_stdout = 1;
143: cvs_noexec = 1;
1.127 joris 144: nflag = 1;
1.101 joris 145: break;
1.77 xsa 146: case 'R':
1.110 tobias 147: flags |= CR_RECURSE_DIRS;
1.54 joris 148: break;
1.93 niallo 149: case 'r':
1.132 tobias 150: reset_tag = 0;
1.97 joris 151: cvs_specified_tag = optarg;
1.93 niallo 152: break;
1.1 jfb 153: default:
1.53 joris 154: fatal("%s", cvs_cmd_checkout.cmd_synopsis);
1.1 jfb 155: }
156: }
157:
158: argc -= optind;
159: argv += optind;
160:
1.53 joris 161: if (argc == 0)
162: fatal("%s", cvs_cmd_checkout.cmd_synopsis);
1.22 jfb 163:
1.151 joris 164: if (cvs_server_active == 1 && disable_fast_checkout != 1) {
165: cmdp->cmd_flags &= ~CVS_USE_WDIR;
166: cvs_noexec = 1;
167: }
168:
1.61 xsa 169: checkout_check_repository(argc, argv);
170:
1.151 joris 171: if (cvs_server_active == 1 && disable_fast_checkout != 1)
172: cvs_noexec = 0;
173:
1.61 xsa 174: return (0);
175: }
176:
177: int
178: cvs_export(int argc, char **argv)
179: {
1.78 xsa 180: int ch;
1.61 xsa 181:
182: prune_dirs = 1;
183:
184: while ((ch = getopt(argc, argv, cvs_cmd_export.cmd_opts)) != -1) {
185: switch (ch) {
1.157 pyr 186: case 'd':
187: if (dflag != NULL)
188: fatal("-d specified two or more times");
189: dflag = optarg;
190: checkout_target_dir = dflag;
191:
192: if (cvs_server_active == 1)
193: disable_fast_checkout = 1;
194: break;
1.125 tobias 195: case 'k':
196: koptstr = optarg;
197: kflag = rcs_kflag_get(koptstr);
198: if (RCS_KWEXP_INVAL(kflag)) {
199: cvs_log(LP_ERR,
1.144 tobias 200: "invalid RCS keyword expansion mode");
1.165 sthen 201: fatal("%s", cvs_cmd_export.cmd_synopsis);
1.125 tobias 202: }
203: break;
1.61 xsa 204: case 'l':
205: flags &= ~CR_RECURSE_DIRS;
1.164 joris 206: break;
207: case 'N':
1.61 xsa 208: break;
209: case 'R':
1.110 tobias 210: flags |= CR_RECURSE_DIRS;
1.98 xsa 211: break;
212: case 'r':
213: cvs_specified_tag = optarg;
1.61 xsa 214: break;
215: default:
216: fatal("%s", cvs_cmd_export.cmd_synopsis);
217: }
218: }
219:
220: argc -= optind;
221: argv += optind;
222:
1.108 tobias 223: if (cvs_specified_tag == NULL)
224: fatal("must specify a tag or date");
225:
1.61 xsa 226: if (argc == 0)
227: fatal("%s", cvs_cmd_export.cmd_synopsis);
228:
229: checkout_check_repository(argc, argv);
230:
231: return (0);
232: }
233:
234: static void
235: checkout_check_repository(int argc, char **argv)
236: {
1.67 xsa 237: int i;
1.123 joris 238: char *wdir, *d;
1.79 joris 239: struct cvs_recursion cr;
1.119 joris 240: struct module_checkout *mc;
1.123 joris 241: struct cvs_ignpat *ip;
242: struct cvs_filelist *fl, *nxt;
243: char repo[MAXPATHLEN], fpath[MAXPATHLEN], *f[1];
1.79 joris 244:
1.102 tobias 245: build_dirs = print_stdout ? 0 : 1;
246:
1.79 joris 247: if (current_cvsroot->cr_method != CVS_METHOD_LOCAL) {
248: cvs_client_connect_to_server();
249:
1.97 joris 250: if (cvs_specified_tag != NULL)
251: cvs_client_send_request("Argument -r%s",
252: cvs_specified_tag);
1.132 tobias 253: if (Aflag)
1.79 joris 254: cvs_client_send_request("Argument -A");
1.133 joris 255:
256: if (dateflag != NULL)
257: cvs_client_send_request("Argument -D%s", dateflag);
1.122 joris 258:
1.125 tobias 259: if (kflag)
260: cvs_client_send_request("Argument -k%s", koptstr);
261:
1.122 joris 262: if (dflag != NULL)
263: cvs_client_send_request("Argument -d%s", dflag);
1.80 xsa 264:
265: if (!(flags & CR_RECURSE_DIRS))
266: cvs_client_send_request("Argument -l");
1.79 joris 267:
268: if (cvs_cmdop == CVS_OP_CHECKOUT && prune_dirs == 1)
269: cvs_client_send_request("Argument -P");
270:
1.101 joris 271: if (print_stdout == 1)
272: cvs_client_send_request("Argument -p");
273:
1.127 joris 274: if (nflag == 1)
275: cvs_client_send_request("Argument -n");
276:
1.79 joris 277: cr.enterdir = NULL;
278: cr.leavedir = NULL;
1.103 tobias 279: if (print_stdout)
280: cr.fileproc = NULL;
281: else
282: cr.fileproc = cvs_client_sendfile;
283:
284: flags &= ~CR_REPO;
1.79 joris 285: cr.flags = flags;
286:
1.108 tobias 287: if (cvs_cmdop != CVS_OP_EXPORT)
288: cvs_file_run(argc, argv, &cr);
1.79 joris 289:
290: cvs_client_send_files(argv, argc);
291: cvs_client_senddir(".");
292:
293: cvs_client_send_request("%s",
294: (cvs_cmdop == CVS_OP_CHECKOUT) ? "co" : "export");
295:
296: cvs_client_get_responses();
297:
298: return;
299: }
1.104 joris 300:
1.53 joris 301: for (i = 0; i < argc; i++) {
1.119 joris 302: mc = cvs_module_lookup(argv[i]);
303: current_module = mc;
1.116 joris 304:
1.162 joris 305: RB_FOREACH(fl, cvs_flisthead, &(mc->mc_ignores))
1.123 joris 306: cvs_file_ignore(fl->file_path, &checkout_ign_pats);
1.13 jfb 307:
1.162 joris 308: RB_FOREACH(fl, cvs_flisthead, &(mc->mc_modules)) {
1.139 tobias 309: module_repo_root = NULL;
310:
1.123 joris 311: (void)xsnprintf(repo, sizeof(repo), "%s/%s",
312: current_cvsroot->cr_dir, fl->file_path);
1.121 joris 313:
1.123 joris 314: if (!(mc->mc_flags & MODULE_ALIAS) || dflag != NULL)
1.139 tobias 315: module_repo_root = xstrdup(fl->file_path);
1.123 joris 316:
317: if (mc->mc_flags & MODULE_NORECURSE)
318: flags &= ~CR_RECURSE_DIRS;
319:
320: if (dflag != NULL)
321: wdir = dflag;
1.124 joris 322: else if (mc->mc_flags & MODULE_ALIAS)
323: wdir = fl->file_path;
1.123 joris 324: else
1.124 joris 325: wdir = mc->mc_name;
1.123 joris 326:
327: switch (checkout_classify(repo, fl->file_path)) {
328: case CVS_FILE:
329: cr.fileproc = cvs_update_local;
330: cr.flags = flags;
331:
332: if (!(mc->mc_flags & MODULE_ALIAS)) {
333: module_repo_root =
1.139 tobias 334: xstrdup(dirname(fl->file_path));
1.123 joris 335: d = wdir;
336: (void)xsnprintf(fpath, sizeof(fpath),
337: "%s/%s", d,
338: basename(fl->file_path));
339: } else {
340: d = dirname(wdir);
341: strlcpy(fpath, fl->file_path,
342: sizeof(fpath));
343: }
344:
345: if (build_dirs == 1)
346: cvs_mkpath(d, cvs_specified_tag);
347:
348: f[0] = fpath;
349: cvs_file_run(1, f, &cr);
350: break;
351: case CVS_DIR:
352: if (build_dirs == 1)
353: cvs_mkpath(wdir, cvs_specified_tag);
354: checkout_repository(repo, wdir);
355: break;
356: default:
357: break;
358: }
1.126 joris 359:
1.127 joris 360: if (nflag != 1 && mc->mc_prog != NULL &&
1.128 joris 361: mc->mc_flags & MODULE_RUN_ON_CHECKOUT)
1.147 joris 362: cvs_exec(mc->mc_prog, NULL, 0);
1.139 tobias 363:
364: if (module_repo_root != NULL)
365: xfree(module_repo_root);
1.123 joris 366: }
1.119 joris 367:
1.123 joris 368: if (mc->mc_canfree == 1) {
1.162 joris 369: for (fl = RB_MIN(cvs_flisthead, &(mc->mc_modules));
370: fl != NULL; fl = nxt) {
371: nxt = RB_NEXT(cvs_flisthead,
372: &(mc->mc_modules), fl);
373: RB_REMOVE(cvs_flisthead,
374: &(mc->mc_modules), fl);
1.123 joris 375: xfree(fl->file_path);
376: xfree(fl);
377: }
378: }
1.120 joris 379:
1.123 joris 380: while ((ip = TAILQ_FIRST(&checkout_ign_pats)) != NULL) {
381: TAILQ_REMOVE(&checkout_ign_pats, ip, ip_list);
382: xfree(ip);
1.113 tobias 383: }
1.119 joris 384:
385: xfree(mc);
1.113 tobias 386: }
387: }
1.100 tobias 388:
1.113 tobias 389: static int
390: checkout_classify(const char *repo, const char *arg)
391: {
392: char *d, *f, fpath[MAXPATHLEN];
393: struct stat sb;
394:
395: if (stat(repo, &sb) == 0) {
1.123 joris 396: if (S_ISDIR(sb.st_mode))
397: return CVS_DIR;
1.113 tobias 398: }
1.97 joris 399:
1.113 tobias 400: d = dirname(repo);
401: f = basename(repo);
402:
403: (void)xsnprintf(fpath, sizeof(fpath), "%s/%s%s", d, f, RCS_FILE_EXT);
404: if (stat(fpath, &sb) == 0) {
405: if (!S_ISREG(sb.st_mode)) {
406: cvs_log(LP_ERR, "ignoring %s: not a regular file", arg);
407: return 0;
408: }
409: return CVS_FILE;
1.33 xsa 410: }
1.113 tobias 411:
412: (void)xsnprintf(fpath, sizeof(fpath), "%s/%s/%s%s",
413: d, CVS_PATH_ATTIC, f, RCS_FILE_EXT);
414: if (stat(fpath, &sb) == 0) {
415: if (!S_ISREG(sb.st_mode)) {
416: cvs_log(LP_ERR, "ignoring %s: not a regular file", arg);
417: return 0;
418: }
419: return CVS_FILE;
420: }
421:
422: cvs_log(LP_ERR, "cannot find module `%s' - ignored", arg);
423: return 0;
1.14 joris 424: }
1.9 jfb 425:
1.53 joris 426: static void
427: checkout_repository(const char *repobase, const char *wdbase)
1.14 joris 428: {
1.53 joris 429: struct cvs_flisthead fl, dl;
430: struct cvs_recursion cr;
431:
1.162 joris 432: RB_INIT(&fl);
433: RB_INIT(&dl);
1.94 joris 434:
1.99 xsa 435: cvs_history_add((cvs_cmdop == CVS_OP_CHECKOUT) ?
436: CVS_HISTORY_CHECKOUT : CVS_HISTORY_EXPORT, NULL, wdbase);
1.41 joris 437:
1.112 tobias 438: if (print_stdout) {
439: cr.enterdir = NULL;
440: cr.leavedir = NULL;
441: } else {
442: cr.enterdir = cvs_update_enterdir;
1.151 joris 443: if (cvs_server_active == 1) {
444: if (disable_fast_checkout != 1)
445: cr.leavedir = NULL;
446: else
447: cr.leavedir = cvs_update_leavedir;
448: } else {
449: cr.leavedir = prune_dirs ? cvs_update_leavedir : NULL;
450: }
1.112 tobias 451: }
1.64 joris 452: cr.fileproc = cvs_update_local;
1.78 xsa 453: cr.flags = flags;
1.41 joris 454:
1.143 joris 455: cvs_repository_lock(repobase, 0);
1.111 tobias 456: cvs_repository_getdir(repobase, wdbase, &fl, &dl,
1.158 joris 457: flags & CR_RECURSE_DIRS ? REPOSITORY_DODIRS : 0);
1.1 jfb 458:
1.53 joris 459: cvs_file_walklist(&fl, &cr);
460: cvs_file_freelist(&fl);
1.23 joris 461:
1.53 joris 462: cvs_repository_unlock(repobase);
1.23 joris 463:
1.53 joris 464: cvs_file_walklist(&dl, &cr);
465: cvs_file_freelist(&dl);
466: }
1.23 joris 467:
1.58 joris 468: void
1.105 joris 469: cvs_checkout_file(struct cvs_file *cf, RCSNUM *rnum, char *tag, int co_flags)
1.53 joris 470: {
1.151 joris 471: BUF *bp;
1.148 joris 472: mode_t mode;
1.156 joris 473: int cf_kflag, exists;
1.53 joris 474: time_t rcstime;
475: CVSENTRIES *ent;
476: struct timeval tv[2];
1.149 tobias 477: struct tm datetm;
1.151 joris 478: char *entry, *tosend;
1.115 xsa 479: char kbuf[8], sticky[CVS_REV_BUFSZ], rev[CVS_REV_BUFSZ];
1.96 xsa 480: char timebuf[CVS_TIME_BUFSZ], tbuf[CVS_TIME_BUFSZ];
1.22 jfb 481:
1.87 joris 482: exists = 0;
483: tosend = NULL;
1.104 joris 484:
485: if (!(co_flags & CO_REMOVE))
486: rcsnum_tostr(rnum, rev, sizeof(rev));
1.155 tobias 487: else
488: rev[0] = '\0';
1.41 joris 489:
1.66 joris 490: cvs_log(LP_TRACE, "cvs_checkout_file(%s, %s, %d) -> %s",
1.78 xsa 491: cf->file_path, rev, co_flags,
1.66 joris 492: (cvs_server_active) ? "to client" : "to disk");
1.42 joris 493:
1.78 xsa 494: if (co_flags & CO_DUMP) {
1.106 tobias 495: rcs_rev_write_fd(cf->file_rcs, rnum, STDOUT_FILENO, 0);
1.65 reyk 496: return;
497: }
1.87 joris 498:
1.66 joris 499: if (cvs_server_active == 0) {
1.141 joris 500: (void)unlink(cf->file_path);
501:
1.87 joris 502: if (!(co_flags & CO_MERGE)) {
1.159 joris 503: if (cf->file_flags & FILE_ON_DISK) {
1.87 joris 504: exists = 1;
505: (void)close(cf->fd);
506: }
507:
1.141 joris 508: cf->fd = open(cf->file_path,
1.142 joris 509: O_CREAT | O_RDWR | O_TRUNC);
1.87 joris 510: if (cf->fd == -1)
511: fatal("cvs_checkout_file: open: %s",
512: strerror(errno));
513:
1.106 tobias 514: rcs_rev_write_fd(cf->file_rcs, rnum, cf->fd, 0);
1.159 joris 515: cf->file_flags |= FILE_ON_DISK;
1.87 joris 516: } else {
1.142 joris 517: cvs_merge_file(cf, (cvs_join_rev1 == NULL));
1.66 joris 518: }
519:
1.148 joris 520: mode = cf->file_rcs->rf_mode;
521: mode |= S_IWUSR;
522:
523: if (fchmod(cf->fd, mode) == -1)
1.66 joris 524: fatal("cvs_checkout_file: fchmod: %s", strerror(errno));
525:
1.87 joris 526: if ((exists == 0) && (cf->file_ent == NULL) &&
527: !(co_flags & CO_MERGE))
1.66 joris 528: rcstime = rcs_rev_getdate(cf->file_rcs, rnum);
1.84 joris 529: else
1.66 joris 530: time(&rcstime);
531:
532: tv[0].tv_sec = rcstime;
533: tv[0].tv_usec = 0;
534: tv[1] = tv[0];
535: if (futimes(cf->fd, tv) == -1)
536: fatal("cvs_checkout_file: futimes: %s",
537: strerror(errno));
1.53 joris 538: } else {
539: time(&rcstime);
1.41 joris 540: }
541:
1.149 tobias 542: gmtime_r(&rcstime, &datetm);
543: asctime_r(&datetm, tbuf);
1.107 tobias 544: tbuf[strcspn(tbuf, "\n")] = '\0';
1.58 joris 545:
1.78 xsa 546: if (co_flags & CO_MERGE) {
1.89 xsa 547: (void)xsnprintf(timebuf, sizeof(timebuf), "Result of merge+%s",
1.58 joris 548: tbuf);
549: } else {
550: strlcpy(timebuf, tbuf, sizeof(timebuf));
551: }
1.41 joris 552:
1.154 tobias 553: if (reset_tag) {
554: sticky[0] = '\0';
555: } else if (co_flags & CO_SETSTICKY)
1.105 joris 556: if (tag != NULL)
1.114 xsa 557: (void)xsnprintf(sticky, sizeof(sticky), "T%s", tag);
1.136 joris 558: else if (cvs_specified_date != -1) {
1.149 tobias 559: gmtime_r(&cvs_specified_date, &datetm);
1.138 xsa 560: (void)strftime(sticky, sizeof(sticky),
1.149 tobias 561: "D"CVS_DATE_FMT, &datetm);
1.154 tobias 562: } else if (cvs_directory_date != -1) {
563: gmtime_r(&cvs_directory_date, &datetm);
564: (void)strftime(sticky, sizeof(sticky),
565: "D"CVS_DATE_FMT, &datetm);
1.134 tobias 566: } else
1.114 xsa 567: (void)xsnprintf(sticky, sizeof(sticky), "T%s", rev);
1.154 tobias 568: else if (cf->file_ent != NULL && cf->file_ent->ce_tag != NULL)
1.114 xsa 569: (void)xsnprintf(sticky, sizeof(sticky), "T%s",
1.109 tobias 570: cf->file_ent->ce_tag);
1.89 xsa 571: else
1.114 xsa 572: sticky[0] = '\0';
1.60 joris 573:
1.85 xsa 574: kbuf[0] = '\0';
1.161 joris 575: if (cf->file_rcs != NULL && cf->file_rcs->rf_expand != NULL) {
1.125 tobias 576: cf_kflag = rcs_kflag_get(cf->file_rcs->rf_expand);
577: if (kflag || cf_kflag != RCS_KWEXP_DEFAULT)
578: (void)xsnprintf(kbuf, sizeof(kbuf),
579: "-k%s", cf->file_rcs->rf_expand);
1.132 tobias 580: } else if (!reset_option && cf->file_ent != NULL) {
1.85 xsa 581: if (cf->file_ent->ce_opts != NULL)
582: strlcpy(kbuf, cf->file_ent->ce_opts, sizeof(kbuf));
583: }
584:
1.135 xsa 585: entry = xmalloc(CVS_ENT_MAXLINELEN);
586: cvs_ent_line_str(cf->file_name, rev, timebuf, kbuf, sticky, 0, 0,
587: entry, CVS_ENT_MAXLINELEN);
1.41 joris 588:
1.66 joris 589: if (cvs_server_active == 0) {
1.108 tobias 590: if (!(co_flags & CO_REMOVE) && cvs_cmdop != CVS_OP_EXPORT) {
1.95 joris 591: ent = cvs_ent_open(cf->file_wd);
592: cvs_ent_add(ent, entry);
1.142 joris 593: cf->file_ent = cvs_ent_parse(entry);
1.95 joris 594: }
1.66 joris 595: } else {
1.87 joris 596: if (co_flags & CO_MERGE) {
1.141 joris 597: (void)unlink(cf->file_path);
1.142 joris 598: cvs_merge_file(cf, (cvs_join_rev1 == NULL));
1.87 joris 599: tosend = cf->file_path;
1.160 joris 600: }
601:
602: /*
603: * If this file has a tag, push out the Directory with the
1.163 joris 604: * tag to the client. Except when this file was explicitly
605: * specified on the command line.
1.160 joris 606: */
1.163 joris 607: if (tag != NULL && strcmp(cf->file_wd, lastwd) &&
608: !(cf->file_flags & FILE_USER_SUPPLIED)) {
1.160 joris 609: strlcpy(lastwd, cf->file_wd, MAXPATHLEN);
610: cvs_server_set_sticky(cf->file_wd, sticky);
1.87 joris 611: }
612:
1.78 xsa 613: if (co_flags & CO_COMMIT)
1.137 tobias 614: cvs_server_update_entry("Updated", cf);
1.87 joris 615: else if (co_flags & CO_MERGE)
616: cvs_server_update_entry("Merged", cf);
1.95 joris 617: else if (co_flags & CO_REMOVE)
618: cvs_server_update_entry("Removed", cf);
1.69 joris 619: else
620: cvs_server_update_entry("Updated", cf);
1.68 joris 621:
1.135 xsa 622: if (!(co_flags & CO_REMOVE)) {
1.95 joris 623: cvs_remote_output(entry);
1.66 joris 624:
1.87 joris 625: if (!(co_flags & CO_MERGE)) {
1.148 joris 626: mode = cf->file_rcs->rf_mode;
627: mode |= S_IWUSR;
1.151 joris 628: bp = rcs_rev_getbuf(cf->file_rcs, rnum, 0);
629: cvs_remote_send_file_buf(cf->file_path,
630: bp, mode);
631: } else {
1.156 joris 632: cvs_remote_send_file(tosend, cf->fd);
1.87 joris 633: }
1.68 joris 634: }
1.66 joris 635: }
1.152 tobias 636:
637: xfree(entry);
1.1 jfb 638: }