Fossil SCM
In the new HOST:PATH extension to "diff --tk" (check-in [3daa780e2ccd1d04]), make sure that the HOST:PATH argument is not a valid argument to an options like --from or --to or similar.
Commit
2c72fb8742493fedc7b69fc7667daa8585b5949102ba73649f4f742a111426d8
Parent
ae4bbd8e752117f…
1 file changed
+24
+24
| --- src/diffcmd.c | ||
| +++ src/diffcmd.c | ||
| @@ -1212,10 +1212,33 @@ | ||
| 1212 | 1212 | blob_appendf(pBlob, "\\%03o", (unsigned char)z[j]); |
| 1213 | 1213 | } |
| 1214 | 1214 | } |
| 1215 | 1215 | } |
| 1216 | 1216 | } |
| 1217 | + | |
| 1218 | +/* | |
| 1219 | +** Return TRUE (non-zero) if zArg is a valid option to "diff" or | |
| 1220 | +** "gdiff" that takes an argument that might be confused for a | |
| 1221 | +** HOST:PATH or USER@HOST:PATH filename. | |
| 1222 | +*/ | |
| 1223 | +static int isDiffOptionWithArg(const char *zArg){ | |
| 1224 | + int i; | |
| 1225 | + const char *az[] = { | |
| 1226 | + "binary", | |
| 1227 | + "branch", | |
| 1228 | + "ci", "checkin", | |
| 1229 | + "r", "from", | |
| 1230 | + "to" | |
| 1231 | + }; | |
| 1232 | + if( zArg[0]!='-' ) return 0; | |
| 1233 | + zArg++; | |
| 1234 | + if( zArg[0]=='-' ) zArg++; | |
| 1235 | + for(i=0; i<count(az); i++){ | |
| 1236 | + if( fossil_strcmp(zArg, az[i])==0 ) return 1; | |
| 1237 | + } | |
| 1238 | + return 0; | |
| 1239 | +} | |
| 1217 | 1240 | |
| 1218 | 1241 | /* |
| 1219 | 1242 | ** Show diff output in a Tcl/Tk window, in response to the --tk option |
| 1220 | 1243 | ** to the diff command. |
| 1221 | 1244 | ** |
| @@ -1260,10 +1283,11 @@ | ||
| 1260 | 1283 | ** for testing and debugging. */ |
| 1261 | 1284 | zTempFile = find_option("script",0,1); |
| 1262 | 1285 | for(i=firstArg; i<g.argc; i++){ |
| 1263 | 1286 | const char *z = g.argv[i]; |
| 1264 | 1287 | if( zHost==0 |
| 1288 | + && (i==firstArg || !isDiffOptionWithArg(g.argv[i-1])) | |
| 1265 | 1289 | && !file_isfile_or_link(z) |
| 1266 | 1290 | && (zDir = file_skip_userhost(z))!=0 |
| 1267 | 1291 | ){ |
| 1268 | 1292 | zHost = mprintf("%.*s", (int)(zDir - z - 1), z); |
| 1269 | 1293 | continue; |
| 1270 | 1294 |
| --- src/diffcmd.c | |
| +++ src/diffcmd.c | |
| @@ -1212,10 +1212,33 @@ | |
| 1212 | blob_appendf(pBlob, "\\%03o", (unsigned char)z[j]); |
| 1213 | } |
| 1214 | } |
| 1215 | } |
| 1216 | } |
| 1217 | |
| 1218 | /* |
| 1219 | ** Show diff output in a Tcl/Tk window, in response to the --tk option |
| 1220 | ** to the diff command. |
| 1221 | ** |
| @@ -1260,10 +1283,11 @@ | |
| 1260 | ** for testing and debugging. */ |
| 1261 | zTempFile = find_option("script",0,1); |
| 1262 | for(i=firstArg; i<g.argc; i++){ |
| 1263 | const char *z = g.argv[i]; |
| 1264 | if( zHost==0 |
| 1265 | && !file_isfile_or_link(z) |
| 1266 | && (zDir = file_skip_userhost(z))!=0 |
| 1267 | ){ |
| 1268 | zHost = mprintf("%.*s", (int)(zDir - z - 1), z); |
| 1269 | continue; |
| 1270 |
| --- src/diffcmd.c | |
| +++ src/diffcmd.c | |
| @@ -1212,10 +1212,33 @@ | |
| 1212 | blob_appendf(pBlob, "\\%03o", (unsigned char)z[j]); |
| 1213 | } |
| 1214 | } |
| 1215 | } |
| 1216 | } |
| 1217 | |
| 1218 | /* |
| 1219 | ** Return TRUE (non-zero) if zArg is a valid option to "diff" or |
| 1220 | ** "gdiff" that takes an argument that might be confused for a |
| 1221 | ** HOST:PATH or USER@HOST:PATH filename. |
| 1222 | */ |
| 1223 | static int isDiffOptionWithArg(const char *zArg){ |
| 1224 | int i; |
| 1225 | const char *az[] = { |
| 1226 | "binary", |
| 1227 | "branch", |
| 1228 | "ci", "checkin", |
| 1229 | "r", "from", |
| 1230 | "to" |
| 1231 | }; |
| 1232 | if( zArg[0]!='-' ) return 0; |
| 1233 | zArg++; |
| 1234 | if( zArg[0]=='-' ) zArg++; |
| 1235 | for(i=0; i<count(az); i++){ |
| 1236 | if( fossil_strcmp(zArg, az[i])==0 ) return 1; |
| 1237 | } |
| 1238 | return 0; |
| 1239 | } |
| 1240 | |
| 1241 | /* |
| 1242 | ** Show diff output in a Tcl/Tk window, in response to the --tk option |
| 1243 | ** to the diff command. |
| 1244 | ** |
| @@ -1260,10 +1283,11 @@ | |
| 1283 | ** for testing and debugging. */ |
| 1284 | zTempFile = find_option("script",0,1); |
| 1285 | for(i=firstArg; i<g.argc; i++){ |
| 1286 | const char *z = g.argv[i]; |
| 1287 | if( zHost==0 |
| 1288 | && (i==firstArg || !isDiffOptionWithArg(g.argv[i-1])) |
| 1289 | && !file_isfile_or_link(z) |
| 1290 | && (zDir = file_skip_userhost(z))!=0 |
| 1291 | ){ |
| 1292 | zHost = mprintf("%.*s", (int)(zDir - z - 1), z); |
| 1293 | continue; |
| 1294 |