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

Annotation of src/usr.bin/cvs/add.c, Revision 1.112

1.112   ! nicm        1: /*     $OpenBSD: add.c,v 1.111 2015/01/16 06:40:06 deraadt Exp $       */
1.1       jfb         2: /*
1.43      joris       3:  * Copyright (c) 2006 Joris Vink <joris@openbsd.org>
1.55      xsa         4:  * Copyright (c) 2005, 2006 Xavier Santolaria <xsa@openbsd.org>
1.1       jfb         5:  *
1.43      joris       6:  * Permission to use, copy, modify, and distribute this software for any
                      7:  * purpose with or without fee is hereby granted, provided that the above
                      8:  * copyright notice and this permission notice appear in all copies.
1.1       jfb         9:  *
1.43      joris      10:  * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
                     11:  * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
                     12:  * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
                     13:  * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
                     14:  * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
                     15:  * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
                     16:  * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
1.1       jfb        17:  */
                     18:
1.77      otto       19: #include <sys/stat.h>
                     20:
                     21: #include <errno.h>
1.105     tobias     22: #include <fcntl.h>
1.112   ! nicm       23: #include <stdlib.h>
1.77      otto       24: #include <string.h>
                     25: #include <unistd.h>
1.1       jfb        26:
                     27: #include "cvs.h"
1.61      xsa        28: #include "remote.h"
1.1       jfb        29:
1.48      xsa        30: extern char *__progname;
                     31:
1.100     joris      32: void   cvs_add_loginfo(char *);
1.63      joris      33: void   cvs_add_entry(struct cvs_file *);
1.85      tobias     34: void   cvs_add_remote(struct cvs_file *);
1.1       jfb        35:
1.45      joris      36: static void add_directory(struct cvs_file *);
                     37: static void add_file(struct cvs_file *);
1.55      xsa        38: static void add_entry(struct cvs_file *);
1.45      joris      39:
1.90      tobias     40: int            kflag = 0;
1.108     zinovik    41: static u_int   added_files = 0;
1.90      tobias     42: static char    kbuf[8];
1.72      xsa        43:
1.100     joris      44: extern char    *logmsg;
                     45: extern char    *loginfo;
1.21      jfb        46:
                     47: struct cvs_cmd cvs_cmd_add = {
1.88      tobias     48:        CVS_OP_ADD, CVS_USE_WDIR, "add",
1.21      jfb        49:        { "ad", "new" },
1.43      joris      50:        "Add a new file or directory to the repository",
1.72      xsa        51:        "[-k mode] [-m message] ...",
                     52:        "k:m:",
1.21      jfb        53:        NULL,
1.43      joris      54:        cvs_add
1.15      joris      55: };
1.3       jfb        56:
1.43      joris      57: int
                     58: cvs_add(int argc, char **argv)
1.1       jfb        59: {
1.15      joris      60:        int ch;
1.43      joris      61:        int flags;
                     62:        struct cvs_recursion cr;
1.1       jfb        63:
1.45      joris      64:        flags = CR_REPO;
1.1       jfb        65:
1.43      joris      66:        while ((ch = getopt(argc, argv, cvs_cmd_add.cmd_opts)) != -1) {
1.1       jfb        67:                switch (ch) {
1.72      xsa        68:                case 'k':
1.90      tobias     69:                        kflag = rcs_kflag_get(optarg);
1.72      xsa        70:                        if (RCS_KWEXP_INVAL(kflag)) {
                     71:                                cvs_log(LP_ERR,
1.98      tobias     72:                                    "invalid RCS keyword expansion mode");
1.72      xsa        73:                                fatal("%s", cvs_cmd_add.cmd_synopsis);
                     74:                        }
1.90      tobias     75:                        (void)xsnprintf(kbuf, sizeof(kbuf), "-k%s", optarg);
1.72      xsa        76:                        break;
1.1       jfb        77:                case 'm':
1.87      tobias     78:                        logmsg = optarg;
1.1       jfb        79:                        break;
                     80:                default:
1.43      joris      81:                        fatal("%s", cvs_cmd_add.cmd_synopsis);
1.1       jfb        82:                }
                     83:        }
                     84:
1.43      joris      85:        argc -= optind;
                     86:        argv += optind;
1.28      xsa        87:
1.46      joris      88:        if (argc == 0)
                     89:                fatal("%s", cvs_cmd_add.cmd_synopsis);
                     90:
1.43      joris      91:        cr.enterdir = NULL;
                     92:        cr.leavedir = NULL;
1.61      xsa        93:
                     94:        if (current_cvsroot->cr_method != CVS_METHOD_LOCAL) {
1.66      joris      95:                cvs_client_connect_to_server();
1.85      tobias     96:                cr.fileproc = cvs_add_remote;
1.97      joris      97:                flags = 0;
1.61      xsa        98:
1.92      joris      99:                if (kflag)
1.72      xsa       100:                        cvs_client_send_request("Argument %s", kbuf);
                    101:
1.61      xsa       102:                if (logmsg != NULL)
1.80      joris     103:                        cvs_client_send_logmsg(logmsg);
1.61      xsa       104:        } else {
1.100     joris     105:                if (logmsg != NULL && cvs_logmsg_verify(logmsg))
                    106:                        return (0);
                    107:
1.61      xsa       108:                cr.fileproc = cvs_add_local;
                    109:        }
                    110:
1.43      joris     111:        cr.flags = flags;
                    112:
1.46      joris     113:        cvs_file_run(argc, argv, &cr);
1.61      xsa       114:
1.108     zinovik   115:        if (added_files != 0) {
                    116:                cvs_log(LP_NOTICE, "use '%s commit' to add %s "
                    117:                    "permanently", __progname,
                    118:                    (added_files == 1) ? "this file" : "these files");
                    119:        }
                    120:
1.61      xsa       121:        if (current_cvsroot->cr_method != CVS_METHOD_LOCAL) {
1.85      tobias    122:                cvs_client_senddir(".");
1.61      xsa       123:                cvs_client_send_files(argv, argc);
                    124:                cvs_client_send_request("add");
                    125:                cvs_client_get_responses();
1.63      joris     126:
                    127:                if (server_response == SERVER_OK) {
                    128:                        cr.fileproc = cvs_add_entry;
                    129:                        cvs_file_run(argc, argv, &cr);
                    130:                }
1.61      xsa       131:        }
                    132:
1.3       jfb       133:        return (0);
1.63      joris     134: }
                    135:
                    136: void
                    137: cvs_add_entry(struct cvs_file *cf)
                    138: {
1.94      xsa       139:        char *entry;
1.63      joris     140:        CVSENTRIES *entlist;
                    141:
                    142:        if (cf->file_type == CVS_DIR) {
1.94      xsa       143:                entry = xmalloc(CVS_ENT_MAXLINELEN);
                    144:                cvs_ent_line_str(cf->file_name, NULL, NULL, NULL, NULL, 1, 0,
                    145:                    entry, CVS_ENT_MAXLINELEN);
1.64      joris     146:
1.63      joris     147:                entlist = cvs_ent_open(cf->file_wd);
                    148:                cvs_ent_add(entlist, entry);
1.94      xsa       149:
1.112   ! nicm      150:                free(entry);
1.63      joris     151:        } else {
                    152:                add_entry(cf);
                    153:        }
1.3       jfb       154: }
                    155:
1.43      joris     156: void
                    157: cvs_add_local(struct cvs_file *cf)
1.3       jfb       158: {
1.45      joris     159:        cvs_log(LP_TRACE, "cvs_add_local(%s)", cf->file_path);
                    160:
1.96      joris     161:        if (cvs_cmdop != CVS_OP_CHECKOUT && cvs_cmdop != CVS_OP_UPDATE)
                    162:                cvs_file_classify(cf, cvs_directory_tag);
1.49      xsa       163:
                    164:        /* dont use `cvs add *' */
                    165:        if (strcmp(cf->file_name, ".") == 0 ||
                    166:            strcmp(cf->file_name, "..") == 0 ||
                    167:            strcmp(cf->file_name, CVS_PATH_CVSDIR) == 0) {
                    168:                if (verbosity > 1)
                    169:                        cvs_log(LP_ERR,
                    170:                            "cannot add special file `%s'; skipping",
                    171:                            cf->file_name);
                    172:                return;
                    173:        }
1.45      joris     174:
                    175:        if (cf->file_type == CVS_DIR)
                    176:                add_directory(cf);
                    177:        else
                    178:                add_file(cf);
                    179: }
                    180:
1.85      tobias    181: void
                    182: cvs_add_remote(struct cvs_file *cf)
                    183: {
1.111     deraadt   184:        char path[PATH_MAX];
1.85      tobias    185:
                    186:        cvs_log(LP_TRACE, "cvs_add_remote(%s)", cf->file_path);
                    187:
                    188:        cvs_file_classify(cf, cvs_directory_tag);
                    189:
                    190:        if (cf->file_type == CVS_DIR) {
1.111     deraadt   191:                cvs_get_repository_path(cf->file_wd, path, PATH_MAX);
1.85      tobias    192:                if (strlcat(path, "/", sizeof(path)) >= sizeof(path))
                    193:                        fatal("cvs_add_remote: truncation");
                    194:                if (strlcat(path, cf->file_path, sizeof(path)) >= sizeof(path))
                    195:                        fatal("cvs_add_remote: truncation");
                    196:                cvs_client_send_request("Directory %s\n%s", cf->file_path,
                    197:                    path);
                    198:
                    199:                add_directory(cf);
                    200:        } else {
                    201:                cvs_client_sendfile(cf);
                    202:        }
                    203: }
                    204:
1.100     joris     205: void
                    206: cvs_add_loginfo(char *repo)
                    207: {
                    208:        BUF *buf;
1.111     deraadt   209:        char pwd[PATH_MAX];
1.100     joris     210:
                    211:        if (getcwd(pwd, sizeof(pwd)) == NULL)
                    212:                fatal("Can't get working directory");
                    213:
1.109     ray       214:        buf = buf_alloc(1024);
1.100     joris     215:
                    216:        cvs_trigger_loginfo_header(buf, repo);
                    217:
1.109     ray       218:        buf_puts(buf, "Log Message:\nDirectory ");
                    219:        buf_puts(buf, current_cvsroot->cr_dir);
                    220:        buf_putc(buf, '/');
                    221:        buf_puts(buf, repo);
                    222:        buf_puts(buf, " added to the repository\n");
1.100     joris     223:
1.109     ray       224:        buf_putc(buf, '\0');
1.100     joris     225:
1.109     ray       226:        loginfo = buf_release(buf);
1.105     tobias    227: }
                    228:
                    229: void
                    230: cvs_add_tobranch(struct cvs_file *cf, char *tag)
                    231: {
                    232:        BUF *bp;
1.111     deraadt   233:        char attic[PATH_MAX], repo[PATH_MAX];
1.105     tobias    234:        char *msg;
                    235:        struct stat st;
                    236:        RCSNUM *branch;
                    237:
                    238:        cvs_log(LP_TRACE, "cvs_add_tobranch(%s)", cf->file_name);
                    239:
                    240:        if (cvs_noexec == 1)
                    241:                return;
                    242:
                    243:        if (fstat(cf->fd, &st) == -1)
                    244:                fatal("cvs_add_tobranch: %s", strerror(errno));
                    245:
1.111     deraadt   246:        cvs_get_repository_path(cf->file_wd, repo, PATH_MAX);
                    247:        (void)xsnprintf(attic, PATH_MAX, "%s/%s",
1.105     tobias    248:            repo, CVS_PATH_ATTIC);
                    249:
                    250:        if (mkdir(attic, 0755) == -1 && errno != EEXIST)
                    251:                fatal("cvs_add_tobranch: failed to create Attic");
                    252:
1.111     deraadt   253:        (void)xsnprintf(attic, PATH_MAX, "%s/%s/%s%s", repo,
1.105     tobias    254:            CVS_PATH_ATTIC, cf->file_name, RCS_FILE_EXT);
                    255:
1.112   ! nicm      256:        free(cf->file_rpath);
1.105     tobias    257:        cf->file_rpath = xstrdup(attic);
                    258:
                    259:        cf->repo_fd = open(cf->file_rpath, O_CREAT|O_RDONLY);
                    260:        if (cf->repo_fd < 0)
                    261:                fatal("cvs_add_tobranch: %s: %s", cf->file_rpath,
                    262:                    strerror(errno));
                    263:
                    264:        cf->file_rcs = rcs_open(cf->file_rpath, cf->repo_fd,
                    265:            RCS_CREATE|RCS_WRITE, 0444);
                    266:        if (cf->file_rcs == NULL)
                    267:                fatal("cvs_add_tobranch: failed to create RCS file for %s",
                    268:                    cf->file_path);
                    269:
                    270:        if ((branch = rcsnum_parse("1.1.2")) == NULL)
                    271:                fatal("cvs_add_tobranch: failed to parse branch");
                    272:
                    273:        if (rcs_sym_add(cf->file_rcs, tag, branch) == -1)
                    274:                fatal("cvs_add_tobranch: failed to add vendor tag");
                    275:
                    276:        (void)xasprintf(&msg, "file %s was initially added on branch %s.",
                    277:            cf->file_name, tag);
                    278:        if (rcs_rev_add(cf->file_rcs, RCS_HEAD_REV, msg, -1, NULL) == -1)
                    279:                fatal("cvs_add_tobranch: failed to create first branch "
                    280:                    "revision");
1.112   ! nicm      281:        free(msg);
1.105     tobias    282:
1.110     nicm      283:        if (rcs_findrev(cf->file_rcs, cf->file_rcs->rf_head) == NULL)
1.105     tobias    284:                fatal("cvs_add_tobranch: cannot find newly added revision");
                    285:
1.109     ray       286:        bp = buf_alloc(1);
1.105     tobias    287:
                    288:        if (rcs_deltatext_set(cf->file_rcs,
                    289:            cf->file_rcs->rf_head, bp) == -1)
                    290:                fatal("cvs_add_tobranch: failed to set deltatext");
                    291:
                    292:        rcs_comment_set(cf->file_rcs, " * ");
                    293:
                    294:        if (rcs_state_set(cf->file_rcs, cf->file_rcs->rf_head, RCS_STATE_DEAD)
                    295:            == -1)
                    296:                fatal("cvs_add_tobranch: failed to set state");
1.100     joris     297: }
                    298:
1.45      joris     299: static void
                    300: add_directory(struct cvs_file *cf)
                    301: {
1.74      xsa       302:        int added, nb;
1.45      joris     303:        struct stat st;
1.44      joris     304:        CVSENTRIES *entlist;
1.111     deraadt   305:        char *date, entry[PATH_MAX], msg[1024], repo[PATH_MAX], *tag, *p;
1.100     joris     306:        struct file_info_list files_info;
                    307:        struct file_info *fi;
                    308:        struct trigger_list *line_list;
1.45      joris     309:
                    310:        cvs_log(LP_TRACE, "add_directory(%s)", cf->file_path);
1.44      joris     311:
1.111     deraadt   312:        (void)xsnprintf(entry, PATH_MAX, "%s%s",
1.74      xsa       313:            cf->file_rpath, RCS_FILE_EXT);
1.45      joris     314:
1.53      joris     315:        added = 1;
1.45      joris     316:        if (stat(entry, &st) != -1) {
                    317:                cvs_log(LP_NOTICE, "cannot add directory %s: "
                    318:                    "a file with that name already exists",
                    319:                    cf->file_path);
1.53      joris     320:                added = 0;
1.45      joris     321:        } else {
1.56      xsa       322:                /* Let's see if we have any per-directory tags first. */
                    323:                cvs_parse_tagfile(cf->file_wd, &tag, &date, &nb);
                    324:
1.111     deraadt   325:                (void)xsnprintf(entry, PATH_MAX, "%s/%s",
1.76      xsa       326:                    cf->file_path, CVS_PATH_CVSDIR);
1.45      joris     327:
1.85      tobias    328:                if (cvs_server_active) {
                    329:                        if (mkdir(cf->file_rpath, 0755) == -1 &&
                    330:                            errno != EEXIST)
                    331:                                fatal("add_directory: %s: %s", cf->file_rpath,
                    332:                                    strerror(errno));
                    333:                } else if (stat(entry, &st) != -1) {
1.45      joris     334:                        if (!S_ISDIR(st.st_mode)) {
                    335:                                cvs_log(LP_ERR, "%s exists but is not "
                    336:                                    "directory", entry);
                    337:                        } else {
                    338:                                cvs_log(LP_NOTICE, "%s already exists",
                    339:                                    entry);
                    340:                        }
1.53      joris     341:                        added = 0;
                    342:                } else if (cvs_noexec != 1) {
1.45      joris     343:                        if (mkdir(cf->file_rpath, 0755) == -1 &&
                    344:                            errno != EEXIST)
1.85      tobias    345:                                fatal("add_directory: %s: %s", cf->file_rpath,
1.45      joris     346:                                    strerror(errno));
                    347:
                    348:                        cvs_get_repository_name(cf->file_wd, repo,
1.111     deraadt   349:                            PATH_MAX);
1.45      joris     350:
1.111     deraadt   351:                        (void)xsnprintf(entry, PATH_MAX, "%s/%s",
1.76      xsa       352:                            repo, cf->file_name);
1.45      joris     353:
                    354:                        cvs_mkadmin(cf->file_path, current_cvsroot->cr_dir,
1.91      tobias    355:                            entry, tag, date);
1.45      joris     356:
1.70      otto      357:                        p = xmalloc(CVS_ENT_MAXLINELEN);
1.94      xsa       358:                        cvs_ent_line_str(cf->file_name, NULL, NULL, NULL,
                    359:                            NULL, 1, 0, p, CVS_ENT_MAXLINELEN);
                    360:
1.45      joris     361:                        entlist = cvs_ent_open(cf->file_wd);
1.70      otto      362:                        cvs_ent_add(entlist, p);
1.112   ! nicm      363:                        free(p);
1.53      joris     364:                }
                    365:        }
1.45      joris     366:
1.85      tobias    367:        if (added == 1 && current_cvsroot->cr_method == CVS_METHOD_LOCAL) {
1.74      xsa       368:                (void)xsnprintf(msg, sizeof(msg),
1.56      xsa       369:                    "Directory %s added to the repository", cf->file_rpath);
                    370:
                    371:                if (tag != NULL) {
                    372:                        (void)strlcat(msg,
                    373:                            "\n--> Using per-directory sticky tag ",
                    374:                            sizeof(msg));
                    375:                        (void)strlcat(msg, tag, sizeof(msg));
                    376:                }
                    377:                if (date != NULL) {
                    378:                        (void)strlcat(msg,
                    379:                            "\n--> Using per-directory sticky date ",
                    380:                            sizeof(msg));
                    381:                        (void)strlcat(msg, date, sizeof(msg));
                    382:                }
                    383:                cvs_printf("%s\n", msg);
                    384:
1.112   ! nicm      385:                free(tag);
        !           386:                free(date);
1.100     joris     387:
1.111     deraadt   388:                cvs_get_repository_name(cf->file_path, repo, PATH_MAX);
1.100     joris     389:                line_list = cvs_trigger_getlines(CVS_PATH_LOGINFO, repo);
                    390:                if (line_list != NULL) {
                    391:                        TAILQ_INIT(&files_info);
                    392:                        fi = xcalloc(1, sizeof(*fi));
                    393:                        fi->file_path = xstrdup(cf->file_path);
                    394:                        TAILQ_INSERT_TAIL(&files_info, fi, flist);
                    395:
                    396:                        cvs_add_loginfo(repo);
                    397:                        cvs_trigger_handle(CVS_TRIGGER_LOGINFO, repo,
                    398:                            loginfo, line_list, &files_info);
                    399:
                    400:                        cvs_trigger_freeinfo(&files_info);
                    401:                        cvs_trigger_freelist(line_list);
1.112   ! nicm      402:                        free(loginfo);
1.100     joris     403:                }
1.45      joris     404:        }
                    405:
                    406:        cf->file_status = FILE_SKIP;
                    407: }
1.3       jfb       408:
1.45      joris     409: static void
                    410: add_file(struct cvs_file *cf)
                    411: {
1.108     zinovik   412:        int nb, stop;
1.78      xsa       413:        char revbuf[CVS_REV_BUFSZ];
1.104     tobias    414:        RCSNUM *head = NULL;
1.93      tobias    415:        char *tag;
                    416:
                    417:        cvs_parse_tagfile(cf->file_wd, &tag, NULL, &nb);
                    418:        if (nb) {
                    419:                cvs_log(LP_ERR, "cannot add file on non-branch tag %s", tag);
                    420:                return;
                    421:        }
1.10      xsa       422:
1.68      joris     423:        if (cf->file_rcs != NULL) {
                    424:                head = rcs_head_get(cf->file_rcs);
1.104     tobias    425:                if (head == NULL) {
                    426:                        cvs_log(LP_NOTICE, "no head revision in RCS file for "
                    427:                            "%s", cf->file_path);
                    428:                }
1.68      joris     429:                rcsnum_tostr(head, revbuf, sizeof(revbuf));
                    430:        }
1.44      joris     431:
1.108     zinovik   432:        stop = 0;
1.43      joris     433:        switch (cf->file_status) {
                    434:        case FILE_ADDED:
1.101     tobias    435:        case FILE_CHECKOUT:
1.48      xsa       436:                if (verbosity > 1)
                    437:                        cvs_log(LP_NOTICE, "%s has already been entered",
                    438:                            cf->file_path);
                    439:                stop = 1;
                    440:                break;
                    441:        case FILE_REMOVED:
                    442:                if (cf->file_rcs == NULL) {
                    443:                        cvs_log(LP_NOTICE, "cannot resurrect %s; "
                    444:                            "RCS file removed by second party", cf->file_name);
1.107     joris     445:                } else if (!(cf->file_flags & FILE_ON_DISK)) {
1.55      xsa       446:                        add_entry(cf);
1.48      xsa       447:
1.55      xsa       448:                        /* Restore the file. */
1.82      joris     449:                        cvs_checkout_file(cf, head, NULL, 0);
1.68      joris     450:
1.48      xsa       451:                        cvs_printf("U %s\n", cf->file_path);
                    452:
                    453:                        cvs_log(LP_NOTICE, "%s, version %s, resurrected",
                    454:                            cf->file_name, revbuf);
                    455:
                    456:                        cf->file_status = FILE_UPTODATE;
                    457:                }
1.44      joris     458:                stop = 1;
                    459:                break;
1.50      xsa       460:        case FILE_CONFLICT:
                    461:        case FILE_LOST:
                    462:        case FILE_MODIFIED:
1.44      joris     463:        case FILE_UPTODATE:
                    464:                if (cf->file_rcs != NULL && cf->file_rcs->rf_dead == 0) {
                    465:                        cvs_log(LP_NOTICE, "%s already exists, with version "
                    466:                             "number %s", cf->file_path, revbuf);
                    467:                        stop = 1;
                    468:                }
1.43      joris     469:                break;
                    470:        case FILE_UNKNOWN:
1.44      joris     471:                if (cf->file_rcs != NULL && cf->file_rcs->rf_dead == 1) {
                    472:                        cvs_log(LP_NOTICE, "re-adding file %s "
                    473:                            "(instead of dead revision %s)",
                    474:                            cf->file_path, revbuf);
1.108     zinovik   475:                        added_files++;
1.107     joris     476:                } else if (cf->file_flags & FILE_ON_DISK) {
1.44      joris     477:                        cvs_log(LP_NOTICE, "scheduling file '%s' for addition",
                    478:                            cf->file_path);
1.108     zinovik   479:                        added_files++;
1.73      joris     480:                } else {
                    481:                        stop = 1;
1.44      joris     482:                }
1.43      joris     483:                break;
                    484:        default:
                    485:                break;
1.1       jfb       486:        }
1.104     tobias    487:
                    488:        if (head != NULL)
                    489:                rcsnum_free(head);
1.44      joris     490:
                    491:        if (stop == 1)
                    492:                return;
                    493:
1.55      xsa       494:        add_entry(cf);
                    495: }
                    496:
                    497: static void
                    498: add_entry(struct cvs_file *cf)
                    499: {
                    500:        FILE *fp;
1.111     deraadt   501:        char *entry, path[PATH_MAX];
1.78      xsa       502:        char revbuf[CVS_REV_BUFSZ], tbuf[CVS_TIME_BUFSZ];
1.93      tobias    503:        char sticky[CVS_ENT_MAXLINELEN];
1.55      xsa       504:        CVSENTRIES *entlist;
                    505:
                    506:        if (cvs_noexec == 1)
                    507:                return;
                    508:
1.93      tobias    509:        sticky[0] = '\0';
1.94      xsa       510:        entry = xmalloc(CVS_ENT_MAXLINELEN);
1.93      tobias    511:
1.55      xsa       512:        if (cf->file_status == FILE_REMOVED) {
                    513:                rcsnum_tostr(cf->file_ent->ce_rev, revbuf, sizeof(revbuf));
                    514:
                    515:                ctime_r(&cf->file_ent->ce_mtime, tbuf);
1.86      tobias    516:                tbuf[strcspn(tbuf, "\n")] = '\0';
1.55      xsa       517:
1.93      tobias    518:                if (cf->file_ent->ce_tag != NULL)
                    519:                        (void)xsnprintf(sticky, sizeof(sticky), "T%s",
                    520:                            cf->file_ent->ce_tag);
                    521:
1.55      xsa       522:                /* Remove the '-' prefixing the version number. */
1.94      xsa       523:                cvs_ent_line_str(cf->file_name, revbuf, tbuf,
                    524:                    cf->file_ent->ce_opts ? cf->file_ent->ce_opts : "", sticky,
                    525:                    0, 0, entry, CVS_ENT_MAXLINELEN);
1.55      xsa       526:        } else {
                    527:                if (logmsg != NULL) {
1.111     deraadt   528:                        (void)xsnprintf(path, PATH_MAX, "%s/%s/%s%s",
1.99      tobias    529:                            cf->file_wd, CVS_PATH_CVSDIR, cf->file_name,
                    530:                            CVS_DESCR_FILE_EXT);
1.55      xsa       531:
                    532:                        if ((fp = fopen(path, "w+")) == NULL)
                    533:                                fatal("add_entry: fopen `%s': %s",
                    534:                                    path, strerror(errno));
                    535:
                    536:                        if (fputs(logmsg, fp) == EOF) {
                    537:                                (void)unlink(path);
                    538:                                fatal("add_entry: fputs `%s': %s",
                    539:                                    path, strerror(errno));
                    540:                        }
                    541:                        (void)fclose(fp);
                    542:                }
                    543:
1.93      tobias    544:                if (cvs_directory_tag != NULL)
                    545:                        (void)xsnprintf(sticky, sizeof(sticky), "T%s",
                    546:                            cvs_directory_tag);
                    547:
                    548:                tbuf[0] = '\0';
                    549:                if (!cvs_server_active)
                    550:                        (void)xsnprintf(tbuf, sizeof(tbuf), "Initial %s",
                    551:                            cf->file_name);
                    552:
1.94      xsa       553:                cvs_ent_line_str(cf->file_name, "0", tbuf, kflag ? kbuf : "",
                    554:                    sticky, 0, 0, entry, CVS_ENT_MAXLINELEN);
1.55      xsa       555:        }
                    556:
1.84      tobias    557:        if (cvs_server_active) {
                    558:                cvs_server_send_response("Checked-in %s/", cf->file_wd);
1.106     canacar   559:                cvs_server_send_response("%s", cf->file_path);
                    560:                cvs_server_send_response("%s", entry);
1.84      tobias    561:        } else {
                    562:                entlist = cvs_ent_open(cf->file_wd);
                    563:                cvs_ent_add(entlist, entry);
                    564:        }
1.112   ! nicm      565:        free(entry);
1.1       jfb       566: }