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

1.162   ! joris       1: /*     $OpenBSD: checkout.c,v 1.161 2009/03/18 09:14:09 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.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;
                     98:                        cvs_specified_date = cvs_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.125     tobias    125:                                fatal("%s", cvs_cmd_add.cmd_synopsis);
                    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.125     tobias    200:                                fatal("%s", cvs_cmd_add.cmd_synopsis);
                    201:                        }
                    202:                        break;
1.61      xsa       203:                case 'l':
                    204:                        flags &= ~CR_RECURSE_DIRS;
                    205:                        break;
                    206:                case 'R':
1.110     tobias    207:                        flags |= CR_RECURSE_DIRS;
1.98      xsa       208:                        break;
                    209:                case 'r':
                    210:                        cvs_specified_tag = optarg;
1.61      xsa       211:                        break;
                    212:                default:
                    213:                        fatal("%s", cvs_cmd_export.cmd_synopsis);
                    214:                }
                    215:        }
                    216:
                    217:        argc -= optind;
                    218:        argv += optind;
                    219:
1.108     tobias    220:        if (cvs_specified_tag == NULL)
                    221:                fatal("must specify a tag or date");
                    222:
1.61      xsa       223:        if (argc == 0)
                    224:                fatal("%s", cvs_cmd_export.cmd_synopsis);
                    225:
                    226:        checkout_check_repository(argc, argv);
                    227:
                    228:        return (0);
                    229: }
                    230:
                    231: static void
                    232: checkout_check_repository(int argc, char **argv)
                    233: {
1.67      xsa       234:        int i;
1.123     joris     235:        char *wdir, *d;
1.79      joris     236:        struct cvs_recursion cr;
1.119     joris     237:        struct module_checkout *mc;
1.123     joris     238:        struct cvs_ignpat *ip;
                    239:        struct cvs_filelist *fl, *nxt;
                    240:        char repo[MAXPATHLEN], fpath[MAXPATHLEN], *f[1];
1.79      joris     241:
1.102     tobias    242:        build_dirs = print_stdout ? 0 : 1;
                    243:
1.79      joris     244:        if (current_cvsroot->cr_method != CVS_METHOD_LOCAL) {
                    245:                cvs_client_connect_to_server();
                    246:
1.97      joris     247:                if (cvs_specified_tag != NULL)
                    248:                        cvs_client_send_request("Argument -r%s",
                    249:                            cvs_specified_tag);
1.132     tobias    250:                if (Aflag)
1.79      joris     251:                        cvs_client_send_request("Argument -A");
1.133     joris     252:
                    253:                if (dateflag != NULL)
                    254:                        cvs_client_send_request("Argument -D%s", dateflag);
1.122     joris     255:
1.125     tobias    256:                if (kflag)
                    257:                        cvs_client_send_request("Argument -k%s", koptstr);
                    258:
1.122     joris     259:                if (dflag != NULL)
                    260:                        cvs_client_send_request("Argument -d%s", dflag);
1.80      xsa       261:
                    262:                if (!(flags & CR_RECURSE_DIRS))
                    263:                        cvs_client_send_request("Argument -l");
1.79      joris     264:
                    265:                if (cvs_cmdop == CVS_OP_CHECKOUT && prune_dirs == 1)
                    266:                        cvs_client_send_request("Argument -P");
                    267:
1.101     joris     268:                if (print_stdout == 1)
                    269:                        cvs_client_send_request("Argument -p");
                    270:
1.127     joris     271:                if (nflag == 1)
                    272:                        cvs_client_send_request("Argument -n");
                    273:
1.79      joris     274:                cr.enterdir = NULL;
                    275:                cr.leavedir = NULL;
1.103     tobias    276:                if (print_stdout)
                    277:                        cr.fileproc = NULL;
                    278:                else
                    279:                        cr.fileproc = cvs_client_sendfile;
                    280:
                    281:                flags &= ~CR_REPO;
1.79      joris     282:                cr.flags = flags;
                    283:
1.108     tobias    284:                if (cvs_cmdop != CVS_OP_EXPORT)
                    285:                        cvs_file_run(argc, argv, &cr);
1.79      joris     286:
                    287:                cvs_client_send_files(argv, argc);
                    288:                cvs_client_senddir(".");
                    289:
                    290:                cvs_client_send_request("%s",
                    291:                    (cvs_cmdop == CVS_OP_CHECKOUT) ? "co" : "export");
                    292:
                    293:                cvs_client_get_responses();
                    294:
                    295:                return;
                    296:        }
1.104     joris     297:
1.53      joris     298:        for (i = 0; i < argc; i++) {
1.119     joris     299:                mc = cvs_module_lookup(argv[i]);
                    300:                current_module = mc;
1.116     joris     301:
1.162   ! joris     302:                RB_FOREACH(fl, cvs_flisthead, &(mc->mc_ignores))
1.123     joris     303:                        cvs_file_ignore(fl->file_path, &checkout_ign_pats);
1.13      jfb       304:
1.162   ! joris     305:                RB_FOREACH(fl, cvs_flisthead, &(mc->mc_modules)) {
1.139     tobias    306:                        module_repo_root = NULL;
                    307:
1.123     joris     308:                        (void)xsnprintf(repo, sizeof(repo), "%s/%s",
                    309:                            current_cvsroot->cr_dir, fl->file_path);
1.121     joris     310:
1.123     joris     311:                        if (!(mc->mc_flags & MODULE_ALIAS) || dflag != NULL)
1.139     tobias    312:                                module_repo_root = xstrdup(fl->file_path);
1.123     joris     313:
                    314:                        if (mc->mc_flags & MODULE_NORECURSE)
                    315:                                flags &= ~CR_RECURSE_DIRS;
                    316:
                    317:                        if (dflag != NULL)
                    318:                                wdir = dflag;
1.124     joris     319:                        else if (mc->mc_flags & MODULE_ALIAS)
                    320:                                wdir = fl->file_path;
1.123     joris     321:                        else
1.124     joris     322:                                wdir = mc->mc_name;
1.123     joris     323:
                    324:                        switch (checkout_classify(repo, fl->file_path)) {
                    325:                        case CVS_FILE:
                    326:                                cr.fileproc = cvs_update_local;
                    327:                                cr.flags = flags;
                    328:
                    329:                                if (!(mc->mc_flags & MODULE_ALIAS)) {
                    330:                                        module_repo_root =
1.139     tobias    331:                                            xstrdup(dirname(fl->file_path));
1.123     joris     332:                                        d = wdir;
                    333:                                        (void)xsnprintf(fpath, sizeof(fpath),
                    334:                                            "%s/%s", d,
                    335:                                            basename(fl->file_path));
                    336:                                } else {
                    337:                                        d = dirname(wdir);
                    338:                                        strlcpy(fpath, fl->file_path,
                    339:                                            sizeof(fpath));
                    340:                                }
                    341:
                    342:                                if (build_dirs == 1)
                    343:                                        cvs_mkpath(d, cvs_specified_tag);
                    344:
                    345:                                f[0] = fpath;
                    346:                                cvs_file_run(1, f, &cr);
                    347:                                break;
                    348:                        case CVS_DIR:
                    349:                                if (build_dirs == 1)
                    350:                                        cvs_mkpath(wdir, cvs_specified_tag);
                    351:                                checkout_repository(repo, wdir);
                    352:                                break;
                    353:                        default:
                    354:                                break;
                    355:                        }
1.126     joris     356:
1.127     joris     357:                        if (nflag != 1 && mc->mc_prog != NULL &&
1.128     joris     358:                            mc->mc_flags & MODULE_RUN_ON_CHECKOUT)
1.147     joris     359:                                cvs_exec(mc->mc_prog, NULL, 0);
1.139     tobias    360:
                    361:                        if (module_repo_root != NULL)
                    362:                                xfree(module_repo_root);
1.123     joris     363:                }
1.119     joris     364:
1.123     joris     365:                if (mc->mc_canfree == 1) {
1.162   ! joris     366:                        for (fl = RB_MIN(cvs_flisthead, &(mc->mc_modules));
        !           367:                            fl != NULL; fl = nxt) {
        !           368:                                nxt = RB_NEXT(cvs_flisthead,
        !           369:                                    &(mc->mc_modules), fl);
        !           370:                                RB_REMOVE(cvs_flisthead,
        !           371:                                    &(mc->mc_modules), fl);
1.123     joris     372:                                xfree(fl->file_path);
                    373:                                xfree(fl);
                    374:                        }
                    375:                }
1.120     joris     376:
1.123     joris     377:                while ((ip = TAILQ_FIRST(&checkout_ign_pats)) != NULL) {
                    378:                        TAILQ_REMOVE(&checkout_ign_pats, ip, ip_list);
                    379:                        xfree(ip);
1.113     tobias    380:                }
1.119     joris     381:
                    382:                xfree(mc);
1.113     tobias    383:        }
                    384: }
1.100     tobias    385:
1.113     tobias    386: static int
                    387: checkout_classify(const char *repo, const char *arg)
                    388: {
                    389:        char *d, *f, fpath[MAXPATHLEN];
                    390:        struct stat sb;
                    391:
                    392:        if (stat(repo, &sb) == 0) {
1.123     joris     393:                if (S_ISDIR(sb.st_mode))
                    394:                        return CVS_DIR;
1.113     tobias    395:        }
1.97      joris     396:
1.113     tobias    397:        d = dirname(repo);
                    398:        f = basename(repo);
                    399:
                    400:        (void)xsnprintf(fpath, sizeof(fpath), "%s/%s%s", d, f, RCS_FILE_EXT);
                    401:        if (stat(fpath, &sb) == 0) {
                    402:                if (!S_ISREG(sb.st_mode)) {
                    403:                        cvs_log(LP_ERR, "ignoring %s: not a regular file", arg);
                    404:                        return 0;
                    405:                }
                    406:                return CVS_FILE;
1.33      xsa       407:        }
1.113     tobias    408:
                    409:        (void)xsnprintf(fpath, sizeof(fpath), "%s/%s/%s%s",
                    410:            d, CVS_PATH_ATTIC, f, RCS_FILE_EXT);
                    411:        if (stat(fpath, &sb) == 0) {
                    412:                if (!S_ISREG(sb.st_mode)) {
                    413:                        cvs_log(LP_ERR, "ignoring %s: not a regular file", arg);
                    414:                        return 0;
                    415:                }
                    416:                return CVS_FILE;
                    417:        }
                    418:
                    419:        cvs_log(LP_ERR, "cannot find module `%s' - ignored", arg);
                    420:        return 0;
1.14      joris     421: }
1.9       jfb       422:
1.53      joris     423: static void
                    424: checkout_repository(const char *repobase, const char *wdbase)
1.14      joris     425: {
1.53      joris     426:        struct cvs_flisthead fl, dl;
                    427:        struct cvs_recursion cr;
                    428:
1.162   ! joris     429:        RB_INIT(&fl);
        !           430:        RB_INIT(&dl);
1.94      joris     431:
1.99      xsa       432:        cvs_history_add((cvs_cmdop == CVS_OP_CHECKOUT) ?
                    433:            CVS_HISTORY_CHECKOUT : CVS_HISTORY_EXPORT, NULL, wdbase);
1.41      joris     434:
1.112     tobias    435:        if (print_stdout) {
                    436:                cr.enterdir = NULL;
                    437:                cr.leavedir = NULL;
                    438:        } else {
                    439:                cr.enterdir = cvs_update_enterdir;
1.151     joris     440:                if (cvs_server_active == 1) {
                    441:                        if (disable_fast_checkout != 1)
                    442:                                cr.leavedir = NULL;
                    443:                        else
                    444:                                cr.leavedir = cvs_update_leavedir;
                    445:                } else {
                    446:                        cr.leavedir = prune_dirs ? cvs_update_leavedir : NULL;
                    447:                }
1.112     tobias    448:        }
1.64      joris     449:        cr.fileproc = cvs_update_local;
1.78      xsa       450:        cr.flags = flags;
1.41      joris     451:
1.143     joris     452:        cvs_repository_lock(repobase, 0);
1.111     tobias    453:        cvs_repository_getdir(repobase, wdbase, &fl, &dl,
1.158     joris     454:            flags & CR_RECURSE_DIRS ? REPOSITORY_DODIRS : 0);
1.1       jfb       455:
1.53      joris     456:        cvs_file_walklist(&fl, &cr);
                    457:        cvs_file_freelist(&fl);
1.23      joris     458:
1.53      joris     459:        cvs_repository_unlock(repobase);
1.23      joris     460:
1.53      joris     461:        cvs_file_walklist(&dl, &cr);
                    462:        cvs_file_freelist(&dl);
                    463: }
1.23      joris     464:
1.58      joris     465: void
1.105     joris     466: cvs_checkout_file(struct cvs_file *cf, RCSNUM *rnum, char *tag, int co_flags)
1.53      joris     467: {
1.151     joris     468:        BUF *bp;
1.148     joris     469:        mode_t mode;
1.156     joris     470:        int cf_kflag, exists;
1.53      joris     471:        time_t rcstime;
                    472:        CVSENTRIES *ent;
                    473:        struct timeval tv[2];
1.149     tobias    474:        struct tm datetm;
1.151     joris     475:        char *entry, *tosend;
1.115     xsa       476:        char kbuf[8], sticky[CVS_REV_BUFSZ], rev[CVS_REV_BUFSZ];
1.96      xsa       477:        char timebuf[CVS_TIME_BUFSZ], tbuf[CVS_TIME_BUFSZ];
1.22      jfb       478:
1.87      joris     479:        exists = 0;
                    480:        tosend = NULL;
1.104     joris     481:
                    482:        if (!(co_flags & CO_REMOVE))
                    483:                rcsnum_tostr(rnum, rev, sizeof(rev));
1.155     tobias    484:        else
                    485:                rev[0] = '\0';
1.41      joris     486:
1.66      joris     487:        cvs_log(LP_TRACE, "cvs_checkout_file(%s, %s, %d) -> %s",
1.78      xsa       488:            cf->file_path, rev, co_flags,
1.66      joris     489:            (cvs_server_active) ? "to client" : "to disk");
1.42      joris     490:
1.78      xsa       491:        if (co_flags & CO_DUMP) {
1.106     tobias    492:                rcs_rev_write_fd(cf->file_rcs, rnum, STDOUT_FILENO, 0);
1.65      reyk      493:                return;
                    494:        }
1.87      joris     495:
1.66      joris     496:        if (cvs_server_active == 0) {
1.141     joris     497:                (void)unlink(cf->file_path);
                    498:
1.87      joris     499:                if (!(co_flags & CO_MERGE)) {
1.159     joris     500:                        if (cf->file_flags & FILE_ON_DISK) {
1.87      joris     501:                                exists = 1;
                    502:                                (void)close(cf->fd);
                    503:                        }
                    504:
1.141     joris     505:                        cf->fd = open(cf->file_path,
1.142     joris     506:                            O_CREAT | O_RDWR | O_TRUNC);
1.87      joris     507:                        if (cf->fd == -1)
                    508:                                fatal("cvs_checkout_file: open: %s",
                    509:                                    strerror(errno));
                    510:
1.106     tobias    511:                        rcs_rev_write_fd(cf->file_rcs, rnum, cf->fd, 0);
1.159     joris     512:                        cf->file_flags |= FILE_ON_DISK;
1.87      joris     513:                } else {
1.142     joris     514:                        cvs_merge_file(cf, (cvs_join_rev1 == NULL));
1.66      joris     515:                }
                    516:
1.148     joris     517:                mode = cf->file_rcs->rf_mode;
                    518:                mode |= S_IWUSR;
                    519:
                    520:                if (fchmod(cf->fd, mode) == -1)
1.66      joris     521:                        fatal("cvs_checkout_file: fchmod: %s", strerror(errno));
                    522:
1.87      joris     523:                if ((exists == 0) && (cf->file_ent == NULL) &&
                    524:                    !(co_flags & CO_MERGE))
1.66      joris     525:                        rcstime = rcs_rev_getdate(cf->file_rcs, rnum);
1.84      joris     526:                else
1.66      joris     527:                        time(&rcstime);
                    528:
                    529:                tv[0].tv_sec = rcstime;
                    530:                tv[0].tv_usec = 0;
                    531:                tv[1] = tv[0];
                    532:                if (futimes(cf->fd, tv) == -1)
                    533:                        fatal("cvs_checkout_file: futimes: %s",
                    534:                            strerror(errno));
1.53      joris     535:        } else {
                    536:                time(&rcstime);
1.41      joris     537:        }
                    538:
1.149     tobias    539:        gmtime_r(&rcstime, &datetm);
                    540:        asctime_r(&datetm, tbuf);
1.107     tobias    541:        tbuf[strcspn(tbuf, "\n")] = '\0';
1.58      joris     542:
1.78      xsa       543:        if (co_flags & CO_MERGE) {
1.89      xsa       544:                (void)xsnprintf(timebuf, sizeof(timebuf), "Result of merge+%s",
1.58      joris     545:                    tbuf);
                    546:        } else {
                    547:                strlcpy(timebuf, tbuf, sizeof(timebuf));
                    548:        }
1.41      joris     549:
1.154     tobias    550:        if (reset_tag) {
                    551:                sticky[0] = '\0';
                    552:        } else if (co_flags & CO_SETSTICKY)
1.105     joris     553:                if (tag != NULL)
1.114     xsa       554:                        (void)xsnprintf(sticky, sizeof(sticky), "T%s", tag);
1.136     joris     555:                else if (cvs_specified_date != -1) {
1.149     tobias    556:                        gmtime_r(&cvs_specified_date, &datetm);
1.138     xsa       557:                        (void)strftime(sticky, sizeof(sticky),
1.149     tobias    558:                            "D"CVS_DATE_FMT, &datetm);
1.154     tobias    559:                } else if (cvs_directory_date != -1) {
                    560:                        gmtime_r(&cvs_directory_date, &datetm);
                    561:                        (void)strftime(sticky, sizeof(sticky),
                    562:                            "D"CVS_DATE_FMT, &datetm);
1.134     tobias    563:                } else
1.114     xsa       564:                        (void)xsnprintf(sticky, sizeof(sticky), "T%s", rev);
1.154     tobias    565:        else if (cf->file_ent != NULL && cf->file_ent->ce_tag != NULL)
1.114     xsa       566:                (void)xsnprintf(sticky, sizeof(sticky), "T%s",
1.109     tobias    567:                    cf->file_ent->ce_tag);
1.89      xsa       568:        else
1.114     xsa       569:                sticky[0] = '\0';
1.60      joris     570:
1.85      xsa       571:        kbuf[0] = '\0';
1.161     joris     572:        if (cf->file_rcs != NULL && cf->file_rcs->rf_expand != NULL) {
1.125     tobias    573:                cf_kflag = rcs_kflag_get(cf->file_rcs->rf_expand);
                    574:                if (kflag || cf_kflag != RCS_KWEXP_DEFAULT)
                    575:                        (void)xsnprintf(kbuf, sizeof(kbuf),
                    576:                            "-k%s", cf->file_rcs->rf_expand);
1.132     tobias    577:        } else if (!reset_option && cf->file_ent != NULL) {
1.85      xsa       578:                if (cf->file_ent->ce_opts != NULL)
                    579:                        strlcpy(kbuf, cf->file_ent->ce_opts, sizeof(kbuf));
                    580:        }
                    581:
1.135     xsa       582:        entry = xmalloc(CVS_ENT_MAXLINELEN);
                    583:        cvs_ent_line_str(cf->file_name, rev, timebuf, kbuf, sticky, 0, 0,
                    584:            entry, CVS_ENT_MAXLINELEN);
1.41      joris     585:
1.66      joris     586:        if (cvs_server_active == 0) {
1.108     tobias    587:                if (!(co_flags & CO_REMOVE) && cvs_cmdop != CVS_OP_EXPORT) {
1.95      joris     588:                        ent = cvs_ent_open(cf->file_wd);
                    589:                        cvs_ent_add(ent, entry);
1.142     joris     590:                        cf->file_ent = cvs_ent_parse(entry);
1.95      joris     591:                }
1.66      joris     592:        } else {
1.87      joris     593:                if (co_flags & CO_MERGE) {
1.141     joris     594:                        (void)unlink(cf->file_path);
1.142     joris     595:                        cvs_merge_file(cf, (cvs_join_rev1 == NULL));
1.87      joris     596:                        tosend = cf->file_path;
1.160     joris     597:                }
                    598:
                    599:                /*
                    600:                 * If this file has a tag, push out the Directory with the
                    601:                 * tag to the client.
                    602:                 */
                    603:                if (tag != NULL && strcmp(cf->file_wd, lastwd)) {
                    604:                        strlcpy(lastwd, cf->file_wd, MAXPATHLEN);
                    605:                        cvs_server_set_sticky(cf->file_wd, sticky);
1.87      joris     606:                }
                    607:
1.78      xsa       608:                if (co_flags & CO_COMMIT)
1.137     tobias    609:                        cvs_server_update_entry("Updated", cf);
1.87      joris     610:                else if (co_flags & CO_MERGE)
                    611:                        cvs_server_update_entry("Merged", cf);
1.95      joris     612:                else if (co_flags & CO_REMOVE)
                    613:                        cvs_server_update_entry("Removed", cf);
1.69      joris     614:                else
                    615:                        cvs_server_update_entry("Updated", cf);
1.68      joris     616:
1.135     xsa       617:                if (!(co_flags & CO_REMOVE)) {
1.95      joris     618:                        cvs_remote_output(entry);
1.66      joris     619:
1.87      joris     620:                        if (!(co_flags & CO_MERGE)) {
1.148     joris     621:                                mode = cf->file_rcs->rf_mode;
                    622:                                mode |= S_IWUSR;
1.151     joris     623:                                bp = rcs_rev_getbuf(cf->file_rcs, rnum, 0);
                    624:                                cvs_remote_send_file_buf(cf->file_path,
                    625:                                    bp, mode);
                    626:                        } else {
1.156     joris     627:                                cvs_remote_send_file(tosend, cf->fd);
1.87      joris     628:                        }
1.68      joris     629:                }
1.66      joris     630:        }
1.152     tobias    631:
                    632:        xfree(entry);
1.1       jfb       633: }