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

1.160   ! joris       1: /*     $OpenBSD: checkout.c,v 1.159 2009/02/21 14:50:53 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.123     joris     302:                TAILQ_FOREACH(fl, &(mc->mc_ignores), flist)
                    303:                        cvs_file_ignore(fl->file_path, &checkout_ign_pats);
1.13      jfb       304:
1.123     joris     305:                TAILQ_FOREACH(fl, &(mc->mc_modules), flist) {
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) {
                    366:                        for (fl = TAILQ_FIRST(&(mc->mc_modules));
                    367:                            fl != TAILQ_END(&(mc->mc_modules)); fl = nxt) {
                    368:                                nxt = TAILQ_NEXT(fl, flist);
                    369:                                TAILQ_REMOVE(&(mc->mc_modules), fl, flist);
                    370:                                xfree(fl->file_path);
                    371:                                xfree(fl);
                    372:                        }
                    373:                }
1.120     joris     374:
1.123     joris     375:                while ((ip = TAILQ_FIRST(&checkout_ign_pats)) != NULL) {
                    376:                        TAILQ_REMOVE(&checkout_ign_pats, ip, ip_list);
                    377:                        xfree(ip);
1.113     tobias    378:                }
1.119     joris     379:
                    380:                xfree(mc);
1.113     tobias    381:        }
                    382: }
1.100     tobias    383:
1.113     tobias    384: static int
                    385: checkout_classify(const char *repo, const char *arg)
                    386: {
                    387:        char *d, *f, fpath[MAXPATHLEN];
                    388:        struct stat sb;
                    389:
                    390:        if (stat(repo, &sb) == 0) {
1.123     joris     391:                if (S_ISDIR(sb.st_mode))
                    392:                        return CVS_DIR;
1.113     tobias    393:        }
1.97      joris     394:
1.113     tobias    395:        d = dirname(repo);
                    396:        f = basename(repo);
                    397:
                    398:        (void)xsnprintf(fpath, sizeof(fpath), "%s/%s%s", d, f, RCS_FILE_EXT);
                    399:        if (stat(fpath, &sb) == 0) {
                    400:                if (!S_ISREG(sb.st_mode)) {
                    401:                        cvs_log(LP_ERR, "ignoring %s: not a regular file", arg);
                    402:                        return 0;
                    403:                }
                    404:                return CVS_FILE;
1.33      xsa       405:        }
1.113     tobias    406:
                    407:        (void)xsnprintf(fpath, sizeof(fpath), "%s/%s/%s%s",
                    408:            d, CVS_PATH_ATTIC, f, RCS_FILE_EXT);
                    409:        if (stat(fpath, &sb) == 0) {
                    410:                if (!S_ISREG(sb.st_mode)) {
                    411:                        cvs_log(LP_ERR, "ignoring %s: not a regular file", arg);
                    412:                        return 0;
                    413:                }
                    414:                return CVS_FILE;
                    415:        }
                    416:
                    417:        cvs_log(LP_ERR, "cannot find module `%s' - ignored", arg);
                    418:        return 0;
1.14      joris     419: }
1.9       jfb       420:
1.53      joris     421: static void
                    422: checkout_repository(const char *repobase, const char *wdbase)
1.14      joris     423: {
1.53      joris     424:        struct cvs_flisthead fl, dl;
                    425:        struct cvs_recursion cr;
                    426:
                    427:        TAILQ_INIT(&fl);
                    428:        TAILQ_INIT(&dl);
1.94      joris     429:
1.99      xsa       430:        cvs_history_add((cvs_cmdop == CVS_OP_CHECKOUT) ?
                    431:            CVS_HISTORY_CHECKOUT : CVS_HISTORY_EXPORT, NULL, wdbase);
1.41      joris     432:
1.112     tobias    433:        if (print_stdout) {
                    434:                cr.enterdir = NULL;
                    435:                cr.leavedir = NULL;
                    436:        } else {
                    437:                cr.enterdir = cvs_update_enterdir;
1.151     joris     438:                if (cvs_server_active == 1) {
                    439:                        if (disable_fast_checkout != 1)
                    440:                                cr.leavedir = NULL;
                    441:                        else
                    442:                                cr.leavedir = cvs_update_leavedir;
                    443:                } else {
                    444:                        cr.leavedir = prune_dirs ? cvs_update_leavedir : NULL;
                    445:                }
1.112     tobias    446:        }
1.64      joris     447:        cr.fileproc = cvs_update_local;
1.78      xsa       448:        cr.flags = flags;
1.41      joris     449:
1.143     joris     450:        cvs_repository_lock(repobase, 0);
1.111     tobias    451:        cvs_repository_getdir(repobase, wdbase, &fl, &dl,
1.158     joris     452:            flags & CR_RECURSE_DIRS ? REPOSITORY_DODIRS : 0);
1.1       jfb       453:
1.53      joris     454:        cvs_file_walklist(&fl, &cr);
                    455:        cvs_file_freelist(&fl);
1.23      joris     456:
1.53      joris     457:        cvs_repository_unlock(repobase);
1.23      joris     458:
1.53      joris     459:        cvs_file_walklist(&dl, &cr);
                    460:        cvs_file_freelist(&dl);
                    461: }
1.23      joris     462:
1.58      joris     463: void
1.105     joris     464: cvs_checkout_file(struct cvs_file *cf, RCSNUM *rnum, char *tag, int co_flags)
1.53      joris     465: {
1.151     joris     466:        BUF *bp;
1.148     joris     467:        mode_t mode;
1.156     joris     468:        int cf_kflag, exists;
1.53      joris     469:        time_t rcstime;
                    470:        CVSENTRIES *ent;
                    471:        struct timeval tv[2];
1.149     tobias    472:        struct tm datetm;
1.151     joris     473:        char *entry, *tosend;
1.115     xsa       474:        char kbuf[8], sticky[CVS_REV_BUFSZ], rev[CVS_REV_BUFSZ];
1.96      xsa       475:        char timebuf[CVS_TIME_BUFSZ], tbuf[CVS_TIME_BUFSZ];
1.22      jfb       476:
1.87      joris     477:        exists = 0;
                    478:        tosend = NULL;
1.104     joris     479:
                    480:        if (!(co_flags & CO_REMOVE))
                    481:                rcsnum_tostr(rnum, rev, sizeof(rev));
1.155     tobias    482:        else
                    483:                rev[0] = '\0';
1.41      joris     484:
1.66      joris     485:        cvs_log(LP_TRACE, "cvs_checkout_file(%s, %s, %d) -> %s",
1.78      xsa       486:            cf->file_path, rev, co_flags,
1.66      joris     487:            (cvs_server_active) ? "to client" : "to disk");
1.42      joris     488:
1.78      xsa       489:        if (co_flags & CO_DUMP) {
1.106     tobias    490:                rcs_rev_write_fd(cf->file_rcs, rnum, STDOUT_FILENO, 0);
1.65      reyk      491:                return;
                    492:        }
1.87      joris     493:
1.66      joris     494:        if (cvs_server_active == 0) {
1.141     joris     495:                (void)unlink(cf->file_path);
                    496:
1.87      joris     497:                if (!(co_flags & CO_MERGE)) {
1.159     joris     498:                        if (cf->file_flags & FILE_ON_DISK) {
1.87      joris     499:                                exists = 1;
                    500:                                (void)close(cf->fd);
                    501:                        }
                    502:
1.141     joris     503:                        cf->fd = open(cf->file_path,
1.142     joris     504:                            O_CREAT | O_RDWR | O_TRUNC);
1.87      joris     505:                        if (cf->fd == -1)
                    506:                                fatal("cvs_checkout_file: open: %s",
                    507:                                    strerror(errno));
                    508:
1.106     tobias    509:                        rcs_rev_write_fd(cf->file_rcs, rnum, cf->fd, 0);
1.159     joris     510:                        cf->file_flags |= FILE_ON_DISK;
1.87      joris     511:                } else {
1.142     joris     512:                        cvs_merge_file(cf, (cvs_join_rev1 == NULL));
1.66      joris     513:                }
                    514:
1.148     joris     515:                mode = cf->file_rcs->rf_mode;
                    516:                mode |= S_IWUSR;
                    517:
                    518:                if (fchmod(cf->fd, mode) == -1)
1.66      joris     519:                        fatal("cvs_checkout_file: fchmod: %s", strerror(errno));
                    520:
1.87      joris     521:                if ((exists == 0) && (cf->file_ent == NULL) &&
                    522:                    !(co_flags & CO_MERGE))
1.66      joris     523:                        rcstime = rcs_rev_getdate(cf->file_rcs, rnum);
1.84      joris     524:                else
1.66      joris     525:                        time(&rcstime);
                    526:
                    527:                tv[0].tv_sec = rcstime;
                    528:                tv[0].tv_usec = 0;
                    529:                tv[1] = tv[0];
                    530:                if (futimes(cf->fd, tv) == -1)
                    531:                        fatal("cvs_checkout_file: futimes: %s",
                    532:                            strerror(errno));
1.53      joris     533:        } else {
                    534:                time(&rcstime);
1.41      joris     535:        }
                    536:
1.149     tobias    537:        gmtime_r(&rcstime, &datetm);
                    538:        asctime_r(&datetm, tbuf);
1.107     tobias    539:        tbuf[strcspn(tbuf, "\n")] = '\0';
1.58      joris     540:
1.78      xsa       541:        if (co_flags & CO_MERGE) {
1.89      xsa       542:                (void)xsnprintf(timebuf, sizeof(timebuf), "Result of merge+%s",
1.58      joris     543:                    tbuf);
                    544:        } else {
                    545:                strlcpy(timebuf, tbuf, sizeof(timebuf));
                    546:        }
1.41      joris     547:
1.154     tobias    548:        if (reset_tag) {
                    549:                sticky[0] = '\0';
                    550:        } else if (co_flags & CO_SETSTICKY)
1.105     joris     551:                if (tag != NULL)
1.114     xsa       552:                        (void)xsnprintf(sticky, sizeof(sticky), "T%s", tag);
1.136     joris     553:                else if (cvs_specified_date != -1) {
1.149     tobias    554:                        gmtime_r(&cvs_specified_date, &datetm);
1.138     xsa       555:                        (void)strftime(sticky, sizeof(sticky),
1.149     tobias    556:                            "D"CVS_DATE_FMT, &datetm);
1.154     tobias    557:                } else if (cvs_directory_date != -1) {
                    558:                        gmtime_r(&cvs_directory_date, &datetm);
                    559:                        (void)strftime(sticky, sizeof(sticky),
                    560:                            "D"CVS_DATE_FMT, &datetm);
1.134     tobias    561:                } else
1.114     xsa       562:                        (void)xsnprintf(sticky, sizeof(sticky), "T%s", rev);
1.154     tobias    563:        else if (cf->file_ent != NULL && cf->file_ent->ce_tag != NULL)
1.114     xsa       564:                (void)xsnprintf(sticky, sizeof(sticky), "T%s",
1.109     tobias    565:                    cf->file_ent->ce_tag);
1.89      xsa       566:        else
1.114     xsa       567:                sticky[0] = '\0';
1.60      joris     568:
1.85      xsa       569:        kbuf[0] = '\0';
1.125     tobias    570:        if (cf->file_rcs->rf_expand != NULL) {
                    571:                cf_kflag = rcs_kflag_get(cf->file_rcs->rf_expand);
                    572:                if (kflag || cf_kflag != RCS_KWEXP_DEFAULT)
                    573:                        (void)xsnprintf(kbuf, sizeof(kbuf),
                    574:                            "-k%s", cf->file_rcs->rf_expand);
1.132     tobias    575:        } else if (!reset_option && cf->file_ent != NULL) {
1.85      xsa       576:                if (cf->file_ent->ce_opts != NULL)
                    577:                        strlcpy(kbuf, cf->file_ent->ce_opts, sizeof(kbuf));
                    578:        }
                    579:
1.135     xsa       580:        entry = xmalloc(CVS_ENT_MAXLINELEN);
                    581:        cvs_ent_line_str(cf->file_name, rev, timebuf, kbuf, sticky, 0, 0,
                    582:            entry, CVS_ENT_MAXLINELEN);
1.41      joris     583:
1.66      joris     584:        if (cvs_server_active == 0) {
1.108     tobias    585:                if (!(co_flags & CO_REMOVE) && cvs_cmdop != CVS_OP_EXPORT) {
1.95      joris     586:                        ent = cvs_ent_open(cf->file_wd);
                    587:                        cvs_ent_add(ent, entry);
1.142     joris     588:                        cf->file_ent = cvs_ent_parse(entry);
1.95      joris     589:                }
1.66      joris     590:        } else {
1.87      joris     591:                if (co_flags & CO_MERGE) {
1.141     joris     592:                        (void)unlink(cf->file_path);
1.142     joris     593:                        cvs_merge_file(cf, (cvs_join_rev1 == NULL));
1.87      joris     594:                        tosend = cf->file_path;
1.160   ! joris     595:                }
        !           596:
        !           597:                /*
        !           598:                 * If this file has a tag, push out the Directory with the
        !           599:                 * tag to the client.
        !           600:                 */
        !           601:                if (tag != NULL && strcmp(cf->file_wd, lastwd)) {
        !           602:                        strlcpy(lastwd, cf->file_wd, MAXPATHLEN);
        !           603:                        cvs_server_set_sticky(cf->file_wd, sticky);
1.87      joris     604:                }
                    605:
1.78      xsa       606:                if (co_flags & CO_COMMIT)
1.137     tobias    607:                        cvs_server_update_entry("Updated", cf);
1.87      joris     608:                else if (co_flags & CO_MERGE)
                    609:                        cvs_server_update_entry("Merged", cf);
1.95      joris     610:                else if (co_flags & CO_REMOVE)
                    611:                        cvs_server_update_entry("Removed", cf);
1.69      joris     612:                else
                    613:                        cvs_server_update_entry("Updated", cf);
1.68      joris     614:
1.135     xsa       615:                if (!(co_flags & CO_REMOVE)) {
1.95      joris     616:                        cvs_remote_output(entry);
1.66      joris     617:
1.87      joris     618:                        if (!(co_flags & CO_MERGE)) {
1.148     joris     619:                                mode = cf->file_rcs->rf_mode;
                    620:                                mode |= S_IWUSR;
1.151     joris     621:                                bp = rcs_rev_getbuf(cf->file_rcs, rnum, 0);
                    622:                                cvs_remote_send_file_buf(cf->file_path,
                    623:                                    bp, mode);
                    624:                        } else {
1.156     joris     625:                                cvs_remote_send_file(tosend, cf->fd);
1.87      joris     626:                        }
1.68      joris     627:                }
1.66      joris     628:        }
1.152     tobias    629:
                    630:        xfree(entry);
1.1       jfb       631: }