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

Annotation of src/usr.bin/cvs/update.c, Revision 1.136

1.136   ! joris       1: /*     $OpenBSD: update.c,v 1.135 2008/03/02 19:05:34 tobias Exp $     */
1.1       jfb         2: /*
1.59      joris       3:  * Copyright (c) 2006 Joris Vink <joris@openbsd.org>
1.1       jfb         4:  *
1.59      joris       5:  * Permission to use, copy, modify, and distribute this software for any
                      6:  * purpose with or without fee is hereby granted, provided that the above
                      7:  * copyright notice and this permission notice appear in all copies.
1.1       jfb         8:  *
1.59      joris       9:  * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
                     10:  * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
                     11:  * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
                     12:  * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
                     13:  * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
                     14:  * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
                     15:  * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
1.1       jfb        16:  */
                     17:
1.97      otto       18: #include <sys/stat.h>
                     19:
                     20: #include <errno.h>
                     21: #include <fcntl.h>
                     22: #include <string.h>
                     23: #include <unistd.h>
1.1       jfb        24:
                     25: #include "cvs.h"
1.59      joris      26: #include "diff.h"
1.80      joris      27: #include "remote.h"
1.1       jfb        28:
1.60      joris      29: int    prune_dirs = 0;
1.108     joris      30: int    print_stdout = 0;
1.63      joris      31: int    build_dirs = 0;
1.124     tobias     32: int    reset_option = 0;
                     33: int    reset_tag = 0;
1.104     joris      34: char *cvs_specified_tag = NULL;
1.136   ! joris      35: char *cvs_join_rev1 = NULL;
        !            36: char *cvs_join_rev2 = NULL;
1.63      joris      37:
1.119     tobias     38: static char *koptstr;
1.125     joris      39: static char *dateflag = NULL;
1.124     tobias     40: static int Aflag = 0;
1.119     tobias     41:
1.65      joris      42: static void update_clear_conflict(struct cvs_file *);
1.136   ! joris      43: static void update_join_file(struct cvs_file *);
1.65      joris      44:
1.29      jfb        45: struct cvs_cmd cvs_cmd_update = {
1.116     tobias     46:        CVS_OP_UPDATE, CVS_USE_WDIR, "update",
1.29      jfb        47:        { "up", "upd" },
                     48:        "Bring work tree in sync with repository",
                     49:        "[-ACdflPpR] [-D date | -r rev] [-I ign] [-j rev] [-k mode] "
                     50:        "[-t id] ...",
1.106     joris      51:        "ACD:dfI:j:k:lPpQqRr:t:u",
1.29      jfb        52:        NULL,
1.59      joris      53:        cvs_update
1.18      joris      54: };
1.2       jfb        55:
1.59      joris      56: int
                     57: cvs_update(int argc, char **argv)
1.1       jfb        58: {
1.18      joris      59:        int ch;
1.59      joris      60:        char *arg = ".";
1.61      joris      61:        int flags;
1.59      joris      62:        struct cvs_recursion cr;
1.2       jfb        63:
1.80      joris      64:        flags = CR_RECURSE_DIRS;
1.61      joris      65:
1.59      joris      66:        while ((ch = getopt(argc, argv, cvs_cmd_update.cmd_opts)) != -1) {
1.1       jfb        67:                switch (ch) {
                     68:                case 'A':
1.124     tobias     69:                        Aflag = 1;
                     70:                        if (koptstr == NULL)
                     71:                                reset_option = 1;
                     72:                        if (cvs_specified_tag == NULL)
                     73:                                reset_tag = 1;
1.24      joris      74:                        break;
1.1       jfb        75:                case 'C':
1.126     joris      76:                        break;
1.1       jfb        77:                case 'D':
1.125     joris      78:                        dateflag = optarg;
                     79:                        cvs_specified_date = cvs_date_parse(dateflag);
1.32      xsa        80:                        break;
1.1       jfb        81:                case 'd':
1.63      joris      82:                        build_dirs = 1;
1.24      joris      83:                        break;
1.1       jfb        84:                case 'f':
1.2       jfb        85:                        break;
1.35      xsa        86:                case 'I':
                     87:                        break;
                     88:                case 'j':
1.136   ! joris      89:                        if (cvs_join_rev1 == NULL)
        !            90:                                cvs_join_rev1 = optarg;
        !            91:                        else if (cvs_join_rev2 == NULL)
        !            92:                                cvs_join_rev2 = optarg;
        !            93:                        else
        !            94:                                fatal("too many -j options");
1.35      xsa        95:                        break;
                     96:                case 'k':
1.124     tobias     97:                        reset_option = 0;
1.119     tobias     98:                        koptstr = optarg;
                     99:                        kflag = rcs_kflag_get(koptstr);
                    100:                        if (RCS_KWEXP_INVAL(kflag)) {
                    101:                                cvs_log(LP_ERR,
                    102:                                    "invalid RCS keyword expension mode");
1.135     tobias    103:                                fatal("%s", cvs_cmd_update.cmd_synopsis);
1.119     tobias    104:                        }
1.35      xsa       105:                        break;
1.1       jfb       106:                case 'l':
1.61      joris     107:                        flags &= ~CR_RECURSE_DIRS;
1.2       jfb       108:                        break;
1.1       jfb       109:                case 'P':
1.60      joris     110:                        prune_dirs = 1;
1.24      joris     111:                        break;
1.1       jfb       112:                case 'p':
1.108     joris     113:                        print_stdout = 1;
1.79      xsa       114:                        cvs_noexec = 1;
1.27      xsa       115:                        break;
1.1       jfb       116:                case 'Q':
                    117:                case 'q':
1.2       jfb       118:                        break;
1.1       jfb       119:                case 'R':
1.115     tobias    120:                        flags |= CR_RECURSE_DIRS;
1.2       jfb       121:                        break;
1.1       jfb       122:                case 'r':
1.124     tobias    123:                        reset_tag = 0;
1.104     joris     124:                        cvs_specified_tag = optarg;
1.106     joris     125:                        break;
                    126:                case 'u':
1.1       jfb       127:                        break;
                    128:                default:
1.59      joris     129:                        fatal("%s", cvs_cmd_update.cmd_synopsis);
1.1       jfb       130:                }
1.32      xsa       131:        }
                    132:
1.59      joris     133:        argc -= optind;
                    134:        argv += optind;
1.2       jfb       135:
1.80      joris     136:        if (current_cvsroot->cr_method == CVS_METHOD_LOCAL) {
                    137:                cr.enterdir = cvs_update_enterdir;
1.118     tobias    138:                cr.leavedir = prune_dirs ? cvs_update_leavedir : NULL;
1.80      joris     139:                cr.fileproc = cvs_update_local;
                    140:                flags |= CR_REPO;
                    141:        } else {
1.82      joris     142:                cvs_client_connect_to_server();
1.124     tobias    143:                if (Aflag)
1.80      joris     144:                        cvs_client_send_request("Argument -A");
1.125     joris     145:                if (dateflag != NULL)
                    146:                        cvs_client_send_request("Argument -D%s", dateflag);
1.80      joris     147:                if (build_dirs)
                    148:                        cvs_client_send_request("Argument -d");
1.119     tobias    149:                if (kflag)
                    150:                        cvs_client_send_request("Argument -k%s", koptstr);
1.80      joris     151:                if (!(flags & CR_RECURSE_DIRS))
                    152:                        cvs_client_send_request("Argument -l");
                    153:                if (prune_dirs)
                    154:                        cvs_client_send_request("Argument -P");
1.108     joris     155:                if (print_stdout)
1.80      joris     156:                        cvs_client_send_request("Argument -p");
                    157:
1.110     joris     158:                if (cvs_specified_tag != NULL)
                    159:                        cvs_client_send_request("Argument -r%s",
                    160:                            cvs_specified_tag);
                    161:
1.80      joris     162:                cr.enterdir = NULL;
                    163:                cr.leavedir = NULL;
                    164:                cr.fileproc = cvs_client_sendfile;
                    165:        }
                    166:
1.61      joris     167:        cr.flags = flags;
1.49      joris     168:
1.59      joris     169:        if (argc > 0)
                    170:                cvs_file_run(argc, argv, &cr);
                    171:        else
                    172:                cvs_file_run(1, &arg, &cr);
1.80      joris     173:
                    174:        if (current_cvsroot->cr_method != CVS_METHOD_LOCAL) {
                    175:                cvs_client_send_files(argv, argc);
                    176:                cvs_client_senddir(".");
                    177:                cvs_client_send_request("update");
                    178:                cvs_client_get_responses();
                    179:        }
1.35      xsa       180:
1.24      joris     181:        return (0);
                    182: }
1.2       jfb       183:
1.59      joris     184: void
                    185: cvs_update_enterdir(struct cvs_file *cf)
1.2       jfb       186: {
1.59      joris     187:        CVSENTRIES *entlist;
1.104     joris     188:        char *entry, fpath[MAXPATHLEN];
1.59      joris     189:
                    190:        cvs_log(LP_TRACE, "cvs_update_enterdir(%s)", cf->file_path);
                    191:
1.110     joris     192:        cvs_file_classify(cf, cvs_directory_tag);
1.59      joris     193:
1.63      joris     194:        if (cf->file_status == DIR_CREATE && build_dirs == 1) {
1.104     joris     195:                cvs_mkpath(cf->file_path, cvs_specified_tag);
1.59      joris     196:                if ((cf->fd = open(cf->file_path, O_RDONLY)) == -1)
1.87      xsa       197:                        fatal("cvs_update_enterdir: `%s': %s",
                    198:                            cf->file_path, strerror(errno));
1.59      joris     199:
1.114     tobias    200:                if (cvs_cmdop != CVS_OP_EXPORT) {
                    201:                        (void)xasprintf(&entry, "D/%s////", cf->file_name);
1.59      joris     202:
1.114     tobias    203:                        entlist = cvs_ent_open(cf->file_wd);
                    204:                        cvs_ent_add(entlist, entry);
                    205:                        cvs_ent_close(entlist, ENT_SYNC);
                    206:                        xfree(entry);
                    207:                }
1.94      xsa       208:        } else if ((cf->file_status == DIR_CREATE && build_dirs == 0) ||
                    209:                    cf->file_status == FILE_UNKNOWN) {
1.67      joris     210:                cf->file_status = FILE_SKIP;
1.124     tobias    211:        } else if (reset_tag) {
1.104     joris     212:                (void)xsnprintf(fpath, MAXPATHLEN, "%s/%s",
                    213:                    cf->file_path, CVS_PATH_TAG);
                    214:                (void)unlink(fpath);
                    215:        } else {
1.131     joris     216:                if (cvs_specified_tag != NULL || cvs_specified_date != -1)
1.104     joris     217:                        cvs_write_tagfile(cf->file_path,
1.120     tobias    218:                                    cvs_specified_tag, NULL);
1.60      joris     219:        }
                    220: }
                    221:
                    222: void
                    223: cvs_update_leavedir(struct cvs_file *cf)
                    224: {
                    225:        long base;
                    226:        int nbytes;
1.81      xsa       227:        int isempty;
1.60      joris     228:        size_t bufsize;
                    229:        struct stat st;
                    230:        struct dirent *dp;
                    231:        char *buf, *ebuf, *cp;
                    232:        struct cvs_ent *ent;
                    233:        struct cvs_ent_line *line;
                    234:        CVSENTRIES *entlist;
                    235:
1.67      joris     236:        cvs_log(LP_TRACE, "cvs_update_leavedir(%s)", cf->file_path);
1.86      joris     237:
1.105     joris     238:        if (cvs_server_active == 1 && !strcmp(cf->file_name, "."))
                    239:                return;
1.69      joris     240:
1.60      joris     241:        if (fstat(cf->fd, &st) == -1)
                    242:                fatal("cvs_update_leavedir: %s", strerror(errno));
                    243:
                    244:        bufsize = st.st_size;
                    245:        if (bufsize < st.st_blksize)
                    246:                bufsize = st.st_blksize;
                    247:
                    248:        isempty = 1;
                    249:        buf = xmalloc(bufsize);
                    250:
1.73      joris     251:        if (lseek(cf->fd, 0, SEEK_SET) == -1)
1.60      joris     252:                fatal("cvs_update_leavedir: %s", strerror(errno));
                    253:
                    254:        while ((nbytes = getdirentries(cf->fd, buf, bufsize, &base)) > 0) {
                    255:                ebuf = buf + nbytes;
                    256:                cp = buf;
                    257:
                    258:                while (cp < ebuf) {
                    259:                        dp = (struct dirent *)cp;
                    260:                        if (!strcmp(dp->d_name, ".") ||
                    261:                            !strcmp(dp->d_name, "..") ||
1.95      joris     262:                            dp->d_fileno == 0) {
1.60      joris     263:                                cp += dp->d_reclen;
                    264:                                continue;
                    265:                        }
                    266:
                    267:                        if (!strcmp(dp->d_name, CVS_PATH_CVSDIR)) {
                    268:                                entlist = cvs_ent_open(cf->file_path);
                    269:                                TAILQ_FOREACH(line, &(entlist->cef_ent),
                    270:                                    entries_list) {
                    271:                                        ent = cvs_ent_parse(line->buf);
                    272:
                    273:                                        if (ent->ce_status == CVS_ENT_REMOVED) {
                    274:                                                isempty = 0;
                    275:                                                cvs_ent_free(ent);
                    276:                                                break;
                    277:                                        }
                    278:
                    279:                                        cvs_ent_free(ent);
                    280:                                }
                    281:                                cvs_ent_close(entlist, ENT_NOSYNC);
                    282:                        } else {
                    283:                                isempty = 0;
                    284:                        }
                    285:
                    286:                        if (isempty == 0)
                    287:                                break;
                    288:
                    289:                        cp += dp->d_reclen;
                    290:                }
                    291:        }
                    292:
                    293:        if (nbytes == -1)
                    294:                fatal("cvs_update_leavedir: %s", strerror(errno));
                    295:
                    296:        xfree(buf);
                    297:
                    298:        if (isempty == 1 && prune_dirs == 1) {
1.69      joris     299:                /* XXX */
1.60      joris     300:                cvs_rmdir(cf->file_path);
                    301:
1.114     tobias    302:                if (cvs_server_active == 0 && cvs_cmdop != CVS_OP_EXPORT) {
1.88      joris     303:                        entlist = cvs_ent_open(cf->file_wd);
                    304:                        cvs_ent_remove(entlist, cf->file_name);
                    305:                        cvs_ent_close(entlist, ENT_SYNC);
                    306:                }
1.2       jfb       307:        }
                    308: }
                    309:
1.59      joris     310: void
                    311: cvs_update_local(struct cvs_file *cf)
1.2       jfb       312: {
1.136   ! joris     313:        CVSENTRIES *entlist;
1.133     tobias    314:        int ent_kflag, rcs_kflag, ret, flags;
1.136   ! joris     315:        char *tag, rbuf[CVS_REV_BUFSZ];
1.59      joris     316:
                    317:        cvs_log(LP_TRACE, "cvs_update_local(%s)", cf->file_path);
1.37      joris     318:
1.59      joris     319:        if (cf->file_type == CVS_DIR) {
1.114     tobias    320:                if (cf->file_status == FILE_SKIP) {
                    321:                        if (cvs_cmdop == CVS_OP_EXPORT && verbosity > 0)
                    322:                                cvs_printf("? %s\n", cf->file_path);
1.63      joris     323:                        return;
1.114     tobias    324:                }
1.63      joris     325:
1.59      joris     326:                if (cf->file_status != FILE_UNKNOWN &&
                    327:                    verbosity > 1)
                    328:                        cvs_log(LP_NOTICE, "Updating %s", cf->file_path);
                    329:                return;
1.26      jfb       330:        }
                    331:
1.70      joris     332:        flags = 0;
1.112     joris     333:        if (cvs_specified_tag != NULL)
                    334:                tag = cvs_specified_tag;
1.122     joris     335:        else if (cf->file_ent != NULL && cf->file_ent->ce_tag != NULL)
                    336:                tag = cf->file_ent->ce_tag;
1.112     joris     337:        else
                    338:                tag = cvs_directory_tag;
                    339:
                    340:        cvs_file_classify(cf, tag);
                    341:
1.119     tobias    342:        if (kflag)
                    343:                rcs_kwexp_set(cf->file_rcs, kflag);
1.70      joris     344:
1.91      joris     345:        if ((cf->file_status == FILE_UPTODATE ||
                    346:            cf->file_status == FILE_MODIFIED) && cf->file_ent != NULL &&
1.124     tobias    347:            cf->file_ent->ce_tag != NULL && reset_tag) {
1.91      joris     348:                if (cf->file_status == FILE_MODIFIED)
                    349:                        cf->file_status = FILE_MERGE;
                    350:                else
                    351:                        cf->file_status = FILE_CHECKOUT;
1.110     joris     352:
1.70      joris     353:                cf->file_rcsrev = rcs_head_get(cf->file_rcs);
1.104     joris     354:
                    355:                /* might be a bit overkill */
                    356:                if (cvs_server_active == 1)
                    357:                        cvs_server_clear_sticky(cf->file_wd);
1.76      reyk      358:        }
                    359:
1.117     tobias    360:        if (print_stdout && cf->file_status != FILE_UNKNOWN &&
                    361:            !cf->file_rcs->rf_dead) {
1.76      reyk      362:                rcsnum_tostr(cf->file_rcsrev, rbuf, sizeof(rbuf));
1.109     tobias    363:                if (verbosity > 1) {
                    364:                        cvs_log(LP_RCS, RCS_DIFF_DIV);
                    365:                        cvs_log(LP_RCS, "Checking out %s", cf->file_path);
                    366:                        cvs_log(LP_RCS, "RCS:  %s", cf->file_rpath);
                    367:                        cvs_log(LP_RCS, "VERS: %s", rbuf);
                    368:                        cvs_log(LP_RCS, "***************");
                    369:                }
1.112     joris     370:                cvs_checkout_file(cf, cf->file_rcsrev, tag, CO_DUMP);
1.76      reyk      371:                return;
1.70      joris     372:        }
1.45      joris     373:
1.119     tobias    374:        if (cf->file_ent != NULL) {
                    375:                if (cf->file_ent->ce_opts == NULL) {
                    376:                        if (kflag)
                    377:                                cf->file_status = FILE_CHECKOUT;
                    378:                } else {
1.133     tobias    379:                        if (strlen(cf->file_ent->ce_opts) < 3)
                    380:                                fatal("malformed option for file %s",
                    381:                                    cf->file_path);
                    382:
                    383:                        ent_kflag = rcs_kflag_get(cf->file_ent->ce_opts + 2);
                    384:                        rcs_kflag = rcs_kwexp_get(cf->file_rcs);
                    385:
                    386:                        if ((kflag && (kflag != ent_kflag)) ||
                    387:                            (reset_option && (ent_kflag != rcs_kflag)))
1.119     tobias    388:                                cf->file_status = FILE_CHECKOUT;
                    389:                }
                    390:        }
                    391:
1.59      joris     392:        switch (cf->file_status) {
                    393:        case FILE_UNKNOWN:
                    394:                cvs_printf("? %s\n", cf->file_path);
1.45      joris     395:                break;
1.59      joris     396:        case FILE_MODIFIED:
1.65      joris     397:                ret = update_has_conflict_markers(cf);
                    398:                if (cf->file_ent->ce_conflict != NULL && ret == 1) {
1.59      joris     399:                        cvs_printf("C %s\n", cf->file_path);
1.65      joris     400:                } else {
                    401:                        if (cf->file_ent->ce_conflict != NULL && ret == 0)
                    402:                                update_clear_conflict(cf);
1.59      joris     403:                        cvs_printf("M %s\n", cf->file_path);
1.65      joris     404:                }
1.45      joris     405:                break;
1.59      joris     406:        case FILE_ADDED:
                    407:                cvs_printf("A %s\n", cf->file_path);
1.45      joris     408:                break;
1.59      joris     409:        case FILE_REMOVED:
                    410:                cvs_printf("R %s\n", cf->file_path);
1.45      joris     411:                break;
1.59      joris     412:        case FILE_CONFLICT:
                    413:                cvs_printf("C %s\n", cf->file_path);
                    414:                break;
                    415:        case FILE_LOST:
                    416:        case FILE_CHECKOUT:
                    417:        case FILE_PATCH:
1.131     joris     418:                if ((tag != NULL && !reset_tag) || cvs_specified_date != -1 ||
1.110     joris     419:                    (((cf->file_ent != NULL) && cf->file_ent->ce_tag != NULL) &&
1.124     tobias    420:                    !reset_tag))
1.70      joris     421:                        flags = CO_SETSTICKY;
                    422:
1.112     joris     423:                cvs_checkout_file(cf, cf->file_rcsrev, tag, flags);
1.65      joris     424:                cvs_printf("U %s\n", cf->file_path);
1.100     joris     425:                cvs_history_add(CVS_HISTORY_UPDATE_CO, cf, NULL);
1.59      joris     426:                break;
                    427:        case FILE_MERGE:
1.136   ! joris     428:                d3rev1 = cf->file_ent->ce_rev;
        !           429:                d3rev2 = cf->file_rcsrev;
1.112     joris     430:                cvs_checkout_file(cf, cf->file_rcsrev, tag, CO_MERGE);
1.65      joris     431:
                    432:                if (diff3_conflicts != 0) {
                    433:                        cvs_printf("C %s\n", cf->file_path);
1.100     joris     434:                        cvs_history_add(CVS_HISTORY_UPDATE_MERGED_ERR,
                    435:                            cf, NULL);
1.65      joris     436:                } else {
                    437:                        update_clear_conflict(cf);
                    438:                        cvs_printf("M %s\n", cf->file_path);
1.100     joris     439:                        cvs_history_add(CVS_HISTORY_UPDATE_MERGED, cf, NULL);
1.65      joris     440:                }
1.59      joris     441:                break;
                    442:        case FILE_UNLINK:
                    443:                (void)unlink(cf->file_path);
1.102     joris     444:                if (cvs_server_active == 1)
1.112     joris     445:                        cvs_checkout_file(cf, cf->file_rcsrev, tag, CO_REMOVE);
1.59      joris     446:        case FILE_REMOVE_ENTRY:
                    447:                entlist = cvs_ent_open(cf->file_wd);
                    448:                cvs_ent_remove(entlist, cf->file_name);
                    449:                cvs_ent_close(entlist, ENT_SYNC);
1.100     joris     450:                cvs_history_add(CVS_HISTORY_UPDATE_REMOVE, cf, NULL);
1.110     joris     451:                break;
                    452:        case FILE_UPTODATE:
                    453:                if (cvs_cmdop != CVS_OP_UPDATE)
                    454:                        break;
                    455:
1.130     joris     456:                if (cf->file_rcsrev == NULL)
                    457:                        break;
                    458:
1.131     joris     459:                if (tag == NULL && cvs_specified_date == -1)
1.130     joris     460:                        break;
                    461:
                    462:                if (cf->file_rcs->rf_dead != 1 &&
                    463:                    (cf->file_flags & FILE_HAS_TAG))
1.112     joris     464:                        cvs_checkout_file(cf, cf->file_rcsrev,
                    465:                            tag, CO_SETSTICKY);
1.45      joris     466:                break;
                    467:        default:
                    468:                break;
                    469:        }
1.136   ! joris     470:
        !           471:        if (cvs_join_rev1 != NULL)
        !           472:                update_join_file(cf);
1.65      joris     473: }
                    474:
                    475: static void
                    476: update_clear_conflict(struct cvs_file *cf)
                    477: {
                    478:        time_t now;
                    479:        CVSENTRIES *entlist;
1.103     xsa       480:        char *entry, revbuf[CVS_REV_BUFSZ], timebuf[CVS_TIME_BUFSZ];
1.136   ! joris     481:        char sticky[CVS_ENT_MAXLINELEN], opt[4];
1.65      joris     482:
                    483:        cvs_log(LP_TRACE, "update_clear_conflict(%s)", cf->file_path);
                    484:
                    485:        time(&now);
                    486:        ctime_r(&now, timebuf);
1.113     tobias    487:        timebuf[strcspn(timebuf, "\n")] = '\0';
1.65      joris     488:
1.134     joris     489:        rcsnum_tostr(cf->file_rcsrev, revbuf, sizeof(revbuf));
1.65      joris     490:
1.121     tobias    491:        sticky[0] = '\0';
1.136   ! joris     492:        if (cf->file_ent != NULL && cf->file_ent->ce_tag != NULL)
1.121     tobias    493:                (void)xsnprintf(sticky, sizeof(sticky), "T%s",
                    494:                    cf->file_ent->ce_tag);
                    495:
1.136   ! joris     496:        opt[0] = '\0';
        !           497:        if (cf->file_ent != NULL && cf->file_ent->ce_opts != NULL)
        !           498:                strlcpy(opt, cf->file_ent->ce_opts, sizeof(opt));
        !           499:
1.65      joris     500:        entry = xmalloc(CVS_ENT_MAXLINELEN);
1.129     xsa       501:        cvs_ent_line_str(cf->file_name, revbuf, timebuf,
1.136   ! joris     502:            opt[0] != '\0' ? opt : "", sticky, 0, 0,
1.129     xsa       503:            entry, CVS_ENT_MAXLINELEN);
1.65      joris     504:
                    505:        entlist = cvs_ent_open(cf->file_wd);
                    506:        cvs_ent_add(entlist, entry);
                    507:        cvs_ent_close(entlist, ENT_SYNC);
                    508:        xfree(entry);
                    509: }
                    510:
                    511: /*
                    512:  * XXX - this is the way GNU cvs checks for outstanding conflicts
                    513:  * in a file after a merge. It is a very very bad approach and
                    514:  * should be looked at once opencvs is working decently.
                    515:  */
                    516: int
                    517: update_has_conflict_markers(struct cvs_file *cf)
                    518: {
                    519:        BUF *bp;
                    520:        int conflict;
                    521:        char *content;
                    522:        struct cvs_line *lp;
                    523:        struct cvs_lines *lines;
1.83      niallo    524:        size_t len;
1.65      joris     525:
                    526:        cvs_log(LP_TRACE, "update_has_conflict_markers(%s)", cf->file_path);
1.78      joris     527:
                    528:        if (cf->fd == -1)
                    529:                return (0);
1.65      joris     530:
1.132     tobias    531:        bp = cvs_buf_load_fd(cf->fd);
1.65      joris     532:
                    533:        cvs_buf_putc(bp, '\0');
1.83      niallo    534:        len = cvs_buf_len(bp);
1.65      joris     535:        content = cvs_buf_release(bp);
1.83      niallo    536:        if ((lines = cvs_splitlines(content, len)) == NULL)
1.65      joris     537:                fatal("update_has_conflict_markers: failed to split lines");
                    538:
                    539:        conflict = 0;
                    540:        TAILQ_FOREACH(lp, &(lines->l_lines), l_list) {
                    541:                if (lp->l_line == NULL)
                    542:                        continue;
                    543:
                    544:                if (!strncmp(lp->l_line, RCS_CONFLICT_MARKER1,
1.107     tobias    545:                    sizeof(RCS_CONFLICT_MARKER1) - 1) ||
1.65      joris     546:                    !strncmp(lp->l_line, RCS_CONFLICT_MARKER2,
1.107     tobias    547:                    sizeof(RCS_CONFLICT_MARKER2) - 1) ||
1.65      joris     548:                    !strncmp(lp->l_line, RCS_CONFLICT_MARKER3,
1.107     tobias    549:                    sizeof(RCS_CONFLICT_MARKER3) - 1)) {
1.65      joris     550:                        conflict = 1;
                    551:                        break;
                    552:                }
                    553:        }
                    554:
                    555:        cvs_freelines(lines);
1.83      niallo    556:        xfree(content);
1.65      joris     557:        return (conflict);
1.136   ! joris     558: }
        !           559:
        !           560: void
        !           561: update_join_file(struct cvs_file *cf)
        !           562: {
        !           563:        int flag;
        !           564:        time_t told;
        !           565:        RCSNUM *rev1, *rev2;
        !           566:        const char *state1, *state2;
        !           567:        char rbuf[CVS_REV_BUFSZ], *jrev1, *jrev2, *p;
        !           568:
        !           569:        rev1 = rev2 = NULL;
        !           570:        jrev1 = jrev2 = NULL;
        !           571:
        !           572:        jrev1 = xstrdup(cvs_join_rev1);
        !           573:        if (cvs_join_rev2 != NULL)
        !           574:                jrev2 = xstrdup(cvs_join_rev2);
        !           575:
        !           576:        if (jrev2 == NULL) {
        !           577:                jrev2 = jrev1;
        !           578:                jrev1 = NULL;
        !           579:        }
        !           580:
        !           581:        told = cvs_specified_date;
        !           582:
        !           583:        if ((p = strrchr(jrev2, ':')) != NULL) {
        !           584:                (*p++) = '\0';
        !           585:                cvs_specified_date = cvs_date_parse(p);
        !           586:        }
        !           587:
        !           588:        rev2 = rcs_translate_tag(jrev2, cf->file_rcs);
        !           589:        cvs_specified_date = told;
        !           590:
        !           591:        if (jrev1 != NULL) {
        !           592:                if ((p = strrchr(jrev1, ':')) != NULL) {
        !           593:                        (*p++) = '\0';
        !           594:                        cvs_specified_date = cvs_date_parse(p);
        !           595:                }
        !           596:
        !           597:                rev1 = rcs_translate_tag(jrev1, cf->file_rcs);
        !           598:                cvs_specified_date = told;
        !           599:        } else {
        !           600:                if (rev2 == NULL)
        !           601:                        goto out;
        !           602:
        !           603:                rev1 = rcsnum_alloc();
        !           604:                rcsnum_cpy(cf->file_rcsrev, rev1, 0);
        !           605:        }
        !           606:
        !           607:        state1 = state2 = RCS_STATE_DEAD;
        !           608:
        !           609:        if (rev1 != NULL)
        !           610:                state1 = rcs_state_get(cf->file_rcs, rev1);
        !           611:        if (rev2 != NULL)
        !           612:                state2 = rcs_state_get(cf->file_rcs, rev2);
        !           613:
        !           614:        if (rev2 == NULL || !strcmp(state2, RCS_STATE_DEAD)) {
        !           615:                if (rev1 == NULL || !strcmp(state1, RCS_STATE_DEAD))
        !           616:                        goto out;
        !           617:
        !           618:                if (cf->file_status == FILE_REMOVED ||
        !           619:                    cf->file_rcs->rf_dead == 1)
        !           620:                        goto out;
        !           621:
        !           622:                if (cf->file_status == FILE_MODIFIED ||
        !           623:                    cf->file_status == FILE_ADDED)
        !           624:                        goto out;
        !           625:
        !           626:                (void)unlink(cf->file_path);
        !           627:                (void)close(cf->fd);
        !           628:                cf->fd = -1;
        !           629:                cvs_remove_local(cf);
        !           630:                goto out;
        !           631:        }
        !           632:
        !           633:        if (cf->file_ent != NULL) {
        !           634:                if (!rcsnum_cmp(cf->file_ent->ce_rev, rev2, 0))
        !           635:                        goto out;
        !           636:        }
        !           637:
        !           638:        if (rev1 == NULL || !strcmp(state1, RCS_STATE_DEAD)) {
        !           639:                if (cf->fd != -1) {
        !           640:                        cvs_printf("%s exists but has been added in %s\n",
        !           641:                            cf->file_path, cvs_join_rev2);
        !           642:                } else {
        !           643:                        cvs_checkout_file(cf, cf->file_rcsrev, NULL, 0);
        !           644:                        cvs_add_local(cf);
        !           645:                }
        !           646:                goto out;
        !           647:        }
        !           648:
        !           649:        if (cf->fd == -1)
        !           650:                goto out;
        !           651:
        !           652:        flag = rcs_kwexp_get(cf->file_rcs);
        !           653:        if (flag & RCS_KWEXP_NONE) {
        !           654:                cvs_printf("non-mergable file: %s needs merge!\n",
        !           655:                    cf->file_path);
        !           656:                goto out;
        !           657:        }
        !           658:
        !           659:        cvs_printf("joining ");
        !           660:        rcsnum_tostr(rev1, rbuf, sizeof(rbuf));
        !           661:        cvs_printf("%s ", rbuf);
        !           662:
        !           663:        rcsnum_tostr(rev2, rbuf, sizeof(rbuf));
        !           664:        cvs_printf("%s ", rbuf);
        !           665:
        !           666:        rcsnum_tostr(cf->file_rcsrev, rbuf, sizeof(rbuf));
        !           667:        cvs_printf("into %s (%s)\n", cf->file_path, rbuf);
        !           668:
        !           669:        d3rev1 = rev1;
        !           670:        d3rev2 = rev2;
        !           671:        cvs_checkout_file(cf, cf->file_rcsrev, NULL, CO_MERGE);
        !           672:
        !           673:        if (diff3_conflicts == 0) {
        !           674:                update_clear_conflict(cf);
        !           675:                cvs_history_add(CVS_HISTORY_UPDATE_MERGED, cf, NULL);
        !           676:        }
        !           677:
        !           678: out:
        !           679:        if (rev1 != NULL)
        !           680:                rcsnum_free(rev1);
        !           681:        if (rev2 != NULL)
        !           682:                rcsnum_free(rev2);
        !           683:
        !           684:        if (jrev1 != NULL)
        !           685:                xfree(jrev1);
        !           686:        if (jrev2 != NULL)
        !           687:                xfree(jrev2);
1.1       jfb       688: }