Annotation of src/usr.bin/cvs/checkout.c, Revision 1.172
1.172 ! naddy 1: /* $OpenBSD: checkout.c,v 1.171 2017/06/01 08:08:24 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.169 deraadt 18: #include <sys/types.h>
1.92 otto 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;
1.172 ! naddy 242: char repo[PATH_MAX], fpath[PATH_MAX], path[PATH_MAX], *f[1];
1.79 joris 243:
1.102 tobias 244: build_dirs = print_stdout ? 0 : 1;
245:
1.171 joris 246: if (cvsroot_is_remote()) {
1.79 joris 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)) {
1.172 ! naddy 332: if (strlcpy(path, fl->file_path,
! 333: sizeof(path)) >= sizeof(path))
! 334: fatal("%s: truncation",
! 335: __func__);
1.123 joris 336: module_repo_root =
1.172 ! naddy 337: xstrdup(dirname(path));
1.123 joris 338: d = wdir;
1.172 ! naddy 339: if (strlcpy(path, fl->file_path,
! 340: sizeof(path)) >= sizeof(path))
! 341: fatal("%s: truncation",
! 342: __func__);
1.123 joris 343: (void)xsnprintf(fpath, sizeof(fpath),
1.172 ! naddy 344: "%s/%s", d, basename(path));
1.123 joris 345: } else {
1.172 ! naddy 346: if (strlcpy(path, wdir,
! 347: sizeof(path)) >= sizeof(path))
! 348: fatal("%s: truncation",
! 349: __func__);
! 350: d = dirname(path);
1.123 joris 351: strlcpy(fpath, fl->file_path,
352: sizeof(fpath));
353: }
354:
355: if (build_dirs == 1)
356: cvs_mkpath(d, cvs_specified_tag);
357:
358: f[0] = fpath;
359: cvs_file_run(1, f, &cr);
360: break;
361: case CVS_DIR:
362: if (build_dirs == 1)
363: cvs_mkpath(wdir, cvs_specified_tag);
364: checkout_repository(repo, wdir);
365: break;
366: default:
367: break;
368: }
1.126 joris 369:
1.127 joris 370: if (nflag != 1 && mc->mc_prog != NULL &&
1.128 joris 371: mc->mc_flags & MODULE_RUN_ON_CHECKOUT)
1.147 joris 372: cvs_exec(mc->mc_prog, NULL, 0);
1.139 tobias 373:
1.170 nicm 374: free(module_repo_root);
1.123 joris 375: }
1.119 joris 376:
1.123 joris 377: if (mc->mc_canfree == 1) {
1.162 joris 378: for (fl = RB_MIN(cvs_flisthead, &(mc->mc_modules));
379: fl != NULL; fl = nxt) {
380: nxt = RB_NEXT(cvs_flisthead,
381: &(mc->mc_modules), fl);
382: RB_REMOVE(cvs_flisthead,
383: &(mc->mc_modules), fl);
1.170 nicm 384: free(fl->file_path);
385: free(fl);
1.123 joris 386: }
387: }
1.120 joris 388:
1.123 joris 389: while ((ip = TAILQ_FIRST(&checkout_ign_pats)) != NULL) {
390: TAILQ_REMOVE(&checkout_ign_pats, ip, ip_list);
1.170 nicm 391: free(ip);
1.113 tobias 392: }
1.119 joris 393:
1.170 nicm 394: free(mc);
1.113 tobias 395: }
396: }
1.100 tobias 397:
1.113 tobias 398: static int
399: checkout_classify(const char *repo, const char *arg)
400: {
1.172 ! naddy 401: char *d, dbuf[PATH_MAX], *f, fbuf[PATH_MAX], fpath[PATH_MAX];
1.113 tobias 402: struct stat sb;
403:
404: if (stat(repo, &sb) == 0) {
1.123 joris 405: if (S_ISDIR(sb.st_mode))
406: return CVS_DIR;
1.113 tobias 407: }
1.97 joris 408:
1.172 ! naddy 409: if (strlcpy(dbuf, repo, sizeof(dbuf)) >= sizeof(dbuf))
! 410: fatal("checkout_classify: truncation");
! 411: d = dirname(dbuf);
! 412:
! 413: if (strlcpy(fbuf, repo, sizeof(fbuf)) >= sizeof(fbuf))
! 414: fatal("checkout_classify: truncation");
! 415: f = basename(fbuf);
1.113 tobias 416:
417: (void)xsnprintf(fpath, sizeof(fpath), "%s/%s%s", d, f, RCS_FILE_EXT);
418: if (stat(fpath, &sb) == 0) {
419: if (!S_ISREG(sb.st_mode)) {
420: cvs_log(LP_ERR, "ignoring %s: not a regular file", arg);
421: return 0;
422: }
423: return CVS_FILE;
1.33 xsa 424: }
1.113 tobias 425:
426: (void)xsnprintf(fpath, sizeof(fpath), "%s/%s/%s%s",
427: d, CVS_PATH_ATTIC, f, RCS_FILE_EXT);
428: if (stat(fpath, &sb) == 0) {
429: if (!S_ISREG(sb.st_mode)) {
430: cvs_log(LP_ERR, "ignoring %s: not a regular file", arg);
431: return 0;
432: }
433: return CVS_FILE;
434: }
435:
436: cvs_log(LP_ERR, "cannot find module `%s' - ignored", arg);
437: return 0;
1.14 joris 438: }
1.9 jfb 439:
1.53 joris 440: static void
441: checkout_repository(const char *repobase, const char *wdbase)
1.14 joris 442: {
1.53 joris 443: struct cvs_flisthead fl, dl;
444: struct cvs_recursion cr;
445:
1.162 joris 446: RB_INIT(&fl);
447: RB_INIT(&dl);
1.94 joris 448:
1.99 xsa 449: cvs_history_add((cvs_cmdop == CVS_OP_CHECKOUT) ?
450: CVS_HISTORY_CHECKOUT : CVS_HISTORY_EXPORT, NULL, wdbase);
1.41 joris 451:
1.112 tobias 452: if (print_stdout) {
453: cr.enterdir = NULL;
454: cr.leavedir = NULL;
455: } else {
456: cr.enterdir = cvs_update_enterdir;
1.151 joris 457: if (cvs_server_active == 1) {
458: if (disable_fast_checkout != 1)
459: cr.leavedir = NULL;
460: else
461: cr.leavedir = cvs_update_leavedir;
462: } else {
463: cr.leavedir = prune_dirs ? cvs_update_leavedir : NULL;
464: }
1.112 tobias 465: }
1.64 joris 466: cr.fileproc = cvs_update_local;
1.78 xsa 467: cr.flags = flags;
1.41 joris 468:
1.143 joris 469: cvs_repository_lock(repobase, 0);
1.111 tobias 470: cvs_repository_getdir(repobase, wdbase, &fl, &dl,
1.158 joris 471: flags & CR_RECURSE_DIRS ? REPOSITORY_DODIRS : 0);
1.1 jfb 472:
1.53 joris 473: cvs_file_walklist(&fl, &cr);
474: cvs_file_freelist(&fl);
1.23 joris 475:
1.53 joris 476: cvs_repository_unlock(repobase);
1.23 joris 477:
1.53 joris 478: cvs_file_walklist(&dl, &cr);
479: cvs_file_freelist(&dl);
480: }
1.23 joris 481:
1.58 joris 482: void
1.105 joris 483: cvs_checkout_file(struct cvs_file *cf, RCSNUM *rnum, char *tag, int co_flags)
1.53 joris 484: {
1.151 joris 485: BUF *bp;
1.148 joris 486: mode_t mode;
1.156 joris 487: int cf_kflag, exists;
1.53 joris 488: time_t rcstime;
489: CVSENTRIES *ent;
490: struct timeval tv[2];
1.149 tobias 491: struct tm datetm;
1.151 joris 492: char *entry, *tosend;
1.115 xsa 493: char kbuf[8], sticky[CVS_REV_BUFSZ], rev[CVS_REV_BUFSZ];
1.96 xsa 494: char timebuf[CVS_TIME_BUFSZ], tbuf[CVS_TIME_BUFSZ];
1.169 deraadt 495: static char lastwd[PATH_MAX];
1.22 jfb 496:
1.87 joris 497: exists = 0;
498: tosend = NULL;
1.104 joris 499:
500: if (!(co_flags & CO_REMOVE))
501: rcsnum_tostr(rnum, rev, sizeof(rev));
1.155 tobias 502: else
503: rev[0] = '\0';
1.41 joris 504:
1.66 joris 505: cvs_log(LP_TRACE, "cvs_checkout_file(%s, %s, %d) -> %s",
1.78 xsa 506: cf->file_path, rev, co_flags,
1.66 joris 507: (cvs_server_active) ? "to client" : "to disk");
1.42 joris 508:
1.78 xsa 509: if (co_flags & CO_DUMP) {
1.106 tobias 510: rcs_rev_write_fd(cf->file_rcs, rnum, STDOUT_FILENO, 0);
1.65 reyk 511: return;
512: }
1.87 joris 513:
1.66 joris 514: if (cvs_server_active == 0) {
1.141 joris 515: (void)unlink(cf->file_path);
516:
1.87 joris 517: if (!(co_flags & CO_MERGE)) {
1.159 joris 518: if (cf->file_flags & FILE_ON_DISK) {
1.87 joris 519: exists = 1;
520: (void)close(cf->fd);
521: }
522:
1.141 joris 523: cf->fd = open(cf->file_path,
1.142 joris 524: O_CREAT | O_RDWR | O_TRUNC);
1.87 joris 525: if (cf->fd == -1)
526: fatal("cvs_checkout_file: open: %s",
527: strerror(errno));
528:
1.106 tobias 529: rcs_rev_write_fd(cf->file_rcs, rnum, cf->fd, 0);
1.159 joris 530: cf->file_flags |= FILE_ON_DISK;
1.87 joris 531: } else {
1.142 joris 532: cvs_merge_file(cf, (cvs_join_rev1 == NULL));
1.66 joris 533: }
534:
1.148 joris 535: mode = cf->file_rcs->rf_mode;
536: mode |= S_IWUSR;
537:
538: if (fchmod(cf->fd, mode) == -1)
1.66 joris 539: fatal("cvs_checkout_file: fchmod: %s", strerror(errno));
540:
1.87 joris 541: if ((exists == 0) && (cf->file_ent == NULL) &&
542: !(co_flags & CO_MERGE))
1.66 joris 543: rcstime = rcs_rev_getdate(cf->file_rcs, rnum);
1.84 joris 544: else
1.66 joris 545: time(&rcstime);
546:
547: tv[0].tv_sec = rcstime;
548: tv[0].tv_usec = 0;
549: tv[1] = tv[0];
550: if (futimes(cf->fd, tv) == -1)
551: fatal("cvs_checkout_file: futimes: %s",
552: strerror(errno));
1.53 joris 553: } else {
554: time(&rcstime);
1.41 joris 555: }
556:
1.149 tobias 557: gmtime_r(&rcstime, &datetm);
558: asctime_r(&datetm, tbuf);
1.107 tobias 559: tbuf[strcspn(tbuf, "\n")] = '\0';
1.58 joris 560:
1.78 xsa 561: if (co_flags & CO_MERGE) {
1.89 xsa 562: (void)xsnprintf(timebuf, sizeof(timebuf), "Result of merge+%s",
1.58 joris 563: tbuf);
564: } else {
565: strlcpy(timebuf, tbuf, sizeof(timebuf));
566: }
1.41 joris 567:
1.154 tobias 568: if (reset_tag) {
569: sticky[0] = '\0';
570: } else if (co_flags & CO_SETSTICKY)
1.105 joris 571: if (tag != NULL)
1.114 xsa 572: (void)xsnprintf(sticky, sizeof(sticky), "T%s", tag);
1.136 joris 573: else if (cvs_specified_date != -1) {
1.149 tobias 574: gmtime_r(&cvs_specified_date, &datetm);
1.138 xsa 575: (void)strftime(sticky, sizeof(sticky),
1.149 tobias 576: "D"CVS_DATE_FMT, &datetm);
1.154 tobias 577: } else if (cvs_directory_date != -1) {
578: gmtime_r(&cvs_directory_date, &datetm);
579: (void)strftime(sticky, sizeof(sticky),
580: "D"CVS_DATE_FMT, &datetm);
1.134 tobias 581: } else
1.114 xsa 582: (void)xsnprintf(sticky, sizeof(sticky), "T%s", rev);
1.154 tobias 583: else if (cf->file_ent != NULL && cf->file_ent->ce_tag != NULL)
1.114 xsa 584: (void)xsnprintf(sticky, sizeof(sticky), "T%s",
1.109 tobias 585: cf->file_ent->ce_tag);
1.89 xsa 586: else
1.114 xsa 587: sticky[0] = '\0';
1.60 joris 588:
1.85 xsa 589: kbuf[0] = '\0';
1.161 joris 590: if (cf->file_rcs != NULL && cf->file_rcs->rf_expand != NULL) {
1.125 tobias 591: cf_kflag = rcs_kflag_get(cf->file_rcs->rf_expand);
592: if (kflag || cf_kflag != RCS_KWEXP_DEFAULT)
593: (void)xsnprintf(kbuf, sizeof(kbuf),
594: "-k%s", cf->file_rcs->rf_expand);
1.132 tobias 595: } else if (!reset_option && cf->file_ent != NULL) {
1.85 xsa 596: if (cf->file_ent->ce_opts != NULL)
597: strlcpy(kbuf, cf->file_ent->ce_opts, sizeof(kbuf));
598: }
599:
1.135 xsa 600: entry = xmalloc(CVS_ENT_MAXLINELEN);
601: cvs_ent_line_str(cf->file_name, rev, timebuf, kbuf, sticky, 0, 0,
602: entry, CVS_ENT_MAXLINELEN);
1.41 joris 603:
1.66 joris 604: if (cvs_server_active == 0) {
1.108 tobias 605: if (!(co_flags & CO_REMOVE) && cvs_cmdop != CVS_OP_EXPORT) {
1.95 joris 606: ent = cvs_ent_open(cf->file_wd);
607: cvs_ent_add(ent, entry);
1.142 joris 608: cf->file_ent = cvs_ent_parse(entry);
1.95 joris 609: }
1.66 joris 610: } else {
1.87 joris 611: if (co_flags & CO_MERGE) {
1.141 joris 612: (void)unlink(cf->file_path);
1.142 joris 613: cvs_merge_file(cf, (cvs_join_rev1 == NULL));
1.87 joris 614: tosend = cf->file_path;
1.160 joris 615: }
616:
617: /*
618: * If this file has a tag, push out the Directory with the
1.163 joris 619: * tag to the client. Except when this file was explicitly
620: * specified on the command line.
1.160 joris 621: */
1.163 joris 622: if (tag != NULL && strcmp(cf->file_wd, lastwd) &&
623: !(cf->file_flags & FILE_USER_SUPPLIED)) {
1.169 deraadt 624: strlcpy(lastwd, cf->file_wd, PATH_MAX);
1.160 joris 625: cvs_server_set_sticky(cf->file_wd, sticky);
1.87 joris 626: }
627:
1.78 xsa 628: if (co_flags & CO_COMMIT)
1.137 tobias 629: cvs_server_update_entry("Updated", cf);
1.87 joris 630: else if (co_flags & CO_MERGE)
631: cvs_server_update_entry("Merged", cf);
1.95 joris 632: else if (co_flags & CO_REMOVE)
633: cvs_server_update_entry("Removed", cf);
1.69 joris 634: else
635: cvs_server_update_entry("Updated", cf);
1.68 joris 636:
1.135 xsa 637: if (!(co_flags & CO_REMOVE)) {
1.95 joris 638: cvs_remote_output(entry);
1.66 joris 639:
1.87 joris 640: if (!(co_flags & CO_MERGE)) {
1.148 joris 641: mode = cf->file_rcs->rf_mode;
642: mode |= S_IWUSR;
1.151 joris 643: bp = rcs_rev_getbuf(cf->file_rcs, rnum, 0);
644: cvs_remote_send_file_buf(cf->file_path,
645: bp, mode);
646: } else {
1.156 joris 647: cvs_remote_send_file(tosend, cf->fd);
1.87 joris 648: }
1.68 joris 649: }
1.66 joris 650: }
1.152 tobias 651:
1.170 nicm 652: free(entry);
1.1 jfb 653: }