| | @@ -37,15 +37,10 @@ |
| 37 | 37 | ** a quick status and does not check for up-to-date-ness of the file. |
| 38 | 38 | ** |
| 39 | 39 | ** The -p form, there's an optional flag "-r|--revision REVISION". The |
| 40 | 40 | ** specified version (or the latest checked out version) is printed to |
| 41 | 41 | ** stdout. |
| 42 | | -** |
| 43 | | -** Print the change history for a single file. |
| 44 | | -** |
| 45 | | -** The "--limit N" and "--offset P" options limit the output to the first |
| 46 | | -** N changes after skipping P changes. |
| 47 | 42 | */ |
| 48 | 43 | void finfo_cmd(void){ |
| 49 | 44 | int vid; |
| 50 | 45 | |
| 51 | 46 | db_must_be_within_tree(); |
| | @@ -53,138 +48,140 @@ |
| 53 | 48 | if( vid==0 ){ |
| 54 | 49 | fossil_panic("no checkout to finfo files in"); |
| 55 | 50 | } |
| 56 | 51 | vfile_check_signature(vid, 1); |
| 57 | 52 | if (find_option("status","s",0)) { |
| 58 | | - Stmt q; |
| 59 | | - Blob line; |
| 60 | | - Blob fname; |
| 61 | | - |
| 62 | | - if (g.argc != 3) { |
| 63 | | - usage("-s|--status FILENAME"); |
| 64 | | - } |
| 65 | | - file_tree_name(g.argv[2], &fname, 1); |
| 66 | | - db_prepare(&q, |
| 67 | | - "SELECT pathname, deleted, rid, chnged, coalesce(origname!=pathname,0)" |
| 68 | | - " FROM vfile WHERE vfile.pathname=%B", &fname); |
| 69 | | - blob_zero(&line); |
| 70 | | - if ( db_step(&q)==SQLITE_ROW ) { |
| 71 | | - Blob uuid; |
| 72 | | - int isDeleted = db_column_int(&q, 1); |
| 73 | | - int isNew = db_column_int(&q,2) == 0; |
| 74 | | - int chnged = db_column_int(&q,3); |
| 75 | | - int renamed = db_column_int(&q,4); |
| 76 | | - |
| 77 | | - blob_zero(&uuid); |
| 78 | | - db_blob(&uuid,"SELECT uuid FROM blob, mlink, vfile WHERE " |
| 79 | | - "blob.rid = mlink.mid AND mlink.fid = vfile.rid AND " |
| 80 | | - "vfile.pathname=%B",&fname); |
| 81 | | - if (isNew) { |
| 82 | | - blob_appendf(&line, "new"); |
| 83 | | - } else if (isDeleted) { |
| 84 | | - blob_appendf(&line, "deleted"); |
| 85 | | - } else if (renamed) { |
| 86 | | - blob_appendf(&line, "renamed"); |
| 87 | | - } else if (chnged) { |
| 88 | | - blob_appendf(&line, "edited"); |
| 89 | | - } else { |
| 90 | | - blob_appendf(&line, "unchanged"); |
| 91 | | - } |
| 92 | | - blob_appendf(&line, " "); |
| 93 | | - blob_appendf(&line, " %10.10s", blob_str(&uuid)); |
| 94 | | - blob_reset(&uuid); |
| 95 | | - } else { |
| 96 | | - blob_appendf(&line, "unknown 0000000000"); |
| 97 | | - } |
| 98 | | - db_finalize(&q); |
| 99 | | - printf("%s\n", blob_str(&line)); |
| 100 | | - blob_reset(&fname); |
| 101 | | - blob_reset(&line); |
| 102 | | - } else if (find_option("print","p",0)) { |
| 103 | | - Blob record; |
| 104 | | - Blob fname; |
| 105 | | - const char *zRevision = find_option("revision", "r", 1); |
| 106 | | - |
| 107 | | - file_tree_name(g.argv[2], &fname, 1); |
| 108 | | - if (zRevision) { |
| 109 | | - historical_version_of_file(zRevision, blob_str(&fname), &record, 0); |
| 110 | | - } else { |
| 111 | | - int rid = db_int(0, "SELECT rid FROM vfile WHERE pathname=%B", &fname); |
| 112 | | - if( rid==0 ){ |
| 113 | | - fossil_fatal("no history for file: %b", &fname); |
| 114 | | - } |
| 115 | | - content_get(rid, &record); |
| 116 | | - } |
| 117 | | - blob_write_to_file(&record, "-"); |
| 118 | | - blob_reset(&record); |
| 119 | | - blob_reset(&fname); |
| 120 | | - } else { |
| 121 | | - Blob line; |
| 122 | | - Stmt q; |
| 123 | | - Blob fname; |
| 124 | | - int rid; |
| 125 | | - const char *zFilename; |
| 126 | | - const char *zLimit; |
| 127 | | - const char *zOffset; |
| 128 | | - int iLimit, iOffset, iBrief; |
| 129 | | - |
| 130 | | - if (find_option("log","l",0)) { /* this is the default, no-op */ |
| 131 | | - } |
| 132 | | - zLimit = find_option("limit",0,1); |
| 133 | | - iLimit = zLimit ? atoi(zLimit) : -1; |
| 134 | | - zOffset = find_option("offset",0,1); |
| 135 | | - iOffset = zOffset ? atoi(zOffset) : 0; |
| 136 | | - iBrief = (find_option("brief","b",0) == 0); |
| 137 | | - if (g.argc != 3) { |
| 138 | | - usage("?-l|--log? ?-b|--brief? FILENAME"); |
| 139 | | - } |
| 140 | | - file_tree_name(g.argv[2], &fname, 1); |
| 141 | | - rid = db_int(0, "SELECT rid FROM vfile WHERE pathname=%B", &fname); |
| 142 | | - if( rid==0 ){ |
| 143 | | - fossil_fatal("no history for file: %b", &fname); |
| 144 | | - } |
| 145 | | - zFilename = blob_str(&fname); |
| 146 | | - db_prepare(&q, |
| 147 | | - "SELECT b.uuid, ci.uuid, date(event.mtime,'localtime')," |
| 148 | | - " coalesce(event.ecomment, event.comment)," |
| 149 | | - " coalesce(event.euser, event.user)" |
| 150 | | - " FROM mlink, blob b, event, blob ci" |
| 151 | | - " WHERE mlink.fnid=(SELECT fnid FROM filename WHERE name=%Q)" |
| 152 | | - " AND b.rid=mlink.fid" |
| 153 | | - " AND event.objid=mlink.mid" |
| 154 | | - " AND event.objid=ci.rid" |
| 155 | | - " ORDER BY event.mtime DESC LIMIT %d OFFSET %d", |
| 156 | | - zFilename, iLimit, iOffset |
| 157 | | - ); |
| 158 | | - blob_zero(&line); |
| 159 | | - if (iBrief) { |
| 160 | | - printf("History of %s\n", blob_str(&fname)); |
| 161 | | - } |
| 162 | | - while( db_step(&q)==SQLITE_ROW ){ |
| 163 | | - const char *zFileUuid = db_column_text(&q, 0); |
| 164 | | - const char *zCiUuid = db_column_text(&q,1); |
| 165 | | - const char *zDate = db_column_text(&q, 2); |
| 166 | | - const char *zCom = db_column_text(&q, 3); |
| 167 | | - const char *zUser = db_column_text(&q, 4); |
| 168 | | - char *zOut; |
| 169 | | - if (iBrief) { |
| 170 | | - printf("%s ", zDate); |
| 171 | | - zOut = sqlite3_mprintf("[%.10s] %s (user: %s, artifact: [%.10s])", |
| 172 | | - zCiUuid, zCom, zUser, zFileUuid); |
| 173 | | - comment_print(zOut, 11, 79); |
| 174 | | - sqlite3_free(zOut); |
| 175 | | - } else { |
| 176 | | - blob_reset(&line); |
| 177 | | - blob_appendf(&line, "%.10s ", zCiUuid); |
| 178 | | - blob_appendf(&line, "%.10s ", zDate); |
| 179 | | - blob_appendf(&line, "%8.8s ", zUser); |
| 180 | | - blob_appendf(&line,"%-40.40s\n", zCom ); |
| 181 | | - comment_print(blob_str(&line), 0, 79); |
| 182 | | - } |
| 183 | | - } |
| 184 | | - db_finalize(&q); |
| 185 | | - blob_reset(&fname); |
| 53 | + Stmt q; |
| 54 | + Blob line; |
| 55 | + Blob fname; |
| 56 | + |
| 57 | + if( g.argc!=3 ) usage("-s|--status FILENAME"); |
| 58 | + file_tree_name(g.argv[2], &fname, 1); |
| 59 | + db_prepare(&q, |
| 60 | + "SELECT pathname, deleted, rid, chnged, coalesce(origname!=pathname,0)" |
| 61 | + " FROM vfile WHERE vfile.pathname=%B", &fname); |
| 62 | + blob_zero(&line); |
| 63 | + if ( db_step(&q)==SQLITE_ROW ) { |
| 64 | + Blob uuid; |
| 65 | + int isDeleted = db_column_int(&q, 1); |
| 66 | + int isNew = db_column_int(&q,2) == 0; |
| 67 | + int chnged = db_column_int(&q,3); |
| 68 | + int renamed = db_column_int(&q,4); |
| 69 | + |
| 70 | + blob_zero(&uuid); |
| 71 | + db_blob(&uuid, |
| 72 | + "SELECT uuid FROM blob, mlink, vfile WHERE " |
| 73 | + "blob.rid = mlink.mid AND mlink.fid = vfile.rid AND " |
| 74 | + "vfile.pathname=%B", |
| 75 | + &fname |
| 76 | + ); |
| 77 | + if( isNew ){ |
| 78 | + blob_appendf(&line, "new"); |
| 79 | + }else if( isDeleted ){ |
| 80 | + blob_appendf(&line, "deleted"); |
| 81 | + }else if( renamed ){ |
| 82 | + blob_appendf(&line, "renamed"); |
| 83 | + }else if( chnged ){ |
| 84 | + blob_appendf(&line, "edited"); |
| 85 | + }else{ |
| 86 | + blob_appendf(&line, "unchanged"); |
| 87 | + } |
| 88 | + blob_appendf(&line, " "); |
| 89 | + blob_appendf(&line, " %10.10s", blob_str(&uuid)); |
| 90 | + blob_reset(&uuid); |
| 91 | + }else{ |
| 92 | + blob_appendf(&line, "unknown 0000000000"); |
| 93 | + } |
| 94 | + db_finalize(&q); |
| 95 | + printf("%s\n", blob_str(&line)); |
| 96 | + blob_reset(&fname); |
| 97 | + blob_reset(&line); |
| 98 | + }else if( find_option("print","p",0) ){ |
| 99 | + Blob record; |
| 100 | + Blob fname; |
| 101 | + const char *zRevision = find_option("revision", "r", 1); |
| 102 | + |
| 103 | + file_tree_name(g.argv[2], &fname, 1); |
| 104 | + if( zRevision ){ |
| 105 | + historical_version_of_file(zRevision, blob_str(&fname), &record, 0); |
| 106 | + }else{ |
| 107 | + int rid = db_int(0, "SELECT rid FROM vfile WHERE pathname=%B", &fname); |
| 108 | + if( rid==0 ){ |
| 109 | + fossil_fatal("no history for file: %b", &fname); |
| 110 | + } |
| 111 | + content_get(rid, &record); |
| 112 | + } |
| 113 | + blob_write_to_file(&record, "-"); |
| 114 | + blob_reset(&record); |
| 115 | + blob_reset(&fname); |
| 116 | + }else{ |
| 117 | + Blob line; |
| 118 | + Stmt q; |
| 119 | + Blob fname; |
| 120 | + int rid; |
| 121 | + const char *zFilename; |
| 122 | + const char *zLimit; |
| 123 | + const char *zOffset; |
| 124 | + int iLimit, iOffset, iBrief; |
| 125 | + |
| 126 | + if( find_option("log","l",0) ){ |
| 127 | + /* this is the default, no-op */ |
| 128 | + } |
| 129 | + zLimit = find_option("limit",0,1); |
| 130 | + iLimit = zLimit ? atoi(zLimit) : -1; |
| 131 | + zOffset = find_option("offset",0,1); |
| 132 | + iOffset = zOffset ? atoi(zOffset) : 0; |
| 133 | + iBrief = (find_option("brief","b",0) == 0); |
| 134 | + if( g.argc!=3 ){ |
| 135 | + usage("?-l|--log? ?-b|--brief? FILENAME"); |
| 136 | + } |
| 137 | + file_tree_name(g.argv[2], &fname, 1); |
| 138 | + rid = db_int(0, "SELECT rid FROM vfile WHERE pathname=%B", &fname); |
| 139 | + if( rid==0 ){ |
| 140 | + fossil_fatal("no history for file: %b", &fname); |
| 141 | + } |
| 142 | + zFilename = blob_str(&fname); |
| 143 | + db_prepare(&q, |
| 144 | + "SELECT b.uuid, ci.uuid, date(event.mtime,'localtime')," |
| 145 | + " coalesce(event.ecomment, event.comment)," |
| 146 | + " coalesce(event.euser, event.user)" |
| 147 | + " FROM mlink, blob b, event, blob ci" |
| 148 | + " WHERE mlink.fnid=(SELECT fnid FROM filename WHERE name=%Q)" |
| 149 | + " AND b.rid=mlink.fid" |
| 150 | + " AND event.objid=mlink.mid" |
| 151 | + " AND event.objid=ci.rid" |
| 152 | + " ORDER BY event.mtime DESC LIMIT %d OFFSET %d", |
| 153 | + zFilename, iLimit, iOffset |
| 154 | + ); |
| 155 | + blob_zero(&line); |
| 156 | + if( iBrief ){ |
| 157 | + printf("History of %s\n", blob_str(&fname)); |
| 158 | + } |
| 159 | + while( db_step(&q)==SQLITE_ROW ){ |
| 160 | + const char *zFileUuid = db_column_text(&q, 0); |
| 161 | + const char *zCiUuid = db_column_text(&q,1); |
| 162 | + const char *zDate = db_column_text(&q, 2); |
| 163 | + const char *zCom = db_column_text(&q, 3); |
| 164 | + const char *zUser = db_column_text(&q, 4); |
| 165 | + char *zOut; |
| 166 | + if( iBrief ){ |
| 167 | + printf("%s ", zDate); |
| 168 | + zOut = sqlite3_mprintf("[%.10s] %s (user: %s, artifact: [%.10s])", |
| 169 | + zCiUuid, zCom, zUser, zFileUuid); |
| 170 | + comment_print(zOut, 11, 79); |
| 171 | + sqlite3_free(zOut); |
| 172 | + }else{ |
| 173 | + blob_reset(&line); |
| 174 | + blob_appendf(&line, "%.10s ", zCiUuid); |
| 175 | + blob_appendf(&line, "%.10s ", zDate); |
| 176 | + blob_appendf(&line, "%8.8s ", zUser); |
| 177 | + blob_appendf(&line,"%-40.40s\n", zCom ); |
| 178 | + comment_print(blob_str(&line), 0, 79); |
| 179 | + } |
| 180 | + } |
| 181 | + db_finalize(&q); |
| 182 | + blob_reset(&fname); |
| 186 | 183 | } |
| 187 | 184 | } |
| 188 | 185 | |
| 189 | 186 | |
| 190 | 187 | /* |
| 191 | 188 | |