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

Annotation of src/usr.bin/cvs/history.c, Revision 1.35

1.35    ! tobias      1: /*     $OpenBSD: history.c,v 1.34 2007/09/10 10:56:37 tobias Exp $     */
1.1       jfb         2: /*
1.28      joris       3:  * Copyright (c) 2007 Joris Vink <joris@openbsd.org>
1.1       jfb         4:  *
1.28      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.28      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.28      joris      18: #include <sys/stat.h>
                     19:
                     20: #include <ctype.h>
                     21: #include <errno.h>
                     22: #include <pwd.h>
                     23: #include <stdlib.h>
                     24: #include <string.h>
                     25: #include <unistd.h>
1.1       jfb        26:
                     27: #include "cvs.h"
1.28      joris      28: #include "remote.h"
1.1       jfb        29:
1.28      joris      30: void   cvs_history_local(struct cvs_file *);
1.1       jfb        31:
1.28      joris      32: struct cvs_cmd         cvs_cmd_history = {
1.35    ! tobias     33:        CVS_OP_HISTORY, CVS_USE_WDIR, "history",
1.29      xsa        34:        { "hi", "his" },                        /* omghi2you */
1.34      tobias     35:        "Display history of actions done in the base repository",
1.28      joris      36:        "[-ac]",
                     37:        "ac",
1.14      jfb        38:        NULL,
1.28      joris      39:        cvs_history
                     40: };
                     41:
                     42: /* keep in sync with the defines for history stuff in cvs.h */
                     43: const char historytab[] = {
                     44:        'T',
                     45:        'O',
                     46:        'E',
                     47:        'F',
                     48:        'W',
                     49:        'U',
                     50:        'G',
                     51:        'C',
                     52:        'M',
                     53:        'A',
                     54:        'R',
1.33      ray        55:        '\0'
1.9       joris      56: };
                     57:
1.28      joris      58: #define HISTORY_ALL_USERS              0x01
                     59: #define HISTORY_DISPLAY_ARCHIVED       0x02
1.1       jfb        60:
1.28      joris      61: void
                     62: cvs_history_add(int type, struct cvs_file *cf, const char *argument)
1.1       jfb        63: {
1.28      joris      64:        FILE *fp;
                     65:        char *cwd;
1.31      xsa        66:        char revbuf[CVS_REV_BUFSZ], repo[MAXPATHLEN], fpath[MAXPATHLEN];
1.1       jfb        67:
1.28      joris      68:        if (cvs_nolog == 1)
                     69:                return;
1.19      xsa        70:
1.28      joris      71:        if (cvs_cmdop == CVS_OP_CHECKOUT || cvs_cmdop == CVS_OP_EXPORT) {
                     72:                if (type != CVS_HISTORY_CHECKOUT &&
                     73:                    type != CVS_HISTORY_EXPORT)
                     74:                        return;
1.1       jfb        75:        }
                     76:
1.28      joris      77:        cvs_log(LP_TRACE, "cvs_history_add(`%c', `%s', `%s')",
                     78:            historytab[type], (cf != NULL) ? cf->file_name : "", argument);
1.1       jfb        79:
1.30      joris      80:        if (cvs_server_active == 1) {
                     81:                cwd = "<remote>";
                     82:        } else {
                     83:                if ((cwd = getcwd(NULL, MAXPATHLEN)) == NULL)
                     84:                        fatal("cvs_history_add: getcwd: %s", strerror(errno));
                     85:        }
1.1       jfb        86:
1.28      joris      87:        /* construct repository field */
                     88:        if (cvs_cmdop != CVS_OP_CHECKOUT && cvs_cmdop != CVS_OP_EXPORT) {
                     89:                cvs_get_repository_name(".", repo, sizeof(repo));
                     90:        } else {
                     91:                strlcpy(repo, argument, sizeof(repo));
                     92:        }
1.24      joris      93:
1.28      joris      94:        /* construct revision field */
                     95:        revbuf[0] = '\0';
                     96:        if (cvs_cmdop != CVS_OP_CHECKOUT && cvs_cmdop != CVS_OP_EXPORT) {
                     97:                switch (type) {
                     98:                case CVS_HISTORY_TAG:
                     99:                        strlcpy(revbuf, argument, sizeof(revbuf));
                    100:                        break;
                    101:                case CVS_HISTORY_CHECKOUT:
                    102:                case CVS_HISTORY_EXPORT:
                    103:                        /* copy TAG or DATE to revbuf */
                    104:                        break;
                    105:                case CVS_HISTORY_UPDATE_MERGED:
                    106:                case CVS_HISTORY_UPDATE_MERGED_ERR:
                    107:                case CVS_HISTORY_COMMIT_MODIFIED:
                    108:                case CVS_HISTORY_COMMIT_ADDED:
                    109:                case CVS_HISTORY_COMMIT_REMOVED:
                    110:                case CVS_HISTORY_UPDATE_CO:
                    111:                        rcsnum_tostr(cf->file_rcs->rf_head,
                    112:                            revbuf, sizeof(revbuf));
                    113:                        break;
1.15      xsa       114:                }
1.28      joris     115:        }
1.20      joris     116:
1.28      joris     117:        (void)xsnprintf(fpath, sizeof(fpath), "%s/%s",
                    118:            current_cvsroot->cr_dir, CVS_PATH_HISTORY);
1.20      joris     119:
1.28      joris     120:        if ((fp = fopen(fpath, "a")) != NULL) {
                    121:                fprintf(fp, "%c%x|%s|%s|%s|%s|%s\n",
                    122:                    historytab[type], time(NULL), getlogin(), cwd, repo,
                    123:                    revbuf, (cf != NULL) ? cf->file_name : argument);
                    124:
                    125:                (void)fclose(fp);
                    126:        } else {
                    127:                cvs_log(LP_ERR, "failed to add entry to history file");
1.15      xsa       128:        }
1.1       jfb       129:
1.30      joris     130:        if (cvs_server_active != 1)
                    131:                xfree(cwd);
1.1       jfb       132: }
                    133:
1.28      joris     134: int
                    135: cvs_history(int argc, char **argv)
                    136: {
                    137:        int ch, flags;
1.1       jfb       138:
1.28      joris     139:        flags = 0;
1.1       jfb       140:
1.28      joris     141:        while ((ch = getopt(argc, argv, cvs_cmd_history.cmd_opts)) != -1) {
                    142:                switch (ch) {
                    143:                case 'a':
                    144:                        flags |= HISTORY_ALL_USERS;
                    145:                        break;
                    146:                case 'c':
                    147:                        flags |= HISTORY_DISPLAY_ARCHIVED;
                    148:                        break;
                    149:                default:
                    150:                        fatal("%s", cvs_cmd_history.cmd_synopsis);
                    151:                }
1.1       jfb       152:        }
                    153:
1.28      joris     154:        argc -= optind;
                    155:        argv += optind;
                    156:
                    157:        return (0);
1.1       jfb       158: }