Annotation of src/usr.bin/cvs/checkout.c, Revision 1.168
1.168 ! nicm 1: /* $OpenBSD: checkout.c,v 1.167 2010/07/30 21:47:18 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.133 joris 51: char *checkout_target_dir = NULL;
1.151 joris 52:
1.136 joris 53: time_t cvs_specified_date = -1;
1.154 tobias 54: time_t cvs_directory_date = -1;
1.151 joris 55: int disable_fast_checkout = 0;
1.131 tobias 56:
1.22 jfb 57: struct cvs_cmd cvs_cmd_checkout = {
1.112 tobias 58: CVS_OP_CHECKOUT, CVS_USE_WDIR, "checkout",
1.22 jfb 59: { "co", "get" },
1.53 joris 60: "Checkout a working copy of a repository",
1.33 xsa 61: "[-AcflNnPpRs] [-D date | -r tag] [-d dir] [-j rev] [-k mode] "
1.22 jfb 62: "[-t id] module ...",
1.77 xsa 63: "AcD:d:fj:k:lNnPpRr:st:",
1.59 joris 64: NULL,
65: cvs_checkout
66: };
67:
68: struct cvs_cmd cvs_cmd_export = {
1.112 tobias 69: CVS_OP_EXPORT, CVS_USE_WDIR, "export",
1.59 joris 70: { "exp", "ex" },
71: "Export sources from CVS, similar to checkout",
1.61 xsa 72: "[-flNnR] [-d dir] [-k mode] -D date | -r rev module ...",
73: "D:d:k:flNnRr:",
1.22 jfb 74: NULL,
1.61 xsa 75: cvs_export
1.33 xsa 76: };
77:
1.53 joris 78: int
79: cvs_checkout(int argc, char **argv)
1.1 jfb 80: {
1.78 xsa 81: int ch;
1.13 jfb 82:
1.53 joris 83: while ((ch = getopt(argc, argv, cvs_cmd_checkout.cmd_opts)) != -1) {
1.1 jfb 84: switch (ch) {
1.76 xsa 85: case 'A':
1.132 tobias 86: Aflag = 1;
87: if (koptstr == NULL)
88: reset_option = 1;
89: if (cvs_specified_tag == NULL)
90: reset_tag = 1;
1.76 xsa 91: break;
1.129 joris 92: case 'c':
93: cvs_modules_list();
94: exit(0);
1.131 tobias 95: case 'D':
1.133 joris 96: dateflag = optarg;
1.167 ray 97: if ((cvs_specified_date = date_parse(dateflag)) == -1)
98: fatal("invalid date: %s", dateflag);
1.154 tobias 99: reset_tag = 0;
1.131 tobias 100: break;
1.120 joris 101: case 'd':
102: if (dflag != NULL)
103: fatal("-d specified two or more times");
104: dflag = optarg;
1.133 joris 105: checkout_target_dir = dflag;
1.151 joris 106:
107: if (cvs_server_active == 1)
108: disable_fast_checkout = 1;
1.120 joris 109: break;
1.142 joris 110: case 'j':
111: if (cvs_join_rev1 == NULL)
112: cvs_join_rev1 = optarg;
113: else if (cvs_join_rev2 == NULL)
114: cvs_join_rev2 = optarg;
115: else
116: fatal("too many -j options");
117: break;
1.125 tobias 118: case 'k':
1.132 tobias 119: reset_option = 0;
1.125 tobias 120: koptstr = optarg;
121: kflag = rcs_kflag_get(koptstr);
122: if (RCS_KWEXP_INVAL(kflag)) {
123: cvs_log(LP_ERR,
1.144 tobias 124: "invalid RCS keyword expansion mode");
1.165 sthen 125: fatal("%s", cvs_cmd_checkout.cmd_synopsis);
1.125 tobias 126: }
127: break;
1.77 xsa 128: case 'l':
129: flags &= ~CR_RECURSE_DIRS;
130: break;
1.104 joris 131: case 'N':
132: break;
1.127 joris 133: case 'n':
134: nflag = 1;
135: break;
1.54 joris 136: case 'P':
137: prune_dirs = 1;
1.77 xsa 138: break;
1.101 joris 139: case 'p':
1.112 tobias 140: cmdp->cmd_flags &= ~CVS_USE_WDIR;
1.101 joris 141: print_stdout = 1;
142: cvs_noexec = 1;
1.127 joris 143: nflag = 1;
1.101 joris 144: break;
1.77 xsa 145: case 'R':
1.110 tobias 146: flags |= CR_RECURSE_DIRS;
1.54 joris 147: break;
1.93 niallo 148: case 'r':
1.132 tobias 149: reset_tag = 0;
1.97 joris 150: cvs_specified_tag = optarg;
1.93 niallo 151: break;
1.1 jfb 152: default:
1.53 joris 153: fatal("%s", cvs_cmd_checkout.cmd_synopsis);
1.1 jfb 154: }
155: }
156:
157: argc -= optind;
158: argv += optind;
159:
1.53 joris 160: if (argc == 0)
161: fatal("%s", cvs_cmd_checkout.cmd_synopsis);
1.22 jfb 162:
1.151 joris 163: if (cvs_server_active == 1 && disable_fast_checkout != 1) {
164: cmdp->cmd_flags &= ~CVS_USE_WDIR;
165: cvs_noexec = 1;
166: }
167:
1.61 xsa 168: checkout_check_repository(argc, argv);
169:
1.151 joris 170: if (cvs_server_active == 1 && disable_fast_checkout != 1)
171: cvs_noexec = 0;
172:
1.61 xsa 173: return (0);
174: }
175:
176: int
177: cvs_export(int argc, char **argv)
178: {
1.78 xsa 179: int ch;
1.61 xsa 180:
181: prune_dirs = 1;
182:
183: while ((ch = getopt(argc, argv, cvs_cmd_export.cmd_opts)) != -1) {
184: switch (ch) {
1.157 pyr 185: case 'd':
186: if (dflag != NULL)
187: fatal("-d specified two or more times");
188: dflag = optarg;
189: checkout_target_dir = dflag;
190:
191: if (cvs_server_active == 1)
192: disable_fast_checkout = 1;
193: break;
1.125 tobias 194: case 'k':
195: koptstr = optarg;
196: kflag = rcs_kflag_get(koptstr);
197: if (RCS_KWEXP_INVAL(kflag)) {
198: cvs_log(LP_ERR,
1.144 tobias 199: "invalid RCS keyword expansion mode");
1.165 sthen 200: fatal("%s", cvs_cmd_export.cmd_synopsis);
1.125 tobias 201: }
202: break;
1.61 xsa 203: case 'l':
204: flags &= ~CR_RECURSE_DIRS;
1.164 joris 205: break;
206: case 'N':
1.61 xsa 207: break;
208: case 'R':
1.110 tobias 209: flags |= CR_RECURSE_DIRS;
1.98 xsa 210: break;
211: case 'r':
212: cvs_specified_tag = optarg;
1.61 xsa 213: break;
214: default:
215: fatal("%s", cvs_cmd_export.cmd_synopsis);
216: }
217: }
218:
219: argc -= optind;
220: argv += optind;
221:
1.108 tobias 222: if (cvs_specified_tag == NULL)
223: fatal("must specify a tag or date");
224:
1.61 xsa 225: if (argc == 0)
226: fatal("%s", cvs_cmd_export.cmd_synopsis);
227:
228: checkout_check_repository(argc, argv);
229:
230: return (0);
231: }
232:
233: static void
234: checkout_check_repository(int argc, char **argv)
235: {
1.67 xsa 236: int i;
1.123 joris 237: char *wdir, *d;
1.79 joris 238: struct cvs_recursion cr;
1.119 joris 239: struct module_checkout *mc;
1.123 joris 240: struct cvs_ignpat *ip;
241: struct cvs_filelist *fl, *nxt;
242: char repo[MAXPATHLEN], fpath[MAXPATHLEN], *f[1];
1.79 joris 243:
1.102 tobias 244: build_dirs = print_stdout ? 0 : 1;
245:
1.79 joris 246: if (current_cvsroot->cr_method != CVS_METHOD_LOCAL) {
247: cvs_client_connect_to_server();
248:
1.97 joris 249: if (cvs_specified_tag != NULL)
250: cvs_client_send_request("Argument -r%s",
251: cvs_specified_tag);
1.132 tobias 252: if (Aflag)
1.79 joris 253: cvs_client_send_request("Argument -A");
1.133 joris 254:
255: if (dateflag != NULL)
256: cvs_client_send_request("Argument -D%s", dateflag);
1.122 joris 257:
1.125 tobias 258: if (kflag)
259: cvs_client_send_request("Argument -k%s", koptstr);
260:
1.122 joris 261: if (dflag != NULL)
262: cvs_client_send_request("Argument -d%s", dflag);
1.80 xsa 263:
264: if (!(flags & CR_RECURSE_DIRS))
265: cvs_client_send_request("Argument -l");
1.79 joris 266:
267: if (cvs_cmdop == CVS_OP_CHECKOUT && prune_dirs == 1)
268: cvs_client_send_request("Argument -P");
269:
1.101 joris 270: if (print_stdout == 1)
271: cvs_client_send_request("Argument -p");
272:
1.127 joris 273: if (nflag == 1)
274: cvs_client_send_request("Argument -n");
275:
1.79 joris 276: cr.enterdir = NULL;
277: cr.leavedir = NULL;
1.103 tobias 278: if (print_stdout)
279: cr.fileproc = NULL;
280: else
281: cr.fileproc = cvs_client_sendfile;
282:
283: flags &= ~CR_REPO;
1.79 joris 284: cr.flags = flags;
285:
1.108 tobias 286: if (cvs_cmdop != CVS_OP_EXPORT)
287: cvs_file_run(argc, argv, &cr);
1.79 joris 288:
289: cvs_client_send_files(argv, argc);
290: cvs_client_senddir(".");
291:
292: cvs_client_send_request("%s",
293: (cvs_cmdop == CVS_OP_CHECKOUT) ? "co" : "export");
294:
295: cvs_client_get_responses();
296:
297: return;
298: }
1.104 joris 299:
1.53 joris 300: for (i = 0; i < argc; i++) {
1.119 joris 301: mc = cvs_module_lookup(argv[i]);
302: current_module = mc;
1.116 joris 303:
1.162 joris 304: RB_FOREACH(fl, cvs_flisthead, &(mc->mc_ignores))
1.123 joris 305: cvs_file_ignore(fl->file_path, &checkout_ign_pats);
1.13 jfb 306:
1.162 joris 307: RB_FOREACH(fl, cvs_flisthead, &(mc->mc_modules)) {
1.139 tobias 308: module_repo_root = NULL;
309:
1.123 joris 310: (void)xsnprintf(repo, sizeof(repo), "%s/%s",
311: current_cvsroot->cr_dir, fl->file_path);
1.121 joris 312:
1.123 joris 313: if (!(mc->mc_flags & MODULE_ALIAS) || dflag != NULL)
1.139 tobias 314: module_repo_root = xstrdup(fl->file_path);
1.123 joris 315:
316: if (mc->mc_flags & MODULE_NORECURSE)
317: flags &= ~CR_RECURSE_DIRS;
318:
319: if (dflag != NULL)
320: wdir = dflag;
1.124 joris 321: else if (mc->mc_flags & MODULE_ALIAS)
322: wdir = fl->file_path;
1.123 joris 323: else
1.124 joris 324: wdir = mc->mc_name;
1.123 joris 325:
326: switch (checkout_classify(repo, fl->file_path)) {
327: case CVS_FILE:
328: cr.fileproc = cvs_update_local;
329: cr.flags = flags;
330:
331: if (!(mc->mc_flags & MODULE_ALIAS)) {
332: module_repo_root =
1.139 tobias 333: xstrdup(dirname(fl->file_path));
1.123 joris 334: d = wdir;
335: (void)xsnprintf(fpath, sizeof(fpath),
336: "%s/%s", d,
337: basename(fl->file_path));
338: } else {
339: d = dirname(wdir);
340: strlcpy(fpath, fl->file_path,
341: sizeof(fpath));
342: }
343:
344: if (build_dirs == 1)
345: cvs_mkpath(d, cvs_specified_tag);
346:
347: f[0] = fpath;
348: cvs_file_run(1, f, &cr);
349: break;
350: case CVS_DIR:
351: if (build_dirs == 1)
352: cvs_mkpath(wdir, cvs_specified_tag);
353: checkout_repository(repo, wdir);
354: break;
355: default:
356: break;
357: }
1.126 joris 358:
1.127 joris 359: if (nflag != 1 && mc->mc_prog != NULL &&
1.128 joris 360: mc->mc_flags & MODULE_RUN_ON_CHECKOUT)
1.147 joris 361: cvs_exec(mc->mc_prog, NULL, 0);
1.139 tobias 362:
363: if (module_repo_root != NULL)
364: xfree(module_repo_root);
1.123 joris 365: }
1.119 joris 366:
1.123 joris 367: if (mc->mc_canfree == 1) {
1.162 joris 368: for (fl = RB_MIN(cvs_flisthead, &(mc->mc_modules));
369: fl != NULL; fl = nxt) {
370: nxt = RB_NEXT(cvs_flisthead,
371: &(mc->mc_modules), fl);
372: RB_REMOVE(cvs_flisthead,
373: &(mc->mc_modules), fl);
1.123 joris 374: xfree(fl->file_path);
375: xfree(fl);
376: }
377: }
1.120 joris 378:
1.123 joris 379: while ((ip = TAILQ_FIRST(&checkout_ign_pats)) != NULL) {
380: TAILQ_REMOVE(&checkout_ign_pats, ip, ip_list);
381: xfree(ip);
1.113 tobias 382: }
1.119 joris 383:
384: xfree(mc);
1.113 tobias 385: }
386: }
1.100 tobias 387:
1.113 tobias 388: static int
389: checkout_classify(const char *repo, const char *arg)
390: {
391: char *d, *f, fpath[MAXPATHLEN];
392: struct stat sb;
393:
394: if (stat(repo, &sb) == 0) {
1.123 joris 395: if (S_ISDIR(sb.st_mode))
396: return CVS_DIR;
1.113 tobias 397: }
1.97 joris 398:
1.113 tobias 399: d = dirname(repo);
400: f = basename(repo);
401:
402: (void)xsnprintf(fpath, sizeof(fpath), "%s/%s%s", d, f, RCS_FILE_EXT);
403: if (stat(fpath, &sb) == 0) {
404: if (!S_ISREG(sb.st_mode)) {
405: cvs_log(LP_ERR, "ignoring %s: not a regular file", arg);
406: return 0;
407: }
408: return CVS_FILE;
1.33 xsa 409: }
1.113 tobias 410:
411: (void)xsnprintf(fpath, sizeof(fpath), "%s/%s/%s%s",
412: d, CVS_PATH_ATTIC, f, RCS_FILE_EXT);
413: if (stat(fpath, &sb) == 0) {
414: if (!S_ISREG(sb.st_mode)) {
415: cvs_log(LP_ERR, "ignoring %s: not a regular file", arg);
416: return 0;
417: }
418: return CVS_FILE;
419: }
420:
421: cvs_log(LP_ERR, "cannot find module `%s' - ignored", arg);
422: return 0;
1.14 joris 423: }
1.9 jfb 424:
1.53 joris 425: static void
426: checkout_repository(const char *repobase, const char *wdbase)
1.14 joris 427: {
1.53 joris 428: struct cvs_flisthead fl, dl;
429: struct cvs_recursion cr;
430:
1.162 joris 431: RB_INIT(&fl);
432: RB_INIT(&dl);
1.94 joris 433:
1.99 xsa 434: cvs_history_add((cvs_cmdop == CVS_OP_CHECKOUT) ?
435: CVS_HISTORY_CHECKOUT : CVS_HISTORY_EXPORT, NULL, wdbase);
1.41 joris 436:
1.112 tobias 437: if (print_stdout) {
438: cr.enterdir = NULL;
439: cr.leavedir = NULL;
440: } else {
441: cr.enterdir = cvs_update_enterdir;
1.151 joris 442: if (cvs_server_active == 1) {
443: if (disable_fast_checkout != 1)
444: cr.leavedir = NULL;
445: else
446: cr.leavedir = cvs_update_leavedir;
447: } else {
448: cr.leavedir = prune_dirs ? cvs_update_leavedir : NULL;
449: }
1.112 tobias 450: }
1.64 joris 451: cr.fileproc = cvs_update_local;
1.78 xsa 452: cr.flags = flags;
1.41 joris 453:
1.143 joris 454: cvs_repository_lock(repobase, 0);
1.111 tobias 455: cvs_repository_getdir(repobase, wdbase, &fl, &dl,
1.158 joris 456: flags & CR_RECURSE_DIRS ? REPOSITORY_DODIRS : 0);
1.1 jfb 457:
1.53 joris 458: cvs_file_walklist(&fl, &cr);
459: cvs_file_freelist(&fl);
1.23 joris 460:
1.53 joris 461: cvs_repository_unlock(repobase);
1.23 joris 462:
1.53 joris 463: cvs_file_walklist(&dl, &cr);
464: cvs_file_freelist(&dl);
465: }
1.23 joris 466:
1.58 joris 467: void
1.105 joris 468: cvs_checkout_file(struct cvs_file *cf, RCSNUM *rnum, char *tag, int co_flags)
1.53 joris 469: {
1.151 joris 470: BUF *bp;
1.148 joris 471: mode_t mode;
1.156 joris 472: int cf_kflag, exists;
1.53 joris 473: time_t rcstime;
474: CVSENTRIES *ent;
475: struct timeval tv[2];
1.149 tobias 476: struct tm datetm;
1.151 joris 477: char *entry, *tosend;
1.115 xsa 478: char kbuf[8], sticky[CVS_REV_BUFSZ], rev[CVS_REV_BUFSZ];
1.96 xsa 479: char timebuf[CVS_TIME_BUFSZ], tbuf[CVS_TIME_BUFSZ];
1.168 ! nicm 480: static char lastwd[MAXPATHLEN];
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: }