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

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