Fossil SCM
give 'json status' the same rename treatment as recent status work As reported by larrybr on the forum: [forum:9e9778f2e6], 'fossil json status' reports renamed _and_ edited files as only renamed. This change reports such cases as both edited and renamed, and displays the filename prior to being renamed as well as the renamed path. We now also update the vfile table before generating the status report to ensure the current checkout state is reported.
Commit
771e592b4c59ad59a28f586bba12a528a27e8e4892e72d48000bc38c8cc6c623
Parent
36adf66b7876275…
1 file changed
+19
-5
+19
-5
| --- src/json_status.c | ||
| +++ src/json_status.c | ||
| @@ -60,10 +60,11 @@ | ||
| 60 | 60 | vid = db_lget_int("checkout", 0); |
| 61 | 61 | if(!vid){ |
| 62 | 62 | json_set_err( FSL_JSON_E_UNKNOWN, "Can this even happen?" ); |
| 63 | 63 | return 0; |
| 64 | 64 | } |
| 65 | + vfile_check_signature(vid, 0); | |
| 65 | 66 | /* TODO: dupe show_common_info() state */ |
| 66 | 67 | tmpO = cson_new_object(); |
| 67 | 68 | cson_object_set(oPay, "checkout", cson_object_value(tmpO)); |
| 68 | 69 | |
| 69 | 70 | zTmp = db_text(0, "SELECT uuid FROM blob WHERE rid=%d", vid); |
| @@ -93,16 +94,18 @@ | ||
| 93 | 94 | /* Now get the list of non-pristine files... */ |
| 94 | 95 | aFiles = cson_new_array(); |
| 95 | 96 | cson_object_set( oPay, "files", cson_array_value( aFiles ) ); |
| 96 | 97 | |
| 97 | 98 | db_prepare(&q, |
| 98 | - "SELECT pathname, deleted, chnged, rid, coalesce(origname!=pathname,0)" | |
| 99 | + "SELECT pathname, deleted, chnged, rid, " | |
| 100 | + " coalesce(origname!=pathname,0), origname" | |
| 99 | 101 | " FROM vfile " |
| 100 | 102 | " WHERE is_selected(id)" |
| 101 | 103 | " AND (chnged OR deleted OR rid=0 OR pathname!=origname) ORDER BY 1" |
| 102 | 104 | ); |
| 103 | 105 | while( db_step(&q)==SQLITE_ROW ){ |
| 106 | + cson_array *aStatuses = NULL; | |
| 104 | 107 | const char *zPathname = db_column_text(&q,0); |
| 105 | 108 | int isDeleted = db_column_int(&q, 1); |
| 106 | 109 | int isChnged = db_column_int(&q,2); |
| 107 | 110 | int isNew = db_column_int(&q,3)==0; |
| 108 | 111 | int isRenamed = db_column_int(&q,4); |
| @@ -112,12 +115,10 @@ | ||
| 112 | 115 | if( isDeleted ){ |
| 113 | 116 | zStatus = "deleted"; |
| 114 | 117 | }else if( isNew ){ |
| 115 | 118 | zStatus = "new" /* maintenance reminder: MUST come |
| 116 | 119 | BEFORE the isChnged checks. */; |
| 117 | - }else if( isRenamed ){ | |
| 118 | - zStatus = "renamed"; | |
| 119 | 120 | }else if( !file_isfile_or_link(zFullName) ){ |
| 120 | 121 | if( file_access(zFullName, F_OK)==0 ){ |
| 121 | 122 | zStatus = "notAFile"; |
| 122 | 123 | ++nErr; |
| 123 | 124 | }else{ |
| @@ -137,17 +138,30 @@ | ||
| 137 | 138 | zStatus = "conflict"; |
| 138 | 139 | }else{ |
| 139 | 140 | zStatus = "edited"; |
| 140 | 141 | } |
| 141 | 142 | } |
| 142 | - | |
| 143 | 143 | oFile = cson_new_object(); |
| 144 | 144 | cson_array_append( aFiles, cson_object_value(oFile) ); |
| 145 | + if( isRenamed ){ | |
| 146 | + if( *zStatus!='?' ){ | |
| 147 | + aStatuses = cson_new_array(); | |
| 148 | + cson_object_set( oFile, "status", cson_array_value( aStatuses ) ); | |
| 149 | + cson_array_append(aStatuses, | |
| 150 | + cson_value_new_string(zStatus, strlen(zStatus))); | |
| 151 | + cson_array_append(aStatuses, cson_value_new_string("renamed", 7)); | |
| 152 | + }else{ | |
| 153 | + zStatus = "renamed"; | |
| 154 | + } | |
| 155 | + cson_object_set( oFile, "priorName", | |
| 156 | + cson_sqlite3_column_to_value(q.pStmt,5)); | |
| 157 | + } | |
| 145 | 158 | /* optimization potential: move these keys into cson_strings |
| 146 | 159 | to take advantage of refcounting. */ |
| 147 | 160 | cson_object_set( oFile, "name", json_new_string( zPathname ) ); |
| 148 | - cson_object_set( oFile, "status", json_new_string( zStatus ) ); | |
| 161 | + cson_object_set( oFile, "status", aStatuses!=NULL ? | |
| 162 | + cson_array_value(aStatuses) : json_new_string( zStatus ) ); | |
| 149 | 163 | |
| 150 | 164 | free(zFullName); |
| 151 | 165 | } |
| 152 | 166 | cson_object_set( oPay, "errorCount", json_new_int( nErr ) ); |
| 153 | 167 | db_finalize(&q); |
| 154 | 168 |
| --- src/json_status.c | |
| +++ src/json_status.c | |
| @@ -60,10 +60,11 @@ | |
| 60 | vid = db_lget_int("checkout", 0); |
| 61 | if(!vid){ |
| 62 | json_set_err( FSL_JSON_E_UNKNOWN, "Can this even happen?" ); |
| 63 | return 0; |
| 64 | } |
| 65 | /* TODO: dupe show_common_info() state */ |
| 66 | tmpO = cson_new_object(); |
| 67 | cson_object_set(oPay, "checkout", cson_object_value(tmpO)); |
| 68 | |
| 69 | zTmp = db_text(0, "SELECT uuid FROM blob WHERE rid=%d", vid); |
| @@ -93,16 +94,18 @@ | |
| 93 | /* Now get the list of non-pristine files... */ |
| 94 | aFiles = cson_new_array(); |
| 95 | cson_object_set( oPay, "files", cson_array_value( aFiles ) ); |
| 96 | |
| 97 | db_prepare(&q, |
| 98 | "SELECT pathname, deleted, chnged, rid, coalesce(origname!=pathname,0)" |
| 99 | " FROM vfile " |
| 100 | " WHERE is_selected(id)" |
| 101 | " AND (chnged OR deleted OR rid=0 OR pathname!=origname) ORDER BY 1" |
| 102 | ); |
| 103 | while( db_step(&q)==SQLITE_ROW ){ |
| 104 | const char *zPathname = db_column_text(&q,0); |
| 105 | int isDeleted = db_column_int(&q, 1); |
| 106 | int isChnged = db_column_int(&q,2); |
| 107 | int isNew = db_column_int(&q,3)==0; |
| 108 | int isRenamed = db_column_int(&q,4); |
| @@ -112,12 +115,10 @@ | |
| 112 | if( isDeleted ){ |
| 113 | zStatus = "deleted"; |
| 114 | }else if( isNew ){ |
| 115 | zStatus = "new" /* maintenance reminder: MUST come |
| 116 | BEFORE the isChnged checks. */; |
| 117 | }else if( isRenamed ){ |
| 118 | zStatus = "renamed"; |
| 119 | }else if( !file_isfile_or_link(zFullName) ){ |
| 120 | if( file_access(zFullName, F_OK)==0 ){ |
| 121 | zStatus = "notAFile"; |
| 122 | ++nErr; |
| 123 | }else{ |
| @@ -137,17 +138,30 @@ | |
| 137 | zStatus = "conflict"; |
| 138 | }else{ |
| 139 | zStatus = "edited"; |
| 140 | } |
| 141 | } |
| 142 | |
| 143 | oFile = cson_new_object(); |
| 144 | cson_array_append( aFiles, cson_object_value(oFile) ); |
| 145 | /* optimization potential: move these keys into cson_strings |
| 146 | to take advantage of refcounting. */ |
| 147 | cson_object_set( oFile, "name", json_new_string( zPathname ) ); |
| 148 | cson_object_set( oFile, "status", json_new_string( zStatus ) ); |
| 149 | |
| 150 | free(zFullName); |
| 151 | } |
| 152 | cson_object_set( oPay, "errorCount", json_new_int( nErr ) ); |
| 153 | db_finalize(&q); |
| 154 |
| --- src/json_status.c | |
| +++ src/json_status.c | |
| @@ -60,10 +60,11 @@ | |
| 60 | vid = db_lget_int("checkout", 0); |
| 61 | if(!vid){ |
| 62 | json_set_err( FSL_JSON_E_UNKNOWN, "Can this even happen?" ); |
| 63 | return 0; |
| 64 | } |
| 65 | vfile_check_signature(vid, 0); |
| 66 | /* TODO: dupe show_common_info() state */ |
| 67 | tmpO = cson_new_object(); |
| 68 | cson_object_set(oPay, "checkout", cson_object_value(tmpO)); |
| 69 | |
| 70 | zTmp = db_text(0, "SELECT uuid FROM blob WHERE rid=%d", vid); |
| @@ -93,16 +94,18 @@ | |
| 94 | /* Now get the list of non-pristine files... */ |
| 95 | aFiles = cson_new_array(); |
| 96 | cson_object_set( oPay, "files", cson_array_value( aFiles ) ); |
| 97 | |
| 98 | db_prepare(&q, |
| 99 | "SELECT pathname, deleted, chnged, rid, " |
| 100 | " coalesce(origname!=pathname,0), origname" |
| 101 | " FROM vfile " |
| 102 | " WHERE is_selected(id)" |
| 103 | " AND (chnged OR deleted OR rid=0 OR pathname!=origname) ORDER BY 1" |
| 104 | ); |
| 105 | while( db_step(&q)==SQLITE_ROW ){ |
| 106 | cson_array *aStatuses = NULL; |
| 107 | const char *zPathname = db_column_text(&q,0); |
| 108 | int isDeleted = db_column_int(&q, 1); |
| 109 | int isChnged = db_column_int(&q,2); |
| 110 | int isNew = db_column_int(&q,3)==0; |
| 111 | int isRenamed = db_column_int(&q,4); |
| @@ -112,12 +115,10 @@ | |
| 115 | if( isDeleted ){ |
| 116 | zStatus = "deleted"; |
| 117 | }else if( isNew ){ |
| 118 | zStatus = "new" /* maintenance reminder: MUST come |
| 119 | BEFORE the isChnged checks. */; |
| 120 | }else if( !file_isfile_or_link(zFullName) ){ |
| 121 | if( file_access(zFullName, F_OK)==0 ){ |
| 122 | zStatus = "notAFile"; |
| 123 | ++nErr; |
| 124 | }else{ |
| @@ -137,17 +138,30 @@ | |
| 138 | zStatus = "conflict"; |
| 139 | }else{ |
| 140 | zStatus = "edited"; |
| 141 | } |
| 142 | } |
| 143 | oFile = cson_new_object(); |
| 144 | cson_array_append( aFiles, cson_object_value(oFile) ); |
| 145 | if( isRenamed ){ |
| 146 | if( *zStatus!='?' ){ |
| 147 | aStatuses = cson_new_array(); |
| 148 | cson_object_set( oFile, "status", cson_array_value( aStatuses ) ); |
| 149 | cson_array_append(aStatuses, |
| 150 | cson_value_new_string(zStatus, strlen(zStatus))); |
| 151 | cson_array_append(aStatuses, cson_value_new_string("renamed", 7)); |
| 152 | }else{ |
| 153 | zStatus = "renamed"; |
| 154 | } |
| 155 | cson_object_set( oFile, "priorName", |
| 156 | cson_sqlite3_column_to_value(q.pStmt,5)); |
| 157 | } |
| 158 | /* optimization potential: move these keys into cson_strings |
| 159 | to take advantage of refcounting. */ |
| 160 | cson_object_set( oFile, "name", json_new_string( zPathname ) ); |
| 161 | cson_object_set( oFile, "status", aStatuses!=NULL ? |
| 162 | cson_array_value(aStatuses) : json_new_string( zStatus ) ); |
| 163 | |
| 164 | free(zFullName); |
| 165 | } |
| 166 | cson_object_set( oPay, "errorCount", json_new_int( nErr ) ); |
| 167 | db_finalize(&q); |
| 168 |