[BACK]Return to checkout.c CVS log [TXT][DIR] Up to [local] / src / usr.bin / cvs

Annotation of src/usr.bin/cvs/checkout.c, Revision 1.144

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