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

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