Fossil SCM

fossil-scm / src / checkin.c
Source Blame History 3366 lines
dbda8d6… drh 1 /*
c19f34c… drh 2 ** Copyright (c) 2007 D. Richard Hipp
dbda8d6… drh 3 **
dbda8d6… drh 4 ** This program is free software; you can redistribute it and/or
c06edd2… drh 5 ** modify it under the terms of the Simplified BSD License (also
c06edd2… drh 6 ** known as the "2-Clause License" or "FreeBSD License".)
c985d90… drh 7 **
dbda8d6… drh 8 ** This program is distributed in the hope that it will be useful,
c06edd2… drh 9 ** but without any warranty; without even the implied warranty of
c06edd2… drh 10 ** merchantability or fitness for a particular purpose.
dbda8d6… drh 11 **
dbda8d6… drh 12 ** Author contact information:
dbda8d6… drh 13 ** [email protected]
dbda8d6… drh 14 ** http://www.hwaci.com/drh/
dbda8d6… drh 15 **
dbda8d6… drh 16 *******************************************************************************
dbda8d6… drh 17 **
b7a9353… aku 18 ** This file contains code used to check-in versions of the project
dbda8d6… drh 19 ** from the local repository.
dbda8d6… drh 20 */
dbda8d6… drh 21 #include "config.h"
dbda8d6… drh 22 #include "checkin.h"
dbda8d6… drh 23 #include <assert.h>
dbda8d6… drh 24
dbda8d6… drh 25 /*
e776494… andygoth 26 ** Change filter options.
e776494… andygoth 27 */
e776494… andygoth 28 enum {
e776494… andygoth 29 /* Zero-based bit indexes. */
e776494… andygoth 30 CB_EDITED , CB_UPDATED , CB_CHANGED, CB_MISSING , CB_ADDED, CB_DELETED,
e776494… andygoth 31 CB_RENAMED, CB_CONFLICT, CB_META , CB_UNCHANGED, CB_EXTRA, CB_MERGE ,
e776494… andygoth 32 CB_RELPATH, CB_CLASSIFY, CB_MTIME , CB_SIZE , CB_FATAL, CB_COMMENT,
e776494… andygoth 33
e776494… andygoth 34 /* Bitmask values. */
e776494… andygoth 35 C_EDITED = 1 << CB_EDITED, /* Edited, merged, and conflicted files. */
e776494… andygoth 36 C_UPDATED = 1 << CB_UPDATED, /* Files updated by merge/integrate. */
e776494… andygoth 37 C_CHANGED = 1 << CB_CHANGED, /* Treated the same as the above two. */
e776494… andygoth 38 C_MISSING = 1 << CB_MISSING, /* Missing and non- files. */
e776494… andygoth 39 C_ADDED = 1 << CB_ADDED, /* Added files. */
e776494… andygoth 40 C_DELETED = 1 << CB_DELETED, /* Deleted files. */
e776494… andygoth 41 C_RENAMED = 1 << CB_RENAMED, /* Renamed files. */
e776494… andygoth 42 C_CONFLICT = 1 << CB_CONFLICT, /* Files having merge conflicts. */
e776494… andygoth 43 C_META = 1 << CB_META, /* Files with metadata changes. */
e776494… andygoth 44 C_UNCHANGED = 1 << CB_UNCHANGED, /* Unchanged files. */
e776494… andygoth 45 C_EXTRA = 1 << CB_EXTRA, /* Unmanaged files. */
e776494… andygoth 46 C_MERGE = 1 << CB_MERGE, /* Merge contributors. */
e776494… andygoth 47 C_FILTER = C_EDITED | C_UPDATED | C_CHANGED | C_MISSING | C_ADDED
e776494… andygoth 48 | C_DELETED | C_RENAMED | C_CONFLICT | C_META | C_UNCHANGED
e776494… andygoth 49 | C_EXTRA | C_MERGE, /* All filter bits. */
e776494… andygoth 50 C_ALL = C_FILTER & ~(C_EXTRA | C_MERGE),/* All managed files. */
e776494… andygoth 51 C_DIFFER = C_FILTER & ~(C_UNCHANGED | C_MERGE),/* All differences. */
e776494… andygoth 52 C_RELPATH = 1 << CB_RELPATH, /* Show relative paths. */
e776494… andygoth 53 C_CLASSIFY = 1 << CB_CLASSIFY, /* Show file change types. */
e776494… andygoth 54 C_DEFAULT = (C_ALL & ~C_UNCHANGED) | C_MERGE | C_CLASSIFY,
e776494… andygoth 55 C_MTIME = 1 << CB_MTIME, /* Show file modification time. */
e776494… andygoth 56 C_SIZE = 1 << CB_SIZE, /* Show file size in bytes. */
e9a43ae… andygoth 57 C_FATAL = 1 << CB_FATAL, /* Fail on MISSING/NOT_A_FILE. */
e776494… andygoth 58 C_COMMENT = 1 << CB_COMMENT, /* Precede each line with "# ". */
e776494… andygoth 59 };
e776494… andygoth 60
e776494… andygoth 61 /*
e776494… andygoth 62 ** Create a TEMP table named SFILE and add all unmanaged files named on
e776494… andygoth 63 ** the command-line to that table. If directories are named, then add
e776494… andygoth 64 ** all unmanaged files contained underneath those directories. If there
e776494… andygoth 65 ** are no files or directories named on the command-line, then add all
bc36fdc… danield 66 ** unmanaged files anywhere in the check-out.
f741baa… drh 67 **
f741baa… drh 68 ** This routine never follows symlinks. It always treats symlinks as
f741baa… drh 69 ** object unto themselves.
e776494… andygoth 70 */
e776494… andygoth 71 static void locate_unmanaged_files(
e776494… andygoth 72 int argc, /* Number of command-line arguments to examine */
e776494… andygoth 73 char **argv, /* values of command-line arguments */
e776494… andygoth 74 unsigned scanFlags, /* Zero or more SCAN_xxx flags */
e776494… andygoth 75 Glob *pIgnore /* Do not add files that match this GLOB */
e776494… andygoth 76 ){
e776494… andygoth 77 Blob name; /* Name of a candidate file or directory */
e776494… andygoth 78 char *zName; /* Name of a candidate file or directory */
e776494… andygoth 79 int isDir; /* 1 for a directory, 0 if doesn't exist, 2 for anything else */
e776494… andygoth 80 int i; /* Loop counter */
e776494… andygoth 81 int nRoot; /* length of g.zLocalRoot */
e776494… andygoth 82
e776494… andygoth 83 db_multi_exec("CREATE TEMP TABLE sfile(pathname TEXT PRIMARY KEY %s,"
e776494… andygoth 84 " mtime INTEGER, size INTEGER)", filename_collation());
e776494… andygoth 85 nRoot = (int)strlen(g.zLocalRoot);
e776494… andygoth 86 if( argc==0 ){
e776494… andygoth 87 blob_init(&name, g.zLocalRoot, nRoot - 1);
f741baa… drh 88 vfile_scan(&name, blob_size(&name), scanFlags, pIgnore, 0, SymFILE);
e776494… andygoth 89 blob_reset(&name);
e776494… andygoth 90 }else{
e776494… andygoth 91 for(i=0; i<argc; i++){
e776494… andygoth 92 file_canonical_name(argv[i], &name, 0);
e776494… andygoth 93 zName = blob_str(&name);
f741baa… drh 94 isDir = file_isdir(zName, SymFILE);
e776494… andygoth 95 if( isDir==1 ){
f741baa… drh 96 vfile_scan(&name, nRoot-1, scanFlags, pIgnore, 0, SymFILE);
e776494… andygoth 97 }else if( isDir==0 ){
e776494… andygoth 98 fossil_warning("not found: %s", &zName[nRoot]);
e776494… andygoth 99 }else if( file_access(zName, R_OK) ){
e776494… andygoth 100 fossil_fatal("cannot open %s", &zName[nRoot]);
e776494… andygoth 101 }else{
39eb451… mark 102 /* Only add unmanaged file paths specified on the command line. */
e776494… andygoth 103 db_multi_exec(
39eb451… mark 104 "INSERT OR IGNORE INTO sfile(pathname)"
39eb451… mark 105 " SELECT %Q WHERE NOT EXISTS"
39eb451… mark 106 " (SELECT 1 FROM vfile WHERE pathname=%Q)",
39eb451… mark 107 &zName[nRoot], &zName[nRoot]
e776494… andygoth 108 );
e776494… andygoth 109 }
e776494… andygoth 110 blob_reset(&name);
e776494… andygoth 111 }
e776494… andygoth 112 }
e776494… andygoth 113 }
e776494… andygoth 114
e776494… andygoth 115 /*
e776494… andygoth 116 ** Generate text describing all changes.
dbda8d6… drh 117 **
dbda8d6… drh 118 ** We assume that vfile_check_signature has been run.
dbda8d6… drh 119 */
76f169f… drh 120 static void status_report(
76f169f… drh 121 Blob *report, /* Append the status report here */
e776494… andygoth 122 unsigned flags /* Filter and other configuration flags */
76f169f… drh 123 ){
dbda8d6… drh 124 Stmt q;
76f169f… drh 125 int nErr = 0;
ca9d0dd… mark 126 Blob rewrittenOrigName, rewrittenPathname;
e776494… andygoth 127 Blob sql = BLOB_INITIALIZER, where = BLOB_INITIALIZER;
ae01244… jan.nijtmans 128 const char *zName;
ae01244… jan.nijtmans 129 int i;
ae01244… jan.nijtmans 130
e776494… andygoth 131 /* Skip the file report if no files are requested at all. */
e776494… andygoth 132 if( !(flags & (C_ALL | C_EXTRA)) ){
e776494… andygoth 133 goto skipFiles;
e776494… andygoth 134 }
e776494… andygoth 135
e776494… andygoth 136 /* Assemble the path-limiting WHERE clause, if any. */
ae01244… jan.nijtmans 137 blob_zero(&where);
7d257de… mistachkin 138 for(i=2; i<g.argc; i++){
eb4d631… jan.nijtmans 139 Blob fname;
c56a387… mistachkin 140 file_tree_name(g.argv[i], &fname, 0, 1);
ae01244… jan.nijtmans 141 zName = blob_str(&fname);
7d257de… mistachkin 142 if( fossil_strcmp(zName, ".")==0 ){
ae01244… jan.nijtmans 143 blob_reset(&where);
ae01244… jan.nijtmans 144 break;
ae01244… jan.nijtmans 145 }
49b0ff1… drh 146 blob_append_sql(&where,
49b0ff1… drh 147 " %s (pathname=%Q %s) "
49b0ff1… drh 148 "OR (pathname>'%q/' %s AND pathname<'%q0' %s)",
49b0ff1… drh 149 (blob_size(&where)>0) ? "OR" : "AND", zName,
49b0ff1… drh 150 filename_collation(), zName, filename_collation(),
49b0ff1… drh 151 zName, filename_collation()
49b0ff1… drh 152 );
ae01244… jan.nijtmans 153 }
ae01244… jan.nijtmans 154
e776494… andygoth 155 /* Obtain the list of managed files if appropriate. */
e776494… andygoth 156 blob_zero(&sql);
e776494… andygoth 157 if( flags & C_ALL ){
e776494… andygoth 158 /* Start with a list of all managed files. */
e776494… andygoth 159 blob_append_sql(&sql,
e776494… andygoth 160 "SELECT pathname, %s as mtime, %s as size, deleted, chnged, rid,"
1b8cfdb… mark 161 " coalesce(origname!=pathname,0) AS renamed, 1 AS managed,"
1b8cfdb… mark 162 " origname"
e776494… andygoth 163 " FROM vfile LEFT JOIN blob USING (rid)"
e776494… andygoth 164 " WHERE is_selected(id)%s",
e776494… andygoth 165 flags & C_MTIME ? "datetime(checkin_mtime(:vid, rid), "
e776494… andygoth 166 "'unixepoch', toLocal())" : "''" /*safe-for-%s*/,
e776494… andygoth 167 flags & C_SIZE ? "coalesce(blob.size, 0)" : "0" /*safe-for-%s*/,
e776494… andygoth 168 blob_sql_text(&where));
e776494… andygoth 169
e776494… andygoth 170 /* Exclude unchanged files unless requested. */
e776494… andygoth 171 if( !(flags & C_UNCHANGED) ){
e776494… andygoth 172 blob_append_sql(&sql,
e776494… andygoth 173 " AND (chnged OR deleted OR rid=0 OR pathname!=origname)");
e776494… andygoth 174 }
e776494… andygoth 175 }
e776494… andygoth 176
e776494… andygoth 177 /* If C_EXTRA, add unmanaged files to the query result too. */
e776494… andygoth 178 if( flags & C_EXTRA ){
e776494… andygoth 179 if( blob_size(&sql) ){
e776494… andygoth 180 blob_append_sql(&sql, " UNION ALL");
e776494… andygoth 181 }
e776494… andygoth 182 blob_append_sql(&sql,
1b8cfdb… mark 183 " SELECT pathname, %s, %s, 0, 0, 0, 0, 0, NULL"
e776494… andygoth 184 " FROM sfile WHERE pathname NOT IN (%s)%s",
e776494… andygoth 185 flags & C_MTIME ? "datetime(mtime, 'unixepoch', toLocal())" : "''",
e776494… andygoth 186 flags & C_SIZE ? "size" : "0",
e776494… andygoth 187 fossil_all_reserved_names(0), blob_sql_text(&where));
e776494… andygoth 188 }
e776494… andygoth 189 blob_reset(&where);
e776494… andygoth 190
e776494… andygoth 191 /* Pre-create the "ok" temporary table so the checkin_mtime() SQL function
e776494… andygoth 192 * does not lead to SQLITE_ABORT_ROLLBACK during execution of the OP_OpenRead
e776494… andygoth 193 * SQLite opcode. checkin_mtime() calls mtime_of_manifest_file() which
e776494… andygoth 194 * creates a temporary table if it doesn't already exist, thus invalidating
e776494… andygoth 195 * the prepared statement in the middle of its execution. */
e776494… andygoth 196 db_multi_exec("CREATE TEMP TABLE IF NOT EXISTS ok(rid INTEGER PRIMARY KEY)");
e776494… andygoth 197
e776494… andygoth 198 /* Append an ORDER BY clause then compile the query. */
e776494… andygoth 199 blob_append_sql(&sql, " ORDER BY pathname");
e776494… andygoth 200 db_prepare(&q, "%s", blob_sql_text(&sql));
e776494… andygoth 201 blob_reset(&sql);
e776494… andygoth 202
bc36fdc… danield 203 /* Bind the check-out version ID to the query if needed. */
e776494… andygoth 204 if( (flags & C_ALL) && (flags & C_MTIME) ){
e776494… andygoth 205 db_bind_int(&q, ":vid", db_lget_int("checkout", 0));
e776494… andygoth 206 }
e776494… andygoth 207
e776494… andygoth 208 /* Execute the query and assemble the report. */
9a0c995… drh 209 blob_zero(&rewrittenPathname);
ca9d0dd… mark 210 blob_zero(&rewrittenOrigName);
d0305b3… aku 211 while( db_step(&q)==SQLITE_ROW ){
e776494… andygoth 212 const char *zPathname = db_column_text(&q, 0);
e776494… andygoth 213 const char *zClass = 0;
43140fe… andygoth 214 int isManaged = db_column_int(&q, 7);
e776494… andygoth 215 const char *zMtime = db_column_text(&q, 1);
e776494… andygoth 216 int size = db_column_int(&q, 2);
e776494… andygoth 217 int isDeleted = db_column_int(&q, 3);
e776494… andygoth 218 int isChnged = db_column_int(&q, 4);
e776494… andygoth 219 int isNew = isManaged && !db_column_int(&q, 5);
e776494… andygoth 220 int isRenamed = db_column_int(&q, 6);
1b8cfdb… mark 221 const char *zOrigName = 0;
12a2a5e… drh 222 char *zFullName = mprintf("%s%s", g.zLocalRoot, zPathname);
1772357… drh 223 int isMissing = !file_isfile_or_link(zFullName);
e776494… andygoth 224
e776494… andygoth 225 /* Determine the file change classification, if any. */
e9a43ae… andygoth 226 if( isDeleted ){
e9a43ae… andygoth 227 if( flags & C_DELETED ){
e9a43ae… andygoth 228 zClass = "DELETED";
e9a43ae… andygoth 229 }
e9a43ae… andygoth 230 }else if( isMissing ){
9df71fe… jan.nijtmans 231 if( file_access(zFullName, F_OK)==0 ){
e9a43ae… andygoth 232 if( flags & C_MISSING ){
e9a43ae… andygoth 233 zClass = "NOT_A_FILE";
e9a43ae… andygoth 234 }
e776494… andygoth 235 if( flags & C_FATAL ){
e776494… andygoth 236 fossil_warning("not a file: %s", zFullName);
76f169f… drh 237 nErr++;
76f169f… drh 238 }
76f169f… drh 239 }else{
e9a43ae… andygoth 240 if( flags & C_MISSING ){
e9a43ae… andygoth 241 zClass = "MISSING";
e9a43ae… andygoth 242 }
e776494… andygoth 243 if( flags & C_FATAL ){
e776494… andygoth 244 fossil_warning("missing file: %s", zFullName);
76f169f… drh 245 nErr++;
76f169f… drh 246 }
76f169f… drh 247 }
0dea016… andygoth 248 }else if( isNew ){
0dea016… andygoth 249 if( flags & C_ADDED ){
0dea016… andygoth 250 zClass = "ADDED";
0dea016… andygoth 251 }
e776494… andygoth 252 }else if( (flags & (C_UPDATED | C_CHANGED)) && isChnged==2 ){
e776494… andygoth 253 zClass = "UPDATED_BY_MERGE";
e776494… andygoth 254 }else if( (flags & C_ADDED) && isChnged==3 ){
e776494… andygoth 255 zClass = "ADDED_BY_MERGE";
e776494… andygoth 256 }else if( (flags & (C_UPDATED | C_CHANGED)) && isChnged==4 ){
e776494… andygoth 257 zClass = "UPDATED_BY_INTEGRATE";
e776494… andygoth 258 }else if( (flags & C_ADDED) && isChnged==5 ){
e776494… andygoth 259 zClass = "ADDED_BY_INTEGRATE";
e776494… andygoth 260 }else if( (flags & C_META) && isChnged==6 ){
e776494… andygoth 261 zClass = "EXECUTABLE";
e776494… andygoth 262 }else if( (flags & C_META) && isChnged==7 ){
e776494… andygoth 263 zClass = "SYMLINK";
e776494… andygoth 264 }else if( (flags & C_META) && isChnged==8 ){
e776494… andygoth 265 zClass = "UNEXEC";
e776494… andygoth 266 }else if( (flags & C_META) && isChnged==9 ){
e776494… andygoth 267 zClass = "UNLINK";
1772357… drh 268 }else if( (flags & C_CONFLICT) && isChnged && !file_islink(zFullName)
e776494… andygoth 269 && file_contains_merge_marker(zFullName) ){
e776494… andygoth 270 zClass = "CONFLICT";
e776494… andygoth 271 }else if( (flags & (C_EDITED | C_CHANGED)) && isChnged
e776494… andygoth 272 && (isChnged<2 || isChnged>9) ){
e776494… andygoth 273 zClass = "EDITED";
e9a43ae… andygoth 274 }else if( (flags & C_UNCHANGED) && isManaged && !isNew
e9a43ae… andygoth 275 && !isChnged && !isRenamed ){
e776494… andygoth 276 zClass = "UNCHANGED";
e776494… andygoth 277 }else if( (flags & C_EXTRA) && !isManaged ){
e776494… andygoth 278 zClass = "EXTRA";
ca9d0dd… mark 279 }
ca9d0dd… mark 280 if( (flags & C_RENAMED) && isRenamed ){
ca9d0dd… mark 281 zOrigName = db_column_text(&q,8);
ca9d0dd… mark 282 if( zClass==0 ){
ca9d0dd… mark 283 zClass = "RENAMED";
ca9d0dd… mark 284 }
e776494… andygoth 285 }
e776494… andygoth 286
e776494… andygoth 287 /* Only report files for which a change classification was determined. */
e776494… andygoth 288 if( zClass ){
e776494… andygoth 289 if( flags & C_COMMENT ){
e776494… andygoth 290 blob_append(report, "# ", 2);
e776494… andygoth 291 }
e776494… andygoth 292 if( flags & C_CLASSIFY ){
e776494… andygoth 293 blob_appendf(report, "%-10s ", zClass);
e776494… andygoth 294 }
e776494… andygoth 295 if( flags & C_MTIME ){
e776494… andygoth 296 blob_append(report, zMtime, -1);
e776494… andygoth 297 blob_append(report, " ", 2);
e776494… andygoth 298 }
e776494… andygoth 299 if( flags & C_SIZE ){
e776494… andygoth 300 blob_appendf(report, "%7d ", size);
e776494… andygoth 301 }
e776494… andygoth 302 if( flags & C_RELPATH ){
e776494… andygoth 303 /* If C_RELPATH, display paths relative to current directory. */
e776494… andygoth 304 file_relative_name(zFullName, &rewrittenPathname, 0);
ca9d0dd… mark 305 zPathname = blob_str(&rewrittenPathname);
ca9d0dd… mark 306 if( zPathname[0]=='.' && zPathname[1]=='/' ){
ca9d0dd… mark 307 zPathname += 2; /* no unnecessary ./ prefix */
1b8cfdb… mark 308 }
1b8cfdb… mark 309 if( (flags & (C_FILTER ^ C_RENAMED)) && zOrigName ){
ca9d0dd… mark 310 char *zOrigFullName = mprintf("%s%s", g.zLocalRoot, zOrigName);
ca9d0dd… mark 311 file_relative_name(zOrigFullName, &rewrittenOrigName, 0);
ca9d0dd… mark 312 zOrigName = blob_str(&rewrittenOrigName);
ca9d0dd… mark 313 fossil_free(zOrigFullName);
ca9d0dd… mark 314 if( zOrigName[0]=='.' && zOrigName[1]=='/' ){
ca9d0dd… mark 315 zOrigName += 2; /* no unnecessary ./ prefix */
ca9d0dd… mark 316 }
ca9d0dd… mark 317 }
ca9d0dd… mark 318 }
ca9d0dd… mark 319 if( (flags & (C_FILTER ^ C_RENAMED)) && zOrigName ){
ca9d0dd… mark 320 blob_appendf(report, "%s -> ", zOrigName);
ca9d0dd… mark 321 }
ca9d0dd… mark 322 blob_appendf(report, "%s\n", zPathname);
d0305b3… aku 323 }
d0305b3… aku 324 free(zFullName);
d0305b3… aku 325 }
9a0c995… drh 326 blob_reset(&rewrittenPathname);
ca9d0dd… mark 327 blob_reset(&rewrittenOrigName);
e776494… andygoth 328 db_finalize(&q);
e776494… andygoth 329
e776494… andygoth 330 /* If C_MERGE, put merge contributors at the end of the report. */
e776494… andygoth 331 skipFiles:
e776494… andygoth 332 if( flags & C_MERGE ){
fff37e6… drh 333 db_prepare(&q, "SELECT mhash, id FROM vmerge WHERE id<=0" );
e776494… andygoth 334 while( db_step(&q)==SQLITE_ROW ){
e776494… andygoth 335 if( flags & C_COMMENT ){
e776494… andygoth 336 blob_append(report, "# ", 2);
e776494… andygoth 337 }
e776494… andygoth 338 if( flags & C_CLASSIFY ){
e776494… andygoth 339 const char *zClass;
e776494… andygoth 340 switch( db_column_int(&q, 1) ){
e776494… andygoth 341 case -1: zClass = "CHERRYPICK" ; break;
e776494… andygoth 342 case -2: zClass = "BACKOUT" ; break;
e776494… andygoth 343 case -4: zClass = "INTEGRATE" ; break;
e776494… andygoth 344 default: zClass = "MERGED_WITH"; break;
e776494… andygoth 345 }
e776494… andygoth 346 blob_appendf(report, "%-10s ", zClass);
e776494… andygoth 347 }
e776494… andygoth 348 blob_append(report, db_column_text(&q, 0), -1);
e776494… andygoth 349 blob_append(report, "\n", 1);
e776494… andygoth 350 }
e776494… andygoth 351 db_finalize(&q);
e776494… andygoth 352 }
76f169f… drh 353 if( nErr ){
76f169f… drh 354 fossil_fatal("aborting due to prior errors");
76f169f… drh 355 }
76f169f… drh 356 }
76f169f… drh 357
76f169f… drh 358 /*
9a0c995… drh 359 ** Use the "relative-paths" setting and the --abs-paths and
9a0c995… drh 360 ** --rel-paths command line options to determine whether the
9a0c995… drh 361 ** status report should be shown relative to the current
9a0c995… drh 362 ** working directory.
76f169f… drh 363 */
9a0c995… drh 364 static int determine_cwd_relative_option()
9a0c995… drh 365 {
9a0c995… drh 366 int relativePaths = db_get_boolean("relative-paths", 1);
9a0c995… drh 367 int absPathOption = find_option("abs-paths", 0, 0)!=0;
9a0c995… drh 368 int relPathOption = find_option("rel-paths", 0, 0)!=0;
9a0c995… drh 369 if( absPathOption ){ relativePaths = 0; }
9a0c995… drh 370 if( relPathOption ){ relativePaths = 1; }
9a0c995… drh 371 return relativePaths;
dbda8d6… drh 372 }
dbda8d6… drh 373
dbda8d6… drh 374 /*
9a0c995… drh 375 ** COMMAND: changes
dbda8d6… drh 376 ** COMMAND: status
6b85fd1… drh 377 **
e776494… andygoth 378 ** Usage: %fossil changes|status ?OPTIONS? ?PATHS ...?
e776494… andygoth 379 **
bc36fdc… danield 380 ** Report the change status of files in the current check-out. If one or
e776494… andygoth 381 ** more PATHS are specified, only changes among the named files and
e776494… andygoth 382 ** directories are reported. Directories are searched recursively.
e776494… andygoth 383 **
e776494… andygoth 384 ** The status command is similar to the changes command, except it lacks
e776494… andygoth 385 ** several of the options supported by changes and it has its own header
e776494… andygoth 386 ** and footer information. The header information is a subset of that
e776494… andygoth 387 ** shown by the info command, and the footer shows if there are any forks.
e776494… andygoth 388 ** Change type classification is always enabled for the status command.
e776494… andygoth 389 **
e776494… andygoth 390 ** Each line of output is the name of a changed file, with paths shown
e776494… andygoth 391 ** according to the "relative-paths" setting, unless overridden by the
e776494… andygoth 392 ** --abs-paths or --rel-paths options.
e776494… andygoth 393 **
e776494… andygoth 394 ** By default, all changed files are selected for display. This behavior
e776494… andygoth 395 ** can be overridden by using one or more filter options (listed below),
e776494… andygoth 396 ** in which case only files with the specified change type(s) are shown.
e776494… andygoth 397 ** As a special case, the --no-merge option does not inhibit this default.
bc36fdc… danield 398 ** This default shows exactly the set of changes that would be checked-
e776494… andygoth 399 ** in by the commit command.
e776494… andygoth 400 **
e776494… andygoth 401 ** If no filter options are used, or if the --merge option is used, the
fd9b7bd… drh 402 ** artifact hash of each merge contributor check-in version is displayed at
e776494… andygoth 403 ** the end of the report. The --no-merge option is useful to display the
e776494… andygoth 404 ** default set of changed files without the merge contributors.
e776494… andygoth 405 **
e776494… andygoth 406 ** If change type classification is enabled, each output line starts with
e776494… andygoth 407 ** a code describing the file's change type, e.g. EDITED or RENAMED. It
e776494… andygoth 408 ** is enabled by default unless exactly one change type is selected. For
e776494… andygoth 409 ** the purposes of determining the default, --changed counts as selecting
e776494… andygoth 410 ** one change type. The default can be overridden by the --classify or
e776494… andygoth 411 ** --no-classify options.
e776494… andygoth 412 **
e776494… andygoth 413 ** --edited and --updated produce disjoint sets. --updated shows a file
e776494… andygoth 414 ** only when it is identical to that of its merge contributor, and the
e776494… andygoth 415 ** change type classification is UPDATED_BY_MERGE or UPDATED_BY_INTEGRATE.
e776494… andygoth 416 ** If the file had to be merged with any other changes, it is considered
e776494… andygoth 417 ** to be merged or conflicted and therefore will be shown by --edited, not
e776494… andygoth 418 ** --updated, with types EDITED or CONFLICT. The --changed option can be
e776494… andygoth 419 ** used to display the union of --edited and --updated.
e776494… andygoth 420 **
e776494… andygoth 421 ** --differ is so named because it lists all the differences between the
bc36fdc… danield 422 ** checked-out version and the check-out directory. In addition to the
9686570… andygoth 423 ** default changes (excluding --merge), it lists extra files which (if
e776494… andygoth 424 ** ignore-glob is set correctly) may be worth adding. Prior to doing a
e776494… andygoth 425 ** commit, it is good practice to check --differ to see not only which
9686570… andygoth 426 ** changes would be committed but also if any files should be added.
9686570… andygoth 427 **
5c8bdd0… andygoth 428 ** If both --merge and --no-merge are used, --no-merge has priority. The
5c8bdd0… andygoth 429 ** same is true of --classify and --no-classify.
5c8bdd0… andygoth 430 **
5c8bdd0… andygoth 431 ** The "fossil changes --extra" command is equivalent to "fossil extras".
5c8bdd0… andygoth 432 **
e776494… andygoth 433 ** General options:
2e56ef4… km 434 ** --abs-paths Display absolute pathnames
514149f… drh 435 ** -b|--brief Show a single keyword for the status
9a0c995… drh 436 ** --rel-paths Display pathnames relative to the current working
2e56ef4… km 437 ** directory
fd9b7bd… drh 438 ** --hash Verify file status using hashing rather than
2e56ef4… km 439 ** relying on file mtimes
2e56ef4… km 440 ** --case-sensitive BOOL Override case-sensitive setting
2e56ef4… km 441 ** --dotfiles Include unmanaged files beginning with a dot
2e56ef4… km 442 ** --ignore <CSG> Ignore unmanaged files matching CSG glob patterns
e776494… andygoth 443 **
e776494… andygoth 444 ** Options specific to the changes command:
2e56ef4… km 445 ** --header Identify the repository if report is non-empty
2e56ef4… km 446 ** -v|--verbose Say "(none)" if the change report is empty
2e56ef4… km 447 ** --classify Start each line with the file's change type
2e56ef4… km 448 ** --no-classify Do not print file change types
e776494… andygoth 449 **
e776494… andygoth 450 ** Filter options:
2e56ef4… km 451 ** --edited Display edited, merged, and conflicted files
2e56ef4… km 452 ** --updated Display files updated by merge/integrate
2e56ef4… km 453 ** --changed Combination of the above two options
2e56ef4… km 454 ** --missing Display missing files
2e56ef4… km 455 ** --added Display added files
2e56ef4… km 456 ** --deleted Display deleted files
2e56ef4… km 457 ** --renamed Display renamed files
2e56ef4… km 458 ** --conflict Display files having merge conflicts
2e56ef4… km 459 ** --meta Display files with metadata changes
2e56ef4… km 460 ** --unchanged Display unchanged files
2e56ef4… km 461 ** --all Display all managed files, i.e. all of the above
2e56ef4… km 462 ** --extra Display unmanaged files
2e56ef4… km 463 ** --differ Display modified and extra files
2e56ef4… km 464 ** --merge Display merge contributors
2e56ef4… km 465 ** --no-merge Do not display merge contributors
2210be1… drh 466 **
c965636… drh 467 ** See also: [[extras]], [[ls]]
dbda8d6… drh 468 */
dbda8d6… drh 469 void status_cmd(void){
e776494… andygoth 470 /* Affirmative and negative flag option tables. */
e776494… andygoth 471 static const struct {
e776494… andygoth 472 const char *option; /* Flag name. */
e776494… andygoth 473 unsigned mask; /* Flag bits. */
e776494… andygoth 474 } flagDefs[] = {
e776494… andygoth 475 {"edited" , C_EDITED }, {"updated" , C_UPDATED },
e776494… andygoth 476 {"changed" , C_CHANGED }, {"missing" , C_MISSING },
e776494… andygoth 477 {"added" , C_ADDED }, {"deleted" , C_DELETED },
e776494… andygoth 478 {"renamed" , C_RENAMED }, {"conflict" , C_CONFLICT },
e776494… andygoth 479 {"meta" , C_META }, {"unchanged" , C_UNCHANGED},
e776494… andygoth 480 {"all" , C_ALL }, {"extra" , C_EXTRA },
e776494… andygoth 481 {"differ" , C_DIFFER }, {"merge" , C_MERGE },
e776494… andygoth 482 {"classify", C_CLASSIFY},
e776494… andygoth 483 }, noFlagDefs[] = {
e776494… andygoth 484 {"no-merge", C_MERGE }, {"no-classify", C_CLASSIFY },
e776494… andygoth 485 };
e776494… andygoth 486
e776494… andygoth 487 Blob report = BLOB_INITIALIZER;
e776494… andygoth 488 enum {CHANGES, STATUS} command = *g.argv[1]=='s' ? STATUS : CHANGES;
e2bdc10… danield 489 /* --sha1sum is an undocumented alias for --hash for backwards compatibility */
d90e56f… drh 490 int useHash = find_option("hash",0,0)!=0 || find_option("sha1sum",0,0)!=0;
e776494… andygoth 491 int showHdr = command==CHANGES && find_option("header", 0, 0);
e776494… andygoth 492 int verboseFlag = command==CHANGES && find_option("verbose", "v", 0);
e776494… andygoth 493 const char *zIgnoreFlag = find_option("ignore", 0, 1);
e776494… andygoth 494 unsigned scanFlags = 0;
e776494… andygoth 495 unsigned flags = 0;
e776494… andygoth 496 int vid, i;
7b81a99… drh 497
e765f90… drh 498 fossil_pledge("stdio rpath wpath cpath fattr id flock tty chown");
514149f… drh 499
514149f… drh 500 if( find_option("brief","b",0) ){
514149f… drh 501 /* The --brief or -b option is special. It cannot be used with any
514149f… drh 502 ** other options. It outputs a single keyword which indicates the
514149f… drh 503 ** fossil status, for use by shell scripts. The output might be
514149f… drh 504 ** one of:
514149f… drh 505 **
a186d8b… drh 506 ** clean The current working directory is within an
514149f… drh 507 ** unmodified fossil check-out.
514149f… drh 508 **
514149f… drh 509 ** dirty The pwd is within a fossil check-out that has
514149f… drh 510 ** uncommitted changes
514149f… drh 511 **
514149f… drh 512 ** none The pwd is not within a fossil check-out.
514149f… drh 513 */
514149f… drh 514 int chnged;
514149f… drh 515 if( g.argc>2 ){
514149f… drh 516 fossil_fatal("No other arguments or options may occur with --brief");
514149f… drh 517 }
514149f… drh 518 if( db_open_local(0)==0 ){
514149f… drh 519 fossil_print("none\n");
514149f… drh 520 return;
514149f… drh 521 }
514149f… drh 522 vid = db_lget_int("checkout", 0);
514149f… drh 523 vfile_check_signature(vid, 0);
514149f… drh 524 chnged = db_int(0,
514149f… drh 525 "SELECT 1 FROM vfile"
514149f… drh 526 " WHERE vid=%d"
514149f… drh 527 " AND (chnged>0 OR deleted OR rid==0)",
514149f… drh 528 vid
514149f… drh 529 );
514149f… drh 530 if( chnged ){
514149f… drh 531 fossil_print("dirty\n");
514149f… drh 532 }else{
514149f… drh 533 fossil_print("clean\n");
514149f… drh 534 }
514149f… drh 535 return;
514149f… drh 536 }
e776494… andygoth 537
e776494… andygoth 538 /* Load affirmative flag options. */
e776494… andygoth 539 for( i=0; i<count(flagDefs); ++i ){
e776494… andygoth 540 if( (command==CHANGES || !(flagDefs[i].mask & C_CLASSIFY))
e776494… andygoth 541 && find_option(flagDefs[i].option, 0, 0) ){
e776494… andygoth 542 flags |= flagDefs[i].mask;
e776494… andygoth 543 }
e776494… andygoth 544 }
e776494… andygoth 545
e776494… andygoth 546 /* If no filter options are specified, enable defaults. */
e776494… andygoth 547 if( !(flags & C_FILTER) ){
e776494… andygoth 548 flags |= C_DEFAULT;
e776494… andygoth 549 }
e776494… andygoth 550
e776494… andygoth 551 /* If more than one filter is enabled, enable classification. This is tricky.
e776494… andygoth 552 * Having one filter means flags masked by C_FILTER is a power of two. If a
e776494… andygoth 553 * number masked by one less than itself is zero, it's either zero or a power
e776494… andygoth 554 * of two. It's already known to not be zero because of the above defaults.
e776494… andygoth 555 * Unlike --all, --changed is a single filter, i.e. it sets only one bit.
e776494… andygoth 556 * Also force classification for the status command. */
e776494… andygoth 557 if( command==STATUS || (flags & (flags-1) & C_FILTER) ){
e776494… andygoth 558 flags |= C_CLASSIFY;
e776494… andygoth 559 }
e776494… andygoth 560
e776494… andygoth 561 /* Negative flag options override defaults applied above. */
e776494… andygoth 562 for( i=0; i<count(noFlagDefs); ++i ){
e776494… andygoth 563 if( (command==CHANGES || !(noFlagDefs[i].mask & C_CLASSIFY))
e776494… andygoth 564 && find_option(noFlagDefs[i].option, 0, 0) ){
e776494… andygoth 565 flags &= ~noFlagDefs[i].mask;
e776494… andygoth 566 }
e776494… andygoth 567 }
e776494… andygoth 568
bc36fdc… danield 569 /* Confirm current working directory is within check-out. */
dbda8d6… drh 570 db_must_be_within_tree();
e776494… andygoth 571
75c45fd… drh 572 /* Get check-out version. */
dbda8d6… drh 573 vid = db_lget_int("checkout", 0);
e776494… andygoth 574
e776494… andygoth 575 /* Relative path flag determination is done by a shared function. */
e776494… andygoth 576 if( determine_cwd_relative_option() ){
e776494… andygoth 577 flags |= C_RELPATH;
dbda8d6… drh 578 }
e776494… andygoth 579
e776494… andygoth 580 /* If --ignore is not specified, use the ignore-glob setting. */
e776494… andygoth 581 if( !zIgnoreFlag ){
e776494… andygoth 582 zIgnoreFlag = db_get("ignore-glob", 0);
e776494… andygoth 583 }
e776494… andygoth 584
e776494… andygoth 585 /* Get the --dotfiles argument, or read it from the dotfiles setting. */
e776494… andygoth 586 if( find_option("dotfiles", 0, 0) || db_get_boolean("dotfiles", 0) ){
e776494… andygoth 587 scanFlags = SCAN_ALL;
e776494… andygoth 588 }
e776494… andygoth 589
e776494… andygoth 590 /* We should be done with options. */
e776494… andygoth 591 verify_all_options();
e776494… andygoth 592
e776494… andygoth 593 /* Check for changed files. */
fd9b7bd… drh 594 vfile_check_signature(vid, useHash ? CKSIG_HASH : 0);
e776494… andygoth 595
e776494… andygoth 596 /* Search for unmanaged files if requested. */
e776494… andygoth 597 if( flags & C_EXTRA ){
e776494… andygoth 598 Glob *pIgnore = glob_create(zIgnoreFlag);
e776494… andygoth 599 locate_unmanaged_files(g.argc-2, g.argv+2, scanFlags, pIgnore);
e776494… andygoth 600 glob_free(pIgnore);
e776494… andygoth 601 }
e776494… andygoth 602
e776494… andygoth 603 /* The status command prints general information before the change list. */
e776494… andygoth 604 if( command==STATUS ){
e776494… andygoth 605 fossil_print("repository: %s\n", db_repository_filename());
e776494… andygoth 606 fossil_print("local-root: %s\n", g.zLocalRoot);
e776494… andygoth 607 if( g.zConfigDbName ){
e776494… andygoth 608 fossil_print("config-db: %s\n", g.zConfigDbName);
e776494… andygoth 609 }
e776494… andygoth 610 if( vid ){
e776494… andygoth 611 show_common_info(vid, "checkout:", 1, 1);
e776494… andygoth 612 }
e776494… andygoth 613 db_record_repository_filename(0);
e776494… andygoth 614 }
e776494… andygoth 615
e776494… andygoth 616 /* Find and print all requested changes. */
e776494… andygoth 617 blob_zero(&report);
e776494… andygoth 618 status_report(&report, flags);
e51531c… drh 619 if( blob_size(&report) ){
e776494… andygoth 620 if( showHdr ){
203d82d… drh 621 fossil_print(
203d82d… drh 622 "Changes for %s at %s:\n", db_get("project-name", "<unnamed>"),
203d82d… drh 623 g.zLocalRoot);
e776494… andygoth 624 }
e776494… andygoth 625 blob_write_to_file(&report, "-");
e776494… andygoth 626 }else if( verboseFlag ){
e776494… andygoth 627 fossil_print(" (none)\n");
e776494… andygoth 628 }
e776494… andygoth 629 blob_reset(&report);
e776494… andygoth 630
e776494… andygoth 631 /* The status command ends with warnings about ambiguous leaves (forks). */
e776494… andygoth 632 if( command==STATUS ){
e776494… andygoth 633 leaf_ambiguity_warning(vid, vid);
e776494… andygoth 634 }
e776494… andygoth 635 }
e776494… andygoth 636
dd72a96… drh 637 /* zIn is a string that is guaranteed to be followed by \n. Return
dd72a96… drh 638 ** a pointer to the next line after the \n. The returned value might
dd72a96… drh 639 ** point to the \000 string terminator.
dd72a96… drh 640 */
dd72a96… drh 641 static const char *next_line(const char *zIn){
dd72a96… drh 642 const char *z = strchr(zIn, '\n');
dd72a96… drh 643 assert( z!=0 );
dd72a96… drh 644 return z+1;
dd72a96… drh 645 }
dd72a96… drh 646
dd72a96… drh 647 /* zIn is a non-empty list of filenames in sorted order and separated
dd72a96… drh 648 ** by \n. There might be a cluster of lines that have the same n-character
dd72a96… drh 649 ** prefix. Return a pointer to the start of the last line of that
dd72a96… drh 650 ** cluster. The return value might be zIn if the first line of zIn is
dd72a96… drh 651 ** unique in its first n character.
dd72a96… drh 652 */
dd72a96… drh 653 static const char *last_line(const char *zIn, int n){
dd72a96… drh 654 const char *zLast = zIn;
dd72a96… drh 655 const char *z;
dd72a96… drh 656 while( 1 ){
dd72a96… drh 657 z = next_line(zLast);
dd72a96… drh 658 if( z[0]==0 || (n>0 && strncmp(zIn, z, n)!=0) ) break;
dd72a96… drh 659 zLast = z;
dd72a96… drh 660 }
dd72a96… drh 661 return zLast;
dd72a96… drh 662 }
dd72a96… drh 663
dd72a96… drh 664 /*
dd72a96… drh 665 ** Print a section of a filelist hierarchy graph. This is a helper
dd72a96… drh 666 ** routine for print_filelist_as_tree() below.
dd72a96… drh 667 */
dd72a96… drh 668 static const char *print_filelist_section(
dd72a96… drh 669 const char *zIn, /* List of filenames, separated by \n */
dd72a96… drh 670 const char *zLast, /* Last filename in the list to print */
dd72a96… drh 671 const char *zPrefix, /* Prefix so put before each output line */
89da205… danield 672 int nDir /* Ignore this many characters of directory name */
dd72a96… drh 673 ){
7045859… drh 674 /* Unicode box-drawing characters: U+251C, U+2514, U+2502 */
89da205… danield 675 const char *zENTRY = "\342\224\234\342\224\200\342\224\200 ";
89da205… danield 676 const char *zLASTE = "\342\224\224\342\224\200\342\224\200 ";
89da205… danield 677 const char *zCONTU = "\342\224\202 ";
89da205… danield 678 const char *zBLANK = " ";
7045859… drh 679
dd72a96… drh 680 while( zIn<=zLast ){
dd72a96… drh 681 int i;
dd72a96… drh 682 for(i=nDir; zIn[i]!='\n' && zIn[i]!='/'; i++){}
dd72a96… drh 683 if( zIn[i]=='/' ){
dd72a96… drh 684 char *zSubPrefix;
dd72a96… drh 685 const char *zSubLast = last_line(zIn, i+1);
89da205… danield 686 zSubPrefix = mprintf("%s%s", zPrefix, zSubLast==zLast ? zBLANK : zCONTU);
89da205… danield 687 fossil_print("%s%s%.*s\n", zPrefix, zSubLast==zLast ? zLASTE : zENTRY,
89da205… danield 688 i-nDir, &zIn[nDir]);
89da205… danield 689 zIn = print_filelist_section(zIn, zSubLast, zSubPrefix, i+1);
dd72a96… drh 690 fossil_free(zSubPrefix);
dd72a96… drh 691 }else{
89da205… danield 692 fossil_print("%s%s%.*s\n", zPrefix, zIn==zLast ? zLASTE : zENTRY,
dd72a96… drh 693 i-nDir, &zIn[nDir]);
dd72a96… drh 694 zIn = next_line(zIn);
dd72a96… drh 695 }
dd72a96… drh 696 }
dd72a96… drh 697 return zIn;
dd72a96… drh 698 }
dd72a96… drh 699
dd72a96… drh 700 /*
dd72a96… drh 701 ** Input blob pList is a list of filenames, one filename per line,
dd72a96… drh 702 ** in sorted order and with / directory separators. Output this list
dd72a96… drh 703 ** as a tree in a manner similar to the "tree" command on Linux.
dd72a96… drh 704 */
89da205… danield 705 static void print_filelist_as_tree(Blob *pList){
dd72a96… drh 706 char *zAll;
dd72a96… drh 707 const char *zLast;
dd72a96… drh 708 fossil_print("%s\n", g.zLocalRoot);
dd72a96… drh 709 zAll = blob_str(pList);
dd72a96… drh 710 if( zAll[0] ){
dd72a96… drh 711 zLast = last_line(zAll, 0);
89da205… danield 712 print_filelist_section(zAll, zLast, "", 0);
dd72a96… drh 713 }
dd72a96… drh 714 }
dd72a96… drh 715
e567a91… drh 716 /*
e567a91… drh 717 ** Take care of -r version of ls command
e567a91… drh 718 */
6441340… danield 719 void ls_cmd_rev(
e567a91… drh 720 const char *zRev, /* Revision string given */
e567a91… drh 721 int verboseFlag, /* Verbose flag given */
fc3d9f5… jan.nijtmans 722 int showAge, /* Age flag given */
1f8d7b7… danield 723 int showFileHash, /* Show file hash flag given */
1f8d7b7… danield 724 int showCkinHash, /* Show check-in hash flag given */
6441340… danield 725 int showCkinInfo, /* Show check-in infos */
dd72a96… drh 726 int timeOrder, /* Order by time flag given */
dd72a96… drh 727 int treeFmt /* Show output in the tree format */
e567a91… drh 728 ){
e567a91… drh 729 Stmt q;
e567a91… drh 730 char *zOrderBy = "pathname COLLATE nocase";
e567a91… drh 731 char *zName;
e567a91… drh 732 Blob where;
e567a91… drh 733 int rid;
e567a91… drh 734 int i;
dd72a96… drh 735 Blob out;
e567a91… drh 736
e567a91… drh 737 /* Handle given file names */
e567a91… drh 738 blob_zero(&where);
e567a91… drh 739 for(i=2; i<g.argc; i++){
e567a91… drh 740 Blob fname;
c56a387… mistachkin 741 file_tree_name(g.argv[i], &fname, 0, 1);
e567a91… drh 742 zName = blob_str(&fname);
7d257de… mistachkin 743 if( fossil_strcmp(zName, ".")==0 ){
e567a91… drh 744 blob_reset(&where);
e567a91… drh 745 break;
e567a91… drh 746 }
e567a91… drh 747 blob_append_sql(&where,
e567a91… drh 748 " %s (pathname=%Q %s) "
e567a91… drh 749 "OR (pathname>'%q/' %s AND pathname<'%q0' %s)",
e567a91… drh 750 (blob_size(&where)>0) ? "OR" : "AND (", zName,
e567a91… drh 751 filename_collation(), zName, filename_collation(),
e567a91… drh 752 zName, filename_collation()
e567a91… drh 753 );
e567a91… drh 754 }
e567a91… drh 755 if( blob_size(&where)>0 ){
e567a91… drh 756 blob_append_sql(&where, ")");
e567a91… drh 757 }
e567a91… drh 758
e567a91… drh 759 rid = symbolic_name_to_rid(zRev, "ci");
e567a91… drh 760 if( rid==0 ){
e567a91… drh 761 fossil_fatal("not a valid check-in: %s", zRev);
e567a91… drh 762 }
fc3d9f5… jan.nijtmans 763
e567a91… drh 764 if( timeOrder ){
e567a91… drh 765 zOrderBy = "mtime DESC";
e567a91… drh 766 }
e567a91… drh 767
e567a91… drh 768 compute_fileage(rid,0);
6441340… danield 769 if( showCkinInfo ){
6441340… danield 770 db_prepare(&q,
6441340… danield 771 "SELECT datetime(fileage.mtime, toLocal()), fileage.pathname,\n"
6441340… danield 772 " bfh.size, fileage.uuid, bch.uuid,\n"
6441340… danield 773 " coalesce(e.ecomment, e.comment), coalesce(e.euser, e.user)\n"
6441340… danield 774 " FROM fileage, blob bfh, blob bch, event e\n"
6441340… danield 775 " WHERE bfh.rid=fileage.fid AND bch.rid=fileage.mid\n"
6441340… danield 776 " AND e.objid = fileage.mid %s\n"
6441340… danield 777 " ORDER BY %s;",
6441340… danield 778 blob_sql_text(&where),
6441340… danield 779 zOrderBy /*safe-for-%s*/
6441340… danield 780 );
6441340… danield 781 }else{
6441340… danield 782 db_prepare(&q,
ea63a2d… drh 783 "SELECT datetime(fileage.mtime, toLocal()), fileage.pathname,\n"
1f8d7b7… danield 784 " bfh.size, fileage.uuid %s\n"
1f8d7b7… danield 785 " FROM fileage, blob bfh %s\n"
1f8d7b7… danield 786 " WHERE bfh.rid=fileage.fid %s %s\n"
6441340… danield 787 " ORDER BY %s;",
1f8d7b7… danield 788 showCkinHash ? ", bch.uuid" : "",
1f8d7b7… danield 789 showCkinHash ? ", blob bch" : "",
1f8d7b7… danield 790 showCkinHash ? "\n AND bch.rid=fileage.mid" : "",
1f8d7b7… danield 791 blob_sql_text(&where),
1f8d7b7… danield 792 zOrderBy /*safe-for-%s*/
6441340… danield 793 );
6441340… danield 794 }
e567a91… drh 795 blob_reset(&where);
dd72a96… drh 796 if( treeFmt ) blob_init(&out, 0, 0);
e567a91… drh 797
e567a91… drh 798 while( db_step(&q)==SQLITE_ROW ){
e567a91… drh 799 const char *zTime = db_column_text(&q,0);
e567a91… drh 800 const char *zFile = db_column_text(&q,1);
e567a91… drh 801 int size = db_column_int(&q,2);
dd72a96… drh 802 if( treeFmt ){
dd72a96… drh 803 blob_appendf(&out, "%s\n", zFile);
dd72a96… drh 804 }else if( verboseFlag ){
6441340… danield 805 if( showCkinInfo ){
6441340… danield 806 const char *zUuidC = db_column_text(&q,4);
6441340… danield 807 const char *zComm = db_column_text(&q,5);
6441340… danield 808 const char *zUser = db_column_text(&q,6);
6441340… danield 809 fossil_print("%s [%S] %12s ", zTime, zUuidC, zUser);
6441340… danield 810 if( showCkinInfo==2 ) fossil_print("%-20.20s ", zComm);
6441340… danield 811 fossil_print("%s\n", zFile);
6441340… danield 812 }else if( showFileHash ){
1f8d7b7… danield 813 const char *zUuidF = db_column_text(&q,3);
1f8d7b7… danield 814 fossil_print("%s %7d [%S] %s\n", zTime, size, zUuidF, zFile);
1f8d7b7… danield 815 }else if( showCkinHash ){
1f8d7b7… danield 816 const char *zUuidC = db_column_text(&q,4);
1f8d7b7… danield 817 fossil_print("%s %7d [%S] %s\n", zTime, size, zUuidC, zFile);
bd4cec1… danield 818 }else{
bd4cec1… danield 819 fossil_print("%s %7d %s\n", zTime, size, zFile);
bd4cec1… danield 820 }
e567a91… drh 821 }else if( showAge ){
e567a91… drh 822 fossil_print("%s %s\n", zTime, zFile);
e567a91… drh 823 }else{
e567a91… drh 824 fossil_print("%s\n", zFile);
fc3d9f5… jan.nijtmans 825 }
e567a91… drh 826 }
e567a91… drh 827 db_finalize(&q);
dd72a96… drh 828 if( treeFmt ){
89da205… danield 829 print_filelist_as_tree(&out);
dd72a96… drh 830 blob_reset(&out);
dd72a96… drh 831 }
9dab2e0… stephan 832 }
dbda8d6… drh 833
dbda8d6… drh 834 /*
dbda8d6… drh 835 ** COMMAND: ls
6b85fd1… drh 836 **
0a4310b… andygoth 837 ** Usage: %fossil ls ?OPTIONS? ?PATHS ...?
0a4310b… andygoth 838 **
bc36fdc… danield 839 ** List all files in the current check-out. If PATHS is included, only the
0a4310b… andygoth 840 ** named files (or their children if directories) are shown.
0a4310b… andygoth 841 **
ba49279… drh 842 ** The ls command has grown by accretion, with multiple contributors, over
ba49279… drh 843 ** many years, and is hence a little confused. The ls command is essentially
ba49279… drh 844 ** two related commands in one, depending on whether or not the -r option
ba49279… drh 845 ** is given or implied. The -r option selects a specific check-in
0a4310b… andygoth 846 ** version to list, in which case -R can be used to select the repository.
0a4310b… andygoth 847 ** The fine behavior of the --age, -v, and -t options is altered by the -r
ba49279… drh 848 ** option as well, as explained below. The -h and -H options use an
ba49279… drh 849 ** implicit "-r current" option if no -r is specified.
0a4310b… andygoth 850 **
bc5a67d… andygoth 851 ** The --age option displays file commit times. Like -r, --age has the
bc5a67d… andygoth 852 ** side effect of making -t sort by commit time, not modification time.
0a4310b… andygoth 853 **
0a4310b… andygoth 854 ** The -v option provides extra information about each file. Without -r,
ba49279… drh 855 ** -v displays the change status, in the manner of the [[changes]] command.
ba49279… drh 856 ** With -r, -v shows the commit time and size of the checked-in files.
ba49279… drh 857 ** The -h option also shows the file hash prefix. The -H option shows
ba49279… drh 858 ** the check-in hash prefix. The -v option added implicitly if either of the
ba49279… drh 859 ** -h or -H options is used. An implicit "-r current" is also added if
ba49279… drh 860 ** -h or -H are used and no -r is specified.
0a4310b… andygoth 861 **
0a4310b… andygoth 862 ** The -t option changes the sort order. Without -t, files are sorted by
0a4310b… andygoth 863 ** path and name (case insensitive sort if -r). If neither --age nor -r
0a4310b… andygoth 864 ** are used, -t sorts by modification time, otherwise by commit time.
2210be1… drh 865 **
2210be1… drh 866 ** Options:
2e56ef4… km 867 ** --age Show when each file was committed
ba49279… drh 868 ** -h Show file hashes. Implies -v and -r
ba49279… drh 869 ** -H Show check-in hashes. Implies -v and -r
ba49279… drh 870 ** --hash Verify file status using hashing rather than
ba49279… drh 871 ** relying on file sizes and mtimes. Implies -v
2e56ef4… km 872 ** -r VERSION The specific check-in to list
2e56ef4… km 873 ** -R|--repository REPO Extract info from repository REPO
635fa09… danield 874 ** -t Sort output in time order
635fa09… danield 875 ** --tree Tree format
635fa09… danield 876 ** -v|--verbose Provide extra information about each file
6b85fd1… drh 877 **
dd72a96… drh 878 ** See also: [[changes]], [[extras]], [[status]], [[tree]]
dbda8d6… drh 879 */
dbda8d6… drh 880 void ls_cmd(void){
dbda8d6… drh 881 int vid;
dbda8d6… drh 882 Stmt q;
e91d65a… jan.nijtmans 883 int verboseFlag;
9ba8a39… drh 884 int showAge;
dd72a96… drh 885 int treeFmt;
e567a91… drh 886 int timeOrder;
9ba8a39… drh 887 char *zOrderBy = "pathname";
04803ae… drh 888 Blob where;
04803ae… drh 889 int i;
15001dd… stephan 890 int useHash = 0;
1f8d7b7… danield 891 int showFHash = 0; /* Show file hash */
1f8d7b7… danield 892 int showCHash = 0; /* Show check-in hash */
ae01244… jan.nijtmans 893 const char *zName;
e567a91… drh 894 const char *zRev;
9c06ea3… drh 895
e91d65a… jan.nijtmans 896 verboseFlag = find_option("verbose","v", 0)!=0;
67c9cd1… jan.nijtmans 897 if( !verboseFlag ){
e91d65a… jan.nijtmans 898 verboseFlag = find_option("l","l", 0)!=0; /* deprecated */
e91d65a… jan.nijtmans 899 }
9ba8a39… drh 900 showAge = find_option("age",0,0)!=0;
e567a91… drh 901 zRev = find_option("r","r",1);
e567a91… drh 902 timeOrder = find_option("t","t",0)!=0;
ba49279… drh 903 useHash = find_option("hash",0,0)!=0;
ba49279… drh 904 if( useHash ) verboseFlag = 1;
ba49279… drh 905 showFHash = find_option("h","h",0)!=0;
ba49279… drh 906 showCHash = find_option("H","H",0)!=0;
ba49279… drh 907 if( showFHash || showCHash ){
ba49279… drh 908 if( showFHash && showCHash ){
ba49279… drh 909 fossil_fatal("the \"ls\" command cannot use both -h and -H at once");
1f8d7b7… danield 910 }
ba49279… drh 911 verboseFlag = 1;
ba49279… drh 912 if( zRev==0 ) zRev = "current";
dd72a96… drh 913 }
dd72a96… drh 914 treeFmt = find_option("tree",0,0)!=0;
dd72a96… drh 915 if( treeFmt ){
dd72a96… drh 916 if( zRev==0 ) zRev = "current";
15001dd… stephan 917 }
e567a91… drh 918
e567a91… drh 919 if( zRev!=0 ){
e567a91… drh 920 db_find_and_open_repository(0, 0);
e567a91… drh 921 verify_all_options();
6441340… danield 922 ls_cmd_rev(zRev, verboseFlag, showAge, showFHash, showCHash, 0, timeOrder,
6441340… danield 923 treeFmt);
e567a91… drh 924 return;
844a7a7… drh 925 }else if( find_option("R",0,1)!=0 ){
844a7a7… drh 926 fossil_fatal("the -r is required in addition to -R");
e567a91… drh 927 }
e567a91… drh 928
dbda8d6… drh 929 db_must_be_within_tree();
dbda8d6… drh 930 vid = db_lget_int("checkout", 0);
e567a91… drh 931 if( timeOrder ){
9ba8a39… drh 932 if( showAge ){
9ba8a39… drh 933 zOrderBy = mprintf("checkin_mtime(%d,rid) DESC", vid);
9ba8a39… drh 934 }else{
9ba8a39… drh 935 zOrderBy = "mtime DESC";
9ba8a39… drh 936 }
9ba8a39… drh 937 }
9ba8a39… drh 938 verify_all_options();
04803ae… drh 939 blob_zero(&where);
04803ae… drh 940 for(i=2; i<g.argc; i++){
04803ae… drh 941 Blob fname;
c56a387… mistachkin 942 file_tree_name(g.argv[i], &fname, 0, 1);
ae01244… jan.nijtmans 943 zName = blob_str(&fname);
7d257de… mistachkin 944 if( fossil_strcmp(zName, ".")==0 ){
ae01244… jan.nijtmans 945 blob_reset(&where);
ae01244… jan.nijtmans 946 break;
ae01244… jan.nijtmans 947 }
49b0ff1… drh 948 blob_append_sql(&where,
49b0ff1… drh 949 " %s (pathname=%Q %s) "
49b0ff1… drh 950 "OR (pathname>'%q/' %s AND pathname<'%q0' %s)",
49b0ff1… drh 951 (blob_size(&where)>0) ? "OR" : "WHERE", zName,
49b0ff1… drh 952 filename_collation(), zName, filename_collation(),
49b0ff1… drh 953 zName, filename_collation()
49b0ff1… drh 954 );
ae01244… jan.nijtmans 955 }
15001dd… stephan 956 vfile_check_signature(vid, useHash ? CKSIG_HASH : 0);
9ba8a39… drh 957 if( showAge ){
9ba8a39… drh 958 db_prepare(&q,
9ba8a39… drh 959 "SELECT pathname, deleted, rid, chnged, coalesce(origname!=pathname,0),"
ea63a2d… drh 960 " datetime(checkin_mtime(%d,rid),'unixepoch',toLocal())"
04803ae… drh 961 " FROM vfile %s"
49b0ff1… drh 962 " ORDER BY %s",
ea63a2d… drh 963 vid, blob_sql_text(&where), zOrderBy /*safe-for-%s*/
9ba8a39… drh 964 );
9ba8a39… drh 965 }else{
9ba8a39… drh 966 db_prepare(&q,
c985d90… drh 967 "SELECT pathname, deleted, rid, chnged,"
c985d90… drh 968 " coalesce(origname!=pathname,0), islink"
04803ae… drh 969 " FROM vfile %s"
49b0ff1… drh 970 " ORDER BY %s", blob_sql_text(&where), zOrderBy /*safe-for-%s*/
9ba8a39… drh 971 );
9ba8a39… drh 972 }
04803ae… drh 973 blob_reset(&where);
dbda8d6… drh 974 while( db_step(&q)==SQLITE_ROW ){
dbda8d6… drh 975 const char *zPathname = db_column_text(&q,0);
dbda8d6… drh 976 int isDeleted = db_column_int(&q, 1);
dbda8d6… drh 977 int isNew = db_column_int(&q,2)==0;
dbda8d6… drh 978 int chnged = db_column_int(&q,3);
e146d80… drh 979 int renamed = db_column_int(&q,4);
9867a3e… jan.nijtmans 980 int isLink = db_column_int(&q,5);
12a2a5e… drh 981 char *zFullName = mprintf("%s%s", g.zLocalRoot, zPathname);
40d1524… jan.nijtmans 982 const char *type = "";
40d1524… jan.nijtmans 983 if( verboseFlag ){
40d1524… jan.nijtmans 984 if( isNew ){
3ca6979… mistachkin 985 type = "ADDED ";
40d1524… jan.nijtmans 986 }else if( isDeleted ){
3ca6979… mistachkin 987 type = "DELETED ";
1772357… drh 988 }else if( !file_isfile_or_link(zFullName) ){
9df71fe… jan.nijtmans 989 if( file_access(zFullName, F_OK)==0 ){
3ca6979… mistachkin 990 type = "NOT_A_FILE ";
40d1524… jan.nijtmans 991 }else{
3ca6979… mistachkin 992 type = "MISSING ";
40d1524… jan.nijtmans 993 }
40d1524… jan.nijtmans 994 }else if( chnged ){
c41d70d… jan.nijtmans 995 if( chnged==2 ){
3ca6979… mistachkin 996 type = "UPDATED_BY_MERGE ";
c41d70d… jan.nijtmans 997 }else if( chnged==3 ){
3ca6979… mistachkin 998 type = "ADDED_BY_MERGE ";
69dd259… jan.nijtmans 999 }else if( chnged==4 ){
69dd259… jan.nijtmans 1000 type = "UPDATED_BY_INTEGRATE ";
69dd259… jan.nijtmans 1001 }else if( chnged==5 ){
69dd259… jan.nijtmans 1002 type = "ADDED_BY_INTEGRATE ";
9867a3e… jan.nijtmans 1003 }else if( !isLink && file_contains_merge_marker(zFullName) ){
3ca6979… mistachkin 1004 type = "CONFLICT ";
c41d70d… jan.nijtmans 1005 }else{
3ca6979… mistachkin 1006 type = "EDITED ";
c41d70d… jan.nijtmans 1007 }
40d1524… jan.nijtmans 1008 }else if( renamed ){
3ca6979… mistachkin 1009 type = "RENAMED ";
40d1524… jan.nijtmans 1010 }else{
3ca6979… mistachkin 1011 type = "UNCHANGED ";
40d1524… jan.nijtmans 1012 }
40d1524… jan.nijtmans 1013 }
9ba8a39… drh 1014 if( showAge ){
40d1524… jan.nijtmans 1015 fossil_print("%s%s %s\n", type, db_column_text(&q, 5), zPathname);
40d1524… jan.nijtmans 1016 }else{
40d1524… jan.nijtmans 1017 fossil_print("%s%s\n", type, zPathname);
dbda8d6… drh 1018 }
89d100b… drh 1019 free(zFullName);
dbda8d6… drh 1020 }
dbda8d6… drh 1021 db_finalize(&q);
dbda8d6… drh 1022 }
dbda8d6… drh 1023
dbda8d6… drh 1024 /*
dd72a96… drh 1025 ** COMMAND: tree
dd72a96… drh 1026 **
dd72a96… drh 1027 ** Usage: %fossil tree ?OPTIONS? ?PATHS ...?
dd72a96… drh 1028 **
6bb5ff4… brickviking 1029 ** List all files in the current check-out much like the "tree"
6bb5ff4… brickviking 1030 ** command does. If PATHS is included, only the named files
dd72a96… drh 1031 ** (or their children if directories) are shown.
dd72a96… drh 1032 **
dd72a96… drh 1033 ** Options:
dd72a96… drh 1034 ** -r VERSION The specific check-in to list
dd72a96… drh 1035 ** -R|--repository REPO Extract info from repository REPO
dd72a96… drh 1036 **
dd72a96… drh 1037 ** See also: [[ls]]
dd72a96… drh 1038 */
dd72a96… drh 1039 void tree_cmd(void){
dd72a96… drh 1040 const char *zRev;
89da205… danield 1041
dd72a96… drh 1042 zRev = find_option("r","r",1);
dd72a96… drh 1043 if( zRev==0 ) zRev = "current";
dd72a96… drh 1044 db_find_and_open_repository(0, 0);
dd72a96… drh 1045 verify_all_options();
6441340… danield 1046 ls_cmd_rev(zRev,0,0,0,0,0,0,1);
dd72a96… drh 1047 }
dd72a96… drh 1048
dd72a96… drh 1049 /*
554d896… bch 1050 ** COMMAND: extras
c3b5f1d… jan.nijtmans 1051 **
39feb89… drh 1052 ** Usage: %fossil extras ?OPTIONS? ?PATH1 ...?
a274921… drh 1053 **
4843bd5… andygoth 1054 ** Print a list of all files in the source tree that are not part of the
bc36fdc… danield 1055 ** current check-out. See also the "clean" command. If paths are specified,
4843bd5… andygoth 1056 ** only files in the given directories will be listed.
a274921… drh 1057 **
a274921… drh 1058 ** Files and subdirectories whose names begin with "." are normally
a274921… drh 1059 ** ignored but can be included by adding the --dotfiles option.
f12a696… drh 1060 **
4843bd5… andygoth 1061 ** Files whose names match any of the glob patterns in the "ignore-glob"
4843bd5… andygoth 1062 ** setting are ignored. This setting can be overridden by the --ignore
4843bd5… andygoth 1063 ** option, whose CSG argument is a comma-separated list of glob patterns.
9a0c995… drh 1064 **
9a0c995… drh 1065 ** Pathnames are displayed according to the "relative-paths" setting,
9a0c995… drh 1066 ** unless overridden by the --abs-paths or --rel-paths options.
9a0c995… drh 1067 **
9a0c995… drh 1068 ** Options:
4cb50c4… stephan 1069 ** --abs-paths Display absolute pathnames
e58c76a… drh 1070 ** --case-sensitive BOOL Override case-sensitive setting
e58c76a… drh 1071 ** --dotfiles Include files beginning with a dot (".")
e58c76a… drh 1072 ** --header Identify the repository if there are extras
e58c76a… drh 1073 ** --ignore CSG Ignore files matching patterns from the argument
e58c76a… drh 1074 ** --rel-paths Display pathnames relative to the current working
4cb50c4… stephan 1075 ** directory
dd72a96… drh 1076 ** --tree Show output in the tree format
2210be1… drh 1077 **
c965636… drh 1078 ** See also: [[changes]], [[clean]], [[status]]
c9fdb84… drh 1079 */
7afbb70… mistachkin 1080 void extras_cmd(void){
e776494… andygoth 1081 Blob report = BLOB_INITIALIZER;
7c2577b… drh 1082 const char *zIgnoreFlag = find_option("ignore",0,1);
3206b64… drh 1083 unsigned scanFlags = find_option("dotfiles",0,0)!=0 ? SCAN_ALL : 0;
e776494… andygoth 1084 unsigned flags = C_EXTRA;
69974aa… mistachkin 1085 int showHdr = find_option("header",0,0)!=0;
dd72a96… drh 1086 int treeFmt = find_option("tree",0,0)!=0;
8ae9173… drh 1087 Glob *pIgnore;
7c2577b… drh 1088
3206b64… drh 1089 if( find_option("temp",0,0)!=0 ) scanFlags |= SCAN_TEMP;
c9fdb84… drh 1090 db_must_be_within_tree();
e776494… andygoth 1091
e776494… andygoth 1092 if( determine_cwd_relative_option() ){
e776494… andygoth 1093 flags |= C_RELPATH;
e776494… andygoth 1094 }
e1e0ec5… drh 1095
e1e0ec5… drh 1096 if( db_get_boolean("dotfiles", 0) ) scanFlags |= SCAN_ALL;
dd72a96… drh 1097
dd72a96… drh 1098 if( treeFmt ){
dd72a96… drh 1099 flags &= ~C_RELPATH;
dd72a96… drh 1100 }
f741baa… drh 1101
74ac0c9… drh 1102 /* We should be done with options.. */
74ac0c9… drh 1103 verify_all_options();
74ac0c9… drh 1104
7c2577b… drh 1105 if( zIgnoreFlag==0 ){
7c2577b… drh 1106 zIgnoreFlag = db_get("ignore-glob", 0);
7c2577b… drh 1107 }
8ae9173… drh 1108 pIgnore = glob_create(zIgnoreFlag);
e776494… andygoth 1109 locate_unmanaged_files(g.argc-2, g.argv+2, scanFlags, pIgnore);
8ae9173… drh 1110 glob_free(pIgnore);
e776494… andygoth 1111
e776494… andygoth 1112 blob_zero(&report);
e776494… andygoth 1113 status_report(&report, flags);
e776494… andygoth 1114 if( blob_size(&report) ){
69974aa… mistachkin 1115 if( showHdr ){
203d82d… drh 1116 fossil_print("Extras for %s at %s:\n", db_get("project-name","<unnamed>"),
69974aa… mistachkin 1117 g.zLocalRoot);
69974aa… mistachkin 1118 }
dd72a96… drh 1119 if( treeFmt ){
89da205… danield 1120 print_filelist_as_tree(&report);
dd72a96… drh 1121 }else{
dd72a96… drh 1122 blob_write_to_file(&report, "-");
dd72a96… drh 1123 }
69974aa… mistachkin 1124 }
e776494… andygoth 1125 blob_reset(&report);
c9fdb84… drh 1126 }
c9fdb84… drh 1127
c9fdb84… drh 1128 /*
c9fdb84… drh 1129 ** COMMAND: clean
c3b5f1d… jan.nijtmans 1130 **
c353ee8… drh 1131 ** Usage: %fossil clean ?OPTIONS? ?PATH ...?
c353ee8… drh 1132 **
d7955bf… andygoth 1133 ** Delete all "extra" files in the source tree. "Extra" files are files
bc36fdc… danield 1134 ** that are not officially part of the check-out. If one or more PATH
d7955bf… andygoth 1135 ** arguments appear, then only the files named, or files contained with
d7955bf… andygoth 1136 ** directories named, will be removed.
d7955bf… andygoth 1137 **
dd77130… andygoth 1138 ** If the --prompt option is used, prompts are issued to confirm the
dd77130… andygoth 1139 ** permanent removal of each file. Otherwise, files are backed up to the
dd77130… andygoth 1140 ** undo buffer prior to removal, and prompts are issued only for files
dd77130… andygoth 1141 ** whose removal cannot be undone due to their large size or due to
dd77130… andygoth 1142 ** --disable-undo being used.
c3b5f1d… jan.nijtmans 1143 **
dd77130… andygoth 1144 ** The --force option treats all prompts as having been answered yes,
dd77130… andygoth 1145 ** whereas --no-prompt treats them as having been answered no.
c3b5f1d… jan.nijtmans 1146 **
dd77130… andygoth 1147 ** Files matching any glob pattern specified by the --clean option are
dd77130… andygoth 1148 ** deleted without prompting, and the removal cannot be undone.
dd77130… andygoth 1149 **
dd77130… andygoth 1150 ** No file that matches glob patterns specified by --ignore or --keep will
dd77130… andygoth 1151 ** ever be deleted. Files and subdirectories whose names begin with "."
dd77130… andygoth 1152 ** are automatically ignored unless the --dotfiles option is used.
c3b5f1d… jan.nijtmans 1153 **
dd77130… andygoth 1154 ** The default values for --clean, --ignore, and --keep are determined by
dd77130… andygoth 1155 ** the (versionable) clean-glob, ignore-glob, and keep-glob settings.
d7955bf… andygoth 1156 **
d7955bf… andygoth 1157 ** The --verily option ignores the keep-glob and ignore-glob settings and
b727218… drh 1158 ** turns on --force, --emptydirs, --dotfiles, and --disable-undo. Use the
b727218… drh 1159 ** --verily option when you really want to clean up everything. Extreme
b727218… drh 1160 ** care should be exercised when using the --verily option.
2210be1… drh 1161 **
2210be1… drh 1162 ** Options:
bc36fdc… danield 1163 ** --allckouts Check for empty directories within any check-outs
e58c76a… drh 1164 ** that may be nested within the current one. This
e58c76a… drh 1165 ** option should be used with great care because the
e58c76a… drh 1166 ** empty-dirs setting (and other applicable settings)
e58c76a… drh 1167 ** belonging to the other repositories, if any, will
e58c76a… drh 1168 ** not be checked.
e58c76a… drh 1169 ** --case-sensitive BOOL Override case-sensitive setting
e58c76a… drh 1170 ** --dirsonly Only remove empty directories. No files will
e58c76a… drh 1171 ** be removed. Using this option will automatically
e58c76a… drh 1172 ** enable the --emptydirs option as well.
e58c76a… drh 1173 ** --disable-undo WARNING: This option disables use of the undo
e58c76a… drh 1174 ** mechanism for this clean operation and should be
e58c76a… drh 1175 ** used with extreme caution.
4cb50c4… stephan 1176 ** --dotfiles Include files beginning with a dot (".")
e58c76a… drh 1177 ** --emptydirs Remove any empty directories that are not
e58c76a… drh 1178 ** explicitly exempted via the empty-dirs setting
e58c76a… drh 1179 ** or another applicable setting or command line
e58c76a… drh 1180 ** argument. Matching files, if any, are removed
e58c76a… drh 1181 ** prior to checking for any empty directories;
e58c76a… drh 1182 ** therefore, directories that contain only files
e58c76a… drh 1183 ** that were removed will be removed as well.
4cb50c4… stephan 1184 ** -f|--force Remove files without prompting
e58c76a… drh 1185 ** -i|--prompt Prompt before removing each file. This option
e58c76a… drh 1186 ** implies the --disable-undo option.
e58c76a… drh 1187 ** -x|--verily WARNING: Removes everything that is not a managed
e58c76a… drh 1188 ** file or the repository itself. This option
e58c76a… drh 1189 ** implies the --force, --emptydirs, --dotfiles, and
e58c76a… drh 1190 ** --disable-undo options. Furthermore, it
e58c76a… drh 1191 ** completely disregards the keep-glob
e58c76a… drh 1192 ** and ignore-glob settings. However, it does honor
e58c76a… drh 1193 ** the --ignore and --keep options.
e58c76a… drh 1194 ** --clean CSG WARNING: Never prompt to delete any files matching
e58c76a… drh 1195 ** this comma separated list of glob patterns. Also,
e58c76a… drh 1196 ** deletions of any files matching this pattern list
e58c76a… drh 1197 ** cannot be undone.
e58c76a… drh 1198 ** --ignore CSG Ignore files matching patterns from the
4cb50c4… stephan 1199 ** comma separated list of glob patterns
e58c76a… drh 1200 ** --keep <CSG> Keep files matching this comma separated
4cb50c4… stephan 1201 ** list of glob patterns
e58c76a… drh 1202 ** -n|--dry-run Delete nothing, but display what would have been
4cb50c4… stephan 1203 ** deleted
4cb50c4… stephan 1204 ** --no-prompt Do not prompt the user for input and assume an
4cb50c4… stephan 1205 ** answer of 'No' for every question
4cb50c4… stephan 1206 ** --temp Remove only Fossil-generated temporary files
4cb50c4… stephan 1207 ** -v|--verbose Show all files as they are removed
2210be1… drh 1208 **
c965636… drh 1209 ** See also: [[addremove]], [[extras]], [[status]]
dbda8d6… drh 1210 */
c9fdb84… drh 1211 void clean_cmd(void){
238c8da… drh 1212 int allFileFlag, allDirFlag, dryRunFlag, verboseFlag;
238c8da… drh 1213 int emptyDirsFlag, dirsOnlyFlag;
1bf792e… drh 1214 int disableUndo, noPrompt;
c985d90… drh 1215 int alwaysPrompt = 0;
3206b64… drh 1216 unsigned scanFlags = 0;
c353ee8… drh 1217 int verilyFlag = 0;
b7afa97… mistachkin 1218 const char *zIgnoreFlag, *zKeepFlag, *zCleanFlag;
b7afa97… mistachkin 1219 Glob *pIgnore, *pKeep, *pClean;
39feb89… drh 1220 int nRoot;
67c9cd1… jan.nijtmans 1221
1bf792e… drh 1222 #ifndef UNDO_SIZE_LIMIT /* TODO: Setting? */
1bf792e… drh 1223 #define UNDO_SIZE_LIMIT (10*1024*1024) /* 10MiB */
1bf792e… drh 1224 #endif
1bf792e… drh 1225
1bf792e… drh 1226 undo_capture_command_line();
0b86639… jan.nijtmans 1227 dryRunFlag = find_option("dry-run","n",0)!=0;
0b86639… jan.nijtmans 1228 if( !dryRunFlag ){
0b86639… jan.nijtmans 1229 dryRunFlag = find_option("test",0,0)!=0; /* deprecated */
0b86639… jan.nijtmans 1230 }
d30e5a4… mistachkin 1231 if( !dryRunFlag ){
d30e5a4… mistachkin 1232 dryRunFlag = find_option("whatif",0,0)!=0;
d30e5a4… mistachkin 1233 }
1bf792e… drh 1234 disableUndo = find_option("disable-undo",0,0)!=0;
1bf792e… drh 1235 noPrompt = find_option("no-prompt",0,0)!=0;
c985d90… drh 1236 alwaysPrompt = find_option("prompt","i",0)!=0;
238c8da… drh 1237 allFileFlag = allDirFlag = find_option("force","f",0)!=0;
238c8da… drh 1238 dirsOnlyFlag = find_option("dirsonly",0,0)!=0;
f7c022c… mistachkin 1239 emptyDirsFlag = find_option("emptydirs","d",0)!=0 || dirsOnlyFlag;
67c9cd1… jan.nijtmans 1240 if( find_option("dotfiles",0,0)!=0 ) scanFlags |= SCAN_ALL;
67c9cd1… jan.nijtmans 1241 if( find_option("temp",0,0)!=0 ) scanFlags |= SCAN_TEMP;
238c8da… drh 1242 if( find_option("allckouts",0,0)!=0 ) scanFlags |= SCAN_NESTED;
67c9cd1… jan.nijtmans 1243 zIgnoreFlag = find_option("ignore",0,1);
67c9cd1… jan.nijtmans 1244 verboseFlag = find_option("verbose","v",0)!=0;
982f9ec… jan.nijtmans 1245 zKeepFlag = find_option("keep",0,1);
b7afa97… mistachkin 1246 zCleanFlag = find_option("clean",0,1);
dbda8d6… drh 1247 db_must_be_within_tree();
6262e63… jan.nijtmans 1248 if( find_option("verily","x",0)!=0 ){
c353ee8… drh 1249 verilyFlag = allFileFlag = allDirFlag = 1;
b5b62b3… drh 1250 emptyDirsFlag = 1;
1bf792e… drh 1251 disableUndo = 1;
b5b62b3… drh 1252 scanFlags |= SCAN_ALL;
c353ee8… drh 1253 zCleanFlag = 0;
b5b62b3… drh 1254 }
c353ee8… drh 1255 if( zIgnoreFlag==0 && !verilyFlag ){
f12a696… drh 1256 zIgnoreFlag = db_get("ignore-glob", 0);
f12a696… drh 1257 }
c353ee8… drh 1258 if( zKeepFlag==0 && !verilyFlag ){
982f9ec… jan.nijtmans 1259 zKeepFlag = db_get("keep-glob", 0);
982f9ec… jan.nijtmans 1260 }
c353ee8… drh 1261 if( zCleanFlag==0 && !verilyFlag ){
b7afa97… mistachkin 1262 zCleanFlag = db_get("clean-glob", 0);
b7afa97… mistachkin 1263 }
e1e0ec5… drh 1264 if( db_get_boolean("dotfiles", 0) ) scanFlags |= SCAN_ALL;
273ec22… drh 1265 verify_all_options();
982f9ec… jan.nijtmans 1266 pIgnore = glob_create(zIgnoreFlag);
982f9ec… jan.nijtmans 1267 pKeep = glob_create(zKeepFlag);
b7afa97… mistachkin 1268 pClean = glob_create(zCleanFlag);
39feb89… drh 1269 nRoot = (int)strlen(g.zLocalRoot);
238c8da… drh 1270 if( !dirsOnlyFlag ){
238c8da… drh 1271 Stmt q;
238c8da… drh 1272 Blob repo;
1bf792e… drh 1273 if( !dryRunFlag && !disableUndo ) undo_begin();
e776494… andygoth 1274 locate_unmanaged_files(g.argc-2, g.argv+2, scanFlags, pIgnore);
238c8da… drh 1275 db_prepare(&q,
e776494… andygoth 1276 "SELECT %Q || pathname FROM sfile"
e776494… andygoth 1277 " WHERE pathname NOT IN (%s)"
238c8da… drh 1278 " ORDER BY 1",
238c8da… drh 1279 g.zLocalRoot, fossil_all_reserved_names(0)
238c8da… drh 1280 );
c56a387… mistachkin 1281 if( file_tree_name(g.zRepositoryName, &repo, 0, 0) ){
e776494… andygoth 1282 db_multi_exec("DELETE FROM sfile WHERE pathname=%B", &repo);
238c8da… drh 1283 }
e776494… andygoth 1284 db_multi_exec("DELETE FROM sfile WHERE pathname IN"
e776494… andygoth 1285 " (SELECT pathname FROM vfile)");
238c8da… drh 1286 while( db_step(&q)==SQLITE_ROW ){
238c8da… drh 1287 const char *zName = db_column_text(&q, 0);
389d0d7… jan.nijtmans 1288 if( glob_match(pKeep, zName+nRoot) ){
389d0d7… jan.nijtmans 1289 if( verboseFlag ){
389d0d7… jan.nijtmans 1290 fossil_print("KEPT file \"%s\" not removed (due to --keep"
389d0d7… jan.nijtmans 1291 " or \"keep-glob\")\n", zName+nRoot);
389d0d7… jan.nijtmans 1292 }
389d0d7… jan.nijtmans 1293 continue;
389d0d7… jan.nijtmans 1294 }
1bf792e… drh 1295 if( !dryRunFlag && !glob_match(pClean, zName+nRoot) ){
c985d90… drh 1296 char *zPrompt = 0;
c985d90… drh 1297 char cReply;
c985d90… drh 1298 Blob ans = empty_blob;
1bf792e… drh 1299 int undoRc = UNDO_NONE;
c985d90… drh 1300 if( alwaysPrompt ){
c985d90… drh 1301 zPrompt = mprintf("Remove unmanaged file \"%s\" (a=all/y/N)? ",
c985d90… drh 1302 zName+nRoot);
c985d90… drh 1303 prompt_user(zPrompt, &ans);
c985d90… drh 1304 fossil_free(zPrompt);
c985d90… drh 1305 cReply = fossil_toupper(blob_str(&ans)[0]);
c985d90… drh 1306 blob_reset(&ans);
c985d90… drh 1307 if( cReply=='N' ) continue;
c985d90… drh 1308 if( cReply=='A' ){
c985d90… drh 1309 allFileFlag = 1;
c985d90… drh 1310 alwaysPrompt = 0;
c985d90… drh 1311 }else{
c985d90… drh 1312 undoRc = UNDO_SAVED_OK;
c985d90… drh 1313 }
c985d90… drh 1314 }else if( !disableUndo ){
1bf792e… drh 1315 undoRc = undo_maybe_save(zName+nRoot, UNDO_SIZE_LIMIT);
1bf792e… drh 1316 }
1bf792e… drh 1317 if( undoRc!=UNDO_SAVED_OK ){
1bf792e… drh 1318 if( allFileFlag ){
1bf792e… drh 1319 cReply = 'Y';
1bf792e… drh 1320 }else if( !noPrompt ){
1bf792e… drh 1321 Blob ans;
c985d90… drh 1322 zPrompt = mprintf("\nWARNING: Deletion of this file will "
c985d90… drh 1323 "not be undoable via the 'undo'\n"
c985d90… drh 1324 " command because %s.\n\n"
c985d90… drh 1325 "Remove unmanaged file \"%s\" (a=all/y/N)? ",
c985d90… drh 1326 undo_save_message(undoRc), zName+nRoot);
c985d90… drh 1327 prompt_user(zPrompt, &ans);
c985d90… drh 1328 fossil_free(zPrompt);
1bf792e… drh 1329 cReply = blob_str(&ans)[0];
1bf792e… drh 1330 blob_reset(&ans);
1bf792e… drh 1331 }else{
1bf792e… drh 1332 cReply = 'N';
1bf792e… drh 1333 }
1bf792e… drh 1334 if( cReply=='a' || cReply=='A' ){
1bf792e… drh 1335 allFileFlag = 1;
1bf792e… drh 1336 }else if( cReply!='y' && cReply!='Y' ){
1bf792e… drh 1337 continue;
1bf792e… drh 1338 }
1bf792e… drh 1339 }
7d257de… mistachkin 1340 }
7d257de… mistachkin 1341 if( dryRunFlag || file_delete(zName)==0 ){
238c8da… drh 1342 if( verboseFlag || dryRunFlag ){
238c8da… drh 1343 fossil_print("Removed unmanaged file: %s\n", zName+nRoot);
238c8da… drh 1344 }
c985d90… drh 1345 }else{
238c8da… drh 1346 fossil_print("Could not remove file: %s\n", zName+nRoot);
238c8da… drh 1347 }
238c8da… drh 1348 }
238c8da… drh 1349 db_finalize(&q);
1bf792e… drh 1350 if( !dryRunFlag && !disableUndo ) undo_finish();
238c8da… drh 1351 }
238c8da… drh 1352 if( emptyDirsFlag ){
238c8da… drh 1353 Glob *pEmptyDirs = glob_create(db_get("empty-dirs", 0));
238c8da… drh 1354 Stmt q;
238c8da… drh 1355 Blob root;
238c8da… drh 1356 blob_init(&root, g.zLocalRoot, nRoot - 1);
389d0d7… jan.nijtmans 1357 vfile_dir_scan(&root, blob_size(&root), scanFlags, pIgnore,
a3bc655… drh 1358 pEmptyDirs, RepoFILE);
238c8da… drh 1359 blob_reset(&root);
238c8da… drh 1360 db_prepare(&q,
238c8da… drh 1361 "SELECT %Q || x FROM dscan_temp"
238c8da… drh 1362 " WHERE x NOT IN (%s) AND y = 0"
238c8da… drh 1363 " ORDER BY 1 DESC",
238c8da… drh 1364 g.zLocalRoot, fossil_all_reserved_names(0)
238c8da… drh 1365 );
238c8da… drh 1366 while( db_step(&q)==SQLITE_ROW ){
238c8da… drh 1367 const char *zName = db_column_text(&q, 0);
389d0d7… jan.nijtmans 1368 if( glob_match(pKeep, zName+nRoot) ){
389d0d7… jan.nijtmans 1369 if( verboseFlag ){
389d0d7… jan.nijtmans 1370 fossil_print("KEPT directory \"%s\" not removed (due to --keep"
389d0d7… jan.nijtmans 1371 " or \"keep-glob\")\n", zName+nRoot);
389d0d7… jan.nijtmans 1372 }
389d0d7… jan.nijtmans 1373 continue;
389d0d7… jan.nijtmans 1374 }
238c8da… drh 1375 if( !allDirFlag && !dryRunFlag && !glob_match(pClean, zName+nRoot) ){
238c8da… drh 1376 char cReply;
1bf792e… drh 1377 if( !noPrompt ){
1bf792e… drh 1378 Blob ans;
1bf792e… drh 1379 char *prompt = mprintf("Remove empty directory \"%s\" (a=all/y/N)? ",
1bf792e… drh 1380 zName+nRoot);
1bf792e… drh 1381 prompt_user(prompt, &ans);
1bf792e… drh 1382 cReply = blob_str(&ans)[0];
c985d90… drh 1383 fossil_free(prompt);
1bf792e… drh 1384 blob_reset(&ans);
1bf792e… drh 1385 }else{
1bf792e… drh 1386 cReply = 'N';
1bf792e… drh 1387 }
238c8da… drh 1388 if( cReply=='a' || cReply=='A' ){
238c8da… drh 1389 allDirFlag = 1;
238c8da… drh 1390 }else if( cReply!='y' && cReply!='Y' ){
238c8da… drh 1391 continue;
238c8da… drh 1392 }
238c8da… drh 1393 }
7d257de… mistachkin 1394 if( dryRunFlag || file_rmdir(zName)==0 ){
238c8da… drh 1395 if( verboseFlag || dryRunFlag ){
238c8da… drh 1396 fossil_print("Removed unmanaged directory: %s\n", zName+nRoot);
238c8da… drh 1397 }
238c8da… drh 1398 }else if( verboseFlag ){
238c8da… drh 1399 fossil_print("Could not remove directory: %s\n", zName+nRoot);
238c8da… drh 1400 }
238c8da… drh 1401 }
238c8da… drh 1402 db_finalize(&q);
238c8da… drh 1403 glob_free(pEmptyDirs);
b7afa97… mistachkin 1404 }
b7afa97… mistachkin 1405 glob_free(pClean);
238c8da… drh 1406 glob_free(pKeep);
238c8da… drh 1407 glob_free(pIgnore);
16371dc… drh 1408 }
16371dc… drh 1409
16371dc… drh 1410 /*
16371dc… drh 1411 ** Prompt the user for a check-in or stash comment (given in pPrompt),
16371dc… drh 1412 ** gather the response, then return the response in pComment.
16371dc… drh 1413 **
16371dc… drh 1414 ** Lines of the prompt that begin with # are discarded. Excess whitespace
16371dc… drh 1415 ** is removed from the reply.
16371dc… drh 1416 **
16371dc… drh 1417 ** Appropriate encoding translations are made on windows.
16371dc… drh 1418 */
16371dc… drh 1419 void prompt_for_user_comment(Blob *pComment, Blob *pPrompt){
16371dc… drh 1420 const char *zEditor;
16371dc… drh 1421 char *zCmd;
16371dc… drh 1422 char *zFile;
16371dc… drh 1423 Blob reply, line;
16371dc… drh 1424 char *zComment;
16371dc… drh 1425 int i;
16371dc… drh 1426
f2fcdbc… drh 1427 zEditor = fossil_text_editor();
5200323… drh 1428 if( zEditor==0 ){
5200323… drh 1429 if( blob_size(pPrompt)>0 ){
5200323… drh 1430 blob_append(pPrompt,
5200323… drh 1431 "#\n"
5200323… drh 1432 "# Since no default text editor is set using EDITOR or VISUAL\n"
5200323… drh 1433 "# environment variables or the \"fossil set editor\" command,\n"
5200323… drh 1434 "# and because no comment was specified using the \"-m\" or \"-M\"\n"
5200323… drh 1435 "# command-line options, you will need to enter the comment below.\n"
5200323… drh 1436 "# Type \".\" on a line by itself when you are done:\n", -1);
5200323… drh 1437 }
16371dc… drh 1438 zFile = mprintf("-");
16371dc… drh 1439 }else{
3cadf76… jan.nijtmans 1440 Blob fname;
3cadf76… jan.nijtmans 1441 blob_zero(&fname);
1fff403… andybradford 1442 if( g.zLocalRoot!=0 ){
1fff403… andybradford 1443 file_relative_name(g.zLocalRoot, &fname, 1);
1fff403… andybradford 1444 zFile = db_text(0, "SELECT '%qci-comment-'||hex(randomblob(6))||'.txt'",
1fff403… andybradford 1445 blob_str(&fname));
1fff403… andybradford 1446 }else{
1dd2527… drh 1447 file_tempname(&fname, "ci-comment",0);
4c3e172… danield 1448 zFile = fossil_strdup(blob_str(&fname));
1fff403… andybradford 1449 }
3cadf76… jan.nijtmans 1450 blob_reset(&fname);
16371dc… drh 1451 }
16371dc… drh 1452 #if defined(_WIN32)
16371dc… drh 1453 blob_add_cr(pPrompt);
16371dc… drh 1454 #endif
5200323… drh 1455 if( blob_size(pPrompt)>0 ) blob_write_to_file(pPrompt, zFile);
16371dc… drh 1456 if( zEditor ){
4eca7eb… drh 1457 char *z, *zEnd;
2209f55… drh 1458 zCmd = mprintf("%s %$", zEditor, zFile);
16371dc… drh 1459 fossil_print("%s\n", zCmd);
16371dc… drh 1460 if( fossil_system(zCmd) ){
16371dc… drh 1461 fossil_fatal("editor aborted: \"%s\"", zCmd);
16371dc… drh 1462 }
1772357… drh 1463 blob_read_from_file(&reply, zFile, ExtFILE);
4eca7eb… drh 1464 z = blob_str(&reply);
4eca7eb… drh 1465 zEnd = strstr(z, "##########");
4eca7eb… drh 1466 if( zEnd ){
4eca7eb… drh 1467 /* Truncate the reply at any sequence of 10 or more # characters.
4eca7eb… drh 1468 ** The diff for the -v option occurs after such a sequence. */
4eca7eb… drh 1469 blob_resize(&reply, (int)(zEnd - z));
4eca7eb… drh 1470 }
16371dc… drh 1471 }else{
16371dc… drh 1472 char zIn[300];
16371dc… drh 1473 blob_zero(&reply);
16371dc… drh 1474 while( fgets(zIn, sizeof(zIn), stdin)!=0 ){
cc01ec5… drh 1475 if( zIn[0]=='.' && (zIn[1]==0 || zIn[1]=='\r' || zIn[1]=='\n') ){
16371dc… drh 1476 break;
16371dc… drh 1477 }
cc01ec5… drh 1478 blob_append(&reply, zIn, -1);
16371dc… drh 1479 }
16371dc… drh 1480 }
9b800ee… mistachkin 1481 blob_to_utf8_no_bom(&reply, 1);
757585f… mistachkin 1482 blob_to_lf_only(&reply);
16371dc… drh 1483 file_delete(zFile);
16371dc… drh 1484 free(zFile);
16371dc… drh 1485 blob_zero(pComment);
16371dc… drh 1486 while( blob_line(&reply, &line) ){
16371dc… drh 1487 int i, n;
16371dc… drh 1488 char *z;
16371dc… drh 1489 n = blob_size(&line);
16371dc… drh 1490 z = blob_buffer(&line);
16371dc… drh 1491 for(i=0; i<n && fossil_isspace(z[i]); i++){}
16371dc… drh 1492 if( i<n && z[i]=='#' ) continue;
16371dc… drh 1493 if( i<n || blob_size(pComment)>0 ){
16371dc… drh 1494 blob_appendf(pComment, "%b", &line);
d0305b3… aku 1495 }
d0305b3… aku 1496 }
16371dc… drh 1497 blob_reset(&reply);
16371dc… drh 1498 zComment = blob_str(pComment);
16371dc… drh 1499 i = strlen(zComment);
16371dc… drh 1500 while( i>0 && fossil_isspace(zComment[i-1]) ){ i--; }
16371dc… drh 1501 blob_resize(pComment, i);
dbda8d6… drh 1502 }
dbda8d6… drh 1503
dbda8d6… drh 1504 /*
dbda8d6… drh 1505 ** Prepare a commit comment. Let the user modify it using the
dbda8d6… drh 1506 ** editor specified in the global_config table or either
dbda8d6… drh 1507 ** the VISUAL or EDITOR environment variable.
dbda8d6… drh 1508 **
dbda8d6… drh 1509 ** Store the final commit comment in pComment. pComment is assumed
dbda8d6… drh 1510 ** to be uninitialized - any prior content is overwritten.
6df39e3… drh 1511 **
6df39e3… drh 1512 ** zInit is the text of the most recent failed attempt to check in
6df39e3… drh 1513 ** this same change. Use zInit to reinitialize the check-in comment
6df39e3… drh 1514 ** so that the user does not have to retype.
6df39e3… drh 1515 **
6df39e3… drh 1516 ** zBranch is the name of a new branch that this check-in is forced into.
6df39e3… drh 1517 ** zBranch might be NULL or an empty string if no forcing occurs.
6df39e3… drh 1518 **
6df39e3… drh 1519 ** parent_rid is the recordid of the parent check-in.
02a584f… drh 1520 */
6df39e3… drh 1521 static void prepare_commit_comment(
6df39e3… drh 1522 Blob *pComment,
6df39e3… drh 1523 char *zInit,
4dcea80… drh 1524 CheckinInfo *p,
4eca7eb… drh 1525 int parent_rid,
4eca7eb… drh 1526 int dryRunFlag
6df39e3… drh 1527 ){
16371dc… drh 1528 Blob prompt;
d62ca2b… drh 1529 int wikiFlags;
3e90ef6… jan.nijtmans 1530 #if defined(_WIN32) || defined(__CYGWIN__)
9b800ee… mistachkin 1531 int bomSize;
9b800ee… mistachkin 1532 const unsigned char *bom = get_utf8_bom(&bomSize);
9b800ee… mistachkin 1533 blob_init(&prompt, (const char *) bom, bomSize);
7d257de… mistachkin 1534 if( zInit && zInit[0]){
cc01ec5… drh 1535 blob_append(&prompt, zInit, -1);
cc01ec5… drh 1536 }
cc01ec5… drh 1537 #else
16371dc… drh 1538 blob_init(&prompt, zInit, -1);
cc01ec5… drh 1539 #endif
16371dc… drh 1540 blob_append(&prompt,
02a584f… drh 1541 "\n"
d62ca2b… drh 1542 "# Enter the commit message. Formatting rules:\n"
d62ca2b… drh 1543 "# * Lines beginning with # are ignored.\n",
d62ca2b… drh 1544 -1
02a584f… drh 1545 );
d62ca2b… drh 1546 wikiFlags = wiki_convert_flags(1);
d62ca2b… drh 1547 if( wikiFlags & WIKI_LINKSONLY ){
d62ca2b… drh 1548 blob_append(&prompt,"# * Hyperlinks inside of [...]\n", -1);
d62ca2b… drh 1549 if( wikiFlags & WIKI_NEWLINE ){
d62ca2b… drh 1550 blob_append(&prompt,
d62ca2b… drh 1551 "# * Newlines are significant and are displayed as written\n", -1);
d62ca2b… drh 1552 }else{
d62ca2b… drh 1553 blob_append(&prompt,
d62ca2b… drh 1554 "# * Newlines are interpreted as ordinary spaces\n",
d62ca2b… drh 1555 -1
d62ca2b… drh 1556 );
d62ca2b… drh 1557 }
d62ca2b… drh 1558 blob_append(&prompt,
d62ca2b… drh 1559 "# * All other text will be displayed as written\n", -1);
d62ca2b… drh 1560 }else{
d62ca2b… drh 1561 blob_append(&prompt,
d62ca2b… drh 1562 "# * Hyperlinks: [target] or [target|display-text]\n"
d62ca2b… drh 1563 "# * Blank lines cause a paragraph break\n"
0d94d71… wyoung 1564 "# * Other text rendered as if it were HTML\n", -1
d62ca2b… drh 1565 );
d62ca2b… drh 1566 }
d62ca2b… drh 1567 blob_append(&prompt, "#\n", 2);
d62ca2b… drh 1568
4eca7eb… drh 1569 if( dryRunFlag ){
4eca7eb… drh 1570 blob_appendf(&prompt, "# DRY-RUN: This is a test commit. No changes "
4eca7eb… drh 1571 "will be made to the repository\n#\n");
4eca7eb… drh 1572 }
0b3f184… drh 1573 blob_appendf(&prompt, "# user: %s\n",
0b3f184… drh 1574 p->zUserOvrd ? p->zUserOvrd : login_name());
4dcea80… drh 1575 if( p->zBranch && p->zBranch[0] ){
4dcea80… drh 1576 blob_appendf(&prompt, "# tags: %s\n#\n", p->zBranch);
6df39e3… drh 1577 }else{
4943c0e… drh 1578 char *zTags = info_tags_of_checkin(parent_rid, 1);
ae00c63… stephan 1579 if( zTags || p->azTag ){
ae00c63… stephan 1580 blob_append(&prompt, "# tags: ", 8);
ae00c63… stephan 1581 if(zTags){
ae00c63… stephan 1582 blob_appendf(&prompt, "%z%s", zTags, p->azTag ? ", " : "");
ae00c63… stephan 1583 }
ae00c63… stephan 1584 if(p->azTag){
ae00c63… stephan 1585 int i = 0;
ae00c63… stephan 1586 for( ; p->azTag[i]; ++i ){
ae00c63… stephan 1587 blob_appendf(&prompt, "%s%s", p->azTag[i],
ae00c63… stephan 1588 p->azTag[i+1] ? ", " : "");
ae00c63… stephan 1589 }
ae00c63… stephan 1590 }
ae00c63… stephan 1591 blob_appendf(&prompt, "\n#\n");
ae00c63… stephan 1592 }
6df39e3… drh 1593 }
e776494… andygoth 1594 status_report(&prompt, C_DEFAULT | C_FATAL | C_COMMENT);
02a584f… drh 1595 if( g.markPrivate ){
16371dc… drh 1596 blob_append(&prompt,
02a584f… drh 1597 "# PRIVATE BRANCH: This check-in will be private and will not sync to\n"
02a584f… drh 1598 "# repositories.\n"
02a584f… drh 1599 "#\n", -1
02a584f… drh 1600 );
02a584f… drh 1601 }
82f69aa… drh 1602 if( p->integrateFlag ){
82f69aa… drh 1603 blob_append(&prompt,
82f69aa… drh 1604 "#\n"
82f69aa… drh 1605 "# All merged-in branches will be closed due to the --integrate flag\n"
82f69aa… drh 1606 "#\n", -1
82f69aa… drh 1607 );
82f69aa… drh 1608 }
7ee98fe… drh 1609 if( p->verboseFlag ){
1347a1d… drh 1610 DiffConfig DCfg;
4eca7eb… drh 1611 blob_appendf(&prompt,
4eca7eb… drh 1612 "#\n%.78c\n"
4eca7eb… drh 1613 "# The following diff is excluded from the commit message:\n#\n",
4eca7eb… drh 1614 '#'
7ee98fe… drh 1615 );
346de5d… drh 1616 diff_options(&DCfg, 0, 1);
346de5d… drh 1617 DCfg.diffFlags |= DIFF_VERBOSE;
7ee98fe… drh 1618 if( g.aCommitFile ){
caa6ad3… drh 1619 Stmt q;
caa6ad3… drh 1620 Blob sql = BLOB_INITIALIZER;
7ee98fe… drh 1621 FileDirList *diffFiles;
7ee98fe… drh 1622 int i;
bd7f272… danield 1623 for(i=0; g.aCommitFile[i]!=0; ++i){}
bd7f272… danield 1624 diffFiles = fossil_malloc_zero((i+1) * sizeof(*diffFiles));
bd7f272… danield 1625 for(i=0; g.aCommitFile[i]!=0; ++i){
caa6ad3… drh 1626 blob_append_sql(&sql,
77e1f86… stephan 1627 "SELECT pathname, deleted, rid "
77e1f86… stephan 1628 "FROM vfile WHERE id=%d",
caa6ad3… drh 1629 g.aCommitFile[i]);
caa6ad3… drh 1630 db_prepare(&q, "%s", blob_sql_text(&sql));
caa6ad3… drh 1631 blob_reset(&sql);
caa6ad3… drh 1632 assert( db_step(&q)==SQLITE_ROW );
caa6ad3… drh 1633 diffFiles[i].zName = fossil_strdup(db_column_text(&q, 0));
caa6ad3… drh 1634 DCfg.diffFlags &= (~DIFF_FILE_MASK);
caa6ad3… drh 1635 if( db_column_int(&q, 1) ){
caa6ad3… drh 1636 DCfg.diffFlags |= DIFF_FILE_DELETED;
caa6ad3… drh 1637 }else if( db_column_int(&q, 2)==0 ){
caa6ad3… drh 1638 DCfg.diffFlags |= DIFF_FILE_ADDED;
caa6ad3… drh 1639 }
caa6ad3… drh 1640 db_finalize(&q);
7ee98fe… drh 1641 if( fossil_strcmp(diffFiles[i].zName, "." )==0 ){
7ee98fe… drh 1642 diffFiles[0].zName[0] = '.';
7ee98fe… drh 1643 diffFiles[0].zName[1] = 0;
7ee98fe… drh 1644 break;
7ee98fe… drh 1645 }
7ee98fe… drh 1646 diffFiles[i].nName = strlen(diffFiles[i].zName);
7ee98fe… drh 1647 diffFiles[i].nUsed = 0;
7ee98fe… drh 1648 }
99d0baa… drh 1649 diff_version_to_checkout(0, &DCfg, diffFiles, &prompt);
7ee98fe… drh 1650 for( i=0; diffFiles[i].zName; ++i ){
7ee98fe… drh 1651 fossil_free(diffFiles[i].zName);
7ee98fe… drh 1652 }
7ee98fe… drh 1653 fossil_free(diffFiles);
7ee98fe… drh 1654 }else{
99d0baa… drh 1655 diff_version_to_checkout(0, &DCfg, 0, &prompt);
7ee98fe… drh 1656 }
7ee98fe… drh 1657 }
16371dc… drh 1658 prompt_for_user_comment(pComment, &prompt);
16371dc… drh 1659 blob_reset(&prompt);
16371dc… drh 1660 }
9d8db79… drh 1661
9d8db79… drh 1662 /*
9d8db79… drh 1663 ** Prepare text that describes a pending commit and write it into
9d8db79… drh 1664 ** a file at the root of the check-in. Return the name of that file.
9d8db79… drh 1665 **
9d8db79… drh 1666 ** Space to hold the returned filename is obtained from fossil_malloc()
9d8db79… drh 1667 ** and should be freed by the caller. The caller should also unlink
9d8db79… drh 1668 ** the file when it is done.
9d8db79… drh 1669 */
9d8db79… drh 1670 static char *prepare_commit_description_file(
9d8db79… drh 1671 CheckinInfo *p, /* Information about this commit */
4ff4e1c… drh 1672 int parent_rid, /* parent check-in */
4ff4e1c… drh 1673 Blob *pComment, /* Check-in comment */
4ff4e1c… drh 1674 int dryRunFlag /* True for a dry-run only */
9d8db79… drh 1675 ){
9d8db79… drh 1676 Blob *pDesc;
9d8db79… drh 1677 char *zTags;
9d8db79… drh 1678 char *zFilename;
ca0d66b… danield 1679 const char *zMainBranch = db_main_branch();
9d8db79… drh 1680 Blob desc;
9d8db79… drh 1681 blob_init(&desc, 0, 0);
9d8db79… drh 1682 pDesc = &desc;
9d8db79… drh 1683 blob_appendf(pDesc, "checkout %s\n", g.zLocalRoot);
9d8db79… drh 1684 blob_appendf(pDesc, "repository %s\n", g.zRepositoryName);
9d8db79… drh 1685 blob_appendf(pDesc, "user %s\n",
9d8db79… drh 1686 p->zUserOvrd ? p->zUserOvrd : login_name());
9d8db79… drh 1687 blob_appendf(pDesc, "branch %s\n",
3a6dd83… drh 1688 (p->zBranch && p->zBranch[0]) ? p->zBranch : zMainBranch);
9d8db79… drh 1689 zTags = info_tags_of_checkin(parent_rid, 1);
9d8db79… drh 1690 if( zTags || p->azTag ){
9d8db79… drh 1691 blob_append(pDesc, "tags ", -1);
9d8db79… drh 1692 if(zTags){
9d8db79… drh 1693 blob_appendf(pDesc, "%z%s", zTags, p->azTag ? ", " : "");
9d8db79… drh 1694 }
9d8db79… drh 1695 if(p->azTag){
9d8db79… drh 1696 int i = 0;
9d8db79… drh 1697 for( ; p->azTag[i]; ++i ){
9d8db79… drh 1698 blob_appendf(pDesc, "%s%s", p->azTag[i],
9d8db79… drh 1699 p->azTag[i+1] ? ", " : "");
9d8db79… drh 1700 }
9d8db79… drh 1701 }
9d8db79… drh 1702 blob_appendf(pDesc, "\n");
9d8db79… drh 1703 }
9d8db79… drh 1704 status_report(pDesc, C_DEFAULT | C_FATAL);
9d8db79… drh 1705 if( g.markPrivate ){
9d8db79… drh 1706 blob_append(pDesc, "private-branch\n", -1);
9d8db79… drh 1707 }
9d8db79… drh 1708 if( p->integrateFlag ){
9d8db79… drh 1709 blob_append(pDesc, "integrate\n", -1);
9d8db79… drh 1710 }
4ff4e1c… drh 1711 if( pComment && blob_size(pComment)>0 ){
4ff4e1c… drh 1712 blob_appendf(pDesc, "checkin-comment\n%s\n", blob_str(pComment));
4ff4e1c… drh 1713 }
4ff4e1c… drh 1714 if( dryRunFlag ){
4ff4e1c… drh 1715 zFilename = 0;
4ff4e1c… drh 1716 fossil_print("******* Commit Description *******\n%s"
4ff4e1c… drh 1717 "***** End Commit Description *****\n",
4ff4e1c… drh 1718 blob_str(pDesc));
4ff4e1c… drh 1719 }else{
4ff4e1c… drh 1720 unsigned int r[2];
4ff4e1c… drh 1721 sqlite3_randomness(sizeof(r), r);
4ff4e1c… drh 1722 zFilename = mprintf("%scommit-description-%08x%08x.txt",
4ff4e1c… drh 1723 g.zLocalRoot, r[0], r[1]);
4ff4e1c… drh 1724 blob_write_to_file(pDesc, zFilename);
4ff4e1c… drh 1725 }
9d8db79… drh 1726 blob_reset(pDesc);
9d8db79… drh 1727 return zFilename;
9d8db79… drh 1728 }
9d8db79… drh 1729
22552fb… dan 1730
22552fb… dan 1731 /*
22552fb… dan 1732 ** Populate the Global.aCommitFile[] based on the command line arguments
22552fb… dan 1733 ** to a [commit] command. Global.aCommitFile is an array of integers
22552fb… dan 1734 ** sized at (N+1), where N is the number of arguments passed to [commit].
22552fb… dan 1735 ** The contents are the [id] values from the vfile table corresponding
22552fb… dan 1736 ** to the filenames passed as arguments.
22552fb… dan 1737 **
22552fb… dan 1738 ** The last element of aCommitFile[] is always 0 - indicating the end
22552fb… dan 1739 ** of the array.
22552fb… dan 1740 **
22552fb… dan 1741 ** If there were no arguments passed to [commit], aCommitFile is not
22552fb… dan 1742 ** allocated and remains NULL. Other parts of the code interpret this
22552fb… dan 1743 ** to mean "all files".
c31bbd4… jan.nijtmans 1744 **
c31bbd4… jan.nijtmans 1745 ** Returns 1 if there was a warning, 0 otherwise.
16e703b… drh 1746 */
c31bbd4… jan.nijtmans 1747 int select_commit_files(void){
c31bbd4… jan.nijtmans 1748 int result = 0;
c8253f4… drh 1749 assert( g.aCommitFile==0 );
16e703b… drh 1750 if( g.argc>2 ){
7a8808b… jan.nijtmans 1751 int ii, jj=0;
c8253f4… drh 1752 Blob fname;
c8253f4… drh 1753 Stmt q;
c8253f4… drh 1754 Bag toCommit;
16e703b… drh 1755
c8253f4… drh 1756 blob_zero(&fname);
c8253f4… drh 1757 bag_init(&toCommit);
16e703b… drh 1758 for(ii=2; ii<g.argc; ii++){
c8253f4… drh 1759 int cnt = 0;
c56a387… mistachkin 1760 file_tree_name(g.argv[ii], &fname, 0, 1);
c8253f4… drh 1761 if( fossil_strcmp(blob_str(&fname),".")==0 ){
c8253f4… drh 1762 bag_clear(&toCommit);
c8253f4… drh 1763 return result;
c8253f4… drh 1764 }
062b82c… jan.nijtmans 1765 db_prepare(&q,
062b82c… jan.nijtmans 1766 "SELECT id FROM vfile WHERE pathname=%Q %s"
062b82c… jan.nijtmans 1767 " OR (pathname>'%q/' %s AND pathname<'%q0' %s)",
49b0ff1… drh 1768 blob_str(&fname), filename_collation(), blob_str(&fname),
49b0ff1… drh 1769 filename_collation(), blob_str(&fname), filename_collation());
c8253f4… drh 1770 while( db_step(&q)==SQLITE_ROW ){
c8253f4… drh 1771 cnt++;
c8253f4… drh 1772 bag_insert(&toCommit, db_column_int(&q, 0));
c8253f4… drh 1773 }
c8253f4… drh 1774 db_finalize(&q);
c8253f4… drh 1775 if( cnt==0 ){
7a8808b… jan.nijtmans 1776 fossil_warning("fossil knows nothing about: %s", g.argv[ii]);
c31bbd4… jan.nijtmans 1777 result = 1;
7a8808b… jan.nijtmans 1778 }
c8253f4… drh 1779 blob_reset(&fname);
c8253f4… drh 1780 }
0b3f184… drh 1781 g.aCommitFile = fossil_malloc( (bag_count(&toCommit)+1) *
0b3f184… drh 1782 sizeof(g.aCommitFile[0]) );
c8253f4… drh 1783 for(ii=bag_first(&toCommit); ii>0; ii=bag_next(&toCommit, ii)){
c8253f4… drh 1784 g.aCommitFile[jj++] = ii;
7a8808b… jan.nijtmans 1785 }
7a8808b… jan.nijtmans 1786 g.aCommitFile[jj] = 0;
c8253f4… drh 1787 bag_clear(&toCommit);
7a8808b… jan.nijtmans 1788 }
c31bbd4… jan.nijtmans 1789 return result;
c8253f4… drh 1790 }
c8253f4… drh 1791
c8253f4… drh 1792 /*
bc36fdc… danield 1793 ** Returns true if the check-in identified by the first parameter is
1243bf3… stephan 1794 ** older than the given (valid) date/time string, else returns false.
bc36fdc… danield 1795 ** Also returns true if rid does not refer to a check-in, but it is not
1243bf3… stephan 1796 ** intended to be used for that case.
1243bf3… stephan 1797 */
1243bf3… stephan 1798 int checkin_is_younger(
1243bf3… stephan 1799 int rid, /* The record ID of the ancestor */
1243bf3… stephan 1800 const char *zDate /* Date & time of the current check-in */
1243bf3… stephan 1801 ){
1243bf3… stephan 1802 return db_exists(
1243bf3… stephan 1803 "SELECT 1 FROM event"
1243bf3… stephan 1804 " WHERE datetime(mtime)>=%Q"
1243bf3… stephan 1805 " AND type='ci' AND objid=%d",
1243bf3… stephan 1806 zDate, rid
1243bf3… stephan 1807 ) ? 0 : 1;
1243bf3… stephan 1808 }
1243bf3… stephan 1809
1243bf3… stephan 1810 /*
16e703b… drh 1811 ** Make sure the current check-in with timestamp zDate is younger than its
16e703b… drh 1812 ** ancestor identified rid and zUuid. Throw a fatal error if not.
16e703b… drh 1813 */
16e703b… drh 1814 static void checkin_verify_younger(
16e703b… drh 1815 int rid, /* The record ID of the ancestor */
8ad5e46… wyoung 1816 const char *zUuid, /* The artifact hash of the ancestor */
16e703b… drh 1817 const char *zDate /* Date & time of the current check-in */
16e703b… drh 1818 ){
b9d3b42… drh 1819 #ifndef FOSSIL_ALLOW_OUT_OF_ORDER_DATES
1243bf3… stephan 1820 if(checkin_is_younger(rid,zDate)==0){
fe6d393… jan.nijtmans 1821 fossil_fatal("ancestor check-in [%S] (%s) is not older (clock skew?)"
5e83504… mistachkin 1822 " Use --allow-older to override.", zUuid, zDate);
e024877… drh 1823 }
e024877… drh 1824 #endif
e024877… drh 1825 }
1243bf3… stephan 1826
1243bf3… stephan 1827
d503cfd… jan.nijtmans 1828
e024877… drh 1829 /*
e024877… drh 1830 ** zDate should be a valid date string. Convert this string into the
d503cfd… jan.nijtmans 1831 ** format YYYY-MM-DDTHH:MM:SS. If the string is not a valid date,
e024877… drh 1832 ** print a fatal error and quit.
e024877… drh 1833 */
e024877… drh 1834 char *date_in_standard_format(const char *zInputDate){
722d7ca… drh 1835 char *zDate;
44f028c… drh 1836 if( g.perm.Setup && fossil_strcmp(zInputDate,"now")==0 ){
44f028c… drh 1837 zInputDate = PD("date_override","now");
44f028c… drh 1838 }
722d7ca… drh 1839 zDate = db_text(0, "SELECT strftime('%%Y-%%m-%%dT%%H:%%M:%%f',%Q)",
722d7ca… drh 1840 zInputDate);
e024877… drh 1841 if( zDate[0]==0 ){
722d7ca… drh 1842 fossil_fatal(
722d7ca… drh 1843 "unrecognized date format (%s): use \"YYYY-MM-DD HH:MM:SS.SSS\"",
722d7ca… drh 1844 zInputDate
722d7ca… drh 1845 );
e024877… drh 1846 }
e024877… drh 1847 return zDate;
e024877… drh 1848 }
722d7ca… drh 1849
722d7ca… drh 1850 /*
44f028c… drh 1851 ** COMMAND: test-date-format
44f028c… drh 1852 **
44f028c… drh 1853 ** Usage: %fossil test-date-format DATE-STRING...
44f028c… drh 1854 **
44f028c… drh 1855 ** Convert the DATE-STRING into the standard format used in artifacts
44f028c… drh 1856 ** and display the result.
44f028c… drh 1857 */
44f028c… drh 1858 void test_date_format(void){
44f028c… drh 1859 int i;
44f028c… drh 1860 db_find_and_open_repository(OPEN_ANY_SCHEMA, 0);
44f028c… drh 1861 for(i=2; i<g.argc; i++){
44f028c… drh 1862 fossil_print("%s -> %s\n", g.argv[i], date_in_standard_format(g.argv[i]));
44f028c… drh 1863 }
44f028c… drh 1864 }
44f028c… drh 1865
4dcea80… drh 1866 #if INTERFACE
4dcea80… drh 1867 /*
4dcea80… drh 1868 ** The following structure holds some of the information needed to construct a
4dcea80… drh 1869 ** check-in manifest.
4dcea80… drh 1870 */
4dcea80… drh 1871 struct CheckinInfo {
4dcea80… drh 1872 Blob *pComment; /* Check-in comment text */
4dcea80… drh 1873 const char *zMimetype; /* Mimetype of check-in command. May be NULL */
4dcea80… drh 1874 int verifyDate; /* Verify that child is younger */
abf7271… jan.nijtmans 1875 int closeFlag; /* Close the branch being committed */
82f69aa… drh 1876 int integrateFlag; /* Close merged-in branches */
7ee98fe… drh 1877 int verboseFlag; /* Show diff in editor for check-in comment */
4dcea80… drh 1878 Blob *pCksum; /* Repository checksum. May be 0 */
4dcea80… drh 1879 const char *zDateOvrd; /* Date override. If 0 then use 'now' */
840b762… drh 1880 const char *zUserOvrd; /* User override. If 0 then use login_name() */
4dcea80… drh 1881 const char *zBranch; /* Branch name. May be 0 */
4dcea80… drh 1882 const char *zColor; /* One-time background color. May be 0 */
4dcea80… drh 1883 const char *zBrClr; /* Persistent branch color. May be 0 */
4dcea80… drh 1884 const char **azTag; /* Tags to apply to this check-in */
4dcea80… drh 1885 };
4dcea80… drh 1886 #endif /* INTERFACE */
4dcea80… drh 1887
44f028c… drh 1888 /*
d13054c… drh 1889 ** Create a manifest.
d13054c… drh 1890 */
d13054c… drh 1891 static void create_manifest(
d13054c… drh 1892 Blob *pOut, /* Write the manifest here */
8ad5e46… wyoung 1893 const char *zBaselineUuid, /* Hash of baseline, or zero */
d13054c… drh 1894 Manifest *pBaseline, /* Make it a delta manifest if not zero */
4dcea80… drh 1895 int vid, /* BLOB.id for the parent check-in */
4dcea80… drh 1896 CheckinInfo *p, /* Information about the check-in */
4dcea80… drh 1897 int *pnFBcard /* OUT: Number of generated B- and F-cards */
d13054c… drh 1898 ){
d13054c… drh 1899 char *zDate; /* Date of the check-in */
8ad5e46… wyoung 1900 char *zParentUuid = 0; /* Hash of parent check-in */
d13054c… drh 1901 Blob filename; /* A single filename */
d13054c… drh 1902 int nBasename; /* Size of base filename */
4e092e0… jan.nijtmans 1903 Stmt q; /* Various queries */
d13054c… drh 1904 Blob mcksum; /* Manifest checksum */
d13054c… drh 1905 ManifestFile *pFile; /* File from the baseline */
d13054c… drh 1906 int nFBcard = 0; /* Number of B-cards and F-cards */
c4dc635… drh 1907 int i; /* Loop counter */
4dcea80… drh 1908 const char *zColor; /* Modified value of p->zColor */
d13054c… drh 1909
d13054c… drh 1910 assert( pBaseline==0 || pBaseline->zBaseline==0 );
d13054c… drh 1911 assert( pBaseline==0 || zBaselineUuid!=0 );
d13054c… drh 1912 blob_zero(pOut);
ebe92f5… jan.nijtmans 1913 if( vid ){
ebe92f5… jan.nijtmans 1914 zParentUuid = db_text(0, "SELECT uuid FROM blob WHERE rid=%d AND "
ebe92f5… jan.nijtmans 1915 "EXISTS(SELECT 1 FROM event WHERE event.type='ci' and event.objid=%d)",
ebe92f5… jan.nijtmans 1916 vid, vid);
ebe92f5… jan.nijtmans 1917 if( !zParentUuid ){
8e7edc6… jan.nijtmans 1918 fossil_fatal("Could not find a valid check-in for RID %d. "
bc36fdc… danield 1919 "Possible check-out/repo mismatch.", vid);
ebe92f5… jan.nijtmans 1920 }
27dc7a5… jan.nijtmans 1921 }
6d1c038… drh 1922 if( pBaseline ){
d13054c… drh 1923 blob_appendf(pOut, "B %s\n", zBaselineUuid);
d13054c… drh 1924 manifest_file_rewind(pBaseline);
d13054c… drh 1925 pFile = manifest_file_next(pBaseline, 0);
d13054c… drh 1926 nFBcard++;
d13054c… drh 1927 }else{
d13054c… drh 1928 pFile = 0;
d13054c… drh 1929 }
dfd8962… jan.nijtmans 1930 if( blob_size(p->pComment)!=0 ){
dfd8962… jan.nijtmans 1931 blob_appendf(pOut, "C %F\n", blob_str(p->pComment));
dfd8962… jan.nijtmans 1932 }else{
dfd8962… jan.nijtmans 1933 blob_append(pOut, "C (no\\scomment)\n", 16);
dfd8962… jan.nijtmans 1934 }
4dcea80… drh 1935 zDate = date_in_standard_format(p->zDateOvrd ? p->zDateOvrd : "now");
d13054c… drh 1936 blob_appendf(pOut, "D %s\n", zDate);
d13054c… drh 1937 zDate[10] = ' ';
d13054c… drh 1938 db_prepare(&q,
e4f1c1f… drh 1939 "SELECT pathname, uuid, origname, blob.rid, isexe, islink,"
01e4de6… drh 1940 " is_selected(vfile.id)"
d13054c… drh 1941 " FROM vfile JOIN blob ON vfile.mrid=blob.rid"
01e4de6… drh 1942 " WHERE (NOT deleted OR NOT is_selected(vfile.id))"
2ceeeca… drh 1943 " AND vfile.vid=%d"
01e4de6… drh 1944 " ORDER BY if_selected(vfile.id, pathname, origname)",
01e4de6… drh 1945 vid);
d13054c… drh 1946 blob_zero(&filename);
d13054c… drh 1947 blob_appendf(&filename, "%s", g.zLocalRoot);
d13054c… drh 1948 nBasename = blob_size(&filename);
d13054c… drh 1949 while( db_step(&q)==SQLITE_ROW ){
d13054c… drh 1950 const char *zName = db_column_text(&q, 0);
d13054c… drh 1951 const char *zUuid = db_column_text(&q, 1);
d13054c… drh 1952 const char *zOrig = db_column_text(&q, 2);
d13054c… drh 1953 int frid = db_column_int(&q, 3);
9bfa186… dmitry 1954 int isExe = db_column_int(&q, 4);
e4f1c1f… drh 1955 int isLink = db_column_int(&q, 5);
e4f1c1f… drh 1956 int isSelected = db_column_int(&q, 6);
d13054c… drh 1957 const char *zPerm;
d13054c… drh 1958 int cmp;
9bfa186… dmitry 1959
9e6f20b… drh 1960 blob_resize(&filename, nBasename);
d13054c… drh 1961 blob_append(&filename, zName, -1);
9bfa186… dmitry 1962
41c3c19… drh 1963 #if !defined(_WIN32)
41c3c19… drh 1964 /* For unix, extract the "executable" and "symlink" permissions
41c3c19… drh 1965 ** directly from the filesystem. On windows, permissions are
a0da8b3… drh 1966 ** unchanged from the original. However, only do this if the file
a0da8b3… drh 1967 ** itself is actually selected to be part of this check-in.
41c3c19… drh 1968 */
a0da8b3… drh 1969 if( isSelected ){
41c3c19… drh 1970 int mPerm;
41c3c19… drh 1971
1772357… drh 1972 mPerm = file_perm(blob_str(&filename), RepoFILE);
41c3c19… drh 1973 isExe = ( mPerm==PERM_EXE );
41c3c19… drh 1974 isLink = ( mPerm==PERM_LNK );
41c3c19… drh 1975 }
d13054c… drh 1976 #endif
9bfa186… dmitry 1977 if( isExe ){
d13054c… drh 1978 zPerm = " x";
e4f1c1f… drh 1979 }else if( isLink ){
e4f1c1f… drh 1980 zPerm = " l"; /* note: symlinks don't have executable bit on unix */
d13054c… drh 1981 }else{
d13054c… drh 1982 zPerm = "";
d13054c… drh 1983 }
d13054c… drh 1984 if( !g.markPrivate ) content_make_public(frid);
31c52c7… drh 1985 while( pFile && fossil_strcmp(pFile->zName,zName)<0 ){
d13054c… drh 1986 blob_appendf(pOut, "F %F\n", pFile->zName);
d13054c… drh 1987 pFile = manifest_file_next(pBaseline, 0);
d13054c… drh 1988 nFBcard++;
d13054c… drh 1989 }
d13054c… drh 1990 cmp = 1;
d13054c… drh 1991 if( pFile==0
31c52c7… drh 1992 || (cmp = fossil_strcmp(pFile->zName,zName))!=0
31c52c7… drh 1993 || fossil_strcmp(pFile->zUuid, zUuid)!=0
d13054c… drh 1994 ){
2ceeeca… drh 1995 if( zOrig && !isSelected ){ zName = zOrig; zOrig = 0; }
31c52c7… drh 1996 if( zOrig==0 || fossil_strcmp(zOrig,zName)==0 ){
d13054c… drh 1997 blob_appendf(pOut, "F %F %s%s\n", zName, zUuid, zPerm);
d13054c… drh 1998 }else{
d13054c… drh 1999 if( zPerm[0]==0 ){ zPerm = " w"; }
d13054c… drh 2000 blob_appendf(pOut, "F %F %s%s %F\n", zName, zUuid, zPerm, zOrig);
d13054c… drh 2001 }
d13054c… drh 2002 nFBcard++;
d13054c… drh 2003 }
d13054c… drh 2004 if( cmp==0 ) pFile = manifest_file_next(pBaseline,0);
d13054c… drh 2005 }
d13054c… drh 2006 blob_reset(&filename);
d13054c… drh 2007 db_finalize(&q);
d13054c… drh 2008 while( pFile ){
d13054c… drh 2009 blob_appendf(pOut, "F %F\n", pFile->zName);
d13054c… drh 2010 pFile = manifest_file_next(pBaseline, 0);
d13054c… drh 2011 nFBcard++;
d13054c… drh 2012 }
4dcea80… drh 2013 if( p->zMimetype && p->zMimetype[0] ){
4dcea80… drh 2014 blob_appendf(pOut, "N %F\n", p->zMimetype);
4dcea80… drh 2015 }
ebe92f5… jan.nijtmans 2016 if( vid ){
e17e217… drh 2017 blob_appendf(pOut, "P %s", zParentUuid);
e17e217… drh 2018 if( p->verifyDate ) checkin_verify_younger(vid, zParentUuid, zDate);
e17e217… drh 2019 free(zParentUuid);
e17e217… drh 2020 db_prepare(&q, "SELECT merge FROM vmerge WHERE id=0 OR id<-2");
e17e217… drh 2021 while( db_step(&q)==SQLITE_ROW ){
e17e217… drh 2022 char *zMergeUuid;
e17e217… drh 2023 int mid = db_column_int(&q, 0);
0b3f184… drh 2024 if( (!g.markPrivate && content_is_private(mid)) || (mid == vid) ){
0b3f184… drh 2025 continue;
0b3f184… drh 2026 }
d21e3c5… stephan 2027 zMergeUuid = rid_to_uuid(mid);
e17e217… drh 2028 if( zMergeUuid ){
e17e217… drh 2029 blob_appendf(pOut, " %s", zMergeUuid);
e17e217… drh 2030 if( p->verifyDate ) checkin_verify_younger(mid, zMergeUuid, zDate);
e17e217… drh 2031 free(zMergeUuid);
e17e217… drh 2032 }
e17e217… drh 2033 }
e17e217… drh 2034 db_finalize(&q);
e17e217… drh 2035 blob_appendf(pOut, "\n");
e17e217… drh 2036 }
e17e217… drh 2037 free(zDate);
d13054c… drh 2038
4e092e0… jan.nijtmans 2039 db_prepare(&q,
fff37e6… drh 2040 "SELECT CASE vmerge.id WHEN -1 THEN '+' ELSE '-' END || mhash, merge"
fff37e6… drh 2041 " FROM vmerge"
88e60e8… jan.nijtmans 2042 " WHERE (vmerge.id=-1 OR vmerge.id=-2)"
91aa222… drh 2043 " ORDER BY 1");
4e092e0… jan.nijtmans 2044 while( db_step(&q)==SQLITE_ROW ){
4e092e0… jan.nijtmans 2045 const char *zCherrypickUuid = db_column_text(&q, 0);
d564997… jan.nijtmans 2046 int mid = db_column_int(&q, 1);
52a6682… florian 2047 if( (!g.markPrivate && content_is_private(mid)) || (mid == vid) ) continue;
52a6682… florian 2048 blob_appendf(pOut, "Q %s\n", zCherrypickUuid);
91aa222… drh 2049 }
4e092e0… jan.nijtmans 2050 db_finalize(&q);
91aa222… drh 2051
4dcea80… drh 2052 if( p->pCksum ) blob_appendf(pOut, "R %b\n", p->pCksum);
4dcea80… drh 2053 zColor = p->zColor;
4dcea80… drh 2054 if( p->zBranch && p->zBranch[0] ){
3b2d67d… drh 2055 /* Set tags for the new branch */
4dcea80… drh 2056 if( p->zBrClr && p->zBrClr[0] ){
c4dc635… drh 2057 zColor = 0;
4dcea80… drh 2058 blob_appendf(pOut, "T *bgcolor * %F\n", p->zBrClr);
c4dc635… drh 2059 }
4dcea80… drh 2060 blob_appendf(pOut, "T *branch * %F\n", p->zBranch);
4dcea80… drh 2061 blob_appendf(pOut, "T *sym-%F *\n", p->zBranch);
c4dc635… drh 2062 }
c4dc635… drh 2063 if( zColor && zColor[0] ){
c4dc635… drh 2064 /* One-time background color */
c4dc635… drh 2065 blob_appendf(pOut, "T +bgcolor * %F\n", zColor);
c4dc635… drh 2066 }
abf7271… jan.nijtmans 2067 if( p->closeFlag ){
abf7271… jan.nijtmans 2068 blob_appendf(pOut, "T +closed *\n");
abf7271… jan.nijtmans 2069 }
fff37e6… drh 2070 db_prepare(&q, "SELECT mhash,merge FROM vmerge"
82f69aa… drh 2071 " WHERE id %s ORDER BY 1",
82f69aa… drh 2072 p->integrateFlag ? "IN(0,-4)" : "=(-4)");
4e092e0… jan.nijtmans 2073 while( db_step(&q)==SQLITE_ROW ){
4e092e0… jan.nijtmans 2074 const char *zIntegrateUuid = db_column_text(&q, 0);
4e092e0… jan.nijtmans 2075 int rid = db_column_int(&q, 1);
daa8eb9… jan.nijtmans 2076 if( is_a_leaf(rid) && !db_exists("SELECT 1 FROM tagxref "
daa8eb9… jan.nijtmans 2077 " WHERE tagid=%d AND rid=%d AND tagtype>0", TAG_CLOSED, rid)){
b4beadb… drh 2078 #if 0
b4beadb… drh 2079 /* Make sure the check-in manifest of the resulting merge child does not
b4beadb… drh 2080 ** include a +close tag referring to the leaf check-in on a private
b4beadb… drh 2081 ** branch, so as not to generate a missing artifact reference on
b4beadb… drh 2082 ** repository clones without that private branch. The merge command
b4beadb… drh 2083 ** should have dropped the --integrate option, at this point. */
b4beadb… drh 2084 assert( !content_is_private(rid) );
b4beadb… drh 2085 #endif
daa8eb9… jan.nijtmans 2086 blob_appendf(pOut, "T +closed %s\n", zIntegrateUuid);
daa8eb9… jan.nijtmans 2087 }
daa8eb9… jan.nijtmans 2088 }
4e092e0… jan.nijtmans 2089 db_finalize(&q);
daa8eb9… jan.nijtmans 2090
4dcea80… drh 2091 if( p->azTag ){
4dcea80… drh 2092 for(i=0; p->azTag[i]; i++){
c4dc635… drh 2093 /* Add a symbolic tag to this check-in. The tag names have already
c4dc635… drh 2094 ** been sorted and converted using the %F format */
4dcea80… drh 2095 assert( i==0 || strcmp(p->azTag[i-1], p->azTag[i])<=0 );
4dcea80… drh 2096 blob_appendf(pOut, "T +sym-%s *\n", p->azTag[i]);
c4dc635… drh 2097 }
c4dc635… drh 2098 }
4dcea80… drh 2099 if( p->zBranch && p->zBranch[0] ){
c4dc635… drh 2100 /* For a new branch, cancel all prior propagating tags */
d13054c… drh 2101 db_prepare(&q,
d13054c… drh 2102 "SELECT tagname FROM tagxref, tag"
d13054c… drh 2103 " WHERE tagxref.rid=%d AND tagxref.tagid=tag.tagid"
c52927c… drh 2104 " AND tagtype==2 AND tagname GLOB 'sym-*'"
d13054c… drh 2105 " AND tagname!='sym-'||%Q"
d13054c… drh 2106 " ORDER BY tagname",
4dcea80… drh 2107 vid, p->zBranch);
d13054c… drh 2108 while( db_step(&q)==SQLITE_ROW ){
c4dc635… drh 2109 const char *zBrTag = db_column_text(&q, 0);
c4dc635… drh 2110 blob_appendf(pOut, "T -%F *\n", zBrTag);
d13054c… drh 2111 }
d13054c… drh 2112 db_finalize(&q);
d503cfd… jan.nijtmans 2113 }
840b762… drh 2114 blob_appendf(pOut, "U %F\n", p->zUserOvrd ? p->zUserOvrd : login_name());
d13054c… drh 2115 md5sum_blob(pOut, &mcksum);
d13054c… drh 2116 blob_appendf(pOut, "Z %b\n", &mcksum);
d13054c… drh 2117 if( pnFBcard ) *pnFBcard = nFBcard;
d13054c… drh 2118 }
d13054c… drh 2119
0466588… drh 2120 /*
0466588… drh 2121 ** Issue a warning and give the user an opportunity to abandon out
c7b2b2e… jan.nijtmans 2122 ** if a Unicode (UTF-16) byte-order-mark (BOM) or a \r\n line ending
c7b2b2e… jan.nijtmans 2123 ** is seen in a text file.
22b570f… drh 2124 **
22b570f… drh 2125 ** Return 1 if the user pressed 'c'. In that case, the file will have
87320cf… andygoth 2126 ** been converted to UTF-8 (if it was UTF-16) with LF line-endings,
22b570f… drh 2127 ** and the original file will have been renamed to "<filename>-original".
0466588… drh 2128 */
22b570f… drh 2129 static int commit_warning(
de78b73… mistachkin 2130 Blob *pContent, /* The content of the file being committed. */
87320cf… andygoth 2131 int crlfOk, /* Non-zero if CR/LF warnings should be disabled. */
de78b73… mistachkin 2132 int binOk, /* Non-zero if binary warnings should be disabled. */
de78b73… mistachkin 2133 int encodingOk, /* Non-zero if encoding warnings should be disabled. */
3ffe893… drh 2134 int sizeOk, /* Non-zero if oversize warnings are disabled */
de78b73… mistachkin 2135 int noPrompt, /* 0 to always prompt, 1 for 'N', 2 for 'Y'. */
de78b73… mistachkin 2136 const char *zFilename, /* The full name of the file being committed. */
de78b73… mistachkin 2137 Blob *pReason /* Reason for warning, if any (non-fatal only). */
d25f6dd… mistachkin 2138 ){
e3f9a42… mistachkin 2139 int bReverse; /* UTF-16 byte order is reversed? */
3ec3909… jan.nijtmans 2140 int fUnicode; /* return value of could_be_utf16() */
3f78dfe… mistachkin 2141 int fBinary; /* does the blob content appear to be binary? */
30a63b8… mistachkin 2142 int lookFlags; /* output flags from looks_like_utf8/utf16() */
3f78dfe… mistachkin 2143 int fHasAnyCr; /* the blob contains one or more CR chars */
3f78dfe… mistachkin 2144 int fHasLoneCrOnly; /* all detected line endings are CR only */
3f78dfe… mistachkin 2145 int fHasCrLfOnly; /* all detected line endings are CR/LF pairs */
0b3f184… drh 2146 int fHasInvalidUtf8 = 0;/* contains invalid UTF-8 */
9182b85… mistachkin 2147 int fHasNul; /* contains NUL chars? */
9182b85… mistachkin 2148 int fHasLong; /* overly long line? */
0466588… drh 2149 char *zMsg; /* Warning message */
0466588… drh 2150 Blob fname; /* Relative pathname of the file */
0466588… drh 2151 static int allOk = 0; /* Set to true to disable this routine */
0466588… drh 2152
22b570f… drh 2153 if( allOk ) return 0;
3ffe893… drh 2154 if( sizeOk ){
3ffe893… drh 2155 fUnicode = could_be_utf16(pContent, &bReverse);
3ffe893… drh 2156 if( fUnicode ){
3ffe893… drh 2157 lookFlags = looks_like_utf16(pContent, bReverse, LOOK_NUL);
3ffe893… drh 2158 }else{
3ffe893… drh 2159 lookFlags = looks_like_utf8(pContent, LOOK_NUL);
3ffe893… drh 2160 if( !(lookFlags & LOOK_BINARY) && invalid_utf8(pContent) ){
3ffe893… drh 2161 fHasInvalidUtf8 = 1;
3ffe893… drh 2162 }
3ffe893… drh 2163 }
3ffe893… drh 2164 fHasAnyCr = (lookFlags & LOOK_CR);
3ffe893… drh 2165 fBinary = (lookFlags & LOOK_BINARY);
3ffe893… drh 2166 fHasLoneCrOnly = ((lookFlags & LOOK_EOL) == LOOK_LONE_CR);
3ffe893… drh 2167 fHasCrLfOnly = ((lookFlags & LOOK_EOL) == LOOK_CRLF);
9182b85… mistachkin 2168 fHasNul = (lookFlags & LOOK_NUL);
9182b85… mistachkin 2169 fHasLong = (lookFlags & LOOK_LONG);
25eec8c… jan.nijtmans 2170 }else{
3ffe893… drh 2171 fUnicode = fHasAnyCr = fBinary = fHasInvalidUtf8 = 0;
9182b85… mistachkin 2172 fHasLoneCrOnly = fHasCrLfOnly = fHasNul = fHasLong = 0;
3ffe893… drh 2173 }
3ffe893… drh 2174 if( !sizeOk || fUnicode || fHasAnyCr || fBinary || fHasInvalidUtf8 ){
3ffe893… drh 2175 const char *zWarning = 0;
3ffe893… drh 2176 const char *zDisable = 0;
ccdd1ab… mistachkin 2177 const char *zConvert = "c=convert/";
3ffe893… drh 2178 const char *zIn = "in";
ccdd1ab… mistachkin 2179 Blob ans;
ccdd1ab… mistachkin 2180 char cReply;
ccdd1ab… mistachkin 2181
3f78dfe… mistachkin 2182 if( fBinary ){
ccdd1ab… mistachkin 2183 if( binOk ){
ccdd1ab… mistachkin 2184 return 0; /* We don't want binary warnings for this file. */
ccdd1ab… mistachkin 2185 }
3f78dfe… mistachkin 2186 if( !fHasNul && fHasLong ){
10fbcda… mistachkin 2187 zWarning = "long lines";
426a5e7… andygoth 2188 zConvert = ""; /* We cannot convert overlong lines. */
10fbcda… mistachkin 2189 }else{
10fbcda… mistachkin 2190 zWarning = "binary data";
ea2598e… jan.nijtmans 2191 zConvert = ""; /* We cannot convert binary files. */
10fbcda… mistachkin 2192 }
ccdd1ab… mistachkin 2193 zDisable = "\"binary-glob\" setting";
3f78dfe… mistachkin 2194 }else if( fUnicode && fHasAnyCr ){
87320cf… andygoth 2195 if( crlfOk && encodingOk ){
87320cf… andygoth 2196 return 0; /* We don't want CR/LF and Unicode warnings for this file. */
ea2598e… jan.nijtmans 2197 }
3f78dfe… mistachkin 2198 if( fHasLoneCrOnly ){
ea2598e… jan.nijtmans 2199 zWarning = "CR line endings and Unicode";
3f78dfe… mistachkin 2200 }else if( fHasCrLfOnly ){
87320cf… andygoth 2201 zWarning = "CR/LF line endings and Unicode";
ea2598e… jan.nijtmans 2202 }else{
f89e2ec… jan.nijtmans 2203 zWarning = "mixed line endings and Unicode";
f89e2ec… jan.nijtmans 2204 }
87320cf… andygoth 2205 zDisable = "\"crlf-glob\" and \"encoding-glob\" settings";
0cb00c0… jan.nijtmans 2206 }else if( fHasInvalidUtf8 ){
0cb00c0… jan.nijtmans 2207 if( encodingOk ){
0cb00c0… jan.nijtmans 2208 return 0; /* We don't want encoding warnings for this file. */
0cb00c0… jan.nijtmans 2209 }
0cb00c0… jan.nijtmans 2210 zWarning = "invalid UTF-8";
0cb00c0… jan.nijtmans 2211 zDisable = "\"encoding-glob\" setting";
3f78dfe… mistachkin 2212 }else if( fHasAnyCr ){
87320cf… andygoth 2213 if( crlfOk ){
87320cf… andygoth 2214 return 0; /* We don't want CR/LF warnings for this file. */
f89e2ec… jan.nijtmans 2215 }
3f78dfe… mistachkin 2216 if( fHasLoneCrOnly ){
ea2598e… jan.nijtmans 2217 zWarning = "CR line endings";
3f78dfe… mistachkin 2218 }else if( fHasCrLfOnly ){
87320cf… andygoth 2219 zWarning = "CR/LF line endings";
ea2598e… jan.nijtmans 2220 }else{
f89e2ec… jan.nijtmans 2221 zWarning = "mixed line endings";
ea2598e… jan.nijtmans 2222 }
87320cf… andygoth 2223 zDisable = "\"crlf-glob\" setting";
3ffe893… drh 2224 }else if( !sizeOk ){
3ffe893… drh 2225 zWarning = "oversize";
3ffe893… drh 2226 zIn = "file";
3ba9a4d… jan.nijtmans 2227 }else{
3ba9a4d… jan.nijtmans 2228 if( encodingOk ){
7d237c4… jan.nijtmans 2229 return 0; /* We don't want encoding warnings for this file. */
cb856cc… mistachkin 2230 }
1e2fdf9… jan.nijtmans 2231 zWarning = "Unicode";
7d237c4… jan.nijtmans 2232 zDisable = "\"encoding-glob\" setting";
70b4f10… jan.nijtmans 2233 }
135ed93… drh 2234 file_relative_name(zFilename, &fname, 0);
3ffe893… drh 2235 if( !sizeOk ){
3ffe893… drh 2236 zMsg = mprintf(
3ffe893… drh 2237 "%s is more than %,lld bytes in size.\n"
3ffe893… drh 2238 "Commit anyhow (a=all/y/N)? ",
3ffe893… drh 2239 blob_str(&fname), db_large_file_size());
3ffe893… drh 2240 }else{
3ffe893… drh 2241 zMsg = mprintf(
3ffe893… drh 2242 "%s contains %s. Use --no-warnings or the %s to"
3ffe893… drh 2243 " disable this warning.\n"
3ffe893… drh 2244 "Commit anyhow (a=all/%sy/N)? ",
3ffe893… drh 2245 blob_str(&fname), zWarning, zDisable, zConvert);
3ffe893… drh 2246 }
de78b73… mistachkin 2247 if( noPrompt==0 ){
29ef4f5… mistachkin 2248 prompt_user(zMsg, &ans);
29ef4f5… mistachkin 2249 cReply = blob_str(&ans)[0];
29ef4f5… mistachkin 2250 blob_reset(&ans);
de78b73… mistachkin 2251 }else if( noPrompt==2 ){
de78b73… mistachkin 2252 cReply = 'Y';
29ef4f5… mistachkin 2253 }else{
29ef4f5… mistachkin 2254 cReply = 'N';
29ef4f5… mistachkin 2255 }
0466588… drh 2256 fossil_free(zMsg);
d503cfd… jan.nijtmans 2257 if( cReply=='a' || cReply=='A' ){
0466588… drh 2258 allOk = 1;
22b570f… drh 2259 }else if( *zConvert && (cReply=='c' || cReply=='C') ){
22b570f… drh 2260 char *zOrig = file_newname(zFilename, "original", 1);
22b570f… drh 2261 FILE *f;
de78b73… mistachkin 2262 blob_write_to_file(pContent, zOrig);
22b570f… drh 2263 fossil_free(zOrig);
22b570f… drh 2264 f = fossil_fopen(zFilename, "wb");
c3d0954… mgagnon 2265 if( f==0 ){
b763c3c… jan.nijtmans 2266 fossil_warning("cannot open %s for writing", zFilename);
b763c3c… jan.nijtmans 2267 }else{
7d257de… mistachkin 2268 if( fUnicode ){
b763c3c… jan.nijtmans 2269 int bomSize;
b763c3c… jan.nijtmans 2270 const unsigned char *bom = get_utf8_bom(&bomSize);
b763c3c… jan.nijtmans 2271 fwrite(bom, 1, bomSize, f);
de78b73… mistachkin 2272 blob_to_utf8_no_bom(pContent, 0);
45f5184… jan.nijtmans 2273 }else if( fHasInvalidUtf8 ){
de78b73… mistachkin 2274 blob_cp1252_to_utf8(pContent);
b763c3c… jan.nijtmans 2275 }
b763c3c… jan.nijtmans 2276 if( fHasAnyCr ){
de78b73… mistachkin 2277 blob_to_lf_only(pContent);
b763c3c… jan.nijtmans 2278 }
de78b73… mistachkin 2279 fwrite(blob_buffer(pContent), 1, blob_size(pContent), f);
b763c3c… jan.nijtmans 2280 fclose(f);
b763c3c… jan.nijtmans 2281 }
22b570f… drh 2282 return 1;
6feba0d… jan.nijtmans 2283 }else if( cReply!='y' && cReply!='Y' ){
3ffe893… drh 2284 fossil_fatal("Abandoning commit due to %s %s %s",
3ffe893… drh 2285 zWarning, zIn, blob_str(&fname));
de78b73… mistachkin 2286 }else if( noPrompt==2 ){
de78b73… mistachkin 2287 if( pReason ){
de78b73… mistachkin 2288 blob_append(pReason, zWarning, -1);
de78b73… mistachkin 2289 }
de78b73… mistachkin 2290 return 1;
0466588… drh 2291 }
0466588… drh 2292 blob_reset(&fname);
0466588… drh 2293 }
22b570f… drh 2294 return 0;
de78b73… mistachkin 2295 }
de78b73… mistachkin 2296
de78b73… mistachkin 2297 /*
de78b73… mistachkin 2298 ** COMMAND: test-commit-warning
de78b73… mistachkin 2299 **
de78b73… mistachkin 2300 ** Usage: %fossil test-commit-warning ?OPTIONS?
de78b73… mistachkin 2301 **
bc36fdc… danield 2302 ** Check each file in the check-out, including unmodified ones, using all
de78b73… mistachkin 2303 ** the pre-commit checks.
de78b73… mistachkin 2304 **
de78b73… mistachkin 2305 ** Options:
de78b73… mistachkin 2306 ** --no-settings Do not consider any glob settings.
de78b73… mistachkin 2307 ** -v|--verbose Show per-file results for all pre-commit checks.
de78b73… mistachkin 2308 **
de78b73… mistachkin 2309 ** See also: commit, extras
de78b73… mistachkin 2310 */
de78b73… mistachkin 2311 void test_commit_warning(void){
de78b73… mistachkin 2312 int rc = 0;
f00a55b… mistachkin 2313 int noSettings;
f00a55b… mistachkin 2314 int verboseFlag;
3ffe893… drh 2315 i64 mxSize;
de78b73… mistachkin 2316 Stmt q;
f00a55b… mistachkin 2317 noSettings = find_option("no-settings",0,0)!=0;
f00a55b… mistachkin 2318 verboseFlag = find_option("verbose","v",0)!=0;
f00a55b… mistachkin 2319 verify_all_options();
b4a1b2f… mistachkin 2320 db_must_be_within_tree();
3ffe893… drh 2321 mxSize = db_large_file_size();
de78b73… mistachkin 2322 db_prepare(&q,
de78b73… mistachkin 2323 "SELECT %Q || pathname, pathname, %s, %s, %s FROM vfile"
de78b73… mistachkin 2324 " WHERE NOT deleted",
de78b73… mistachkin 2325 g.zLocalRoot,
87320cf… andygoth 2326 glob_expr("pathname", noSettings ? 0 : db_get("crlf-glob",
87320cf… andygoth 2327 db_get("crnl-glob",""))),
de78b73… mistachkin 2328 glob_expr("pathname", noSettings ? 0 : db_get("binary-glob","")),
de78b73… mistachkin 2329 glob_expr("pathname", noSettings ? 0 : db_get("encoding-glob",""))
de78b73… mistachkin 2330 );
de78b73… mistachkin 2331 while( db_step(&q)==SQLITE_ROW ){
de78b73… mistachkin 2332 const char *zFullname;
de78b73… mistachkin 2333 const char *zName;
3852b56… mistachkin 2334 Blob content;
3852b56… mistachkin 2335 Blob reason;
3ffe893… drh 2336 int crlfOk, binOk, encodingOk, sizeOk;
de78b73… mistachkin 2337 int fileRc;
de78b73… mistachkin 2338
de78b73… mistachkin 2339 zFullname = db_column_text(&q, 0);
de78b73… mistachkin 2340 zName = db_column_text(&q, 1);
87320cf… andygoth 2341 crlfOk = db_column_int(&q, 2);
de78b73… mistachkin 2342 binOk = db_column_int(&q, 3);
de78b73… mistachkin 2343 encodingOk = db_column_int(&q, 4);
3ffe893… drh 2344 sizeOk = mxSize<=0 || file_size(zFullname, ExtFILE)<=mxSize;
de78b73… mistachkin 2345 blob_zero(&content);
1772357… drh 2346 blob_read_from_file(&content, zFullname, RepoFILE);
de78b73… mistachkin 2347 blob_zero(&reason);
3ffe893… drh 2348 fileRc = commit_warning(&content, crlfOk, binOk, encodingOk, sizeOk, 2,
de78b73… mistachkin 2349 zFullname, &reason);
de78b73… mistachkin 2350 if( fileRc || verboseFlag ){
de78b73… mistachkin 2351 fossil_print("%d\t%s\t%s\n", fileRc, zName, blob_str(&reason));
de78b73… mistachkin 2352 }
de78b73… mistachkin 2353 blob_reset(&reason);
de78b73… mistachkin 2354 rc |= fileRc;
de78b73… mistachkin 2355 }
de78b73… mistachkin 2356 db_finalize(&q);
de78b73… mistachkin 2357 fossil_print("%d\n", rc);
c4dc635… drh 2358 }
c4dc635… drh 2359
c4dc635… drh 2360 /*
c4dc635… drh 2361 ** qsort() comparison routine for an array of pointers to strings.
c4dc635… drh 2362 */
c4dc635… drh 2363 static int tagCmp(const void *a, const void *b){
c4dc635… drh 2364 char **pA = (char**)a;
c4dc635… drh 2365 char **pB = (char**)b;
c4dc635… drh 2366 return fossil_strcmp(pA[0], pB[0]);
c4dc635… drh 2367 }
c4dc635… drh 2368
c4dc635… drh 2369 /*
74a5e10… drh 2370 ** SETTING: verify-comments width=8 default=on
798b232… drh 2371 **
478a0fa… danield 2372 ** This setting determines how much sanity checking, if any, the
798b232… drh 2373 ** "fossil commit" and "fossil amend" commands do against check-in
798b232… drh 2374 ** comments. Recognized values:
798b232… drh 2375 **
072125b… drh 2376 ** on (Default) Check for bad syntax and/or broken hyperlinks
072125b… drh 2377 ** in check-in comments and offer the user a chance to
072125b… drh 2378 ** continue editing for interactive sessions, or simply
072125b… drh 2379 ** abort the commit if the comment was entered using -m or -M
072125b… drh 2380 **
072125b… drh 2381 ** off Do not do syntax checking of any kind
072125b… drh 2382 **
072125b… drh 2383 ** preview Do all the same checks as "on" but also always preview the
072125b… drh 2384 ** check-in comment to the user during interactive sessions
072125b… drh 2385 ** even if no obvious errors are found, and provide an
072125b… drh 2386 ** opportunity to accept or re-edit
8f4aedc… drh 2387 */
798b232… drh 2388
798b232… drh 2389 #if INTERFACE
072125b… drh 2390 #define COMCK_MARKUP 0x01 /* Check for mistakes */
072125b… drh 2391 #define COMCK_PREVIEW 0x02 /* Always preview, even if no issues found */
798b232… drh 2392 #endif /* INTERFACE */
8f4aedc… drh 2393
8f4aedc… drh 2394 /*
3e87f78… drh 2395 ** Check for possible formatting errors in the comment string pComment.
798b232… drh 2396 **
072125b… drh 2397 ** If issues are found, write an appropriate error notice, probably also
072125b… drh 2398 ** including the complete text of the comment formatted to highlight the
072125b… drh 2399 ** problem, to stdout and return non-zero. The return value is some
072125b… drh 2400 ** combination of the COMCK_* flags, depending on what went wrong.
798b232… drh 2401 **
798b232… drh 2402 ** If no issues are seen, do not output anything and return zero.
3e87f78… drh 2403 */
072125b… drh 2404 int verify_comment(Blob *pComment, int mFlags){
072125b… drh 2405 Blob in, html;
072125b… drh 2406 int mResult;
798b232… drh 2407 int rc = mFlags & COMCK_PREVIEW;
072125b… drh 2408 int wFlags;
798b232… drh 2409
798b232… drh 2410 if( mFlags==0 ) return 0;
072125b… drh 2411 blob_init(&in, blob_str(pComment), -1);
072125b… drh 2412 blob_init(&html, 0, 0);
072125b… drh 2413 wFlags = wiki_convert_flags(0);
d62ca2b… drh 2414 wFlags &= ~WIKI_NOBADLINKS;
072125b… drh 2415 wFlags |= WIKI_MARK;
072125b… drh 2416 mResult = wiki_convert(&in, &html, wFlags);
072125b… drh 2417 if( mResult & RENDER_ANYERROR ) rc |= COMCK_MARKUP;
072125b… drh 2418 if( rc ){
d62ca2b… drh 2419 int htot = ((wFlags & WIKI_NEWLINE)!=0 ? 0 : HTOT_FLOW)|HTOT_TRIM;
072125b… drh 2420 Blob txt;
072125b… drh 2421 if( terminal_is_vt100() ) htot |= HTOT_VT100;
072125b… drh 2422 blob_init(&txt, 0, 0);
072125b… drh 2423 html_to_plaintext(blob_str(&html), &txt, htot);
072125b… drh 2424 if( rc & COMCK_MARKUP ){
072125b… drh 2425 fossil_print("Possible format errors in the check-in comment:\n\n ");
072125b… drh 2426 }else{
072125b… drh 2427 fossil_print("Preview of the check-in comment:\n\n ");
072125b… drh 2428 }
d62ca2b… drh 2429 if( wFlags & WIKI_NEWLINE ){
d62ca2b… drh 2430 Blob line;
d62ca2b… drh 2431 char *zIndent = "";
d62ca2b… drh 2432 while( blob_line(&txt, &line) ){
d62ca2b… drh 2433 fossil_print("%s%b", zIndent, &line);
d62ca2b… drh 2434 zIndent = " ";
d62ca2b… drh 2435 }
d62ca2b… drh 2436 fossil_print("\n");
d62ca2b… drh 2437 }else{
d62ca2b… drh 2438 comment_print(blob_str(&txt), 0, 3, -1, get_comment_format());
d62ca2b… drh 2439 }
072125b… drh 2440 fossil_print("\n");
072125b… drh 2441 fflush(stdout);
072125b… drh 2442 blob_reset(&txt);
798b232… drh 2443 }
072125b… drh 2444 blob_reset(&html);
072125b… drh 2445 blob_reset(&in);
798b232… drh 2446 return rc;
4588959… drh 2447 }
3e87f78… drh 2448
3e87f78… drh 2449 /*
db70849… danield 2450 ** COMMAND: ci#
16e703b… drh 2451 ** COMMAND: commit
16e703b… drh 2452 **
16e703b… drh 2453 ** Usage: %fossil commit ?OPTIONS? ?FILE...?
f616380… stephan 2454 ** or: %fossil ci ?OPTIONS? ?FILE...?
f616380… stephan 2455 **
1ec8dee… drh 2456 ** Create a new check-in containing all of the changes in the current
1ec8dee… drh 2457 ** check-out. All changes are committed unless some subset of files
1ec8dee… drh 2458 ** is specified on the command line, in which case only the named files
1ec8dee… drh 2459 ** become part of the new check-in.
f616380… stephan 2460 **
1ec8dee… drh 2461 ** You will be prompted to enter a check-in comment unless the comment
1ec8dee… drh 2462 ** has been specified on the command-line using "-m" or "-M". The
1ec8dee… drh 2463 ** text editor used is determined by the "editor" setting, or by the
1ec8dee… drh 2464 ** "VISUAL" or "EDITOR" environment variables. Commit message text is
1ec8dee… drh 2465 ** interpreted as fossil-wiki format. Potentially misformatted check-in
798b232… drh 2466 ** comment text is detected and reported unless the --no-verify-comment
1ec8dee… drh 2467 ** option is used.
b6d219b… stephan 2468 **
b6d219b… stephan 2469 ** The --branch option followed by a branch name causes the new
1ec8dee… drh 2470 ** check-in to be placed in a newly-created branch with name specified.
5e83504… mistachkin 2471 **
5e83504… mistachkin 2472 ** A check-in is not permitted to fork unless the --allow-fork option
5e83504… mistachkin 2473 ** appears. An empty check-in (i.e. with nothing changed) is not
5e83504… mistachkin 2474 ** allowed unless the --allow-empty option appears. A check-in may not
5e83504… mistachkin 2475 ** be older than its ancestor unless the --allow-older option appears.
75c45fd… drh 2476 ** If any files in the check-in appear to contain unresolved merge
5e83504… mistachkin 2477 ** conflicts, the check-in will not be allowed unless the
5e83504… mistachkin 2478 ** --allow-conflict option is present. In addition, the entire
5e83504… mistachkin 2479 ** check-in process may be aborted if a file contains content that
87320cf… andygoth 2480 ** appears to be binary, Unicode text, or text with CR/LF line endings
5e83504… mistachkin 2481 ** unless the interactive user chooses to proceed. If there is no
5e83504… mistachkin 2482 ** interactive user or these warnings should be skipped for some other
5e83504… mistachkin 2483 ** reason, the --no-warnings option may be used. A check-in is not
5e83504… mistachkin 2484 ** allowed against a closed leaf.
02a584f… drh 2485 **
02a584f… drh 2486 ** The --private option creates a private check-in that is never synced.
02a584f… drh 2487 ** Children of private check-ins are automatically private.
02a584f… drh 2488 **
a9ad53b… joel 2489 ** The --tag option applies the symbolic tag name to the check-in.
1ec8dee… drh 2490 ** The --tag option can be repeated to assign multiple tags to a check-in.
1ec8dee… drh 2491 ** For example: "... --tag release --tag version-1.2.3 ..."
9d723c5… drh 2492 **
c5f4ec0… bharder 2493 ** Options:
2e56ef4… km 2494 ** --allow-conflict Allow unresolved merge conflicts
2e56ef4… km 2495 ** --allow-empty Allow a commit with no changes
2e56ef4… km 2496 ** --allow-fork Allow the commit to fork
2e56ef4… km 2497 ** --allow-older Allow a commit older than its ancestor
2e56ef4… km 2498 ** --baseline Use a baseline manifest in the commit process
f7a18cf… drh 2499 ** --bgcolor COLOR Apply COLOR to this one check-in only
2e56ef4… km 2500 ** --branch NEW-BRANCH-NAME Check in to this new branch
f7a18cf… drh 2501 ** --branchcolor COLOR Apply given COLOR to the branch
2e56ef4… km 2502 ** --close Close the branch being committed
1ec8dee… drh 2503 ** --date-override DATETIME Make DATETIME the time of the check-in.
1ec8dee… drh 2504 ** Useful when importing historical check-ins
1ec8dee… drh 2505 ** from another version control system.
2e56ef4… km 2506 ** --delta Use a delta manifest in the commit process
7675987… drh 2507 ** --editor NAME Text editor to use for check-in comment.
2e56ef4… km 2508 ** --hash Verify file status using hashing rather
1ec8dee… drh 2509 ** than relying on filesystem mtimes
f36695a… drh 2510 ** --if-changes Make this command a silent no-op if there
f36695a… drh 2511 ** are no changes
bd7f272… danield 2512 ** --ignore-clock-skew If a clock skew is detected, ignore it and
bd7f272… danield 2513 ** behave as if the user had entered 'yes' to
bd7f272… danield 2514 ** the question of whether to proceed despite
bd7f272… danield 2515 ** the skew.
75c45fd… drh 2516 ** --ignore-oversize Do not warn the user about oversized files
2e56ef4… km 2517 ** --integrate Close all merged-in branches
1ec8dee… drh 2518 ** -m|--comment COMMENT-TEXT Use COMMENT-TEXT as the check-in comment
1ec8dee… drh 2519 ** -M|--message-file FILE Read the check-in comment from FILE
1ec8dee… drh 2520 ** -n|--dry-run Do not actually create a new check-in. Just
1ec8dee… drh 2521 ** show what would have happened. For debugging.
4eca7eb… drh 2522 ** -v|--verbose Show a diff in the commit message prompt
29ef4f5… mistachkin 2523 ** --no-prompt This option disables prompting the user for
29ef4f5… mistachkin 2524 ** input and assumes an answer of 'No' for every
29ef4f5… mistachkin 2525 ** question.
2e56ef4… km 2526 ** --no-warnings Omit all warnings about file contents
2e56ef4… km 2527 ** --no-verify Do not run before-commit hooks
798b232… drh 2528 ** --no-verify-comment Do not validate the check-in comment
2e56ef4… km 2529 ** --nosign Do not attempt to sign this commit with gpg
e8a21ab… drh 2530 ** --nosync Do not auto-sync prior to committing
2e56ef4… km 2531 ** --override-lock Allow a check-in even though parent is locked
1ec8dee… drh 2532 ** --private Never sync the resulting check-in and make
1ec8dee… drh 2533 ** all descendants private too.
6d4cd32… mgagnon 2534 ** --proxy PROXY Use PROXY as http proxy during sync operation
1ec8dee… drh 2535 ** --tag TAG-NAME Add TAG-NAME to the check-in. May be repeated.
2e56ef4… km 2536 ** --trace Debug tracing
1ec8dee… drh 2537 ** --user-override USER Record USER as the login that created the
1ec8dee… drh 2538 ** new check-in, rather that the current user.
4588959… drh 2539 ** -w|--wiki FILE Adds FILE's content as a wiki page associated
4588959… drh 2540 ** with this check-in.
4588959… drh 2541 ** --wm|--wiki-mimetype TYPE Mimetype for --wiki-file. Default is from the
4588959… drh 2542 ** file extension: .md=markdown, .wiki=fossil,
4588959… drh 2543 ** otherwise plain text. Accepts "markdown",
4588959… drh 2544 ** "wiki", and "plain" as aliases.
c965636… drh 2545 **
c965636… drh 2546 ** See also: [[branch]], [[changes]], [[update]], [[extras]], [[sync]]
c5f4ec0… bharder 2547 */
c5f4ec0… bharder 2548 void commit_cmd(void){
d13054c… drh 2549 int hasChanges; /* True if unsaved changes exist */
d13054c… drh 2550 int vid; /* blob-id of parent version */
d13054c… drh 2551 int nrid; /* blob-id of a modified file */
d13054c… drh 2552 int nvid; /* Blob-id of the new check-in */
d13054c… drh 2553 Blob comment; /* Check-in comment */
d13054c… drh 2554 const char *zComment; /* Check-in comment */
4e092e0… jan.nijtmans 2555 Stmt q; /* Various queries */
8ad5e46… wyoung 2556 char *zUuid; /* Hash of the new check-in */
fd9b7bd… drh 2557 int useHash = 0; /* True to verify file status using hashing */
c5f4ec0… bharder 2558 int noSign = 0; /* True to omit signing the manifest using GPG */
b4beadb… drh 2559 int privateFlag = 0; /* True if the --private option is present */
b4beadb… drh 2560 int privateParent = 0; /* True if the parent check-in is private */
c5f4ec0… bharder 2561 int isAMerge = 0; /* True if checking in a merge */
cb856cc… mistachkin 2562 int noWarningFlag = 0; /* True if skipping all warnings */
9d8db79… drh 2563 int noVerify = 0; /* Do not run before-commit hooks */
9d8db79… drh 2564 int bTrace = 0; /* Debug tracing */
29ef4f5… mistachkin 2565 int noPrompt = 0; /* True if skipping all prompts */
5e83504… mistachkin 2566 int forceFlag = 0; /* Undocumented: Disables all checks */
d13054c… drh 2567 int forceDelta = 0; /* Force a delta-manifest */
d13054c… drh 2568 int forceBaseline = 0; /* Force a baseline-manifest */
7d34d17… drh 2569 int allowConflict = 0; /* Allow unresolve merge conflicts */
5e83504… mistachkin 2570 int allowEmpty = 0; /* Allow a commit with no changes */
f36695a… drh 2571 int onlyIfChanges = 0; /* No-op if there are no changes */
5e83504… mistachkin 2572 int allowFork = 0; /* Allow the commit to fork */
5e83504… mistachkin 2573 int allowOlder = 0; /* Allow a commit older than its ancestor */
798b232… drh 2574 int noVerifyCom = 0; /* Allow suspicious check-in comments */
d13054c… drh 2575 int useCksum; /* True if checksums should be computed and verified */
0b86639… jan.nijtmans 2576 int dryRunFlag; /* True for a test run. Debugging only */
4dcea80… drh 2577 CheckinInfo sCiInfo; /* Information about this check-in */
ab0a0d7… drh 2578 const char *zComFile; /* Read commit message from this file */
c4dc635… drh 2579 int nTag = 0; /* Number of --tag arguments */
c4dc635… drh 2580 const char *zTag; /* A single --tag argument */
dca018c… andygoth 2581 ManifestFile *pFile; /* File structure in the manifest */
dca018c… andygoth 2582 Manifest *pManifest; /* Manifest structure */
d13054c… drh 2583 Blob manifest; /* Manifest in baseline form */
c5f4ec0… bharder 2584 Blob cksum1, cksum2; /* Before and after commit checksums */
c5f4ec0… bharder 2585 Blob cksum1b; /* Checksum recorded in the manifest */
d13054c… drh 2586 int szD; /* Size of the delta manifest */
d13054c… drh 2587 int szB; /* Size of the baseline manifest */
7d34d17… drh 2588 int nConflict = 0; /* Number of unresolved merge conflicts */
18d5880… drh 2589 int abortCommit = 0; /* Abort the commit due to text format conversions */
18d5880… drh 2590 Blob ans; /* Answer to continuation prompts */
18d5880… drh 2591 char cReply; /* First character of ans */
18d5880… drh 2592 int bRecheck = 0; /* Repeat fork and closed-branch checks*/
bd7f272… danield 2593 int bIgnoreSkew = 0; /* --ignore-clock-skew flag */
3ffe893… drh 2594 int mxSize;
2453717… drh 2595 char *zCurBranch = 0; /* The current branch name of checkout */
2453717… drh 2596 char *zNewBranch = 0; /* The branch name after update */
072125b… drh 2597 int ckComFlgs; /* Flags passed to verify_comment() */
4588959… drh 2598 const char * zWikiFile; /* --wiki X */
4588959… drh 2599 const char * zWikiMime; /* --wiki-mimetype X */
d503cfd… jan.nijtmans 2600
4dcea80… drh 2601 memset(&sCiInfo, 0, sizeof(sCiInfo));
c5f4ec0… bharder 2602 url_proxy_options();
f6d335b… drh 2603 /* Undocumented. Supported only for backwards
f6d335b… drh 2604 ** compatibility -------vvvvvvv */
d90e56f… drh 2605 useHash = find_option("hash",0,0)!=0 || find_option("sha1sum",0,0)!=0;
c5f4ec0… bharder 2606 noSign = find_option("nosign",0,0)!=0;
e8a21ab… drh 2607 if( find_option("nosync",0,0) ) g.fNoSync = 1;
b4beadb… drh 2608 privateFlag = find_option("private",0,0)!=0;
d13054c… drh 2609 forceDelta = find_option("delta",0,0)!=0;
d13054c… drh 2610 forceBaseline = find_option("baseline",0,0)!=0;
ead01b6… danield 2611 db_must_be_within_tree();
884436c… danield 2612 if( db_get_boolean("dont-commit",0) ){
884436c… danield 2613 fossil_fatal("committing is prohibited: the 'dont-commit' option is set");
884436c… danield 2614 }
44ac944… drh 2615 if( forceDelta ){
44ac944… drh 2616 if( forceBaseline ){
44ac944… drh 2617 fossil_fatal("cannot use --delta and --baseline together");
44ac944… drh 2618 }
a439b11… drh 2619 if( db_get_boolean("forbid-delta-manifests",1) ){
44ac944… drh 2620 fossil_fatal("delta manifests are prohibited in this repository");
44ac944… drh 2621 }
d13054c… drh 2622 }
0b86639… jan.nijtmans 2623 dryRunFlag = find_option("dry-run","n",0)!=0;
0b86639… jan.nijtmans 2624 if( !dryRunFlag ){
0b86639… jan.nijtmans 2625 dryRunFlag = find_option("test",0,0)!=0; /* deprecated */
0b86639… jan.nijtmans 2626 }
c5f4ec0… bharder 2627 zComment = find_option("comment","m",1);
c5f4ec0… bharder 2628 forceFlag = find_option("force", "f", 0)!=0;
5e83504… mistachkin 2629 allowConflict = find_option("allow-conflict",0,0)!=0;
5e83504… mistachkin 2630 allowEmpty = find_option("allow-empty",0,0)!=0;
798b232… drh 2631 noVerifyCom = find_option("no-verify-comment",0,0)!=0;
f36695a… drh 2632 onlyIfChanges = find_option("if-changes",0,0)!=0;
5e83504… mistachkin 2633 allowFork = find_option("allow-fork",0,0)!=0;
3a5caa8… drh 2634 if( find_option("override-lock",0,0)!=0 ) allowFork = 1;
5e83504… mistachkin 2635 allowOlder = find_option("allow-older",0,0)!=0;
29ef4f5… mistachkin 2636 noPrompt = find_option("no-prompt", 0, 0)!=0;
cb856cc… mistachkin 2637 noWarningFlag = find_option("no-warnings", 0, 0)!=0;
9d8db79… drh 2638 noVerify = find_option("no-verify",0,0)!=0;
9d8db79… drh 2639 bTrace = find_option("trace",0,0)!=0;
4dcea80… drh 2640 sCiInfo.zBranch = find_option("branch","b",1);
5c8de34… drh 2641
5c8de34… drh 2642 /* NB: the --bgcolor and --branchcolor flags still work, but are
1ec8dee… drh 2643 ** now undocumented, to discourage their use. --mimetype has never
1ec8dee… drh 2644 ** been used for anything, so also leave it undocumented */
5c8de34… drh 2645 sCiInfo.zColor = find_option("bgcolor",0,1); /* Deprecated, undocumented*/
5c8de34… drh 2646 sCiInfo.zBrClr = find_option("branchcolor",0,1); /* Deprecated, undocumented*/
1ec8dee… drh 2647 sCiInfo.zMimetype = find_option("mimetype",0,1); /* Deprecated, undocumented*/
5c8de34… drh 2648
abf7271… jan.nijtmans 2649 sCiInfo.closeFlag = find_option("close",0,0)!=0;
82f69aa… drh 2650 sCiInfo.integrateFlag = find_option("integrate",0,0)!=0;
7ee98fe… drh 2651 sCiInfo.verboseFlag = find_option("verbose", "v", 0)!=0;
c4dc635… drh 2652 while( (zTag = find_option("tag",0,1))!=0 ){
c4dc635… drh 2653 if( zTag[0]==0 ) continue;
0b3f184… drh 2654 sCiInfo.azTag = fossil_realloc((void*)sCiInfo.azTag,
0b3f184… drh 2655 sizeof(char*)*(nTag+2));
4dcea80… drh 2656 sCiInfo.azTag[nTag++] = zTag;
4dcea80… drh 2657 sCiInfo.azTag[nTag] = 0;
c4dc635… drh 2658 }
ab0a0d7… drh 2659 zComFile = find_option("message-file", "M", 1);
4dcea80… drh 2660 sCiInfo.zDateOvrd = find_option("date-override",0,1);
4dcea80… drh 2661 sCiInfo.zUserOvrd = find_option("user-override",0,1);
c5f4ec0… bharder 2662 noSign = db_get_boolean("omitsign", 0)|noSign;
16e703b… drh 2663 if( db_get_boolean("clearsign", 0)==0 ){ noSign = 1; }
d13054c… drh 2664 useCksum = db_get_boolean("repo-cksum", 1);
bd7f272… danield 2665 bIgnoreSkew = find_option("ignore-clock-skew",0,0)!=0;
3ffe893… drh 2666 mxSize = db_large_file_size();
3ffe893… drh 2667 if( find_option("ignore-oversize",0,0)!=0 ) mxSize = 0;
4588959… drh 2668 zWikiFile = find_option("wiki","w",1);
4588959… drh 2669 zWikiMime = find_option("wiki-mimetype","wm",1);
7675987… drh 2670 (void)fossil_text_editor();
c5f4ec0… bharder 2671 verify_all_options();
5c8de34… drh 2672
5c8de34… drh 2673 /* The --no-warnings flag and the --force flag each imply
798b232… drh 2674 ** the --no-verify-comment flag */
5c8de34… drh 2675 if( noWarningFlag || forceFlag ){
798b232… drh 2676 noVerifyCom = 1;
5c8de34… drh 2677 }
0fd6cf1… jan.nijtmans 2678
0fd6cf1… jan.nijtmans 2679 /* Get the ID of the parent manifest artifact */
0fd6cf1… jan.nijtmans 2680 vid = db_lget_int("checkout", 0);
0fd6cf1… jan.nijtmans 2681 if( vid==0 ){
0fd6cf1… jan.nijtmans 2682 useCksum = 1;
b4beadb… drh 2683 if( privateFlag==0 && sCiInfo.zBranch==0 ) {
ca0d66b… danield 2684 sCiInfo.zBranch = db_main_branch();
b4beadb… drh 2685 }
b4beadb… drh 2686 }else{
b4beadb… drh 2687 privateParent = content_is_private(vid);
b4beadb… drh 2688 }
2453717… drh 2689
2453717… drh 2690 user_select();
2453717… drh 2691 /*
2453717… drh 2692 ** Check that the user exists.
2453717… drh 2693 */
2453717… drh 2694 if( !db_exists("SELECT 1 FROM user WHERE login=%Q", g.zLogin) ){
2453717… drh 2695 fossil_fatal("no such user: %s", g.zLogin);
2453717… drh 2696 }
2453717… drh 2697
2453717… drh 2698 /*
2453717… drh 2699 ** Detect if the branch name has changed from the parent check-in
2453717… drh 2700 ** and prompt if necessary
2453717… drh 2701 **/
2453717… drh 2702 zCurBranch = db_text(0,
2453717… drh 2703 " SELECT value FROM tagxref AS tx"
2453717… drh 2704 " WHERE rid=(SELECT pid"
2453717… drh 2705 " FROM tagxref LEFT JOIN event ON srcid=objid"
2453717… drh 2706 " LEFT JOIN plink ON rid=cid"
2453717… drh 2707 " WHERE rid=%d AND tagxref.tagid=%d"
2453717… drh 2708 " AND srcid!=origid"
2453717… drh 2709 " AND tagtype=2 AND coalesce(euser,user)!=%Q)"
2453717… drh 2710 " AND tx.tagid=%d",
2453717… drh 2711 vid, TAG_BRANCH, g.zLogin, TAG_BRANCH
2453717… drh 2712 );
2453717… drh 2713 if( zCurBranch!=0 && zCurBranch[0]!=0
2453717… drh 2714 && forceFlag==0
2453717… drh 2715 && noPrompt==0
2453717… drh 2716 ){
2453717… drh 2717 zNewBranch = branch_of_rid(vid);
2453717… drh 2718 fossil_warning(
2453717… drh 2719 "WARNING: The parent check-in [%.10s] has been moved from branch\n"
2453717… drh 2720 " '%s' over to branch '%s'.",
2453717… drh 2721 rid_to_uuid(vid), zCurBranch, zNewBranch
2453717… drh 2722 );
2453717… drh 2723 prompt_user("Commit anyway? (y/N) ", &ans);
2453717… drh 2724 cReply = blob_str(&ans)[0];
2453717… drh 2725 blob_reset(&ans);
2453717… drh 2726 if( cReply!='y' && cReply!='Y' ){
2453717… drh 2727 fossil_fatal("Abandoning commit because branch has changed");
2453717… drh 2728 }
2453717… drh 2729 fossil_free(zNewBranch);
2453717… drh 2730 fossil_free(zCurBranch);
2453717… drh 2731 zCurBranch = branch_of_rid(vid);
2453717… drh 2732 }
2453717… drh 2733 if( zCurBranch==0 ) zCurBranch = branch_of_rid(vid);
b4beadb… drh 2734
b4beadb… drh 2735 /* Track the "private" status */
b4beadb… drh 2736 g.markPrivate = privateFlag || privateParent;
b4beadb… drh 2737 if( privateFlag && !privateParent ){
b4beadb… drh 2738 /* Apply default branch name ("private") and color ("orange") if not
b4beadb… drh 2739 ** specified otherwise on the command-line, and if the parent is not
b4beadb… drh 2740 ** already private. */
b4beadb… drh 2741 if( sCiInfo.zBranch==0 ) sCiInfo.zBranch = "private";
0fd6cf1… jan.nijtmans 2742 }
b1026f2… drh 2743
b1026f2… drh 2744 /* Do not allow the creation of a new branch using an existing open
b1026f2… drh 2745 ** branch name unless the --force flag is used */
d7e45aa… drh 2746 if( sCiInfo.zBranch!=0
d7e45aa… drh 2747 && !forceFlag
d7e45aa… drh 2748 && fossil_strcmp(sCiInfo.zBranch,"private")!=0
d7e45aa… drh 2749 && branch_is_open(sCiInfo.zBranch)
d7e45aa… drh 2750 ){
b1026f2… drh 2751 fossil_fatal("an open branch named \"%s\" already exists - use --force"
b1026f2… drh 2752 " to override", sCiInfo.zBranch);
b1026f2… drh 2753 }
88e60e8… jan.nijtmans 2754
88e60e8… jan.nijtmans 2755 /* Escape special characters in tags and put all tags in sorted order */
88e60e8… jan.nijtmans 2756 if( nTag ){
88e60e8… jan.nijtmans 2757 int i;
88e60e8… jan.nijtmans 2758 for(i=0; i<nTag; i++) sCiInfo.azTag[i] = mprintf("%F", sCiInfo.azTag[i]);
88e60e8… jan.nijtmans 2759 qsort((void*)sCiInfo.azTag, nTag, sizeof(sCiInfo.azTag[0]), tagCmp);
88e60e8… jan.nijtmans 2760 }
88e60e8… jan.nijtmans 2761
f36695a… drh 2762 hasChanges = unsaved_changes(useHash ? CKSIG_HASH : 0);
f36695a… drh 2763 if( hasChanges==0 && onlyIfChanges ){
f36695a… drh 2764 /* "fossil commit --if-changes" is a no-op if there are no changes. */
f36695a… drh 2765 return;
f36695a… drh 2766 }
f36695a… drh 2767
88e60e8… jan.nijtmans 2768 /*
88e60e8… jan.nijtmans 2769 ** Autosync if autosync is enabled and this is not a private check-in.
88e60e8… jan.nijtmans 2770 */
88e60e8… jan.nijtmans 2771 if( !g.markPrivate ){
03cc332… drh 2772 int syncFlags = SYNC_PULL;
03cc332… drh 2773 if( vid!=0 && !allowFork && !forceFlag ){
03cc332… drh 2774 syncFlags |= SYNC_CKIN_LOCK;
03cc332… drh 2775 }
346e457… drh 2776 if( autosync_loop(syncFlags, 1, "commit") ){
d685096… drh 2777 fossil_exit(1);
14768c2… jan.nijtmans 2778 }
d685096… drh 2779 }
d685096… drh 2780
9116c6f… drh 2781 /* So that older versions of Fossil (that do not understand delta-
52a2be1… drh 2782 ** manifest) can continue to use this repository, and because
52a2be1… drh 2783 ** delta manifests are usually a bad idea unless the repository
478a0fa… danield 2784 ** has a really large number of files, do not create a new
9116c6f… drh 2785 ** delta-manifest unless this repository already contains one or more
9116c6f… drh 2786 ** delta-manifests, or unless the delta-manifest is explicitly requested
9116c6f… drh 2787 ** by the --delta option.
9116c6f… drh 2788 **
52a2be1… drh 2789 ** The forbid-delta-manifests setting prevents new delta manifests,
52a2be1… drh 2790 ** even if the --delta option is used.
9116c6f… drh 2791 **
9116c6f… drh 2792 ** If the remote repository sent an avoid-delta-manifests pragma on
52a2be1… drh 2793 ** the autosync above, then also forbid delta manifests, even if the
9116c6f… drh 2794 ** --delta option is specified. The remote repo will send the
478a0fa… danield 2795 ** avoid-delta-manifests pragma if its "forbid-delta-manifests"
52a2be1… drh 2796 ** setting is enabled.
9116c6f… drh 2797 */
52a2be1… drh 2798 if( !(forceDelta || db_get_boolean("seen-delta-manifest",0))
a439b11… drh 2799 || db_get_boolean("forbid-delta-manifests",1)
9116c6f… drh 2800 || g.bAvoidDeltaManifests
9116c6f… drh 2801 ){
52a2be1… drh 2802 forceBaseline = 1;
9116c6f… drh 2803 }
9116c6f… drh 2804
88e60e8… jan.nijtmans 2805 /* Require confirmation to continue with the check-in if there is
52a2be1… drh 2806 ** clock skew. This helps to prevent timewarps.
88e60e8… jan.nijtmans 2807 */
88e60e8… jan.nijtmans 2808 if( g.clockSkewSeen ){
bd7f272… danield 2809 if( bIgnoreSkew!=0 ){
bd7f272… danield 2810 cReply = 'y';
bd7f272… danield 2811 fossil_warning("Clock skew ignored due to --ignore-clock-skew.");
bd7f272… danield 2812 }else if( !noPrompt ){
29ef4f5… mistachkin 2813 prompt_user("continue in spite of time skew (y/N)? ", &ans);
29ef4f5… mistachkin 2814 cReply = blob_str(&ans)[0];
29ef4f5… mistachkin 2815 blob_reset(&ans);
29ef4f5… mistachkin 2816 }else{
29ef4f5… mistachkin 2817 fossil_print("Abandoning commit due to time skew\n");
29ef4f5… mistachkin 2818 cReply = 'N';
29ef4f5… mistachkin 2819 }
88e60e8… jan.nijtmans 2820 if( cReply!='y' && cReply!='Y' ){
88e60e8… jan.nijtmans 2821 fossil_exit(1);
88e60e8… jan.nijtmans 2822 }
88e60e8… jan.nijtmans 2823 }
88e60e8… jan.nijtmans 2824
88e60e8… jan.nijtmans 2825 /* There are two ways this command may be executed. If there are
88e60e8… jan.nijtmans 2826 ** no arguments following the word "commit", then all modified files
bc36fdc… danield 2827 ** in the checked-out directory are committed. If one or more arguments
88e60e8… jan.nijtmans 2828 ** follows "commit", then only those files are committed.
88e60e8… jan.nijtmans 2829 **
88e60e8… jan.nijtmans 2830 ** After the following function call has returned, the Global.aCommitFile[]
88e60e8… jan.nijtmans 2831 ** array is allocated to contain the "id" field from the vfile table
88e60e8… jan.nijtmans 2832 ** for each file to be committed. Or, if aCommitFile is NULL, all files
88e60e8… jan.nijtmans 2833 ** should be committed.
88e60e8… jan.nijtmans 2834 */
88e60e8… jan.nijtmans 2835 if( select_commit_files() ){
29ef4f5… mistachkin 2836 if( !noPrompt ){
29ef4f5… mistachkin 2837 prompt_user("continue (y/N)? ", &ans);
29ef4f5… mistachkin 2838 cReply = blob_str(&ans)[0];
29ef4f5… mistachkin 2839 blob_reset(&ans);
29ef4f5… mistachkin 2840 }else{
29ef4f5… mistachkin 2841 cReply = 'N';
29ef4f5… mistachkin 2842 }
29ef4f5… mistachkin 2843 if( cReply!='y' && cReply!='Y' ){
29ef4f5… mistachkin 2844 fossil_exit(1);
29ef4f5… mistachkin 2845 }
88e60e8… jan.nijtmans 2846 }
88e60e8… jan.nijtmans 2847 isAMerge = db_exists("SELECT 1 FROM vmerge WHERE id=0 OR id<-2");
88e60e8… jan.nijtmans 2848 if( g.aCommitFile && isAMerge ){
88e60e8… jan.nijtmans 2849 fossil_fatal("cannot do a partial commit of a merge");
88e60e8… jan.nijtmans 2850 }
88e60e8… jan.nijtmans 2851
88e60e8… jan.nijtmans 2852 /* Doing "fossil mv fileA fileB; fossil add fileA; fossil commit fileA"
88e60e8… jan.nijtmans 2853 ** will generate a manifest that has two fileA entries, which is illegal.
88e60e8… jan.nijtmans 2854 ** When you think about it, the sequence above makes no sense. So detect
88e60e8… jan.nijtmans 2855 ** it and disallow it. Ticket [0ff64b0a5fc8].
88e60e8… jan.nijtmans 2856 */
88e60e8… jan.nijtmans 2857 if( g.aCommitFile ){
4e092e0… jan.nijtmans 2858 db_prepare(&q,
88e60e8… jan.nijtmans 2859 "SELECT v1.pathname, v2.pathname"
88e60e8… jan.nijtmans 2860 " FROM vfile AS v1, vfile AS v2"
88e60e8… jan.nijtmans 2861 " WHERE is_selected(v1.id)"
88e60e8… jan.nijtmans 2862 " AND v2.origname IS NOT NULL"
88e60e8… jan.nijtmans 2863 " AND v2.origname=v1.pathname"
88e60e8… jan.nijtmans 2864 " AND NOT is_selected(v2.id)");
4e092e0… jan.nijtmans 2865 if( db_step(&q)==SQLITE_ROW ){
4e092e0… jan.nijtmans 2866 const char *zFrom = db_column_text(&q, 0);
4e092e0… jan.nijtmans 2867 const char *zTo = db_column_text(&q, 1);
88e60e8… jan.nijtmans 2868 fossil_fatal("cannot do a partial commit of '%s' without '%s' because "
88e60e8… jan.nijtmans 2869 "'%s' was renamed to '%s'", zFrom, zTo, zFrom, zTo);
88e60e8… jan.nijtmans 2870 }
4e092e0… jan.nijtmans 2871 db_finalize(&q);
88e60e8… jan.nijtmans 2872 }
88e60e8… jan.nijtmans 2873
e1962ef… drh 2874 db_begin_transaction();
3a5e81c… drh 2875 db_record_repository_filename(0);
5e83504… mistachkin 2876 if( hasChanges==0 && !isAMerge && !allowEmpty && !forceFlag ){
5e83504… mistachkin 2877 fossil_fatal("nothing has changed; use --allow-empty to override");
3a5e81c… drh 2878 }
3a5e81c… drh 2879
3a5e81c… drh 2880 /* If none of the files that were named on the command line have
5e83504… mistachkin 2881 ** been modified, bail out now unless the --allow-empty or --force
5e83504… mistachkin 2882 ** flags is used.
3a5e81c… drh 2883 */
3a5e81c… drh 2884 if( g.aCommitFile
5e83504… mistachkin 2885 && !allowEmpty
3a5e81c… drh 2886 && !forceFlag
3a5e81c… drh 2887 && !db_exists(
3a5e81c… drh 2888 "SELECT 1 FROM vfile "
3a5e81c… drh 2889 " WHERE is_selected(id)"
3a5e81c… drh 2890 " AND (chnged OR deleted OR rid=0 OR pathname!=origname)")
3a5e81c… drh 2891 ){
5e83504… mistachkin 2892 fossil_fatal("none of the selected files have changed; use "
5e83504… mistachkin 2893 "--allow-empty to override.");
5e83504… mistachkin 2894 }
5e83504… mistachkin 2895
18d5880… drh 2896 /* This loop checks for potential forks and for check-ins against a
18d5880… drh 2897 ** closed branch. The checks are repeated once after interactive
18d5880… drh 2898 ** check-in comment editing.
18d5880… drh 2899 */
18d5880… drh 2900 do{
18d5880… drh 2901 /*
18d5880… drh 2902 ** Do not allow a commit that will cause a fork unless the --allow-fork
18d5880… drh 2903 ** or --force flags is used, or unless this is a private check-in.
18d5880… drh 2904 ** The initial commit MUST have tags "trunk" and "sym-trunk".
18d5880… drh 2905 */
18d5880… drh 2906 if( sCiInfo.zBranch==0
18d5880… drh 2907 && allowFork==0
18d5880… drh 2908 && forceFlag==0
18d5880… drh 2909 && g.markPrivate==0
18d5880… drh 2910 && (vid==0 || !is_a_leaf(vid) || g.ckinLockFail)
18d5880… drh 2911 ){
18d5880… drh 2912 if( g.ckinLockFail ){
18d5880… drh 2913 fossil_fatal("Might fork due to a check-in race with user \"%s\"\n"
18d5880… drh 2914 "Try \"update\" first, or --branch, or "
18d5880… drh 2915 "use --override-lock",
18d5880… drh 2916 g.ckinLockFail);
18d5880… drh 2917 }else{
18d5880… drh 2918 fossil_fatal("Would fork. \"update\" first or use --branch or "
18d5880… drh 2919 "--allow-fork.");
18d5880… drh 2920 }
18d5880… drh 2921 }
275da70… danield 2922
18d5880… drh 2923 /*
18d5880… drh 2924 ** Do not allow a commit against a closed leaf unless the commit
18d5880… drh 2925 ** ends up on a different branch.
18d5880… drh 2926 */
18d5880… drh 2927 if(
18d5880… drh 2928 /* parent check-in has the "closed" tag... */
1243bf3… stephan 2929 leaf_is_closed(vid)
18d5880… drh 2930 /* ... and the new check-in has no --branch option or the --branch
18d5880… drh 2931 ** option does not actually change the branch */
18d5880… drh 2932 && (sCiInfo.zBranch==0
18d5880… drh 2933 || db_exists("SELECT 1 FROM tagxref"
18d5880… drh 2934 " WHERE tagid=%d AND rid=%d AND tagtype>0"
18d5880… drh 2935 " AND value=%Q", TAG_BRANCH, vid, sCiInfo.zBranch))
18d5880… drh 2936 ){
18d5880… drh 2937 fossil_fatal("cannot commit against a closed leaf");
18d5880… drh 2938 }
18d5880… drh 2939
2453717… drh 2940 /* Require confirmation to continue with the check-in if the branch
2453717… drh 2941 ** has changed and the committer did not provide the same branch
2453717… drh 2942 */
2453717… drh 2943 zNewBranch = branch_of_rid(vid);
2453717… drh 2944 if( fossil_strcmp(zCurBranch, zNewBranch)!=0
2453717… drh 2945 && fossil_strcmp(sCiInfo.zBranch, zNewBranch)!=0
2453717… drh 2946 && forceFlag==0
2453717… drh 2947 && noPrompt==0
2453717… drh 2948 ){
2453717… drh 2949 fossil_warning("parent check-in [%.10s] branch changed from '%s' to '%s'",
2453717… drh 2950 rid_to_uuid(vid), zCurBranch, zNewBranch);
2453717… drh 2951 prompt_user("continue (y/N)? ", &ans);
2453717… drh 2952 cReply = blob_str(&ans)[0];
2453717… drh 2953 blob_reset(&ans);
2453717… drh 2954 if( cReply!='y' && cReply!='Y' ){
2453717… drh 2955 fossil_fatal("Abandoning commit because branch has changed");
2453717… drh 2956 }
2453717… drh 2957 fossil_free(zCurBranch);
2453717… drh 2958 zCurBranch = branch_of_rid(vid);
2453717… drh 2959 }
2453717… drh 2960 fossil_free(zNewBranch);
2453717… drh 2961
18d5880… drh 2962 /* Always exit the loop on the second pass */
18d5880… drh 2963 if( bRecheck ) break;
9d8db79… drh 2964
2453717… drh 2965
798b232… drh 2966 /* Figure out how much comment verification is requested */
798b232… drh 2967 if( noVerifyCom ){
798b232… drh 2968 ckComFlgs = 0;
798b232… drh 2969 }else{
798b232… drh 2970 const char *zVerComs = db_get("verify-comments","on");
798b232… drh 2971 if( is_false(zVerComs) ){
798b232… drh 2972 ckComFlgs = 0;
798b232… drh 2973 }else if( strcmp(zVerComs,"preview")==0 ){
072125b… drh 2974 ckComFlgs = COMCK_PREVIEW | COMCK_MARKUP;
798b232… drh 2975 }else{
072125b… drh 2976 ckComFlgs = COMCK_MARKUP;
798b232… drh 2977 }
798b232… drh 2978 }
798b232… drh 2979
18d5880… drh 2980 /* Get the check-in comment. This might involve prompting the
18d5880… drh 2981 ** user for the check-in comment, in which case we should resync
18d5880… drh 2982 ** to renew the check-in lock and repeat the checks for conflicts.
18d5880… drh 2983 */
18d5880… drh 2984 if( zComment ){
18d5880… drh 2985 blob_zero(&comment);
18d5880… drh 2986 blob_append(&comment, zComment, -1);
072125b… drh 2987 ckComFlgs &= ~COMCK_PREVIEW;
072125b… drh 2988 if( verify_comment(&comment, ckComFlgs) ){
798b232… drh 2989 fossil_fatal("Commit aborted; "
798b232… drh 2990 "use --no-verify-comment to override");
19fc971… drh 2991 }
18d5880… drh 2992 }else if( zComFile ){
18d5880… drh 2993 blob_zero(&comment);
18d5880… drh 2994 blob_read_from_file(&comment, zComFile, ExtFILE);
18d5880… drh 2995 blob_to_utf8_no_bom(&comment, 1);
072125b… drh 2996 ckComFlgs &= ~COMCK_PREVIEW;
072125b… drh 2997 if( verify_comment(&comment, ckComFlgs) ){
798b232… drh 2998 fossil_fatal("Commit aborted; "
798b232… drh 2999 "use --no-verify-comment to override");
19fc971… drh 3000 }
18d5880… drh 3001 }else if( !noPrompt ){
3e87f78… drh 3002 while( 1/*exit-by-break*/ ){
798b232… drh 3003 int rc;
3e87f78… drh 3004 char *zInit;
ea99abc… drh 3005 assert( db_transaction_nesting_depth()==1 );
3e87f78… drh 3006 zInit = db_text(0,"SELECT value FROM vvar WHERE name='ci-comment'");
3e87f78… drh 3007 prepare_commit_comment(&comment, zInit, &sCiInfo, vid, dryRunFlag);
3e87f78… drh 3008 db_multi_exec("REPLACE INTO vvar VALUES('ci-comment',%B)", &comment);
ea99abc… drh 3009 assert( db_transaction_nesting_depth()==1 );
ea99abc… drh 3010 db_end_transaction(0);
ea99abc… drh 3011 db_begin_transaction();
072125b… drh 3012 if( (rc = verify_comment(&comment, ckComFlgs))!=0 ){
798b232… drh 3013 if( rc==COMCK_PREVIEW ){
072125b… drh 3014 prompt_user("Continue, abort, or edit? (C/a/e)? ", &ans);
798b232… drh 3015 }else{
072125b… drh 3016 prompt_user("Edit, abort, or continue (E/a/c)? ", &ans);
798b232… drh 3017 }
3e87f78… drh 3018 cReply = blob_str(&ans)[0];
798b232… drh 3019 cReply = fossil_tolower(cReply);
3e87f78… drh 3020 blob_reset(&ans);
072125b… drh 3021 if( cReply=='a' ){
777d962… drh 3022 fossil_fatal("Commit aborted.");
777d962… drh 3023 }
072125b… drh 3024 if( cReply=='e' || (cReply!='c' && rc!=COMCK_PREVIEW) ){
3e87f78… drh 3025 fossil_free(zInit);
3e87f78… drh 3026 continue;
3e87f78… drh 3027 }
3e87f78… drh 3028 }
3e87f78… drh 3029 if( zInit && zInit[0] && fossil_strcmp(zInit, blob_str(&comment))==0 ){
3e87f78… drh 3030 prompt_user("unchanged check-in comment. continue (y/N)? ", &ans);
3e87f78… drh 3031 cReply = blob_str(&ans)[0];
3e87f78… drh 3032 blob_reset(&ans);
3e87f78… drh 3033 if( cReply!='y' && cReply!='Y' ){
3e87f78… drh 3034 fossil_fatal("Commit aborted.");
3e87f78… drh 3035 }
3e87f78… drh 3036 }
3e87f78… drh 3037 fossil_free(zInit);
3e87f78… drh 3038 break;
3e87f78… drh 3039 }
3e87f78… drh 3040
18d5880… drh 3041 db_end_transaction(0);
18d5880… drh 3042 db_begin_transaction();
18d5880… drh 3043 if( !g.markPrivate && vid!=0 && !allowFork && !forceFlag ){
18d5880… drh 3044 /* Do another auto-pull, renewing the check-in lock. Then set
18d5880… drh 3045 ** bRecheck so that we loop back above to verify that the check-in
18d5880… drh 3046 ** is still not against a closed branch and still won't fork. */
18d5880… drh 3047 int syncFlags = SYNC_PULL|SYNC_CKIN_LOCK;
346e457… drh 3048 if( autosync_loop(syncFlags, 1, "commit") ){
190d138… danield 3049 fossil_fatal("Auto-pull failed. Commit aborted.");
18d5880… drh 3050 }
18d5880… drh 3051 bRecheck = 1;
29ef4f5… mistachkin 3052 }
d1f74a3… danield 3053 }else{
d1f74a3… danield 3054 blob_zero(&comment);
29ef4f5… mistachkin 3055 }
18d5880… drh 3056 }while( bRecheck );
18d5880… drh 3057
5a12e8c… mistachkin 3058 if( blob_size(&comment)==0 ){
5a12e8c… mistachkin 3059 if( !dryRunFlag ){
29ef4f5… mistachkin 3060 if( !noPrompt ){
29ef4f5… mistachkin 3061 prompt_user("empty check-in comment. continue (y/N)? ", &ans);
29ef4f5… mistachkin 3062 cReply = blob_str(&ans)[0];
29ef4f5… mistachkin 3063 blob_reset(&ans);
29ef4f5… mistachkin 3064 }else{
29ef4f5… mistachkin 3065 cReply = 'N';
29ef4f5… mistachkin 3066 }
5a12e8c… mistachkin 3067 if( cReply!='y' && cReply!='Y' ){
30ac5c0… danield 3068 fossil_fatal("Abandoning commit due to empty check-in comment\n");
4ff4e1c… drh 3069 }
4ff4e1c… drh 3070 }
4ff4e1c… drh 3071 }
4ff4e1c… drh 3072
4ff4e1c… drh 3073 if( !noVerify && hook_exists("before-commit") ){
4ff4e1c… drh 3074 /* Run before-commit hooks */
4ff4e1c… drh 3075 char *zAuxFile;
4ff4e1c… drh 3076 zAuxFile = prepare_commit_description_file(
4ff4e1c… drh 3077 &sCiInfo, vid, &comment, dryRunFlag);
4ff4e1c… drh 3078 if( zAuxFile ){
4ff4e1c… drh 3079 int rc = hook_run("before-commit",zAuxFile,bTrace);
4ff4e1c… drh 3080 file_delete(zAuxFile);
4ff4e1c… drh 3081 fossil_free(zAuxFile);
4ff4e1c… drh 3082 if( rc ){
4ff4e1c… drh 3083 fossil_fatal("Before-commit hook failed\n");
5a12e8c… mistachkin 3084 }
5a12e8c… mistachkin 3085 }
5a12e8c… mistachkin 3086 }
5a12e8c… mistachkin 3087
5a12e8c… mistachkin 3088 /*
5a12e8c… mistachkin 3089 ** Step 1: Compute an aggregate MD5 checksum over the disk image
5a12e8c… mistachkin 3090 ** of every file in vid. The file names are part of the checksum.
5a12e8c… mistachkin 3091 ** The resulting checksum is the same as is expected on the R-card
5a12e8c… mistachkin 3092 ** of a manifest.
5a12e8c… mistachkin 3093 */
5a12e8c… mistachkin 3094 if( useCksum ) vfile_aggregate_checksum_disk(vid, &cksum1);
5a12e8c… mistachkin 3095
5a12e8c… mistachkin 3096 /* Step 2: Insert records for all modified files into the blob
db0c512… drh 3097 ** table. If there were arguments passed to this command, only
db0c512… drh 3098 ** the identified files are inserted (if they have been modified).
db0c512… drh 3099 */
db0c512… drh 3100 db_prepare(&q,
be25d41… andygoth 3101 "SELECT id, %Q || pathname, mrid, %s, %s, %s FROM vfile "
ed5843c… drh 3102 "WHERE chnged<>0 AND NOT deleted AND is_selected(id)",
cb856cc… mistachkin 3103 g.zLocalRoot,
87320cf… andygoth 3104 glob_expr("pathname", db_get("crlf-glob",db_get("crnl-glob",""))),
cb856cc… mistachkin 3105 glob_expr("pathname", db_get("binary-glob","")),
7d237c4… jan.nijtmans 3106 glob_expr("pathname", db_get("encoding-glob",""))
22552fb… dan 3107 );
dbda8d6… drh 3108 while( db_step(&q)==SQLITE_ROW ){
dbda8d6… drh 3109 int id, rid;
dbda8d6… drh 3110 const char *zFullname;
dbda8d6… drh 3111 Blob content;
3ffe893… drh 3112 int crlfOk, binOk, encodingOk, sizeOk;
dbda8d6… drh 3113
dbda8d6… drh 3114 id = db_column_int(&q, 0);
dbda8d6… drh 3115 zFullname = db_column_text(&q, 1);
dbda8d6… drh 3116 rid = db_column_int(&q, 2);
87320cf… andygoth 3117 crlfOk = db_column_int(&q, 3);
be25d41… andygoth 3118 binOk = db_column_int(&q, 4);
be25d41… andygoth 3119 encodingOk = db_column_int(&q, 5);
3ffe893… drh 3120 sizeOk = mxSize<=0 || file_size(zFullname, ExtFILE)<=mxSize;
d13054c… drh 3121
d13054c… drh 3122 blob_zero(&content);
1772357… drh 3123 blob_read_from_file(&content, zFullname, RepoFILE);
cb856cc… mistachkin 3124 /* Do not emit any warnings when they are disabled. */
cb856cc… mistachkin 3125 if( !noWarningFlag ){
87320cf… andygoth 3126 abortCommit |= commit_warning(&content, crlfOk, binOk,
3ffe893… drh 3127 encodingOk, sizeOk, noPrompt,
de78b73… mistachkin 3128 zFullname, 0);
cb856cc… mistachkin 3129 }
be25d41… andygoth 3130 if( contains_merge_marker(&content) ){
2a15d87… jan.nijtmans 3131 Blob fname; /* Relative pathname of the file */
2a15d87… jan.nijtmans 3132
7d34d17… drh 3133 nConflict++;
2a15d87… jan.nijtmans 3134 file_relative_name(zFullname, &fname, 0);
7d34d17… drh 3135 fossil_print("possible unresolved merge conflict in %s\n",
2a15d87… jan.nijtmans 3136 blob_str(&fname));
2a15d87… jan.nijtmans 3137 blob_reset(&fname);
7d34d17… drh 3138 }
1b45161… drh 3139 nrid = content_put(&content);
d13054c… drh 3140 blob_reset(&content);
ed5843c… drh 3141 if( nrid!=rid ){
ed5843c… drh 3142 if( rid>0 ){
ed5843c… drh 3143 content_deltify(rid, &nrid, 1, 0);
ed5843c… drh 3144 }
ed5843c… drh 3145 db_multi_exec("UPDATE vfile SET mrid=%d, rid=%d, mhash=NULL WHERE id=%d",
ed5843c… drh 3146 nrid,nrid,id);
673dc38… stephan 3147 db_add_unsent(nrid);
d13054c… drh 3148 }
d13054c… drh 3149 }
d13054c… drh 3150 db_finalize(&q);
7d34d17… drh 3151 if( nConflict && !allowConflict ){
2ff70a3… mistachkin 3152 fossil_fatal("abort due to unresolved merge conflicts; "
2ff70a3… mistachkin 3153 "use --allow-conflict to override");
79f7eb2… jan.nijtmans 3154 }else if( abortCommit ){
3527aa4… mistachkin 3155 fossil_fatal("one or more files were converted on your request; "
3527aa4… mistachkin 3156 "please re-test before committing");
7d34d17… drh 3157 }
d13054c… drh 3158
d13054c… drh 3159 /* Create the new manifest */
4dcea80… drh 3160 sCiInfo.pComment = &comment;
4dcea80… drh 3161 sCiInfo.pCksum = useCksum ? &cksum1 : 0;
086612a… drh 3162 sCiInfo.verifyDate = !allowOlder && !forceFlag;
d13054c… drh 3163 if( forceDelta ){
d13054c… drh 3164 blob_zero(&manifest);
d13054c… drh 3165 }else{
4dcea80… drh 3166 create_manifest(&manifest, 0, 0, vid, &sCiInfo, &szB);
d13054c… drh 3167 }
d13054c… drh 3168
d13054c… drh 3169 /* See if a delta-manifest would be more appropriate */
d13054c… drh 3170 if( !forceBaseline ){
d13054c… drh 3171 const char *zBaselineUuid;
d13054c… drh 3172 Manifest *pParent;
d13054c… drh 3173 Manifest *pBaseline;
ec81aee… jan.nijtmans 3174 pParent = manifest_get(vid, CFTYPE_MANIFEST, 0);
d13054c… drh 3175 if( pParent && pParent->zBaseline ){
d13054c… drh 3176 zBaselineUuid = pParent->zBaseline;
d13054c… drh 3177 pBaseline = manifest_get_by_name(zBaselineUuid, 0);
d13054c… drh 3178 }else{
d13054c… drh 3179 zBaselineUuid = db_text(0, "SELECT uuid FROM blob WHERE rid=%d", vid);
d13054c… drh 3180 pBaseline = pParent;
d13054c… drh 3181 }
d13054c… drh 3182 if( pBaseline ){
d13054c… drh 3183 Blob delta;
4dcea80… drh 3184 create_manifest(&delta, zBaselineUuid, pBaseline, vid, &sCiInfo, &szD);
d13054c… drh 3185 /*
d13054c… drh 3186 ** At this point, two manifests have been constructed, either of
c49030f… drh 3187 ** which would work for this check-in. The first manifest (held
d13054c… drh 3188 ** in the "manifest" variable) is a baseline manifest and the second
d13054c… drh 3189 ** (held in variable named "delta") is a delta manifest. The
d13054c… drh 3190 ** question now is: which manifest should we use?
d13054c… drh 3191 **
d13054c… drh 3192 ** Let B be the number of F-cards in the baseline manifest and
d13054c… drh 3193 ** let D be the number of F-cards in the delta manifest, plus one for
d13054c… drh 3194 ** the B-card. (B is held in the szB variable and D is held in the
d13054c… drh 3195 ** szD variable.) Assume that all delta manifests adds X new F-cards.
d13054c… drh 3196 ** Then to minimize the total number of F- and B-cards in the repository,
d13054c… drh 3197 ** we should use the delta manifest if and only if:
d13054c… drh 3198 **
d13054c… drh 3199 ** D*D < B*X - X*X
d13054c… drh 3200 **
d13054c… drh 3201 ** X is an unknown here, but for most repositories, we will not be
d13054c… drh 3202 ** far wrong if we assume X=3.
d13054c… drh 3203 */
d13054c… drh 3204 if( forceDelta || (szD*szD)<(szB*3-9) ){
d13054c… drh 3205 blob_reset(&manifest);
d13054c… drh 3206 manifest = delta;
d13054c… drh 3207 }else{
d13054c… drh 3208 blob_reset(&delta);
d13054c… drh 3209 }
d13054c… drh 3210 }else if( forceDelta ){
320f143… drh 3211 fossil_fatal("unable to find a baseline-manifest for the delta");
d13054c… drh 3212 }
d13054c… drh 3213 }
d13054c… drh 3214 if( !noSign && !g.markPrivate && clearsign(&manifest, &manifest) ){
29ef4f5… mistachkin 3215 if( !noPrompt ){
29ef4f5… mistachkin 3216 prompt_user("unable to sign manifest. continue (y/N)? ", &ans);
29ef4f5… mistachkin 3217 cReply = blob_str(&ans)[0];
29ef4f5… mistachkin 3218 blob_reset(&ans);
29ef4f5… mistachkin 3219 }else{
29ef4f5… mistachkin 3220 cReply = 'N';
29ef4f5… mistachkin 3221 }
d503cfd… jan.nijtmans 3222 if( cReply!='y' && cReply!='Y' ){
30ac5c0… danield 3223 fossil_fatal("Abandoning commit due to manifest signing failure\n");
d13054c… drh 3224 }
d13054c… drh 3225 }
d13054c… drh 3226
a38fa0b… jan.nijtmans 3227 /* If the -n|--dry-run option is specified, output the manifest file
d503cfd… jan.nijtmans 3228 ** and rollback the transaction.
d13054c… drh 3229 */
0b86639… jan.nijtmans 3230 if( dryRunFlag ){
d13054c… drh 3231 blob_write_to_file(&manifest, "");
d13054c… drh 3232 }
8c5b5c3… jan.nijtmans 3233
9eb3f5f… jan.nijtmans 3234 nvid = content_put(&manifest);
9eb3f5f… jan.nijtmans 3235 if( nvid==0 ){
320f143… drh 3236 fossil_fatal("trouble committing manifest: %s", g.zErrMsg);
12c30d3… jan.nijtmans 3237 }
673dc38… stephan 3238 db_add_unsent(nvid);
1311841… jan.nijtmans 3239 if( manifest_crosslink(nvid, &manifest,
1311841… jan.nijtmans 3240 dryRunFlag ? MC_NONE : MC_PERMIT_HOOKS)==0 ){
2c42b21… andygoth 3241 fossil_fatal("%s", g.zErrMsg);
1311841… jan.nijtmans 3242 }
12c30d3… jan.nijtmans 3243 assert( blob_is_reset(&manifest) );
a4047a9… drh 3244 content_deltify(vid, &nvid, 1, 0);
12c30d3… jan.nijtmans 3245 zUuid = db_text(0, "SELECT uuid FROM blob WHERE rid=%d", nvid);
8c5b5c3… jan.nijtmans 3246
fff37e6… drh 3247 db_prepare(&q, "SELECT mhash,merge FROM vmerge WHERE id=-4");
69dd259… jan.nijtmans 3248 while( db_step(&q)==SQLITE_ROW ){
69dd259… jan.nijtmans 3249 const char *zIntegrateUuid = db_column_text(&q, 0);
daa8eb9… jan.nijtmans 3250 if( is_a_leaf(db_column_int(&q, 1)) ){
153e17c… andybradford 3251 fossil_print("Closed: %s\n", zIntegrateUuid);
69dd259… jan.nijtmans 3252 }else{
153e17c… andybradford 3253 fossil_print("Not_Closed: %s (not a leaf any more)\n", zIntegrateUuid);
69dd259… jan.nijtmans 3254 }
69dd259… jan.nijtmans 3255 }
69dd259… jan.nijtmans 3256 db_finalize(&q);
69dd259… jan.nijtmans 3257
153e17c… andybradford 3258 fossil_print("New_Version: %s\n", zUuid);
d503cfd… jan.nijtmans 3259
22552fb… dan 3260 /* Update the vfile and vmerge tables */
22552fb… dan 3261 db_multi_exec(
01e4de6… drh 3262 "DELETE FROM vfile WHERE (vid!=%d OR deleted) AND is_selected(id);"
195517a… drh 3263 "DELETE FROM vmerge;"
22552fb… dan 3264 "UPDATE vfile SET vid=%d;"
fff37e6… drh 3265 "UPDATE vfile SET rid=mrid, mhash=NULL, chnged=0, deleted=0, origname=NULL"
01e4de6… drh 3266 " WHERE is_selected(id);"
22552fb… dan 3267 , vid, nvid
22552fb… dan 3268 );
f72ef85… andybradford 3269 db_set_checkout(nvid, !dryRunFlag);
dca018c… andygoth 3270
dca018c… andygoth 3271 /* Update the isexe and islink columns of the vfile table */
dca018c… andygoth 3272 db_prepare(&q,
dca018c… andygoth 3273 "UPDATE vfile SET isexe=:exec, islink=:link"
dca018c… andygoth 3274 " WHERE vid=:vid AND pathname=:path AND (isexe!=:exec OR islink!=:link)"
dca018c… andygoth 3275 );
dca018c… andygoth 3276 db_bind_int(&q, ":vid", nvid);
dca018c… andygoth 3277 pManifest = manifest_get(nvid, CFTYPE_MANIFEST, 0);
dca018c… andygoth 3278 manifest_file_rewind(pManifest);
dca018c… andygoth 3279 while( (pFile = manifest_file_next(pManifest, 0)) ){
dca018c… andygoth 3280 db_bind_int(&q, ":exec", pFile->zPerm && strstr(pFile->zPerm, "x"));
dca018c… andygoth 3281 db_bind_int(&q, ":link", pFile->zPerm && strstr(pFile->zPerm, "l"));
dca018c… andygoth 3282 db_bind_text(&q, ":path", pFile->zName);
dca018c… andygoth 3283 db_step(&q);
dca018c… andygoth 3284 db_reset(&q);
dca018c… andygoth 3285 }
dca018c… andygoth 3286 db_finalize(&q);
dca018c… andygoth 3287 manifest_destroy(pManifest);
d13054c… drh 3288
d13054c… drh 3289 if( useCksum ){
d13054c… drh 3290 /* Verify that the repository checksum matches the expected checksum
c49030f… drh 3291 ** calculated before the check-in started (and stored as the R record
d13054c… drh 3292 ** of the manifest file).
d13054c… drh 3293 */
d13054c… drh 3294 vfile_aggregate_checksum_repository(nvid, &cksum2);
d13054c… drh 3295 if( blob_compare(&cksum1, &cksum2) ){
64459dd… drh 3296 vfile_compare_repository_to_disk(nvid);
bc36fdc… danield 3297 fossil_fatal("working check-out does not match what would have ended "
2ceeeca… drh 3298 "up in the repository: %b versus %b",
2ceeeca… drh 3299 &cksum1, &cksum2);
d13054c… drh 3300 }
d503cfd… jan.nijtmans 3301
d13054c… drh 3302 /* Verify that the manifest checksum matches the expected checksum */
d13054c… drh 3303 vfile_aggregate_checksum_manifest(nvid, &cksum2, &cksum1b);
d13054c… drh 3304 if( blob_compare(&cksum1, &cksum1b) ){
2ceeeca… drh 3305 fossil_fatal("manifest checksum self-test failed: "
d13054c… drh 3306 "%b versus %b", &cksum1, &cksum1b);
d13054c… drh 3307 }
d13054c… drh 3308 if( blob_compare(&cksum1, &cksum2) ){
2ceeeca… drh 3309 fossil_fatal(
bc36fdc… danield 3310 "working check-out does not match manifest after commit: "
2ceeeca… drh 3311 "%b versus %b", &cksum1, &cksum2);
d13054c… drh 3312 }
d503cfd… jan.nijtmans 3313
d13054c… drh 3314 /* Verify that the commit did not modify any disk images. */
d13054c… drh 3315 vfile_aggregate_checksum_disk(nvid, &cksum2);
d13054c… drh 3316 if( blob_compare(&cksum1, &cksum2) ){
bc36fdc… danield 3317 fossil_fatal("working check-out before and after commit does not match");
bc36fdc… danield 3318 }
4588959… drh 3319 }
4588959… drh 3320
4588959… drh 3321 if( zWikiFile ){
4588959… drh 3322 /* Handle --wiki and --wiki-mimetype */
4588959… drh 3323 Blob bWiki = BLOB_INITIALIZER;
4588959… drh 3324 char * zPageName;
4588959… drh 3325 int parentRid = 0;
4588959… drh 3326 blob_read_from_file(&bWiki, zWikiFile, ExtFILE);
4588959… drh 3327 if( !zWikiMime ){
4588959… drh 3328 if( 0==sqlite3_strglob("*.md", zWikiFile) ){
4588959… drh 3329 zWikiMime = "text/x-markdown";
4588959… drh 3330 }else if( 0==sqlite3_strglob("*.wiki", zWikiFile) ){
4588959… drh 3331 zWikiMime = "text/x-fossil-wiki";
4588959… drh 3332 }else{
4588959… drh 3333 zWikiMime = "text/plain";
4588959… drh 3334 }
4588959… drh 3335 }
4588959… drh 3336 zPageName = mprintf("checkin/%s", zUuid);
4588959… drh 3337 zWikiMime = wiki_filter_mimetypes(zWikiMime);
4588959… drh 3338 wiki_cmd_commit(zPageName, parentRid, &bWiki, zWikiMime, 1);
4588959… drh 3339 fossil_print("Added %s (%s)\n", zPageName, zWikiMime);
4588959… drh 3340 blob_reset(&bWiki);
4588959… drh 3341 fossil_free(zPageName);
f72ef85… andybradford 3342 }
f72ef85… andybradford 3343
f76192b… aku 3344 /* Clear the undo/redo stack */
f76192b… aku 3345 undo_reset();
22552fb… dan 3346
22552fb… dan 3347 /* Commit */
68bfc1d… drh 3348 db_multi_exec("DELETE FROM vvar WHERE name='ci-comment'");
06aec61… drh 3349 db_multi_exec("PRAGMA repository.application_id=252006673;");
06aec61… drh 3350 db_multi_exec("PRAGMA localdb.application_id=252006674;");
0b86639… jan.nijtmans 3351 if( dryRunFlag ){
d13054c… drh 3352 db_end_transaction(1);
661bd94… drh 3353 return;
d13054c… drh 3354 }
02a584f… drh 3355 db_end_transaction(0);
02a584f… drh 3356
02a584f… drh 3357 if( !g.markPrivate ){
3350be2… drh 3358 int syncFlags = SYNC_PUSH | SYNC_PULL | SYNC_IFABLE;
346e457… drh 3359 autosync_loop(syncFlags, 0, "commit");
02a584f… drh 3360 }
02a584f… drh 3361 if( count_nonbranch_children(vid)>1 ){
d8ec765… drh 3362 fossil_print("**** warning: a fork has occurred *****\n");
707743d… drh 3363 }else{
707743d… drh 3364 leaf_ambiguity_warning(nvid,nvid);
ab0a0d7… drh 3365 }
dbda8d6… drh 3366 }

Keyboard Shortcuts

Open search /
Next entry (timeline) j
Previous entry (timeline) k
Open focused entry Enter
Show this help ?
Toggle theme Top nav button