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

Annotation of src/usr.bin/cvs/commit.c, Revision 1.127

1.127   ! joris       1: /*     $OpenBSD: commit.c,v 1.126 2008/02/04 15:07:33 tobias Exp $     */
1.1       jfb         2: /*
1.55      joris       3:  * Copyright (c) 2006 Joris Vink <joris@openbsd.org>
1.71      xsa         4:  * Copyright (c) 2006 Xavier Santolaria <xsa@openbsd.org>
1.1       jfb         5:  *
1.55      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.55      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.105     otto       19: #include <sys/stat.h>
                     20:
                     21: #include <errno.h>
                     22: #include <fcntl.h>
                     23: #include <string.h>
                     24: #include <unistd.h>
1.1       jfb        25:
                     26: #include "cvs.h"
1.55      joris      27: #include "diff.h"
1.80      joris      28: #include "remote.h"
1.1       jfb        29:
1.55      joris      30: void   cvs_commit_local(struct cvs_file *);
1.86      joris      31: void   cvs_commit_check_files(struct cvs_file *);
1.55      joris      32:
1.112     joris      33: static BUF *commit_diff(struct cvs_file *, RCSNUM *, int);
1.71      xsa        34: static void commit_desc_set(struct cvs_file *);
1.55      joris      35:
                     36: struct cvs_flisthead files_affected;
1.86      joris      37: struct cvs_flisthead files_added;
                     38: struct cvs_flisthead files_removed;
                     39: struct cvs_flisthead files_modified;
                     40:
1.55      joris      41: int    conflicts_found;
1.86      joris      42: char   *logmsg = NULL;
1.34      jfb        43:
                     44: struct cvs_cmd cvs_cmd_commit = {
1.124     tobias     45:        CVS_OP_COMMIT, CVS_USE_WDIR, "commit",
1.55      joris      46:        { "ci", "com" },
1.34      jfb        47:        "Check files into the repository",
                     48:        "[-flR] [-F logfile | -m msg] [-r rev] ...",
                     49:        "F:flm:Rr:",
1.18      joris      50:        NULL,
1.55      joris      51:        cvs_commit
1.18      joris      52: };
1.1       jfb        53:
1.55      joris      54: int
                     55: cvs_commit(int argc, char **argv)
1.1       jfb        56: {
1.127   ! joris      57:        int flags;
1.121     tobias     58:        int ch, Fflag, mflag;
1.127   ! joris      59:        struct module_checkout *mc;
1.55      joris      60:        struct cvs_recursion cr;
1.127   ! joris      61:        char *arg = ".", repo[MAXPATHLEN];
1.3       krapht     62:
1.58      joris      63:        flags = CR_RECURSE_DIRS;
1.121     tobias     64:        Fflag = mflag = 0;
1.58      joris      65:
1.55      joris      66:        while ((ch = getopt(argc, argv, cvs_cmd_commit.cmd_opts)) != -1) {
1.1       jfb        67:                switch (ch) {
                     68:                case 'F':
1.121     tobias     69:                        /* free previously assigned value */
                     70:                        if (logmsg != NULL)
                     71:                                xfree(logmsg);
1.88      joris      72:                        logmsg = cvs_logmsg_read(optarg);
1.121     tobias     73:                        Fflag = 1;
1.1       jfb        74:                        break;
1.82      xsa        75:                case 'f':
                     76:                        break;
1.1       jfb        77:                case 'l':
1.58      joris      78:                        flags &= ~CR_RECURSE_DIRS;
1.1       jfb        79:                        break;
                     80:                case 'm':
1.121     tobias     81:                        /* free previously assigned value */
                     82:                        if (logmsg != NULL)
                     83:                                xfree(logmsg);
1.55      joris      84:                        logmsg = xstrdup(optarg);
1.121     tobias     85:                        mflag = 1;
1.55      joris      86:                        break;
1.82      xsa        87:                case 'R':
1.120     tobias     88:                        flags |= CR_RECURSE_DIRS;
1.82      xsa        89:                        break;
1.55      joris      90:                case 'r':
1.1       jfb        91:                        break;
                     92:                default:
1.55      joris      93:                        fatal("%s", cvs_cmd_commit.cmd_synopsis);
1.1       jfb        94:                }
                     95:        }
                     96:
1.55      joris      97:        argc -= optind;
                     98:        argv += optind;
1.121     tobias     99:
                    100:        /* -F and -m are mutually exclusive */
                    101:        if (Fflag && mflag)
                    102:                fatal("cannot specify both a log file and a message");
1.1       jfb       103:
1.86      joris     104:        TAILQ_INIT(&files_affected);
                    105:        TAILQ_INIT(&files_added);
                    106:        TAILQ_INIT(&files_removed);
                    107:        TAILQ_INIT(&files_modified);
                    108:        conflicts_found = 0;
                    109:
                    110:        cr.enterdir = NULL;
                    111:        cr.leavedir = NULL;
                    112:        cr.fileproc = cvs_commit_check_files;
                    113:        cr.flags = flags;
                    114:
                    115:        if (argc > 0)
                    116:                cvs_file_run(argc, argv, &cr);
                    117:        else
                    118:                cvs_file_run(1, &arg, &cr);
                    119:
                    120:        if (conflicts_found != 0)
                    121:                fatal("%d conflicts found, please correct these first",
                    122:                    conflicts_found);
1.92      joris     123:
                    124:        if (TAILQ_EMPTY(&files_affected))
                    125:                return (0);
1.86      joris     126:
                    127:        if (logmsg == NULL && cvs_server_active == 0) {
                    128:                logmsg = cvs_logmsg_create(&files_added, &files_removed,
                    129:                    &files_modified);
                    130:        }
                    131:
1.55      joris     132:        if (logmsg == NULL)
1.86      joris     133:                fatal("This shouldnt happen, honestly!");
1.87      joris     134:
                    135:        cvs_file_freelist(&files_modified);
                    136:        cvs_file_freelist(&files_removed);
                    137:        cvs_file_freelist(&files_added);
1.80      joris     138:
                    139:        if (current_cvsroot->cr_method != CVS_METHOD_LOCAL) {
1.89      joris     140:                cvs_client_connect_to_server();
1.80      joris     141:                cr.fileproc = cvs_client_sendfile;
                    142:
                    143:                if (argc > 0)
                    144:                        cvs_file_run(argc, argv, &cr);
                    145:                else
                    146:                        cvs_file_run(1, &arg, &cr);
1.99      xsa       147:
                    148:                if (!(flags & CR_RECURSE_DIRS))
                    149:                        cvs_client_send_request("Argument -l");
1.80      joris     150:
1.123     tobias    151:                cvs_client_send_logmsg(logmsg);
1.80      joris     152:                cvs_client_send_files(argv, argc);
                    153:                cvs_client_senddir(".");
                    154:                cvs_client_send_request("ci");
                    155:                cvs_client_get_responses();
1.86      joris     156:        } else {
                    157:                cr.fileproc = cvs_commit_local;
                    158:                cvs_file_walklist(&files_affected, &cr);
                    159:                cvs_file_freelist(&files_affected);
1.127   ! joris     160:
        !           161:                cvs_get_repository_name(".", repo, MAXPATHLEN);
        !           162:                mc = cvs_module_lookup(repo);
        !           163:                if (mc->mc_prog != NULL &&
        !           164:                    (mc->mc_flags & MODULE_RUN_ON_COMMIT))
        !           165:                        cvs_exec(mc->mc_prog);
1.80      joris     166:        }
1.1       jfb       167:
1.123     tobias    168:        xfree(logmsg);
1.18      joris     169:        return (0);
                    170: }
1.1       jfb       171:
1.55      joris     172: void
1.86      joris     173: cvs_commit_check_files(struct cvs_file *cf)
1.18      joris     174: {
1.112     joris     175:        char *tag;
                    176:        RCSNUM *branch, *brev;
                    177:        char rev[CVS_REV_BUFSZ];
                    178:
1.123     tobias    179:        branch = brev = NULL;
                    180:
1.86      joris     181:        cvs_log(LP_TRACE, "cvs_commit_check_files(%s)", cf->file_path);
1.44      joris     182:
1.108     joris     183:        if (current_cvsroot->cr_method != CVS_METHOD_LOCAL)
                    184:                cvs_remote_classify_file(cf);
                    185:        else
1.110     joris     186:                cvs_file_classify(cf, cvs_directory_tag);
1.59      joris     187:
                    188:        if (cf->file_type == CVS_DIR) {
                    189:                if (verbosity > 1)
                    190:                        cvs_log(LP_NOTICE, "Examining %s", cf->file_path);
                    191:                return;
                    192:        }
1.32      joris     193:
1.55      joris     194:        if (cf->file_status == FILE_CONFLICT ||
1.79      joris     195:            cf->file_status == FILE_UNLINK) {
1.55      joris     196:                conflicts_found++;
1.79      joris     197:                return;
                    198:        }
1.57      joris     199:
1.63      joris     200:        if (cf->file_status != FILE_REMOVED &&
                    201:            update_has_conflict_markers(cf)) {
1.60      joris     202:                cvs_log(LP_ERR, "conflict: unresolved conflicts in %s from "
                    203:                    "merging, please fix these first", cf->file_path);
                    204:                conflicts_found++;
1.79      joris     205:                return;
1.60      joris     206:        }
                    207:
1.57      joris     208:        if (cf->file_status == FILE_MERGE ||
1.72      joris     209:            cf->file_status == FILE_PATCH ||
1.79      joris     210:            cf->file_status == FILE_CHECKOUT ||
                    211:            cf->file_status == FILE_LOST) {
1.57      joris     212:                cvs_log(LP_ERR, "conflict: %s is not up-to-date",
                    213:                    cf->file_path);
                    214:                conflicts_found++;
1.79      joris     215:                return;
1.57      joris     216:        }
1.55      joris     217:
1.112     joris     218:        if (current_cvsroot->cr_method == CVS_METHOD_LOCAL) {
                    219:                tag = cvs_directory_tag;
                    220:                if (cf->file_ent != NULL)
                    221:                        tag = cf->file_ent->ce_tag;
                    222:
                    223:                if (tag != NULL && cf->file_rcs != NULL) {
                    224:                        brev = rcs_sym_getrev(cf->file_rcs, tag);
                    225:                        if (brev != NULL) {
                    226:                                if (RCSNUM_ISBRANCH(brev))
                    227:                                        goto next;
1.125     joris     228:                                rcsnum_free(brev);
1.112     joris     229:                        }
                    230:
                    231:                        brev = rcs_translate_tag(tag, cf->file_rcs);
                    232:
                    233:                        if (brev == NULL) {
                    234:                                fatal("failed to resolve tag: %s",
                    235:                                    cf->file_ent->ce_tag);
                    236:                        }
                    237:
                    238:                        rcsnum_tostr(brev, rev, sizeof(rev));
                    239:                        if ((branch = rcsnum_revtobr(brev)) == NULL) {
                    240:                                cvs_log(LP_ERR, "%s is not a branch revision",
                    241:                                    rev);
                    242:                                conflicts_found++;
1.123     tobias    243:                                rcsnum_free(brev);
1.112     joris     244:                                return;
                    245:                        }
                    246:
                    247:                        if (!RCSNUM_ISBRANCHREV(brev)) {
                    248:                                cvs_log(LP_ERR, "%s is not a branch revision",
                    249:                                    rev);
                    250:                                conflicts_found++;
1.123     tobias    251:                                rcsnum_free(branch);
                    252:                                rcsnum_free(brev);
1.112     joris     253:                                return;
                    254:                        }
                    255:
                    256:                        rcsnum_tostr(branch, rev, sizeof(rev));
                    257:                        if (!RCSNUM_ISBRANCH(branch)) {
                    258:                                cvs_log(LP_ERR, "%s (%s) is not a branch",
                    259:                                    cf->file_ent->ce_tag, rev);
                    260:                                conflicts_found++;
1.123     tobias    261:                                rcsnum_free(branch);
                    262:                                rcsnum_free(brev);
1.112     joris     263:                                return;
                    264:                        }
                    265:                }
                    266:        }
                    267:
                    268: next:
1.123     tobias    269:        if (branch != NULL)
                    270:                rcsnum_free(branch);
                    271:        if (brev != NULL)
                    272:                rcsnum_free(brev);
                    273:
1.55      joris     274:        if (cf->file_status == FILE_ADDED ||
                    275:            cf->file_status == FILE_REMOVED ||
                    276:            cf->file_status == FILE_MODIFIED)
1.110     joris     277:                cvs_file_get(cf->file_path, 0, &files_affected);
1.86      joris     278:
                    279:        switch (cf->file_status) {
                    280:        case FILE_ADDED:
1.110     joris     281:                cvs_file_get(cf->file_path, 0, &files_added);
1.86      joris     282:                break;
                    283:        case FILE_REMOVED:
1.110     joris     284:                cvs_file_get(cf->file_path, 0, &files_removed);
1.86      joris     285:                break;
                    286:        case FILE_MODIFIED:
1.110     joris     287:                cvs_file_get(cf->file_path, 0, &files_modified);
1.86      joris     288:                break;
                    289:        }
1.55      joris     290: }
1.1       jfb       291:
1.55      joris     292: void
                    293: cvs_commit_local(struct cvs_file *cf)
                    294: {
1.112     joris     295:        char *tag;
1.91      joris     296:        BUF *b, *d;
1.112     joris     297:        int onbranch, isnew, histtype;
                    298:        RCSNUM *nrev, *crev, *rrev, *brev;
1.102     xsa       299:        int openflags, rcsflags;
1.119     tobias    300:        char rbuf[CVS_REV_BUFSZ], nbuf[CVS_REV_BUFSZ];
1.56      joris     301:        CVSENTRIES *entlist;
1.100     otto      302:        char attic[MAXPATHLEN], repo[MAXPATHLEN], rcsfile[MAXPATHLEN];
1.17      joris     303:
1.55      joris     304:        cvs_log(LP_TRACE, "cvs_commit_local(%s)", cf->file_path);
1.110     joris     305:        cvs_file_classify(cf, cvs_directory_tag);
1.69      joris     306:
                    307:        if (cvs_noexec == 1)
                    308:                return;
1.35      xsa       309:
1.64      joris     310:        if (cf->file_type != CVS_FILE)
                    311:                fatal("cvs_commit_local: '%s' is not a file", cf->file_path);
                    312:
1.107     joris     313:        if (cf->file_status != FILE_MODIFIED &&
                    314:            cf->file_status != FILE_ADDED &&
                    315:            cf->file_status != FILE_REMOVED) {
                    316:                cvs_log(LP_ERR, "skipping bogus file `%s'", cf->file_path);
                    317:                return;
                    318:        }
                    319:
1.112     joris     320:        onbranch = 0;
                    321:        nrev = RCS_HEAD_REV;
                    322:        crev = NULL;
                    323:        rrev = NULL;
                    324:
1.115     joris     325:        if (cf->file_rcs != NULL && cf->file_rcs->rf_branch != NULL) {
1.114     joris     326:                rcsnum_free(cf->file_rcs->rf_branch);
                    327:                cf->file_rcs->rf_branch = NULL;
                    328:        }
                    329:
1.56      joris     330:        if (cf->file_status == FILE_MODIFIED ||
1.66      joris     331:            cf->file_status == FILE_REMOVED || (cf->file_status == FILE_ADDED
1.93      joris     332:            && cf->file_rcs != NULL && cf->file_rcs->rf_dead == 1)) {
1.112     joris     333:                rrev = rcs_head_get(cf->file_rcs);
                    334:                crev = rcs_head_get(cf->file_rcs);
1.116     tobias    335:                if (crev == NULL || rrev == NULL)
                    336:                        fatal("RCS head empty or missing in %s\n",
                    337:                            cf->file_rcs->rf_path);
1.112     joris     338:
                    339:                tag = cvs_directory_tag;
                    340:                if (cf->file_ent != NULL && cf->file_ent->ce_tag != NULL)
                    341:                        tag = cf->file_ent->ce_tag;
                    342:
                    343:                if (tag != NULL) {
                    344:                        rcsnum_free(crev);
                    345:                        crev = rcs_translate_tag(tag, cf->file_rcs);
                    346:                        if (crev == NULL) {
                    347:                                fatal("failed to resolve existing tag: %s",
                    348:                                    tag);
                    349:                        }
                    350:
                    351:                        if (RCSNUM_ISBRANCHREV(crev)) {
                    352:                                nrev = rcsnum_alloc();
                    353:                                rcsnum_cpy(crev, nrev, 0);
                    354:                                rcsnum_inc(nrev);
                    355:                        } else if (!RCSNUM_ISBRANCH(crev)) {
                    356:                                brev = rcs_sym_getrev(cf->file_rcs, tag);
                    357:                                if (brev == NULL)
                    358:                                        fatal("no more tag?");
                    359:                                nrev = rcsnum_brtorev(brev);
                    360:                                if (nrev == NULL)
                    361:                                        fatal("failed to create branch rev");
1.123     tobias    362:                                rcsnum_free(brev);
1.112     joris     363:                        } else {
                    364:                                fatal("this isnt suppose to happen, honestly");
                    365:                        }
                    366:
                    367:                        rcsnum_free(rrev);
                    368:                        rrev = rcsnum_branch_root(nrev);
                    369:
                    370:                        /* branch stuff was checked in cvs_commit_check_files */
                    371:                        onbranch = 1;
                    372:                }
                    373:
                    374:                rcsnum_tostr(crev, rbuf, sizeof(rbuf));
1.93      joris     375:        } else {
1.61      joris     376:                strlcpy(rbuf, "Non-existent", sizeof(rbuf));
1.93      joris     377:        }
1.61      joris     378:
1.123     tobias    379:        if (rrev != NULL)
                    380:                rcsnum_free(rrev);
1.67      joris     381:        isnew = 0;
1.66      joris     382:        if (cf->file_status == FILE_ADDED) {
1.67      joris     383:                isnew = 1;
1.66      joris     384:                rcsflags = RCS_CREATE;
                    385:                openflags = O_CREAT | O_TRUNC | O_WRONLY;
                    386:                if (cf->file_rcs != NULL) {
1.106     niallo    387:                        if (cf->in_attic == 0)
1.66      joris     388:                                cvs_log(LP_ERR, "warning: expected %s "
                    389:                                    "to be in the Attic", cf->file_path);
                    390:
                    391:                        if (cf->file_rcs->rf_dead == 0)
                    392:                                cvs_log(LP_ERR, "warning: expected %s "
                    393:                                    "to be dead", cf->file_path);
                    394:
                    395:                        cvs_get_repository_path(cf->file_wd, repo, MAXPATHLEN);
1.102     xsa       396:                        (void)xsnprintf(rcsfile, MAXPATHLEN, "%s/%s%s",
1.66      joris     397:                            repo, cf->file_name, RCS_FILE_EXT);
                    398:
                    399:                        if (rename(cf->file_rpath, rcsfile) == -1)
                    400:                                fatal("cvs_commit_local: failed to move %s "
                    401:                                    "outside the Attic: %s", cf->file_path,
                    402:                                    strerror(errno));
                    403:
                    404:                        xfree(cf->file_rpath);
                    405:                        cf->file_rpath = xstrdup(rcsfile);
                    406:
                    407:                        rcsflags = RCS_READ | RCS_PARSE_FULLY;
                    408:                        openflags = O_RDONLY;
                    409:                        rcs_close(cf->file_rcs);
1.67      joris     410:                        isnew = 0;
1.66      joris     411:                }
                    412:
                    413:                cf->repo_fd = open(cf->file_rpath, openflags);
1.61      joris     414:                if (cf->repo_fd < 0)
                    415:                        fatal("cvs_commit_local: %s", strerror(errno));
                    416:
                    417:                cf->file_rcs = rcs_open(cf->file_rpath, cf->repo_fd,
1.103     otto      418:                    rcsflags, 0444);
1.61      joris     419:                if (cf->file_rcs == NULL)
                    420:                        fatal("cvs_commit_local: failed to create RCS file "
                    421:                            "for %s", cf->file_path);
1.71      xsa       422:
                    423:                commit_desc_set(cf);
1.61      joris     424:        }
1.36      joris     425:
1.77      reyk      426:        if (verbosity > 1) {
                    427:                cvs_printf("Checking in %s:\n", cf->file_path);
                    428:                cvs_printf("%s <- %s\n", cf->file_rpath, cf->file_path);
                    429:                cvs_printf("old revision: %s; ", rbuf);
                    430:        }
1.7       jfb       431:
1.112     joris     432:        if (isnew == 0 && onbranch == 0)
                    433:                d = commit_diff(cf, cf->file_rcs->rf_head, 0);
1.7       jfb       434:
1.56      joris     435:        if (cf->file_status == FILE_REMOVED) {
1.112     joris     436:                b = rcs_rev_getbuf(cf->file_rcs, crev, 0);
1.56      joris     437:                if (b == NULL)
1.112     joris     438:                        fatal("cvs_commit_local: failed to get crev");
                    439:        } else if (onbranch == 1) {
                    440:                b = commit_diff(cf, crev, 1);
1.61      joris     441:        } else {
1.73      joris     442:                if ((b = cvs_buf_load_fd(cf->fd, BUF_AUTOEXT)) == NULL)
1.56      joris     443:                        fatal("cvs_commit_local: failed to load file");
                    444:        }
1.7       jfb       445:
1.112     joris     446:        if (isnew == 0 && onbranch == 0) {
                    447:                if (rcs_deltatext_set(cf->file_rcs, crev, d) == -1)
1.61      joris     448:                        fatal("cvs_commit_local: failed to set delta");
                    449:        }
1.3       krapht    450:
1.112     joris     451:        if (rcs_rev_add(cf->file_rcs, nrev, logmsg, -1, NULL) == -1)
1.55      joris     452:                fatal("cvs_commit_local: failed to add new revision");
1.3       krapht    453:
1.112     joris     454:        if (nrev == RCS_HEAD_REV)
                    455:                nrev = cf->file_rcs->rf_head;
                    456:
                    457:        if (rcs_deltatext_set(cf->file_rcs, nrev, b) == -1)
1.55      joris     458:                fatal("cvs_commit_local: failed to set new HEAD delta");
1.3       krapht    459:
1.56      joris     460:        if (cf->file_status == FILE_REMOVED) {
1.112     joris     461:                if (rcs_state_set(cf->file_rcs, nrev, RCS_STATE_DEAD) == -1)
1.56      joris     462:                        fatal("cvs_commit_local: failed to set state");
1.101     xsa       463:        }
                    464:
                    465:        if (cf->file_status == FILE_ADDED && cf->file_ent->ce_opts != NULL) {
1.126     tobias    466:                int cf_kflag;
1.101     xsa       467:
1.126     tobias    468:                cf_kflag = rcs_kflag_get(cf->file_ent->ce_opts + 2);
                    469:                rcs_kwexp_set(cf->file_rcs, cf_kflag);
1.56      joris     470:        }
                    471:
1.55      joris     472:        rcs_write(cf->file_rcs);
1.6       jfb       473:
1.56      joris     474:        if (cf->file_status == FILE_REMOVED) {
1.77      reyk      475:                strlcpy(nbuf, "Removed", sizeof(nbuf));
1.61      joris     476:        } else if (cf->file_status == FILE_ADDED) {
1.66      joris     477:                if (cf->file_rcs->rf_dead == 1)
1.77      reyk      478:                        strlcpy(nbuf, "Initial Revision", sizeof(nbuf));
1.63      joris     479:                else
1.112     joris     480:                        rcsnum_tostr(nrev, nbuf, sizeof(nbuf));
1.56      joris     481:        } else if (cf->file_status == FILE_MODIFIED) {
1.112     joris     482:                rcsnum_tostr(nrev, nbuf, sizeof(nbuf));
1.56      joris     483:        }
                    484:
1.77      reyk      485:        if (verbosity > 1)
                    486:                cvs_printf("new revision: %s\n", nbuf);
1.3       krapht    487:
1.55      joris     488:        (void)unlink(cf->file_path);
                    489:        (void)close(cf->fd);
                    490:        cf->fd = -1;
1.56      joris     491:
                    492:        if (cf->file_status != FILE_REMOVED) {
1.112     joris     493:                cvs_checkout_file(cf, nrev, NULL, CO_COMMIT);
1.56      joris     494:        } else {
                    495:                entlist = cvs_ent_open(cf->file_wd);
                    496:                cvs_ent_remove(entlist, cf->file_name);
                    497:                cvs_ent_close(entlist, ENT_SYNC);
1.64      joris     498:
                    499:                cvs_get_repository_path(cf->file_wd, repo, MAXPATHLEN);
                    500:
1.102     xsa       501:                (void)xsnprintf(attic, MAXPATHLEN, "%s/%s",
                    502:                    repo, CVS_PATH_ATTIC);
1.64      joris     503:
                    504:                if (mkdir(attic, 0755) == -1 && errno != EEXIST)
                    505:                        fatal("cvs_commit_local: failed to create Attic");
                    506:
1.102     xsa       507:                (void)xsnprintf(attic, MAXPATHLEN, "%s/%s/%s%s", repo,
1.64      joris     508:                    CVS_PATH_ATTIC, cf->file_name, RCS_FILE_EXT);
                    509:
                    510:                if (rename(cf->file_rpath, attic) == -1)
                    511:                        fatal("cvs_commit_local: failed to move %s to Attic",
                    512:                            cf->file_path);
                    513:
1.85      joris     514:                if (cvs_server_active == 1)
                    515:                        cvs_server_update_entry("Remove-entry", cf);
1.56      joris     516:        }
1.3       krapht    517:
1.77      reyk      518:        if (verbosity > 1)
                    519:                cvs_printf("done\n");
                    520:        else {
                    521:                cvs_log(LP_NOTICE, "checking in '%s'; revision %s -> %s",
                    522:                    cf->file_path, rbuf, nbuf);
                    523:        }
1.107     joris     524:
                    525:        switch (cf->file_status) {
                    526:        case FILE_MODIFIED:
                    527:                histtype = CVS_HISTORY_COMMIT_MODIFIED;
                    528:                break;
                    529:        case FILE_ADDED:
                    530:                histtype = CVS_HISTORY_COMMIT_ADDED;
                    531:                break;
                    532:        case FILE_REMOVED:
                    533:                histtype = CVS_HISTORY_COMMIT_REMOVED;
                    534:                break;
                    535:        }
1.125     joris     536:
                    537:        if (crev != NULL)
                    538:                rcsnum_free(crev);
1.107     joris     539:
                    540:        cvs_history_add(histtype, cf, NULL);
1.39      xsa       541: }
                    542:
1.91      joris     543: static BUF *
1.112     joris     544: commit_diff(struct cvs_file *cf, RCSNUM *rev, int reverse)
1.39      xsa       545: {
1.112     joris     546:        char *p1, *p2, *p;
1.122     tobias    547:        BUF *b;
1.97      joris     548:
                    549:        (void)xasprintf(&p1, "%s/diff1.XXXXXXXXXX", cvs_tmpdir);
1.39      xsa       550:
1.63      joris     551:        if (cf->file_status == FILE_MODIFIED ||
                    552:            cf->file_status == FILE_ADDED) {
1.122     tobias    553:                if ((b = cvs_buf_load_fd(cf->fd, BUF_AUTOEXT)) == NULL)
1.118     tobias    554:                        fatal("commit_diff: failed to load '%s'",
1.56      joris     555:                            cf->file_path);
1.122     tobias    556:                cvs_buf_write_stmp(b, p1, NULL);
                    557:                cvs_buf_free(b);
1.63      joris     558:        } else {
1.112     joris     559:                rcs_rev_write_stmp(cf->file_rcs, rev, p1, 0);
1.56      joris     560:        }
1.3       krapht    561:
1.97      joris     562:        (void)xasprintf(&p2, "%s/diff2.XXXXXXXXXX", cvs_tmpdir);
1.117     tobias    563:        rcs_rev_write_stmp(cf->file_rcs, rev, p2, RCS_KWEXP_NONE);
1.55      joris     564:
1.122     tobias    565:        if ((b = cvs_buf_alloc(128, BUF_AUTOEXT)) == NULL)
1.112     joris     566:                fatal("commit_diff: failed to create diff buf");
1.55      joris     567:
                    568:        diff_format = D_RCSDIFF;
1.112     joris     569:
                    570:        if (reverse == 1) {
                    571:                p = p1;
                    572:                p1 = p2;
                    573:                p2 = p;
                    574:        }
                    575:
1.122     tobias    576:        if (cvs_diffreg(p1, p2, b) == D_ERROR)
1.112     joris     577:                fatal("commit_diff: failed to get RCS patch");
1.96      joris     578:
                    579:        xfree(p1);
                    580:        xfree(p2);
1.55      joris     581:
1.122     tobias    582:        return (b);
1.71      xsa       583: }
                    584:
                    585: static void
                    586: commit_desc_set(struct cvs_file *cf)
                    587: {
                    588:        BUF *bp;
1.102     xsa       589:        int fd;
1.100     otto      590:        char desc_path[MAXPATHLEN], *desc;
1.71      xsa       591:
1.102     xsa       592:        (void)xsnprintf(desc_path, MAXPATHLEN, "%s/%s%s",
1.71      xsa       593:            CVS_PATH_CVSDIR, cf->file_name, CVS_DESCR_FILE_EXT);
                    594:
1.100     otto      595:        if ((fd = open(desc_path, O_RDONLY)) == -1)
1.71      xsa       596:                return;
                    597:
1.78      joris     598:        bp = cvs_buf_load_fd(fd, BUF_AUTOEXT);
1.71      xsa       599:        cvs_buf_putc(bp, '\0');
                    600:        desc = cvs_buf_release(bp);
                    601:
                    602:        rcs_desc_set(cf->file_rcs, desc);
                    603:
1.76      joris     604:        (void)close(fd);
1.71      xsa       605:        (void)cvs_unlink(desc_path);
                    606:
                    607:        xfree(desc);
1.1       jfb       608: }