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

1.108   ! zinovik     1: /*     $OpenBSD: add.c,v 1.107 2009/02/21 14:50:53 joris 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: {
                    183:        char path[MAXPATHLEN];
                    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) {
                    190:                cvs_get_repository_path(cf->file_wd, path, MAXPATHLEN);
                    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;
                    208:        char pwd[MAXPATHLEN];
                    209:
                    210:        if (getcwd(pwd, sizeof(pwd)) == NULL)
                    211:                fatal("Can't get working directory");
                    212:
                    213:        buf = cvs_buf_alloc(1024);
                    214:
                    215:        cvs_trigger_loginfo_header(buf, repo);
                    216:
                    217:        cvs_buf_puts(buf, "Log Message:\nDirectory ");
                    218:        cvs_buf_puts(buf, current_cvsroot->cr_dir);
                    219:        cvs_buf_putc(buf, '/');
                    220:        cvs_buf_puts(buf, repo);
                    221:        cvs_buf_puts(buf, " added to the repository\n");
                    222:
                    223:        cvs_buf_putc(buf, '\0');
                    224:
                    225:        loginfo = cvs_buf_release(buf);
1.105     tobias    226: }
                    227:
                    228: void
                    229: cvs_add_tobranch(struct cvs_file *cf, char *tag)
                    230: {
                    231:        BUF *bp;
                    232:        char attic[MAXPATHLEN], repo[MAXPATHLEN];
                    233:        char *msg;
                    234:        struct stat st;
                    235:        struct rcs_delta *rdp;
                    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:
                    246:        cvs_get_repository_path(cf->file_wd, repo, MAXPATHLEN);
                    247:        (void)xsnprintf(attic, MAXPATHLEN, "%s/%s",
                    248:            repo, CVS_PATH_ATTIC);
                    249:
                    250:        if (mkdir(attic, 0755) == -1 && errno != EEXIST)
                    251:                fatal("cvs_add_tobranch: failed to create Attic");
                    252:
                    253:        (void)xsnprintf(attic, MAXPATHLEN, "%s/%s/%s%s", repo,
                    254:            CVS_PATH_ATTIC, cf->file_name, RCS_FILE_EXT);
                    255:
                    256:        xfree(cf->file_rpath);
                    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");
                    281:        xfree(msg);
                    282:
                    283:        if ((rdp = rcs_findrev(cf->file_rcs, cf->file_rcs->rf_head)) == NULL)
                    284:                fatal("cvs_add_tobranch: cannot find newly added revision");
                    285:
                    286:        bp = cvs_buf_alloc(1);
                    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.70      otto      305:        char *date, entry[MAXPATHLEN], msg[1024], repo[MAXPATHLEN], *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.74      xsa       312:        (void)xsnprintf(entry, MAXPATHLEN, "%s%s",
                    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.76      xsa       325:                (void)xsnprintf(entry, MAXPATHLEN, "%s/%s",
                    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,
                    349:                            MAXPATHLEN);
                    350:
1.76      xsa       351:                        (void)xsnprintf(entry, MAXPATHLEN, "%s/%s",
                    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.79      joris     363:                        xfree(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:
                    385:                if (tag != NULL)
                    386:                        xfree(tag);
                    387:                if (date != NULL)
                    388:                        xfree(date);
1.100     joris     389:
                    390:                cvs_get_repository_name(cf->file_path, repo, MAXPATHLEN);
                    391:                line_list = cvs_trigger_getlines(CVS_PATH_LOGINFO, repo);
                    392:                if (line_list != NULL) {
                    393:                        TAILQ_INIT(&files_info);
                    394:                        fi = xcalloc(1, sizeof(*fi));
                    395:                        fi->file_path = xstrdup(cf->file_path);
                    396:                        TAILQ_INSERT_TAIL(&files_info, fi, flist);
                    397:
                    398:                        cvs_add_loginfo(repo);
                    399:                        cvs_trigger_handle(CVS_TRIGGER_LOGINFO, repo,
                    400:                            loginfo, line_list, &files_info);
                    401:
                    402:                        cvs_trigger_freeinfo(&files_info);
                    403:                        cvs_trigger_freelist(line_list);
                    404:                        if (loginfo != NULL)
                    405:                                xfree(loginfo);
                    406:                }
1.45      joris     407:        }
                    408:
                    409:        cf->file_status = FILE_SKIP;
                    410: }
1.3       jfb       411:
1.45      joris     412: static void
                    413: add_file(struct cvs_file *cf)
                    414: {
1.108   ! zinovik   415:        int nb, stop;
1.78      xsa       416:        char revbuf[CVS_REV_BUFSZ];
1.104     tobias    417:        RCSNUM *head = NULL;
1.93      tobias    418:        char *tag;
                    419:
                    420:        cvs_parse_tagfile(cf->file_wd, &tag, NULL, &nb);
                    421:        if (nb) {
                    422:                cvs_log(LP_ERR, "cannot add file on non-branch tag %s", tag);
                    423:                return;
                    424:        }
1.10      xsa       425:
1.68      joris     426:        if (cf->file_rcs != NULL) {
                    427:                head = rcs_head_get(cf->file_rcs);
1.104     tobias    428:                if (head == NULL) {
                    429:                        cvs_log(LP_NOTICE, "no head revision in RCS file for "
                    430:                            "%s", cf->file_path);
                    431:                }
1.68      joris     432:                rcsnum_tostr(head, revbuf, sizeof(revbuf));
                    433:        }
1.44      joris     434:
1.108   ! zinovik   435:        stop = 0;
1.43      joris     436:        switch (cf->file_status) {
                    437:        case FILE_ADDED:
1.101     tobias    438:        case FILE_CHECKOUT:
1.48      xsa       439:                if (verbosity > 1)
                    440:                        cvs_log(LP_NOTICE, "%s has already been entered",
                    441:                            cf->file_path);
                    442:                stop = 1;
                    443:                break;
                    444:        case FILE_REMOVED:
                    445:                if (cf->file_rcs == NULL) {
                    446:                        cvs_log(LP_NOTICE, "cannot resurrect %s; "
                    447:                            "RCS file removed by second party", cf->file_name);
1.107     joris     448:                } else if (!(cf->file_flags & FILE_ON_DISK)) {
1.55      xsa       449:                        add_entry(cf);
1.48      xsa       450:
1.55      xsa       451:                        /* Restore the file. */
1.82      joris     452:                        cvs_checkout_file(cf, head, NULL, 0);
1.68      joris     453:
1.48      xsa       454:                        cvs_printf("U %s\n", cf->file_path);
                    455:
                    456:                        cvs_log(LP_NOTICE, "%s, version %s, resurrected",
                    457:                            cf->file_name, revbuf);
                    458:
                    459:                        cf->file_status = FILE_UPTODATE;
                    460:                }
1.44      joris     461:                stop = 1;
                    462:                break;
1.50      xsa       463:        case FILE_CONFLICT:
                    464:        case FILE_LOST:
                    465:        case FILE_MODIFIED:
1.44      joris     466:        case FILE_UPTODATE:
                    467:                if (cf->file_rcs != NULL && cf->file_rcs->rf_dead == 0) {
                    468:                        cvs_log(LP_NOTICE, "%s already exists, with version "
                    469:                             "number %s", cf->file_path, revbuf);
                    470:                        stop = 1;
                    471:                }
1.43      joris     472:                break;
                    473:        case FILE_UNKNOWN:
1.44      joris     474:                if (cf->file_rcs != NULL && cf->file_rcs->rf_dead == 1) {
                    475:                        cvs_log(LP_NOTICE, "re-adding file %s "
                    476:                            "(instead of dead revision %s)",
                    477:                            cf->file_path, revbuf);
1.108   ! zinovik   478:                        added_files++;
1.107     joris     479:                } else if (cf->file_flags & FILE_ON_DISK) {
1.44      joris     480:                        cvs_log(LP_NOTICE, "scheduling file '%s' for addition",
                    481:                            cf->file_path);
1.108   ! zinovik   482:                        added_files++;
1.73      joris     483:                } else {
                    484:                        stop = 1;
1.44      joris     485:                }
1.43      joris     486:                break;
                    487:        default:
                    488:                break;
1.1       jfb       489:        }
1.104     tobias    490:
                    491:        if (head != NULL)
                    492:                rcsnum_free(head);
1.44      joris     493:
                    494:        if (stop == 1)
                    495:                return;
                    496:
1.55      xsa       497:        add_entry(cf);
                    498: }
                    499:
                    500: static void
                    501: add_entry(struct cvs_file *cf)
                    502: {
                    503:        FILE *fp;
1.94      xsa       504:        char *entry, path[MAXPATHLEN];
1.78      xsa       505:        char revbuf[CVS_REV_BUFSZ], tbuf[CVS_TIME_BUFSZ];
1.93      tobias    506:        char sticky[CVS_ENT_MAXLINELEN];
1.55      xsa       507:        CVSENTRIES *entlist;
                    508:
                    509:        if (cvs_noexec == 1)
                    510:                return;
                    511:
1.93      tobias    512:        sticky[0] = '\0';
1.94      xsa       513:        entry = xmalloc(CVS_ENT_MAXLINELEN);
1.93      tobias    514:
1.55      xsa       515:        if (cf->file_status == FILE_REMOVED) {
                    516:                rcsnum_tostr(cf->file_ent->ce_rev, revbuf, sizeof(revbuf));
                    517:
                    518:                ctime_r(&cf->file_ent->ce_mtime, tbuf);
1.86      tobias    519:                tbuf[strcspn(tbuf, "\n")] = '\0';
1.55      xsa       520:
1.93      tobias    521:                if (cf->file_ent->ce_tag != NULL)
                    522:                        (void)xsnprintf(sticky, sizeof(sticky), "T%s",
                    523:                            cf->file_ent->ce_tag);
                    524:
1.55      xsa       525:                /* Remove the '-' prefixing the version number. */
1.94      xsa       526:                cvs_ent_line_str(cf->file_name, revbuf, tbuf,
                    527:                    cf->file_ent->ce_opts ? cf->file_ent->ce_opts : "", sticky,
                    528:                    0, 0, entry, CVS_ENT_MAXLINELEN);
1.55      xsa       529:        } else {
                    530:                if (logmsg != NULL) {
1.99      tobias    531:                        (void)xsnprintf(path, MAXPATHLEN, "%s/%s/%s%s",
                    532:                            cf->file_wd, CVS_PATH_CVSDIR, cf->file_name,
                    533:                            CVS_DESCR_FILE_EXT);
1.55      xsa       534:
                    535:                        if ((fp = fopen(path, "w+")) == NULL)
                    536:                                fatal("add_entry: fopen `%s': %s",
                    537:                                    path, strerror(errno));
                    538:
                    539:                        if (fputs(logmsg, fp) == EOF) {
                    540:                                (void)unlink(path);
                    541:                                fatal("add_entry: fputs `%s': %s",
                    542:                                    path, strerror(errno));
                    543:                        }
                    544:                        (void)fclose(fp);
                    545:                }
                    546:
1.93      tobias    547:                if (cvs_directory_tag != NULL)
                    548:                        (void)xsnprintf(sticky, sizeof(sticky), "T%s",
                    549:                            cvs_directory_tag);
                    550:
                    551:                tbuf[0] = '\0';
                    552:                if (!cvs_server_active)
                    553:                        (void)xsnprintf(tbuf, sizeof(tbuf), "Initial %s",
                    554:                            cf->file_name);
                    555:
1.94      xsa       556:                cvs_ent_line_str(cf->file_name, "0", tbuf, kflag ? kbuf : "",
                    557:                    sticky, 0, 0, entry, CVS_ENT_MAXLINELEN);
1.55      xsa       558:        }
                    559:
1.84      tobias    560:        if (cvs_server_active) {
                    561:                cvs_server_send_response("Checked-in %s/", cf->file_wd);
1.106     canacar   562:                cvs_server_send_response("%s", cf->file_path);
                    563:                cvs_server_send_response("%s", entry);
1.84      tobias    564:        } else {
                    565:                entlist = cvs_ent_open(cf->file_wd);
                    566:                cvs_ent_add(entlist, entry);
                    567:        }
1.94      xsa       568:        xfree(entry);
1.1       jfb       569: }