Fossil SCM

Implement most of the new changes command, still need to do --all, --unmodified, and --extra

andygoth 2016-11-05 22:22 UTC andygoth-changes
Commit 7595bdfbf099418b7b12780563ca1be3d24fc0e3
1 file changed +153 -114
+153 -114
--- src/checkin.c
+++ src/checkin.c
@@ -27,54 +27,50 @@
2727
*/
2828
enum {
2929
/* Zero-based bit indexes. */
3030
CB_EDITED , CB_UPDATED , CB_CHANGED, CB_MISSING , CB_ADDED , CB_DELETED,
3131
CB_RENAMED, CB_CONFLICT, CB_META , CB_UNMODIFIED, CB_EXTRA , CB_MERGE ,
32
- CB_RELPATH, CB_SHA1SUM , CB_HEADER , CB_VERBOSE , CB_CLASSIFY,
32
+ CB_RELPATH, CB_SHA1SUM , CB_HEADER , CB_VERBOSE , CB_CLASSIFY, CB_FATAL ,
33
+ CB_COMMENT,
3334
3435
/* Bitmask values. */
35
- C_EDITED = 1 << CB_EDITED,
36
- C_UPDATED = 1 << CB_UPDATED,
37
- C_CHANGED = 1 << CB_CHANGED, /* Becomes CB_EDITED|CB_UPDATED. */
38
- C_MISSING = 1 << CB_MISSING,
39
- C_ADDED = 1 << CB_ADDED,
40
- C_DELETED = 1 << CB_DELETED,
41
- C_RENAMED = 1 << CB_RENAMED,
42
- C_CONFLICT = 1 << CB_CONFLICT,
43
- C_META = 1 << CB_META,
44
- C_UNMODIFIED = 1 << CB_UNMODIFIED,
45
- C_EXTRA = 1 << CB_EXTRA,
46
- C_MERGE = 1 << CB_MERGE,
36
+ C_EDITED = 1 << CB_EDITED, /* Edited, merged, and conflicted files. */
37
+ C_UPDATED = 1 << CB_UPDATED, /* Files updated by merge/integrate. */
38
+ C_CHANGED = 1 << CB_CHANGED, /* Becomes CB_EDITED|CB_UPDATED. */
39
+ C_MISSING = 1 << CB_MISSING, /* Missing and non- files. */
40
+ C_ADDED = 1 << CB_ADDED, /* Added files. */
41
+ C_DELETED = 1 << CB_DELETED, /* Deleted files. */
42
+ C_RENAMED = 1 << CB_RENAMED, /* Renamed files. */
43
+ C_CONFLICT = 1 << CB_CONFLICT, /* Files having merge conflicts. */
44
+ C_META = 1 << CB_META, /* Files with metadata changes. */
45
+ C_UNMODIFIED = 1 << CB_UNMODIFIED,/* Unmodified files. */
46
+ C_EXTRA = 1 << CB_EXTRA, /* Unmanaged files. */
47
+ C_MERGE = 1 << CB_MERGE, /* Merge contributors. */
4748
C_FILTER = C_EDITED | C_UPDATED | C_CHANGED | C_MISSING | C_ADDED
4849
| C_DELETED | C_RENAMED | C_CONFLICT | C_META | C_UNMODIFIED
4950
| C_EXTRA | C_MERGE,
5051
C_ALL = C_FILTER & ~(C_CHANGED | C_EXTRA | C_MERGE),
51
- C_RELPATH = 1 << CB_RELPATH,
52
- C_SHA1SUM = 1 << CB_SHA1SUM,
53
- C_HEADER = 1 << CB_HEADER,
54
- C_VERBOSE = 1 << CB_VERBOSE,
55
- C_CLASSIFY = 1 << CB_CLASSIFY,
52
+ C_RELPATH = 1 << CB_RELPATH, /* Show relative paths. */
53
+ C_SHA1SUM = 1 << CB_SHA1SUM, /* Use SHA1 checksums not mtimes. */
54
+ C_HEADER = 1 << CB_HEADER, /* Display repository name if non-empty. */
55
+ C_VERBOSE = 1 << CB_VERBOSE, /* Display "(none)" if empty. */
56
+ C_CLASSIFY = 1 << CB_CLASSIFY, /* Show file change types. */
5657
C_DEFAULT = (C_ALL & ~C_UNMODIFIED) | C_MERGE | C_CLASSIFY,
58
+ C_FATAL = (1 << CB_FATAL) | C_MISSING, /* Fail on MISSING/NOT_A_FILE. */
59
+ C_COMMENT = 1 << CB_COMMENT, /* Precede each line with "# ". */
5760
};
5861
5962
/*
60
-** Generate text describing all changes. Prepend zPrefix to each line
61
-** of output.
63
+** Generate text describing all changes.
6264
**
6365
** We assume that vfile_check_signature has been run.
64
-**
65
-** If missingIsFatal is true, then any files that are missing or which
66
-** are not true files results in a fatal error.
6766
*/
6867
static void status_report(
6968
Blob *report, /* Append the status report here */
70
- const char *zPrefix, /* Prefix on each line of the report */
71
- int missingIsFatal, /* MISSING and NOT_A_FILE are fatal errors */
72
- int cwdRelative /* Report relative to the current working dir */
69
+ unsigned flags /* Filter and other configuration flags */
7370
){
7471
Stmt q;
75
- int nPrefix = strlen(zPrefix);
7672
int nErr = 0;
7773
Blob rewrittenPathname;
7874
Blob where;
7975
const char *zName;
8076
int i;
@@ -107,87 +103,128 @@
107103
blob_sql_text(&where)
108104
);
109105
blob_zero(&rewrittenPathname);
110106
while( db_step(&q)==SQLITE_ROW ){
111107
const char *zPathname = db_column_text(&q,0);
112
- const char *zDisplayName = zPathname;
108
+ const char *zClass = 0;
113109
int isDeleted = db_column_int(&q, 1);
114110
int isChnged = db_column_int(&q,2);
115111
int isNew = db_column_int(&q,3)==0;
116112
int isRenamed = db_column_int(&q,4);
117113
int isLink = db_column_int(&q,5);
118114
char *zFullName = mprintf("%s%s", g.zLocalRoot, zPathname);
119
- if( cwdRelative ){
120
- file_relative_name(zFullName, &rewrittenPathname, 0);
121
- zDisplayName = blob_str(&rewrittenPathname);
122
- if( zDisplayName[0]=='.' && zDisplayName[1]=='/' ){
123
- zDisplayName += 2; /* no unnecessary ./ prefix */
124
- }
125
- }
126
- blob_append(report, zPrefix, nPrefix);
127
- if( isDeleted ){
128
- blob_appendf(report, "DELETED %s\n", zDisplayName);
129
- }else if( !file_wd_isfile_or_link(zFullName) ){
130
- if( file_access(zFullName, F_OK)==0 ){
131
- blob_appendf(report, "NOT_A_FILE %s\n", zDisplayName);
132
- if( missingIsFatal ){
133
- fossil_warning("not a file: %s", zDisplayName);
134
- nErr++;
135
- }
136
- }else{
137
- blob_appendf(report, "MISSING %s\n", zDisplayName);
138
- if( missingIsFatal ){
139
- fossil_warning("missing file: %s", zDisplayName);
140
- nErr++;
141
- }
142
- }
143
- }else if( isNew ){
144
- blob_appendf(report, "ADDED %s\n", zDisplayName);
145
- }else if( isChnged ){
146
- if( isChnged==2 ){
147
- blob_appendf(report, "UPDATED_BY_MERGE %s\n", zDisplayName);
148
- }else if( isChnged==3 ){
149
- blob_appendf(report, "ADDED_BY_MERGE %s\n", zDisplayName);
150
- }else if( isChnged==4 ){
151
- blob_appendf(report, "UPDATED_BY_INTEGRATE %s\n", zDisplayName);
152
- }else if( isChnged==5 ){
153
- blob_appendf(report, "ADDED_BY_INTEGRATE %s\n", zDisplayName);
154
- }else if( isChnged==6 ){
155
- blob_appendf(report, "EXECUTABLE %s\n", zDisplayName);
156
- }else if( isChnged==7 ){
157
- blob_appendf(report, "SYMLINK %s\n", zDisplayName);
158
- }else if( isChnged==8 ){
159
- blob_appendf(report, "UNEXEC %s\n", zDisplayName);
160
- }else if( isChnged==9 ){
161
- blob_appendf(report, "UNLINK %s\n", zDisplayName);
162
- }else if( !isLink && file_contains_merge_marker(zFullName) ){
163
- blob_appendf(report, "CONFLICT %s\n", zDisplayName);
164
- }else{
165
- blob_appendf(report, "EDITED %s\n", zDisplayName);
166
- }
167
- }else if( isRenamed ){
168
- blob_appendf(report, "RENAMED %s\n", zDisplayName);
169
- }else{
170
- report->nUsed -= nPrefix;
115
+ int isMissing = !file_wd_isfile_or_link(zFullName);
116
+
117
+ /* Determine the file change classification, if any. */
118
+ if( (flags & C_DELETED) && isDeleted ){
119
+ zClass = "DELETED";
120
+ }else if( (flags & C_MISSING) && isMissing ){
121
+ if( file_access(zFullName, F_OK)==0 ){
122
+ zClass = "NOT_A_FILE";
123
+ if( flags & C_FATAL ){
124
+ fossil_warning("not a file: %s", zFullName);
125
+ nErr++;
126
+ }
127
+ }else{
128
+ zClass = "MISSING";
129
+ if( flags & C_FATAL ){
130
+ fossil_warning("missing file: %s", zFullName);
131
+ nErr++;
132
+ }
133
+ }
134
+ }else if( (flags & C_ADDED) && isNew ){
135
+ zClass = "ADDED";
136
+ }else if( (flags & C_UPDATED) && isChnged==2 ){
137
+ zClass = "UPDATED_BY_MERGE";
138
+ }else if( (flags & C_ADDED) && isChnged==3 ){
139
+ zClass = "ADDED_BY_MERGE";
140
+ }else if( (flags & C_UPDATED) && isChnged==4 ){
141
+ zClass = "UPDATED_BY_INTEGRATE";
142
+ }else if( (flags & C_ADDED) && isChnged==5 ){
143
+ zClass = "ADDED_BY_INTEGRATE";
144
+ }else if( (flags & C_META) && isChnged==6 ){
145
+ zClass = "EXECUTABLE";
146
+ }else if( (flags & C_META) && isChnged==7 ){
147
+ zClass = "SYMLINK";
148
+ }else if( (flags & C_META) && isChnged==8 ){
149
+ zClass = "UNEXEC";
150
+ }else if( (flags & C_META) && isChnged==9 ){
151
+ zClass = "UNLINK";
152
+ }else if( (flags & C_CONFLICT) && isChnged && !isLink
153
+ && file_contains_merge_marker(zFullName) ){
154
+ zClass = "CONFLICT";
155
+ }else if( (flags & C_EDITED) && isChnged ){
156
+ zClass = "EDITED";
157
+ }else if( (flags & C_RENAMED) && isRenamed ){
158
+ zClass = "RENAMED";
159
+ }else if( (flags & C_UNMODIFIED) && !isDeleted && !isMissing && !isNew
160
+ && !isChnged && !isRenamed ){
161
+ /* TODO: never gets executed because query only yields modified files. */
162
+ zClass = "UNMODIFIED";
163
+ }
164
+ /* TODO: implement C_EXTRA. */
165
+
166
+ /* Only report files for which a change classification was determined. */
167
+ if( zClass ){
168
+ /* If C_COMMENT, precede each line with "# ". */
169
+ if( flags & C_COMMENT ){
170
+ blob_append(report, "# ", 2);
171
+ }
172
+
173
+ /* If C_CLASSIFY, include the change classification. */
174
+ if( flags & C_CLASSIFY ){
175
+ blob_appendf(report, "%-10s ", zClass);
176
+ }
177
+
178
+ /* Finish with the filename followed by newline. */
179
+ if( flags & C_RELPATH ){
180
+ /* If C_RELPATH, display paths relative to current directory. */
181
+ const char *zDisplayName;
182
+ file_relative_name(zFullName, &rewrittenPathname, 0);
183
+ zDisplayName = blob_str(&rewrittenPathname);
184
+ if( zDisplayName[0]=='.' && zDisplayName[1]=='/' ){
185
+ zDisplayName += 2; /* no unnecessary ./ prefix */
186
+ }
187
+ blob_append(report, zDisplayName, -1);
188
+ }else{
189
+ /* If not C_RELPATH, display paths relative to project root. */
190
+ blob_append(report, zPathname, -1);
191
+ }
192
+ blob_append(report, "\n", 1);
171193
}
172194
free(zFullName);
173195
}
174196
blob_reset(&rewrittenPathname);
175197
db_finalize(&q);
176
- db_prepare(&q, "SELECT uuid, id FROM vmerge JOIN blob ON merge=rid"
177
- " WHERE id<=0");
178
- while( db_step(&q)==SQLITE_ROW ){
179
- const char *zLabel = "MERGED_WITH ";
180
- switch( db_column_int(&q, 1) ){
181
- case -1: zLabel = "CHERRYPICK "; break;
182
- case -2: zLabel = "BACKOUT "; break;
183
- case -4: zLabel = "INTEGRATE "; break;
184
- }
185
- blob_append(report, zPrefix, nPrefix);
186
- blob_appendf(report, "%s%s\n", zLabel, db_column_text(&q, 0));
187
- }
188
- db_finalize(&q);
198
+
199
+ /* If C_MERGE, put merge contributors at the end of the report. */
200
+ if( flags & C_MERGE ){
201
+ db_prepare(&q, "SELECT uuid, id FROM vmerge JOIN blob ON merge=rid"
202
+ " WHERE id<=0");
203
+ while( db_step(&q)==SQLITE_ROW ){
204
+ /* If C_COMMENT, precede each line with "# ". */
205
+ if( flags & C_COMMENT ){
206
+ blob_append(report, "# ", 2);
207
+ }
208
+
209
+ /* If C_CLASSIFY, include the merge type. */
210
+ if( flags & C_CLASSIFY ){
211
+ const char *zClass = "MERGED_WITH";
212
+ switch( db_column_int(&q, 1) ){
213
+ case -1: zClass = "CHERRYPICK"; break;
214
+ case -2: zClass = "BACKOUT" ; break;
215
+ case -4: zClass = "INTEGRATE" ; break;
216
+ }
217
+ blob_appendf(report, "%-10s ", zClass);
218
+ }
219
+
220
+ /* Finish the line with the full SHA1 of the merge contributor. */
221
+ blob_append(report, db_column_text(&q, 0), -1);
222
+ blob_append(report, "\n", 1);
223
+ }
224
+ db_finalize(&q);
225
+ }
189226
if( nErr ){
190227
fossil_fatal("aborting due to prior errors");
191228
}
192229
}
193230
@@ -206,27 +243,23 @@
206243
if( relPathOption ){ relativePaths = 1; }
207244
return relativePaths;
208245
}
209246
210247
void print_changes(
211
- int useSha1sum, /* Verify file status using SHA1 hashing rather
212
- than relying on file mtimes. */
213
- int showHdr, /* Identify the repository if there are changes */
214
- int verboseFlag, /* Say "(none)" if there are no changes */
215
- int cwdRelative /* Report relative to the current working dir */
248
+ unsigned flags /* Configuration flags */
216249
){
217250
Blob report;
218251
int vid;
219252
blob_zero(&report);
220253
221254
vid = db_lget_int("checkout", 0);
222
- vfile_check_signature(vid, useSha1sum ? CKSIG_SHA1 : 0);
223
- status_report(&report, "", 0, cwdRelative);
224
- if( verboseFlag && blob_size(&report)==0 ){
255
+ vfile_check_signature(vid, flags & C_SHA1SUM ? CKSIG_SHA1 : 0);
256
+ status_report(&report, flags);
257
+ if( (flags & C_VERBOSE) && blob_size(&report)==0 ){
225258
blob_append(&report, " (none)\n", -1);
226259
}
227
- if( showHdr && blob_size(&report)>0 ){
260
+ if( (flags & C_HEADER) && blob_size(&report)>0 ){
228261
fossil_print("Changes for %s at %s:\n", db_get("project-name","???"),
229262
g.zLocalRoot);
230263
}
231264
blob_write_to_file(&report, "-");
232265
blob_reset(&report);
@@ -378,12 +411,11 @@
378411
#endif
379412
380413
/* We should be done with options. */
381414
verify_all_options();
382415
383
- print_changes(flags & C_SHA1SUM, flags & C_HEADER,
384
- flags & C_VERBOSE, flags & C_RELPATH);
416
+ print_changes(flags);
385417
}
386418
387419
/*
388420
** COMMAND: status
389421
**
@@ -404,19 +436,26 @@
404436
**
405437
** See also: changes, extras, ls
406438
*/
407439
void status_cmd(void){
408440
int vid;
409
- int useSha1sum = find_option("sha1sum", 0, 0)!=0;
410
- int showHdr = find_option("header",0,0)!=0;
411
- int verboseFlag = find_option("verbose","v",0)!=0;
412
- int cwdRelative = 0;
441
+ unsigned flags = C_DEFAULT;
442
+
443
+ /* Check options. */
413444
db_must_be_within_tree();
414
- /* 012345678901234 */
415
- cwdRelative = determine_cwd_relative_option();
416
-
417
- /* We should be done with options.. */
445
+ if( find_option("sha1sum", 0, 0) ){
446
+ flags |= C_SHA1SUM;
447
+ }
448
+ if( find_option("header", 0, 0) ){
449
+ flags |= C_HEADER;
450
+ }
451
+ if( find_option("verbose", "v", 0) ){
452
+ flags |= C_VERBOSE;
453
+ }
454
+ if( determine_cwd_relative_option() ){
455
+ flags |= C_RELPATH;
456
+ }
418457
verify_all_options();
419458
420459
fossil_print("repository: %s\n", db_repository_filename());
421460
fossil_print("local-root: %s\n", g.zLocalRoot);
422461
if( g.zConfigDbName ){
@@ -425,11 +464,11 @@
425464
vid = db_lget_int("checkout", 0);
426465
if( vid ){
427466
show_common_info(vid, "checkout:", 1, 1);
428467
}
429468
db_record_repository_filename(0);
430
- print_changes(useSha1sum, showHdr, verboseFlag, cwdRelative);
469
+ print_changes(flags);
431470
leaf_ambiguity_warning(vid, vid);
432471
}
433472
434473
/*
435474
** Take care of -r version of ls command
@@ -1219,11 +1258,11 @@
12191258
}
12201259
}
12211260
blob_appendf(&prompt, "\n#\n");
12221261
}
12231262
}
1224
- status_report(&prompt, "# ", 1, 0);
1263
+ status_report(&prompt, C_DEFAULT | C_FATAL | C_COMMENT);
12251264
if( g.markPrivate ){
12261265
blob_append(&prompt,
12271266
"# PRIVATE BRANCH: This check-in will be private and will not sync to\n"
12281267
"# repositories.\n"
12291268
"#\n", -1
12301269
--- src/checkin.c
+++ src/checkin.c
@@ -27,54 +27,50 @@
27 */
28 enum {
29 /* Zero-based bit indexes. */
30 CB_EDITED , CB_UPDATED , CB_CHANGED, CB_MISSING , CB_ADDED , CB_DELETED,
31 CB_RENAMED, CB_CONFLICT, CB_META , CB_UNMODIFIED, CB_EXTRA , CB_MERGE ,
32 CB_RELPATH, CB_SHA1SUM , CB_HEADER , CB_VERBOSE , CB_CLASSIFY,
 
33
34 /* Bitmask values. */
35 C_EDITED = 1 << CB_EDITED,
36 C_UPDATED = 1 << CB_UPDATED,
37 C_CHANGED = 1 << CB_CHANGED, /* Becomes CB_EDITED|CB_UPDATED. */
38 C_MISSING = 1 << CB_MISSING,
39 C_ADDED = 1 << CB_ADDED,
40 C_DELETED = 1 << CB_DELETED,
41 C_RENAMED = 1 << CB_RENAMED,
42 C_CONFLICT = 1 << CB_CONFLICT,
43 C_META = 1 << CB_META,
44 C_UNMODIFIED = 1 << CB_UNMODIFIED,
45 C_EXTRA = 1 << CB_EXTRA,
46 C_MERGE = 1 << CB_MERGE,
47 C_FILTER = C_EDITED | C_UPDATED | C_CHANGED | C_MISSING | C_ADDED
48 | C_DELETED | C_RENAMED | C_CONFLICT | C_META | C_UNMODIFIED
49 | C_EXTRA | C_MERGE,
50 C_ALL = C_FILTER & ~(C_CHANGED | C_EXTRA | C_MERGE),
51 C_RELPATH = 1 << CB_RELPATH,
52 C_SHA1SUM = 1 << CB_SHA1SUM,
53 C_HEADER = 1 << CB_HEADER,
54 C_VERBOSE = 1 << CB_VERBOSE,
55 C_CLASSIFY = 1 << CB_CLASSIFY,
56 C_DEFAULT = (C_ALL & ~C_UNMODIFIED) | C_MERGE | C_CLASSIFY,
 
 
57 };
58
59 /*
60 ** Generate text describing all changes. Prepend zPrefix to each line
61 ** of output.
62 **
63 ** We assume that vfile_check_signature has been run.
64 **
65 ** If missingIsFatal is true, then any files that are missing or which
66 ** are not true files results in a fatal error.
67 */
68 static void status_report(
69 Blob *report, /* Append the status report here */
70 const char *zPrefix, /* Prefix on each line of the report */
71 int missingIsFatal, /* MISSING and NOT_A_FILE are fatal errors */
72 int cwdRelative /* Report relative to the current working dir */
73 ){
74 Stmt q;
75 int nPrefix = strlen(zPrefix);
76 int nErr = 0;
77 Blob rewrittenPathname;
78 Blob where;
79 const char *zName;
80 int i;
@@ -107,87 +103,128 @@
107 blob_sql_text(&where)
108 );
109 blob_zero(&rewrittenPathname);
110 while( db_step(&q)==SQLITE_ROW ){
111 const char *zPathname = db_column_text(&q,0);
112 const char *zDisplayName = zPathname;
113 int isDeleted = db_column_int(&q, 1);
114 int isChnged = db_column_int(&q,2);
115 int isNew = db_column_int(&q,3)==0;
116 int isRenamed = db_column_int(&q,4);
117 int isLink = db_column_int(&q,5);
118 char *zFullName = mprintf("%s%s", g.zLocalRoot, zPathname);
119 if( cwdRelative ){
120 file_relative_name(zFullName, &rewrittenPathname, 0);
121 zDisplayName = blob_str(&rewrittenPathname);
122 if( zDisplayName[0]=='.' && zDisplayName[1]=='/' ){
123 zDisplayName += 2; /* no unnecessary ./ prefix */
124 }
125 }
126 blob_append(report, zPrefix, nPrefix);
127 if( isDeleted ){
128 blob_appendf(report, "DELETED %s\n", zDisplayName);
129 }else if( !file_wd_isfile_or_link(zFullName) ){
130 if( file_access(zFullName, F_OK)==0 ){
131 blob_appendf(report, "NOT_A_FILE %s\n", zDisplayName);
132 if( missingIsFatal ){
133 fossil_warning("not a file: %s", zDisplayName);
134 nErr++;
135 }
136 }else{
137 blob_appendf(report, "MISSING %s\n", zDisplayName);
138 if( missingIsFatal ){
139 fossil_warning("missing file: %s", zDisplayName);
140 nErr++;
141 }
142 }
143 }else if( isNew ){
144 blob_appendf(report, "ADDED %s\n", zDisplayName);
145 }else if( isChnged ){
146 if( isChnged==2 ){
147 blob_appendf(report, "UPDATED_BY_MERGE %s\n", zDisplayName);
148 }else if( isChnged==3 ){
149 blob_appendf(report, "ADDED_BY_MERGE %s\n", zDisplayName);
150 }else if( isChnged==4 ){
151 blob_appendf(report, "UPDATED_BY_INTEGRATE %s\n", zDisplayName);
152 }else if( isChnged==5 ){
153 blob_appendf(report, "ADDED_BY_INTEGRATE %s\n", zDisplayName);
154 }else if( isChnged==6 ){
155 blob_appendf(report, "EXECUTABLE %s\n", zDisplayName);
156 }else if( isChnged==7 ){
157 blob_appendf(report, "SYMLINK %s\n", zDisplayName);
158 }else if( isChnged==8 ){
159 blob_appendf(report, "UNEXEC %s\n", zDisplayName);
160 }else if( isChnged==9 ){
161 blob_appendf(report, "UNLINK %s\n", zDisplayName);
162 }else if( !isLink && file_contains_merge_marker(zFullName) ){
163 blob_appendf(report, "CONFLICT %s\n", zDisplayName);
164 }else{
165 blob_appendf(report, "EDITED %s\n", zDisplayName);
166 }
167 }else if( isRenamed ){
168 blob_appendf(report, "RENAMED %s\n", zDisplayName);
169 }else{
170 report->nUsed -= nPrefix;
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
171 }
172 free(zFullName);
173 }
174 blob_reset(&rewrittenPathname);
175 db_finalize(&q);
176 db_prepare(&q, "SELECT uuid, id FROM vmerge JOIN blob ON merge=rid"
177 " WHERE id<=0");
178 while( db_step(&q)==SQLITE_ROW ){
179 const char *zLabel = "MERGED_WITH ";
180 switch( db_column_int(&q, 1) ){
181 case -1: zLabel = "CHERRYPICK "; break;
182 case -2: zLabel = "BACKOUT "; break;
183 case -4: zLabel = "INTEGRATE "; break;
184 }
185 blob_append(report, zPrefix, nPrefix);
186 blob_appendf(report, "%s%s\n", zLabel, db_column_text(&q, 0));
187 }
188 db_finalize(&q);
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
189 if( nErr ){
190 fossil_fatal("aborting due to prior errors");
191 }
192 }
193
@@ -206,27 +243,23 @@
206 if( relPathOption ){ relativePaths = 1; }
207 return relativePaths;
208 }
209
210 void print_changes(
211 int useSha1sum, /* Verify file status using SHA1 hashing rather
212 than relying on file mtimes. */
213 int showHdr, /* Identify the repository if there are changes */
214 int verboseFlag, /* Say "(none)" if there are no changes */
215 int cwdRelative /* Report relative to the current working dir */
216 ){
217 Blob report;
218 int vid;
219 blob_zero(&report);
220
221 vid = db_lget_int("checkout", 0);
222 vfile_check_signature(vid, useSha1sum ? CKSIG_SHA1 : 0);
223 status_report(&report, "", 0, cwdRelative);
224 if( verboseFlag && blob_size(&report)==0 ){
225 blob_append(&report, " (none)\n", -1);
226 }
227 if( showHdr && blob_size(&report)>0 ){
228 fossil_print("Changes for %s at %s:\n", db_get("project-name","???"),
229 g.zLocalRoot);
230 }
231 blob_write_to_file(&report, "-");
232 blob_reset(&report);
@@ -378,12 +411,11 @@
378 #endif
379
380 /* We should be done with options. */
381 verify_all_options();
382
383 print_changes(flags & C_SHA1SUM, flags & C_HEADER,
384 flags & C_VERBOSE, flags & C_RELPATH);
385 }
386
387 /*
388 ** COMMAND: status
389 **
@@ -404,19 +436,26 @@
404 **
405 ** See also: changes, extras, ls
406 */
407 void status_cmd(void){
408 int vid;
409 int useSha1sum = find_option("sha1sum", 0, 0)!=0;
410 int showHdr = find_option("header",0,0)!=0;
411 int verboseFlag = find_option("verbose","v",0)!=0;
412 int cwdRelative = 0;
413 db_must_be_within_tree();
414 /* 012345678901234 */
415 cwdRelative = determine_cwd_relative_option();
416
417 /* We should be done with options.. */
 
 
 
 
 
 
 
 
418 verify_all_options();
419
420 fossil_print("repository: %s\n", db_repository_filename());
421 fossil_print("local-root: %s\n", g.zLocalRoot);
422 if( g.zConfigDbName ){
@@ -425,11 +464,11 @@
425 vid = db_lget_int("checkout", 0);
426 if( vid ){
427 show_common_info(vid, "checkout:", 1, 1);
428 }
429 db_record_repository_filename(0);
430 print_changes(useSha1sum, showHdr, verboseFlag, cwdRelative);
431 leaf_ambiguity_warning(vid, vid);
432 }
433
434 /*
435 ** Take care of -r version of ls command
@@ -1219,11 +1258,11 @@
1219 }
1220 }
1221 blob_appendf(&prompt, "\n#\n");
1222 }
1223 }
1224 status_report(&prompt, "# ", 1, 0);
1225 if( g.markPrivate ){
1226 blob_append(&prompt,
1227 "# PRIVATE BRANCH: This check-in will be private and will not sync to\n"
1228 "# repositories.\n"
1229 "#\n", -1
1230
--- src/checkin.c
+++ src/checkin.c
@@ -27,54 +27,50 @@
27 */
28 enum {
29 /* Zero-based bit indexes. */
30 CB_EDITED , CB_UPDATED , CB_CHANGED, CB_MISSING , CB_ADDED , CB_DELETED,
31 CB_RENAMED, CB_CONFLICT, CB_META , CB_UNMODIFIED, CB_EXTRA , CB_MERGE ,
32 CB_RELPATH, CB_SHA1SUM , CB_HEADER , CB_VERBOSE , CB_CLASSIFY, CB_FATAL ,
33 CB_COMMENT,
34
35 /* Bitmask values. */
36 C_EDITED = 1 << CB_EDITED, /* Edited, merged, and conflicted files. */
37 C_UPDATED = 1 << CB_UPDATED, /* Files updated by merge/integrate. */
38 C_CHANGED = 1 << CB_CHANGED, /* Becomes CB_EDITED|CB_UPDATED. */
39 C_MISSING = 1 << CB_MISSING, /* Missing and non- files. */
40 C_ADDED = 1 << CB_ADDED, /* Added files. */
41 C_DELETED = 1 << CB_DELETED, /* Deleted files. */
42 C_RENAMED = 1 << CB_RENAMED, /* Renamed files. */
43 C_CONFLICT = 1 << CB_CONFLICT, /* Files having merge conflicts. */
44 C_META = 1 << CB_META, /* Files with metadata changes. */
45 C_UNMODIFIED = 1 << CB_UNMODIFIED,/* Unmodified files. */
46 C_EXTRA = 1 << CB_EXTRA, /* Unmanaged files. */
47 C_MERGE = 1 << CB_MERGE, /* Merge contributors. */
48 C_FILTER = C_EDITED | C_UPDATED | C_CHANGED | C_MISSING | C_ADDED
49 | C_DELETED | C_RENAMED | C_CONFLICT | C_META | C_UNMODIFIED
50 | C_EXTRA | C_MERGE,
51 C_ALL = C_FILTER & ~(C_CHANGED | C_EXTRA | C_MERGE),
52 C_RELPATH = 1 << CB_RELPATH, /* Show relative paths. */
53 C_SHA1SUM = 1 << CB_SHA1SUM, /* Use SHA1 checksums not mtimes. */
54 C_HEADER = 1 << CB_HEADER, /* Display repository name if non-empty. */
55 C_VERBOSE = 1 << CB_VERBOSE, /* Display "(none)" if empty. */
56 C_CLASSIFY = 1 << CB_CLASSIFY, /* Show file change types. */
57 C_DEFAULT = (C_ALL & ~C_UNMODIFIED) | C_MERGE | C_CLASSIFY,
58 C_FATAL = (1 << CB_FATAL) | C_MISSING, /* Fail on MISSING/NOT_A_FILE. */
59 C_COMMENT = 1 << CB_COMMENT, /* Precede each line with "# ". */
60 };
61
62 /*
63 ** Generate text describing all changes.
 
64 **
65 ** We assume that vfile_check_signature has been run.
 
 
 
66 */
67 static void status_report(
68 Blob *report, /* Append the status report here */
69 unsigned flags /* Filter and other configuration flags */
 
 
70 ){
71 Stmt q;
 
72 int nErr = 0;
73 Blob rewrittenPathname;
74 Blob where;
75 const char *zName;
76 int i;
@@ -107,87 +103,128 @@
103 blob_sql_text(&where)
104 );
105 blob_zero(&rewrittenPathname);
106 while( db_step(&q)==SQLITE_ROW ){
107 const char *zPathname = db_column_text(&q,0);
108 const char *zClass = 0;
109 int isDeleted = db_column_int(&q, 1);
110 int isChnged = db_column_int(&q,2);
111 int isNew = db_column_int(&q,3)==0;
112 int isRenamed = db_column_int(&q,4);
113 int isLink = db_column_int(&q,5);
114 char *zFullName = mprintf("%s%s", g.zLocalRoot, zPathname);
115 int isMissing = !file_wd_isfile_or_link(zFullName);
116
117 /* Determine the file change classification, if any. */
118 if( (flags & C_DELETED) && isDeleted ){
119 zClass = "DELETED";
120 }else if( (flags & C_MISSING) && isMissing ){
121 if( file_access(zFullName, F_OK)==0 ){
122 zClass = "NOT_A_FILE";
123 if( flags & C_FATAL ){
124 fossil_warning("not a file: %s", zFullName);
125 nErr++;
126 }
127 }else{
128 zClass = "MISSING";
129 if( flags & C_FATAL ){
130 fossil_warning("missing file: %s", zFullName);
131 nErr++;
132 }
133 }
134 }else if( (flags & C_ADDED) && isNew ){
135 zClass = "ADDED";
136 }else if( (flags & C_UPDATED) && isChnged==2 ){
137 zClass = "UPDATED_BY_MERGE";
138 }else if( (flags & C_ADDED) && isChnged==3 ){
139 zClass = "ADDED_BY_MERGE";
140 }else if( (flags & C_UPDATED) && isChnged==4 ){
141 zClass = "UPDATED_BY_INTEGRATE";
142 }else if( (flags & C_ADDED) && isChnged==5 ){
143 zClass = "ADDED_BY_INTEGRATE";
144 }else if( (flags & C_META) && isChnged==6 ){
145 zClass = "EXECUTABLE";
146 }else if( (flags & C_META) && isChnged==7 ){
147 zClass = "SYMLINK";
148 }else if( (flags & C_META) && isChnged==8 ){
149 zClass = "UNEXEC";
150 }else if( (flags & C_META) && isChnged==9 ){
151 zClass = "UNLINK";
152 }else if( (flags & C_CONFLICT) && isChnged && !isLink
153 && file_contains_merge_marker(zFullName) ){
154 zClass = "CONFLICT";
155 }else if( (flags & C_EDITED) && isChnged ){
156 zClass = "EDITED";
157 }else if( (flags & C_RENAMED) && isRenamed ){
158 zClass = "RENAMED";
159 }else if( (flags & C_UNMODIFIED) && !isDeleted && !isMissing && !isNew
160 && !isChnged && !isRenamed ){
161 /* TODO: never gets executed because query only yields modified files. */
162 zClass = "UNMODIFIED";
163 }
164 /* TODO: implement C_EXTRA. */
165
166 /* Only report files for which a change classification was determined. */
167 if( zClass ){
168 /* If C_COMMENT, precede each line with "# ". */
169 if( flags & C_COMMENT ){
170 blob_append(report, "# ", 2);
171 }
172
173 /* If C_CLASSIFY, include the change classification. */
174 if( flags & C_CLASSIFY ){
175 blob_appendf(report, "%-10s ", zClass);
176 }
177
178 /* Finish with the filename followed by newline. */
179 if( flags & C_RELPATH ){
180 /* If C_RELPATH, display paths relative to current directory. */
181 const char *zDisplayName;
182 file_relative_name(zFullName, &rewrittenPathname, 0);
183 zDisplayName = blob_str(&rewrittenPathname);
184 if( zDisplayName[0]=='.' && zDisplayName[1]=='/' ){
185 zDisplayName += 2; /* no unnecessary ./ prefix */
186 }
187 blob_append(report, zDisplayName, -1);
188 }else{
189 /* If not C_RELPATH, display paths relative to project root. */
190 blob_append(report, zPathname, -1);
191 }
192 blob_append(report, "\n", 1);
193 }
194 free(zFullName);
195 }
196 blob_reset(&rewrittenPathname);
197 db_finalize(&q);
198
199 /* If C_MERGE, put merge contributors at the end of the report. */
200 if( flags & C_MERGE ){
201 db_prepare(&q, "SELECT uuid, id FROM vmerge JOIN blob ON merge=rid"
202 " WHERE id<=0");
203 while( db_step(&q)==SQLITE_ROW ){
204 /* If C_COMMENT, precede each line with "# ". */
205 if( flags & C_COMMENT ){
206 blob_append(report, "# ", 2);
207 }
208
209 /* If C_CLASSIFY, include the merge type. */
210 if( flags & C_CLASSIFY ){
211 const char *zClass = "MERGED_WITH";
212 switch( db_column_int(&q, 1) ){
213 case -1: zClass = "CHERRYPICK"; break;
214 case -2: zClass = "BACKOUT" ; break;
215 case -4: zClass = "INTEGRATE" ; break;
216 }
217 blob_appendf(report, "%-10s ", zClass);
218 }
219
220 /* Finish the line with the full SHA1 of the merge contributor. */
221 blob_append(report, db_column_text(&q, 0), -1);
222 blob_append(report, "\n", 1);
223 }
224 db_finalize(&q);
225 }
226 if( nErr ){
227 fossil_fatal("aborting due to prior errors");
228 }
229 }
230
@@ -206,27 +243,23 @@
243 if( relPathOption ){ relativePaths = 1; }
244 return relativePaths;
245 }
246
247 void print_changes(
248 unsigned flags /* Configuration flags */
 
 
 
 
249 ){
250 Blob report;
251 int vid;
252 blob_zero(&report);
253
254 vid = db_lget_int("checkout", 0);
255 vfile_check_signature(vid, flags & C_SHA1SUM ? CKSIG_SHA1 : 0);
256 status_report(&report, flags);
257 if( (flags & C_VERBOSE) && blob_size(&report)==0 ){
258 blob_append(&report, " (none)\n", -1);
259 }
260 if( (flags & C_HEADER) && blob_size(&report)>0 ){
261 fossil_print("Changes for %s at %s:\n", db_get("project-name","???"),
262 g.zLocalRoot);
263 }
264 blob_write_to_file(&report, "-");
265 blob_reset(&report);
@@ -378,12 +411,11 @@
411 #endif
412
413 /* We should be done with options. */
414 verify_all_options();
415
416 print_changes(flags);
 
417 }
418
419 /*
420 ** COMMAND: status
421 **
@@ -404,19 +436,26 @@
436 **
437 ** See also: changes, extras, ls
438 */
439 void status_cmd(void){
440 int vid;
441 unsigned flags = C_DEFAULT;
442
443 /* Check options. */
 
444 db_must_be_within_tree();
445 if( find_option("sha1sum", 0, 0) ){
446 flags |= C_SHA1SUM;
447 }
448 if( find_option("header", 0, 0) ){
449 flags |= C_HEADER;
450 }
451 if( find_option("verbose", "v", 0) ){
452 flags |= C_VERBOSE;
453 }
454 if( determine_cwd_relative_option() ){
455 flags |= C_RELPATH;
456 }
457 verify_all_options();
458
459 fossil_print("repository: %s\n", db_repository_filename());
460 fossil_print("local-root: %s\n", g.zLocalRoot);
461 if( g.zConfigDbName ){
@@ -425,11 +464,11 @@
464 vid = db_lget_int("checkout", 0);
465 if( vid ){
466 show_common_info(vid, "checkout:", 1, 1);
467 }
468 db_record_repository_filename(0);
469 print_changes(flags);
470 leaf_ambiguity_warning(vid, vid);
471 }
472
473 /*
474 ** Take care of -r version of ls command
@@ -1219,11 +1258,11 @@
1258 }
1259 }
1260 blob_appendf(&prompt, "\n#\n");
1261 }
1262 }
1263 status_report(&prompt, C_DEFAULT | C_FATAL | C_COMMENT);
1264 if( g.markPrivate ){
1265 blob_append(&prompt,
1266 "# PRIVATE BRANCH: This check-in will be private and will not sync to\n"
1267 "# repositories.\n"
1268 "#\n", -1
1269

Keyboard Shortcuts

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