[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.152

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