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

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