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

Annotation of src/usr.bin/cvs/status.c, Revision 1.68

1.68    ! joris       1: /*     $OpenBSD: status.c,v 1.67 2006/07/07 13:01:40 joris Exp $       */
1.1       jfb         2: /*
1.57      joris       3:  * Copyright (c) 2006 Joris Vink <joris@openbsd.org>
1.64      xsa         4:  * Copyright (c) 2005, 2006 Xavier Santolaria <xsa@openbsd.org>
1.1       jfb         5:  *
1.57      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.57      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.51      xsa        19: #include "includes.h"
1.1       jfb        20:
                     21: #include "cvs.h"
                     22: #include "log.h"
1.68    ! joris      23: #include "remote.h"
1.1       jfb        24:
1.57      joris      25: void   cvs_status_local(struct cvs_file *);
1.22      jfb        26:
1.64      xsa        27: static int show_sym = 0;
                     28:
1.22      jfb        29: struct cvs_cmd cvs_cmd_status = {
1.65      joris      30:        CVS_OP_STATUS, 0, "status",
1.22      jfb        31:        { "st", "stat" },
                     32:        "Display status information on checked out files",
                     33:        "[-lRv]",
1.64      xsa        34:        "lRv",
1.22      jfb        35:        NULL,
1.57      joris      36:        cvs_status
1.10      joris      37: };
1.1       jfb        38:
1.57      joris      39: #define CVS_STATUS_SEP \
                     40:        "==================================================================="
1.1       jfb        41:
1.57      joris      42: const char *status_tab[] = {
                     43:        "Unknown",
                     44:        "Locally Added",
                     45:        "Locally Removed",
                     46:        "Locally Modified",
                     47:        "Up-to-date",
                     48:        "Needs Checkout",
                     49:        "Needs Checkout",
                     50:        "Needs Merge",
                     51:        "Needs Patch",
                     52:        "Entry Invalid",
                     53:        "Unresolved Conflict",
                     54:        "Classifying error",
                     55: };
                     56:
                     57: int
                     58: cvs_status(int argc, char **argv)
1.1       jfb        59: {
1.58      joris      60:        int ch, flags;
1.57      joris      61:        char *arg = ".";
                     62:        struct cvs_recursion cr;
1.1       jfb        63:
1.68    ! joris      64:        flags = CR_RECURSE_DIRS;
1.58      joris      65:
1.57      joris      66:        while ((ch = getopt(argc, argv, cvs_cmd_status.cmd_opts)) != -1) {
1.1       jfb        67:                switch (ch) {
1.7       jfb        68:                case 'l':
1.58      joris      69:                        flags &= ~CR_RECURSE_DIRS;
1.7       jfb        70:                        break;
                     71:                case 'R':
                     72:                        break;
                     73:                case 'v':
1.64      xsa        74:                        show_sym = 1;
1.7       jfb        75:                        break;
1.1       jfb        76:                default:
1.57      joris      77:                        fatal("%s", cvs_cmd_status.cmd_synopsis);
1.1       jfb        78:                }
                     79:        }
                     80:
1.57      joris      81:        argc -= optind;
                     82:        argv += optind;
1.1       jfb        83:
1.57      joris      84:        cr.enterdir = NULL;
                     85:        cr.leavedir = NULL;
1.68    ! joris      86:
        !            87:        if (current_cvsroot->cr_method == CVS_METHOD_LOCAL) {
        !            88:                flags |= CR_REPO;
        !            89:                cr.fileproc = cvs_status_local;
        !            90:        } else {
        !            91:                if (!(flags & CR_RECURSE_DIRS))
        !            92:                        cvs_client_send_request("Argument -l");
        !            93:                if (show_sym)
        !            94:                        cvs_client_send_request("Argument -v");
        !            95:                cr.fileproc = cvs_client_sendfile;
        !            96:        }
        !            97:
1.58      joris      98:        cr.flags = flags;
1.57      joris      99:
                    100:        if (argc > 0)
                    101:                cvs_file_run(argc, argv, &cr);
                    102:        else
                    103:                cvs_file_run(1, &arg, &cr);
1.68    ! joris     104:
        !           105:        if (current_cvsroot->cr_method != CVS_METHOD_LOCAL) {
        !           106:                cvs_client_send_files(argv, argc);
        !           107:                cvs_client_senddir(".");
        !           108:                cvs_client_send_request("status");
        !           109:                cvs_client_get_responses();
        !           110:        }
1.26      xsa       111:
1.1       jfb       112:        return (0);
                    113: }
                    114:
1.57      joris     115: void
                    116: cvs_status_local(struct cvs_file *cf)
1.1       jfb       117: {
1.57      joris     118:        int l;
                    119:        size_t len;
                    120:        const char *status;
                    121:        char buf[128], timebuf[32], revbuf[32];
1.64      xsa       122:        struct rcs_sym *sym;
1.1       jfb       123:
1.57      joris     124:        cvs_log(LP_TRACE, "cvs_status_local(%s)", cf->file_path);
1.1       jfb       125:
1.61      joris     126:        cvs_file_classify(cf, NULL, 1);
1.15      jfb       127:
1.57      joris     128:        if (cf->file_type == CVS_DIR) {
1.33      xsa       129:                if (verbosity > 1)
1.57      joris     130:                        cvs_log(LP_NOTICE, "Examining %s", cf->file_path);
                    131:                return;
1.33      xsa       132:        }
1.15      jfb       133:
1.57      joris     134:        cvs_printf("%s\n", CVS_STATUS_SEP);
1.5       jfb       135:
1.57      joris     136:        status = status_tab[cf->file_status];
                    137:        if (cf->file_status == FILE_MODIFIED &&
                    138:            cf->file_ent->ce_conflict != NULL)
                    139:                status = "File had conflicts on merge";
                    140:
1.63      xsa       141:        if (cf->file_status == FILE_LOST ||
                    142:            cf->file_status == FILE_UNKNOWN ||
1.67      joris     143:            (cf->file_rcs != NULL && cf->file_rcs->rf_inattic == 1)) {
1.63      xsa       144:                l = snprintf(buf, sizeof(buf), "no file %s\t", cf->file_name);
                    145:                if (l == -1 || l >= (int)sizeof(buf))
                    146:                        fatal("cvs_status_local: overflow");
                    147:        } else
                    148:                if (strlcpy(buf, cf->file_name, sizeof(buf)) >= sizeof(buf))
                    149:                        fatal("cvs_status_local: overflow");
                    150:
                    151:        cvs_printf("File: %-17s\tStatus: %s\n\n", buf, status);
1.57      joris     152:
                    153:        if (cf->file_ent == NULL) {
                    154:                l = snprintf(buf, sizeof(buf),
                    155:                    "No entry for %s", cf->file_name);
                    156:                if (l == -1 || l >= (int)sizeof(buf))
                    157:                        fatal("cvs_status_local: overflow");
                    158:        } else if (cf->file_status == FILE_ADDED) {
                    159:                len = strlcpy(buf, "New file!", sizeof(buf));
                    160:                if (len >= sizeof(buf))
                    161:                        fatal("cvs_status_local: truncation");
1.16      jfb       162:        } else {
1.57      joris     163:                rcsnum_tostr(cf->file_ent->ce_rev, revbuf, sizeof(revbuf));
1.35      xsa       164:
1.57      joris     165:                if (cf->file_ent->ce_conflict == NULL) {
                    166:                        ctime_r(&(cf->file_ent->ce_mtime), timebuf);
                    167:                        if (timebuf[strlen(timebuf) - 1] == '\n')
                    168:                                timebuf[strlen(timebuf) - 1] = '\0';
                    169:                } else {
                    170:                        len = strlcpy(timebuf, cf->file_ent->ce_conflict,
                    171:                            sizeof(timebuf));
                    172:                        if (len >= sizeof(timebuf))
                    173:                                fatal("cvs_status_local: truncation");
                    174:                }
1.35      xsa       175:
1.57      joris     176:                l = snprintf(buf, sizeof(buf), "%s\t%s", revbuf, timebuf);
                    177:                if (l == -1 || l >= (int)sizeof(buf))
                    178:                        fatal("cvs_status_local: overflow");
1.16      jfb       179:        }
1.32      joris     180:
1.28      xsa       181:        cvs_printf("   Working revision:\t%s\n", buf);
1.30      xsa       182:
1.57      joris     183:        buf[0] = '\0';
                    184:        if (cf->file_rcs == NULL) {
                    185:                len = strlcat(buf, "No revision control file", sizeof(buf));
                    186:                if (len >= sizeof(buf))
                    187:                        fatal("cvs_status_local: truncation");
1.30      xsa       188:        } else {
1.62      joris     189:                rcsnum_tostr(rcs_head_get(cf->file_rcs),
                    190:                    revbuf, sizeof(revbuf));
1.57      joris     191:                l = snprintf(buf, sizeof(buf), "%s\t%s", revbuf,
                    192:                    cf->file_rpath);
                    193:                if (l == -1 || l >= (int)sizeof(buf))
                    194:                        fatal("cvs_status_local: overflow");
1.30      xsa       195:        }
                    196:
                    197:        cvs_printf("   Repository revision:\t%s\n", buf);
                    198:
1.57      joris     199:        if (cf->file_ent != NULL) {
                    200:                if (cf->file_ent->ce_tag != NULL)
1.60      xsa       201:                        cvs_printf("   Sticky Tag:\t\t%s\n",
1.57      joris     202:                            cf->file_ent->ce_tag);
1.60      xsa       203:                else if (verbosity > 0)
                    204:                        cvs_printf("   Sticky Tag:\t\t(none)\n");
                    205:
1.57      joris     206:                if (cf->file_ent->ce_opts != NULL)
                    207:                        cvs_printf("   Sticky Options:\t%s\n",
                    208:                            cf->file_ent->ce_opts);
1.60      xsa       209:                else if (verbosity > 0)
                    210:                        cvs_printf("   Sticky Options:\t(none)\n");
1.64      xsa       211:        }
                    212:
                    213:        if (show_sym == 1) {
                    214:                cvs_printf("\n");
                    215:                cvs_printf("   Existing Tags:\n");
                    216:
                    217:                if (!TAILQ_EMPTY(&(cf->file_rcs->rf_symbols))) {
                    218:                        TAILQ_FOREACH(sym,
                    219:                            &(cf->file_rcs->rf_symbols), rs_list) {
                    220:                                (void)rcsnum_tostr(sym->rs_num, revbuf,
                    221:                                    sizeof(revbuf));
                    222:
                    223:                                cvs_printf("\t%-25s\t(%s: %s)\n", sym->rs_name,
                    224:                                    RCSNUM_ISBRANCH(sym->rs_num) ? "branch" :
                    225:                                    "revision", revbuf);
                    226:                         }
                    227:                } else
                    228:                        cvs_printf("\tNo Tags Exist\n");
1.41      xsa       229:        }
1.15      jfb       230:
1.25      xsa       231:        cvs_printf("\n");
1.1       jfb       232: }