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

1.57    ! joris       1: /*     $OpenBSD$       */
1.1       jfb         2: /*
1.57    ! joris       3:  * Copyright (c) 2006 Joris Vink <joris@openbsd.org>
1.1       jfb         4:  *
1.57    ! 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.57    ! 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.51      xsa        18: #include "includes.h"
1.1       jfb        19:
                     20: #include "cvs.h"
                     21: #include "log.h"
                     22: #include "proto.h"
                     23:
1.57    ! joris      24: int    cvs_status(int, char **);
        !            25: void   cvs_status_local(struct cvs_file *);
1.22      jfb        26:
                     27: struct cvs_cmd cvs_cmd_status = {
                     28:        CVS_OP_STATUS, CVS_REQ_STATUS, "status",
                     29:        { "st", "stat" },
                     30:        "Display status information on checked out files",
                     31:        "[-lRv]",
1.57    ! joris      32:        "lRv:",
1.22      jfb        33:        NULL,
1.57    ! joris      34:        cvs_status
1.10      joris      35: };
1.1       jfb        36:
1.57    ! joris      37: #define CVS_STATUS_SEP \
        !            38:        "==================================================================="
1.1       jfb        39:
1.57    ! joris      40: const char *status_tab[] = {
        !            41:        "Unknown",
        !            42:        "Locally Added",
        !            43:        "Locally Removed",
        !            44:        "Locally Modified",
        !            45:        "Up-to-date",
        !            46:        "Needs Checkout",
        !            47:        "Needs Checkout",
        !            48:        "Needs Merge",
        !            49:        "Needs Patch",
        !            50:        "Entry Invalid",
        !            51:        "Unresolved Conflict",
        !            52:        "Classifying error",
        !            53: };
        !            54:
        !            55: int
        !            56: cvs_status(int argc, char **argv)
1.1       jfb        57: {
1.10      joris      58:        int ch;
1.57    ! joris      59:        char *arg = ".";
        !            60:        struct cvs_recursion cr;
1.1       jfb        61:
1.57    ! joris      62:        while ((ch = getopt(argc, argv, cvs_cmd_status.cmd_opts)) != -1) {
1.1       jfb        63:                switch (ch) {
1.7       jfb        64:                case 'l':
                     65:                        break;
                     66:                case 'R':
                     67:                        break;
                     68:                case 'v':
                     69:                        break;
1.1       jfb        70:                default:
1.57    ! joris      71:                        fatal("%s", cvs_cmd_status.cmd_synopsis);
1.1       jfb        72:                }
                     73:        }
                     74:
1.57    ! joris      75:        argc -= optind;
        !            76:        argv += optind;
1.1       jfb        77:
1.57    ! joris      78:        cr.enterdir = NULL;
        !            79:        cr.leavedir = NULL;
        !            80:        cr.local = cvs_status_local;
        !            81:        cr.remote = NULL;
        !            82:
        !            83:        if (argc > 0)
        !            84:                cvs_file_run(argc, argv, &cr);
        !            85:        else
        !            86:                cvs_file_run(1, &arg, &cr);
1.26      xsa        87:
1.1       jfb        88:        return (0);
                     89: }
                     90:
1.57    ! joris      91: void
        !            92: cvs_status_local(struct cvs_file *cf)
1.1       jfb        93: {
1.57    ! joris      94:        int l;
        !            95:        size_t len;
        !            96:        const char *status;
        !            97:        char buf[128], timebuf[32], revbuf[32];
1.1       jfb        98:
1.57    ! joris      99:        cvs_log(LP_TRACE, "cvs_status_local(%s)", cf->file_path);
1.1       jfb       100:
1.57    ! joris     101:        cvs_file_classify(cf);
1.15      jfb       102:
1.57    ! joris     103:        if (cf->file_type == CVS_DIR) {
1.33      xsa       104:                if (verbosity > 1)
1.57    ! joris     105:                        cvs_log(LP_NOTICE, "Examining %s", cf->file_path);
        !           106:                return;
1.33      xsa       107:        }
1.15      jfb       108:
1.57    ! joris     109:        cvs_printf("%s\n", CVS_STATUS_SEP);
1.5       jfb       110:
1.57    ! joris     111:        status = status_tab[cf->file_status];
        !           112:        if (cf->file_status == FILE_MODIFIED &&
        !           113:            cf->file_ent->ce_conflict != NULL)
        !           114:                status = "File had conflicts on merge";
        !           115:
        !           116:        cvs_printf("File: %-17s\tStatus: %s\n\n", cf->file_name, status);
        !           117:
        !           118:        if (cf->file_ent == NULL) {
        !           119:                l = snprintf(buf, sizeof(buf),
        !           120:                    "No entry for %s", cf->file_name);
        !           121:                if (l == -1 || l >= (int)sizeof(buf))
        !           122:                        fatal("cvs_status_local: overflow");
        !           123:        } else if (cf->file_status == FILE_ADDED) {
        !           124:                len = strlcpy(buf, "New file!", sizeof(buf));
        !           125:                if (len >= sizeof(buf))
        !           126:                        fatal("cvs_status_local: truncation");
1.16      jfb       127:        } else {
1.57    ! joris     128:                rcsnum_tostr(cf->file_ent->ce_rev, revbuf, sizeof(revbuf));
1.35      xsa       129:
1.57    ! joris     130:                if (cf->file_ent->ce_conflict == NULL) {
        !           131:                        ctime_r(&(cf->file_ent->ce_mtime), timebuf);
        !           132:                        if (timebuf[strlen(timebuf) - 1] == '\n')
        !           133:                                timebuf[strlen(timebuf) - 1] = '\0';
        !           134:                } else {
        !           135:                        len = strlcpy(timebuf, cf->file_ent->ce_conflict,
        !           136:                            sizeof(timebuf));
        !           137:                        if (len >= sizeof(timebuf))
        !           138:                                fatal("cvs_status_local: truncation");
        !           139:                }
1.35      xsa       140:
1.57    ! joris     141:                l = snprintf(buf, sizeof(buf), "%s\t%s", revbuf, timebuf);
        !           142:                if (l == -1 || l >= (int)sizeof(buf))
        !           143:                        fatal("cvs_status_local: overflow");
1.16      jfb       144:        }
1.32      joris     145:
1.28      xsa       146:        cvs_printf("   Working revision:\t%s\n", buf);
1.30      xsa       147:
1.57    ! joris     148:        buf[0] = '\0';
        !           149:        if (cf->file_rcs == NULL) {
        !           150:                len = strlcat(buf, "No revision control file", sizeof(buf));
        !           151:                if (len >= sizeof(buf))
        !           152:                        fatal("cvs_status_local: truncation");
1.30      xsa       153:        } else {
1.57    ! joris     154:                rcsnum_tostr(cf->file_rcs->rf_head, revbuf, sizeof(revbuf));
        !           155:                l = snprintf(buf, sizeof(buf), "%s\t%s", revbuf,
        !           156:                    cf->file_rpath);
        !           157:                if (l == -1 || l >= (int)sizeof(buf))
        !           158:                        fatal("cvs_status_local: overflow");
1.30      xsa       159:        }
                    160:
                    161:        cvs_printf("   Repository revision:\t%s\n", buf);
                    162:
1.57    ! joris     163:        if (cf->file_ent != NULL) {
        !           164:                if (cf->file_ent->ce_tag != NULL)
        !           165:                        cvs_printf("   Sticky Tag:\t%s\n",
        !           166:                            cf->file_ent->ce_tag);
        !           167:                if (cf->file_ent->ce_opts != NULL)
        !           168:                        cvs_printf("   Sticky Options:\t%s\n",
        !           169:                            cf->file_ent->ce_opts);
1.41      xsa       170:        }
1.15      jfb       171:
1.25      xsa       172:        cvs_printf("\n");
1.1       jfb       173: }