Fossil SCM

When running the changes or status command from inside a sub-directory of the check out, only show the changes in or below the current directory unless the --show-all option is used.

ben 2011-07-10 13:01 trunk
Commit e0d2e1f9b85eab0b0eb788a2820161a27ba9a761
1 file changed +55 -14
+55 -14
--- src/checkin.c
+++ src/checkin.c
@@ -32,57 +32,91 @@
3232
** are not true files results in a fatal error.
3333
*/
3434
static void status_report(
3535
Blob *report, /* Append the status report here */
3636
const char *zPrefix, /* Prefix on each line of the report */
37
- int missingIsFatal /* MISSING and NOT_A_FILE are fatal errors */
37
+ int missingIsFatal, /* MISSING and NOT_A_FILE are fatal errors */
38
+ int reportSubdirOnly /* Only report for the current sub-dir */
3839
){
3940
Stmt q;
4041
int nPrefix = strlen(zPrefix);
4142
int nErr = 0;
43
+ Blob currentDir, rootDir;
44
+ const char *zShowSubDir = 0;
45
+ int showSubDirLen = 0;
46
+ int otherChanges = 0;
4247
db_prepare(&q,
4348
"SELECT pathname, deleted, chnged, rid, coalesce(origname!=pathname,0)"
4449
" FROM vfile "
4550
" WHERE file_is_selected(id)"
4651
" AND (chnged OR deleted OR rid=0 OR pathname!=origname) ORDER BY 1"
4752
);
53
+ /* If sub-directory only reports are acceptable, check to see if we're
54
+ ** in a sub-directory of the checkout. */
55
+ if( reportSubdirOnly ){
56
+ blob_zero(&currentDir);
57
+ file_canonical_name(".", &currentDir);
58
+ blob_zero(&rootDir);
59
+ file_canonical_name(g.zLocalRoot, &rootDir);
60
+ if( blob_compare(&currentDir, &rootDir)!=0
61
+ && blob_size(&currentDir)>blob_size(&rootDir) ){
62
+ /* Current directory is not the root of the repository */
63
+ blob_appendf(report, "%sIn sub-directory %s:\n", zPrefix,
64
+ blob_str(&currentDir) + blob_size(&rootDir) + 1);
65
+ blob_append(&currentDir,"/",1);
66
+ zShowSubDir = blob_str(&currentDir) + blob_size(&rootDir) + 1;
67
+ showSubDirLen = blob_size(&currentDir) - blob_size(&rootDir) - 1;
68
+ }
69
+ }
70
+ /* Show the changes */
4871
while( db_step(&q)==SQLITE_ROW ){
4972
const char *zPathname = db_column_text(&q,0);
73
+ const char *zDisplayName = zPathname;
74
+ if( zShowSubDir!=0 ){
75
+ if( strncmp(zPathname,zShowSubDir,showSubDirLen)!=0 ){
76
+ /* Not in sub-directory, don't display this file */
77
+ otherChanges++;
78
+ continue;
79
+ }else{
80
+ /* In sub directory, so hide the prefix */
81
+ zDisplayName += showSubDirLen;
82
+ }
83
+ }
5084
int isDeleted = db_column_int(&q, 1);
5185
int isChnged = db_column_int(&q,2);
5286
int isNew = db_column_int(&q,3)==0;
5387
int isRenamed = db_column_int(&q,4);
5488
char *zFullName = mprintf("%s%s", g.zLocalRoot, zPathname);
5589
blob_append(report, zPrefix, nPrefix);
5690
if( isDeleted ){
57
- blob_appendf(report, "DELETED %s\n", zPathname);
91
+ blob_appendf(report, "DELETED %s\n", zDisplayName);
5892
}else if( !file_isfile(zFullName) ){
5993
if( file_access(zFullName, 0)==0 ){
60
- blob_appendf(report, "NOT_A_FILE %s\n", zPathname);
94
+ blob_appendf(report, "NOT_A_FILE %s\n", zDisplayName);
6195
if( missingIsFatal ){
62
- fossil_warning("not a file: %s", zPathname);
96
+ fossil_warning("not a file: %s", zDisplayName);
6397
nErr++;
6498
}
6599
}else{
66
- blob_appendf(report, "MISSING %s\n", zPathname);
100
+ blob_appendf(report, "MISSING %s\n", zDisplayName);
67101
if( missingIsFatal ){
68
- fossil_warning("missing file: %s", zPathname);
102
+ fossil_warning("missing file: %s", zDisplayName);
69103
nErr++;
70104
}
71105
}
72106
}else if( isNew ){
73
- blob_appendf(report, "ADDED %s\n", zPathname);
107
+ blob_appendf(report, "ADDED %s\n", zDisplayName);
74108
}else if( isDeleted ){
75
- blob_appendf(report, "DELETED %s\n", zPathname);
109
+ blob_appendf(report, "DELETED %s\n", zDisplayName);
76110
}else if( isChnged==2 ){
77
- blob_appendf(report, "UPDATED_BY_MERGE %s\n", zPathname);
111
+ blob_appendf(report, "UPDATED_BY_MERGE %s\n", zDisplayName);
78112
}else if( isChnged==3 ){
79
- blob_appendf(report, "ADDED_BY_MERGE %s\n", zPathname);
113
+ blob_appendf(report, "ADDED_BY_MERGE %s\n", zDisplayName);
80114
}else if( isChnged==1 ){
81
- blob_appendf(report, "EDITED %s\n", zPathname);
115
+ blob_appendf(report, "EDITED %s\n", zDisplayName);
82116
}else if( isRenamed ){
83
- blob_appendf(report, "RENAMED %s\n", zPathname);
117
+ blob_appendf(report, "RENAMED %s\n", zDisplayName);
84118
}
85119
free(zFullName);
86120
}
87121
db_finalize(&q);
88122
db_prepare(&q, "SELECT uuid FROM vmerge JOIN blob ON merge=rid"
@@ -90,10 +124,13 @@
90124
while( db_step(&q)==SQLITE_ROW ){
91125
blob_append(report, zPrefix, nPrefix);
92126
blob_appendf(report, "MERGED_WITH %s\n", db_column_text(&q, 0));
93127
}
94128
db_finalize(&q);
129
+ if( otherChanges!=0 ){
130
+ blob_appendf(report, "%d other changes. Use --show-all option to list all changes.\n");
131
+ }
95132
if( nErr ){
96133
fossil_fatal("aborting due to prior errors");
97134
}
98135
}
99136
@@ -107,20 +144,24 @@
107144
**
108145
** Options:
109146
**
110147
** --sha1sum Verify file status using SHA1 hashing rather
111148
** than relying on file mtimes.
149
+**
150
+** --show-all When invoked from a sub-directory, show changes
151
+** even if they're outside the current directory.
112152
*/
113153
void changes_cmd(void){
114154
Blob report;
115155
int vid;
116156
int useSha1sum = find_option("sha1sum", 0, 0)!=0;
157
+ int showAllFlag = find_option("show-all","S",0)!=0;
117158
db_must_be_within_tree();
118159
blob_zero(&report);
119160
vid = db_lget_int("checkout", 0);
120161
vfile_check_signature(vid, 0, useSha1sum);
121
- status_report(&report, "", 0);
162
+ status_report(&report, "", 0, !showAllFlag);
122163
blob_write_to_file(&report, "-");
123164
}
124165
125166
/*
126167
** COMMAND: status
@@ -367,11 +408,11 @@
367408
"# PRIVATE BRANCH: This check-in will be private and will not sync to\n"
368409
"# repositories.\n"
369410
"#\n", -1
370411
);
371412
}
372
- status_report(&text, "# ", 1);
413
+ status_report(&text, "# ", 1, 0);
373414
zEditor = db_get("editor", 0);
374415
if( zEditor==0 ){
375416
zEditor = getenv("VISUAL");
376417
}
377418
if( zEditor==0 ){
378419
--- src/checkin.c
+++ src/checkin.c
@@ -32,57 +32,91 @@
32 ** are not true files results in a fatal error.
33 */
34 static void status_report(
35 Blob *report, /* Append the status report here */
36 const char *zPrefix, /* Prefix on each line of the report */
37 int missingIsFatal /* MISSING and NOT_A_FILE are fatal errors */
 
38 ){
39 Stmt q;
40 int nPrefix = strlen(zPrefix);
41 int nErr = 0;
 
 
 
 
42 db_prepare(&q,
43 "SELECT pathname, deleted, chnged, rid, coalesce(origname!=pathname,0)"
44 " FROM vfile "
45 " WHERE file_is_selected(id)"
46 " AND (chnged OR deleted OR rid=0 OR pathname!=origname) ORDER BY 1"
47 );
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
48 while( db_step(&q)==SQLITE_ROW ){
49 const char *zPathname = db_column_text(&q,0);
 
 
 
 
 
 
 
 
 
 
 
50 int isDeleted = db_column_int(&q, 1);
51 int isChnged = db_column_int(&q,2);
52 int isNew = db_column_int(&q,3)==0;
53 int isRenamed = db_column_int(&q,4);
54 char *zFullName = mprintf("%s%s", g.zLocalRoot, zPathname);
55 blob_append(report, zPrefix, nPrefix);
56 if( isDeleted ){
57 blob_appendf(report, "DELETED %s\n", zPathname);
58 }else if( !file_isfile(zFullName) ){
59 if( file_access(zFullName, 0)==0 ){
60 blob_appendf(report, "NOT_A_FILE %s\n", zPathname);
61 if( missingIsFatal ){
62 fossil_warning("not a file: %s", zPathname);
63 nErr++;
64 }
65 }else{
66 blob_appendf(report, "MISSING %s\n", zPathname);
67 if( missingIsFatal ){
68 fossil_warning("missing file: %s", zPathname);
69 nErr++;
70 }
71 }
72 }else if( isNew ){
73 blob_appendf(report, "ADDED %s\n", zPathname);
74 }else if( isDeleted ){
75 blob_appendf(report, "DELETED %s\n", zPathname);
76 }else if( isChnged==2 ){
77 blob_appendf(report, "UPDATED_BY_MERGE %s\n", zPathname);
78 }else if( isChnged==3 ){
79 blob_appendf(report, "ADDED_BY_MERGE %s\n", zPathname);
80 }else if( isChnged==1 ){
81 blob_appendf(report, "EDITED %s\n", zPathname);
82 }else if( isRenamed ){
83 blob_appendf(report, "RENAMED %s\n", zPathname);
84 }
85 free(zFullName);
86 }
87 db_finalize(&q);
88 db_prepare(&q, "SELECT uuid FROM vmerge JOIN blob ON merge=rid"
@@ -90,10 +124,13 @@
90 while( db_step(&q)==SQLITE_ROW ){
91 blob_append(report, zPrefix, nPrefix);
92 blob_appendf(report, "MERGED_WITH %s\n", db_column_text(&q, 0));
93 }
94 db_finalize(&q);
 
 
 
95 if( nErr ){
96 fossil_fatal("aborting due to prior errors");
97 }
98 }
99
@@ -107,20 +144,24 @@
107 **
108 ** Options:
109 **
110 ** --sha1sum Verify file status using SHA1 hashing rather
111 ** than relying on file mtimes.
 
 
 
112 */
113 void changes_cmd(void){
114 Blob report;
115 int vid;
116 int useSha1sum = find_option("sha1sum", 0, 0)!=0;
 
117 db_must_be_within_tree();
118 blob_zero(&report);
119 vid = db_lget_int("checkout", 0);
120 vfile_check_signature(vid, 0, useSha1sum);
121 status_report(&report, "", 0);
122 blob_write_to_file(&report, "-");
123 }
124
125 /*
126 ** COMMAND: status
@@ -367,11 +408,11 @@
367 "# PRIVATE BRANCH: This check-in will be private and will not sync to\n"
368 "# repositories.\n"
369 "#\n", -1
370 );
371 }
372 status_report(&text, "# ", 1);
373 zEditor = db_get("editor", 0);
374 if( zEditor==0 ){
375 zEditor = getenv("VISUAL");
376 }
377 if( zEditor==0 ){
378
--- src/checkin.c
+++ src/checkin.c
@@ -32,57 +32,91 @@
32 ** are not true files results in a fatal error.
33 */
34 static void status_report(
35 Blob *report, /* Append the status report here */
36 const char *zPrefix, /* Prefix on each line of the report */
37 int missingIsFatal, /* MISSING and NOT_A_FILE are fatal errors */
38 int reportSubdirOnly /* Only report for the current sub-dir */
39 ){
40 Stmt q;
41 int nPrefix = strlen(zPrefix);
42 int nErr = 0;
43 Blob currentDir, rootDir;
44 const char *zShowSubDir = 0;
45 int showSubDirLen = 0;
46 int otherChanges = 0;
47 db_prepare(&q,
48 "SELECT pathname, deleted, chnged, rid, coalesce(origname!=pathname,0)"
49 " FROM vfile "
50 " WHERE file_is_selected(id)"
51 " AND (chnged OR deleted OR rid=0 OR pathname!=origname) ORDER BY 1"
52 );
53 /* If sub-directory only reports are acceptable, check to see if we're
54 ** in a sub-directory of the checkout. */
55 if( reportSubdirOnly ){
56 blob_zero(&currentDir);
57 file_canonical_name(".", &currentDir);
58 blob_zero(&rootDir);
59 file_canonical_name(g.zLocalRoot, &rootDir);
60 if( blob_compare(&currentDir, &rootDir)!=0
61 && blob_size(&currentDir)>blob_size(&rootDir) ){
62 /* Current directory is not the root of the repository */
63 blob_appendf(report, "%sIn sub-directory %s:\n", zPrefix,
64 blob_str(&currentDir) + blob_size(&rootDir) + 1);
65 blob_append(&currentDir,"/",1);
66 zShowSubDir = blob_str(&currentDir) + blob_size(&rootDir) + 1;
67 showSubDirLen = blob_size(&currentDir) - blob_size(&rootDir) - 1;
68 }
69 }
70 /* Show the changes */
71 while( db_step(&q)==SQLITE_ROW ){
72 const char *zPathname = db_column_text(&q,0);
73 const char *zDisplayName = zPathname;
74 if( zShowSubDir!=0 ){
75 if( strncmp(zPathname,zShowSubDir,showSubDirLen)!=0 ){
76 /* Not in sub-directory, don't display this file */
77 otherChanges++;
78 continue;
79 }else{
80 /* In sub directory, so hide the prefix */
81 zDisplayName += showSubDirLen;
82 }
83 }
84 int isDeleted = db_column_int(&q, 1);
85 int isChnged = db_column_int(&q,2);
86 int isNew = db_column_int(&q,3)==0;
87 int isRenamed = db_column_int(&q,4);
88 char *zFullName = mprintf("%s%s", g.zLocalRoot, zPathname);
89 blob_append(report, zPrefix, nPrefix);
90 if( isDeleted ){
91 blob_appendf(report, "DELETED %s\n", zDisplayName);
92 }else if( !file_isfile(zFullName) ){
93 if( file_access(zFullName, 0)==0 ){
94 blob_appendf(report, "NOT_A_FILE %s\n", zDisplayName);
95 if( missingIsFatal ){
96 fossil_warning("not a file: %s", zDisplayName);
97 nErr++;
98 }
99 }else{
100 blob_appendf(report, "MISSING %s\n", zDisplayName);
101 if( missingIsFatal ){
102 fossil_warning("missing file: %s", zDisplayName);
103 nErr++;
104 }
105 }
106 }else if( isNew ){
107 blob_appendf(report, "ADDED %s\n", zDisplayName);
108 }else if( isDeleted ){
109 blob_appendf(report, "DELETED %s\n", zDisplayName);
110 }else if( isChnged==2 ){
111 blob_appendf(report, "UPDATED_BY_MERGE %s\n", zDisplayName);
112 }else if( isChnged==3 ){
113 blob_appendf(report, "ADDED_BY_MERGE %s\n", zDisplayName);
114 }else if( isChnged==1 ){
115 blob_appendf(report, "EDITED %s\n", zDisplayName);
116 }else if( isRenamed ){
117 blob_appendf(report, "RENAMED %s\n", zDisplayName);
118 }
119 free(zFullName);
120 }
121 db_finalize(&q);
122 db_prepare(&q, "SELECT uuid FROM vmerge JOIN blob ON merge=rid"
@@ -90,10 +124,13 @@
124 while( db_step(&q)==SQLITE_ROW ){
125 blob_append(report, zPrefix, nPrefix);
126 blob_appendf(report, "MERGED_WITH %s\n", db_column_text(&q, 0));
127 }
128 db_finalize(&q);
129 if( otherChanges!=0 ){
130 blob_appendf(report, "%d other changes. Use --show-all option to list all changes.\n");
131 }
132 if( nErr ){
133 fossil_fatal("aborting due to prior errors");
134 }
135 }
136
@@ -107,20 +144,24 @@
144 **
145 ** Options:
146 **
147 ** --sha1sum Verify file status using SHA1 hashing rather
148 ** than relying on file mtimes.
149 **
150 ** --show-all When invoked from a sub-directory, show changes
151 ** even if they're outside the current directory.
152 */
153 void changes_cmd(void){
154 Blob report;
155 int vid;
156 int useSha1sum = find_option("sha1sum", 0, 0)!=0;
157 int showAllFlag = find_option("show-all","S",0)!=0;
158 db_must_be_within_tree();
159 blob_zero(&report);
160 vid = db_lget_int("checkout", 0);
161 vfile_check_signature(vid, 0, useSha1sum);
162 status_report(&report, "", 0, !showAllFlag);
163 blob_write_to_file(&report, "-");
164 }
165
166 /*
167 ** COMMAND: status
@@ -367,11 +408,11 @@
408 "# PRIVATE BRANCH: This check-in will be private and will not sync to\n"
409 "# repositories.\n"
410 "#\n", -1
411 );
412 }
413 status_report(&text, "# ", 1, 0);
414 zEditor = db_get("editor", 0);
415 if( zEditor==0 ){
416 zEditor = getenv("VISUAL");
417 }
418 if( zEditor==0 ){
419

Keyboard Shortcuts

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