Fossil SCM
Refactored symlink_create repeated block of code into a checked_symlink_create function.
Commit
2d3ff7bd23b170343e613564f59f7201f5d5bcc9
Parent
9e0ba1215daee4b…
5 files changed
+9
+1
-8
+1
-8
+1
-8
+1
-8
+9
| --- src/file.c | ||
| +++ src/file.c | ||
| @@ -241,10 +241,19 @@ | ||
| 241 | 241 | blob_set(&content, zTargetFile); |
| 242 | 242 | blob_write_to_file(&content, zLinkFile); |
| 243 | 243 | blob_reset(&content); |
| 244 | 244 | } |
| 245 | 245 | } |
| 246 | + | |
| 247 | +void checked_symlink_create(int needDelete, int needLink, int maybeLink, Blob* blob, const char* zName){ | |
| 248 | + if (needDelete && (needLink || maybeLink)) | |
| 249 | + link_delete(zName); | |
| 250 | + if (needLink) | |
| 251 | + symlink_create(blog_str(blob), zName); | |
| 252 | + else | |
| 253 | + blog_write_to_file(blob, zName); | |
| 254 | +} | |
| 246 | 255 | |
| 247 | 256 | /* |
| 248 | 257 | ** Copy symbolic link from zFrom to zTo. |
| 249 | 258 | */ |
| 250 | 259 | void symlink_copy(const char *zFrom, const char *zTo){ |
| 251 | 260 |
| --- src/file.c | |
| +++ src/file.c | |
| @@ -241,10 +241,19 @@ | |
| 241 | blob_set(&content, zTargetFile); |
| 242 | blob_write_to_file(&content, zLinkFile); |
| 243 | blob_reset(&content); |
| 244 | } |
| 245 | } |
| 246 | |
| 247 | /* |
| 248 | ** Copy symbolic link from zFrom to zTo. |
| 249 | */ |
| 250 | void symlink_copy(const char *zFrom, const char *zTo){ |
| 251 |
| --- src/file.c | |
| +++ src/file.c | |
| @@ -241,10 +241,19 @@ | |
| 241 | blob_set(&content, zTargetFile); |
| 242 | blob_write_to_file(&content, zLinkFile); |
| 243 | blob_reset(&content); |
| 244 | } |
| 245 | } |
| 246 | |
| 247 | void checked_symlink_create(int needDelete, int needLink, int maybeLink, Blob* blob, const char* zName){ |
| 248 | if (needDelete && (needLink || maybeLink)) |
| 249 | link_delete(zName); |
| 250 | if (needLink) |
| 251 | symlink_create(blog_str(blob), zName); |
| 252 | else |
| 253 | blog_write_to_file(blob, zName); |
| 254 | } |
| 255 | |
| 256 | /* |
| 257 | ** Copy symbolic link from zFrom to zTo. |
| 258 | */ |
| 259 | void symlink_copy(const char *zFrom, const char *zTo){ |
| 260 |
+1
-8
| --- src/stash.c | ||
| +++ src/stash.c | ||
| @@ -241,18 +241,11 @@ | ||
| 241 | 241 | blob_read_from_file(&disk, zOPath); |
| 242 | 242 | } |
| 243 | 243 | content_get(rid, &a); |
| 244 | 244 | blob_delta_apply(&a, &delta, &b); |
| 245 | 245 | if( isLink == isNewLink && blob_compare(&disk, &a)==0 ){ |
| 246 | - if( isLink || isNewLink ){ | |
| 247 | - link_delete(zNPath); | |
| 248 | - } | |
| 249 | - if( isLink ){ | |
| 250 | - symlink_create(blob_str(&b), zNPath); | |
| 251 | - }else{ | |
| 252 | - blob_write_to_file(&b, zNPath); | |
| 253 | - } | |
| 246 | + checked_symlink_create(1, isLink, isNewLink, &b, zNPath); | |
| 254 | 247 | file_wd_setexe(zNPath, isExec); |
| 255 | 248 | fossil_print("UPDATE %s\n", zNew); |
| 256 | 249 | }else{ |
| 257 | 250 | int rc; |
| 258 | 251 | if( isLink || isNewLink ){ |
| 259 | 252 |
| --- src/stash.c | |
| +++ src/stash.c | |
| @@ -241,18 +241,11 @@ | |
| 241 | blob_read_from_file(&disk, zOPath); |
| 242 | } |
| 243 | content_get(rid, &a); |
| 244 | blob_delta_apply(&a, &delta, &b); |
| 245 | if( isLink == isNewLink && blob_compare(&disk, &a)==0 ){ |
| 246 | if( isLink || isNewLink ){ |
| 247 | link_delete(zNPath); |
| 248 | } |
| 249 | if( isLink ){ |
| 250 | symlink_create(blob_str(&b), zNPath); |
| 251 | }else{ |
| 252 | blob_write_to_file(&b, zNPath); |
| 253 | } |
| 254 | file_wd_setexe(zNPath, isExec); |
| 255 | fossil_print("UPDATE %s\n", zNew); |
| 256 | }else{ |
| 257 | int rc; |
| 258 | if( isLink || isNewLink ){ |
| 259 |
| --- src/stash.c | |
| +++ src/stash.c | |
| @@ -241,18 +241,11 @@ | |
| 241 | blob_read_from_file(&disk, zOPath); |
| 242 | } |
| 243 | content_get(rid, &a); |
| 244 | blob_delta_apply(&a, &delta, &b); |
| 245 | if( isLink == isNewLink && blob_compare(&disk, &a)==0 ){ |
| 246 | checked_symlink_create(1, isLink, isNewLink, &b, zNPath); |
| 247 | file_wd_setexe(zNPath, isExec); |
| 248 | fossil_print("UPDATE %s\n", zNew); |
| 249 | }else{ |
| 250 | int rc; |
| 251 | if( isLink || isNewLink ){ |
| 252 |
+1
-8
| --- src/undo.c | ||
| +++ src/undo.c | ||
| @@ -70,18 +70,11 @@ | ||
| 70 | 70 | if( new_exists ){ |
| 71 | 71 | fossil_print("%s %s\n", redoFlag ? "REDO" : "UNDO", zPathname); |
| 72 | 72 | }else{ |
| 73 | 73 | fossil_print("NEW %s\n", zPathname); |
| 74 | 74 | } |
| 75 | - if( new_exists && (new_link || old_link) ){ | |
| 76 | - link_delete(zFullname); | |
| 77 | - } | |
| 78 | - if( old_link ){ | |
| 79 | - symlink_create(blob_str(&new), zFullname); | |
| 80 | - }else{ | |
| 81 | - blob_write_to_file(&new, zFullname); | |
| 82 | - } | |
| 75 | + checked_symlink_create(new_exists, old_link, new_link, &new, zFullname); | |
| 83 | 76 | file_wd_setexe(zFullname, old_exe); |
| 84 | 77 | }else{ |
| 85 | 78 | fossil_print("DELETE %s\n", zPathname); |
| 86 | 79 | file_delete(zFullname); |
| 87 | 80 | } |
| 88 | 81 |
| --- src/undo.c | |
| +++ src/undo.c | |
| @@ -70,18 +70,11 @@ | |
| 70 | if( new_exists ){ |
| 71 | fossil_print("%s %s\n", redoFlag ? "REDO" : "UNDO", zPathname); |
| 72 | }else{ |
| 73 | fossil_print("NEW %s\n", zPathname); |
| 74 | } |
| 75 | if( new_exists && (new_link || old_link) ){ |
| 76 | link_delete(zFullname); |
| 77 | } |
| 78 | if( old_link ){ |
| 79 | symlink_create(blob_str(&new), zFullname); |
| 80 | }else{ |
| 81 | blob_write_to_file(&new, zFullname); |
| 82 | } |
| 83 | file_wd_setexe(zFullname, old_exe); |
| 84 | }else{ |
| 85 | fossil_print("DELETE %s\n", zPathname); |
| 86 | file_delete(zFullname); |
| 87 | } |
| 88 |
| --- src/undo.c | |
| +++ src/undo.c | |
| @@ -70,18 +70,11 @@ | |
| 70 | if( new_exists ){ |
| 71 | fossil_print("%s %s\n", redoFlag ? "REDO" : "UNDO", zPathname); |
| 72 | }else{ |
| 73 | fossil_print("NEW %s\n", zPathname); |
| 74 | } |
| 75 | checked_symlink_create(new_exists, old_link, new_link, &new, zFullname); |
| 76 | file_wd_setexe(zFullname, old_exe); |
| 77 | }else{ |
| 78 | fossil_print("DELETE %s\n", zPathname); |
| 79 | file_delete(zFullname); |
| 80 | } |
| 81 |
+1
-8
| --- src/update.c | ||
| +++ src/update.c | ||
| @@ -808,18 +808,11 @@ | ||
| 808 | 808 | zFile, zFile |
| 809 | 809 | ); |
| 810 | 810 | }else{ |
| 811 | 811 | sqlite3_int64 mtime; |
| 812 | 812 | undo_save(zFile); |
| 813 | - if( file_wd_size(zFull)>=0 && (isLink || file_wd_islink(zFull)) ){ | |
| 814 | - link_delete(zFull); | |
| 815 | - } | |
| 816 | - if( isLink ){ | |
| 817 | - symlink_create(blob_str(&record), zFull); | |
| 818 | - }else{ | |
| 819 | - blob_write_to_file(&record, zFull); | |
| 820 | - } | |
| 813 | + checked_symlink_create(file_wd_size(zFull)>=0, isLink, file_wd_islink(zFull), &record, zFull); | |
| 821 | 814 | file_wd_setexe(zFull, isExe); |
| 822 | 815 | fossil_print("REVERTED: %s\n", zFile); |
| 823 | 816 | mtime = file_wd_mtime(zFull); |
| 824 | 817 | db_multi_exec( |
| 825 | 818 | "UPDATE vfile" |
| 826 | 819 |
| --- src/update.c | |
| +++ src/update.c | |
| @@ -808,18 +808,11 @@ | |
| 808 | zFile, zFile |
| 809 | ); |
| 810 | }else{ |
| 811 | sqlite3_int64 mtime; |
| 812 | undo_save(zFile); |
| 813 | if( file_wd_size(zFull)>=0 && (isLink || file_wd_islink(zFull)) ){ |
| 814 | link_delete(zFull); |
| 815 | } |
| 816 | if( isLink ){ |
| 817 | symlink_create(blob_str(&record), zFull); |
| 818 | }else{ |
| 819 | blob_write_to_file(&record, zFull); |
| 820 | } |
| 821 | file_wd_setexe(zFull, isExe); |
| 822 | fossil_print("REVERTED: %s\n", zFile); |
| 823 | mtime = file_wd_mtime(zFull); |
| 824 | db_multi_exec( |
| 825 | "UPDATE vfile" |
| 826 |
| --- src/update.c | |
| +++ src/update.c | |
| @@ -808,18 +808,11 @@ | |
| 808 | zFile, zFile |
| 809 | ); |
| 810 | }else{ |
| 811 | sqlite3_int64 mtime; |
| 812 | undo_save(zFile); |
| 813 | checked_symlink_create(file_wd_size(zFull)>=0, isLink, file_wd_islink(zFull), &record, zFull); |
| 814 | file_wd_setexe(zFull, isExe); |
| 815 | fossil_print("REVERTED: %s\n", zFile); |
| 816 | mtime = file_wd_mtime(zFull); |
| 817 | db_multi_exec( |
| 818 | "UPDATE vfile" |
| 819 |
+1
-8
| --- src/vfile.c | ||
| +++ src/vfile.c | ||
| @@ -320,18 +320,11 @@ | ||
| 320 | 320 | if( verbose ) fossil_print("%s\n", &zName[nRepos]); |
| 321 | 321 | if( file_wd_isdir(zName) == 1 ){ |
| 322 | 322 | /*TODO(dchest): remove directories? */ |
| 323 | 323 | fossil_fatal("%s is directory, cannot overwrite\n", zName); |
| 324 | 324 | } |
| 325 | - if( file_wd_size(zName)>=0 && (isLink || file_wd_islink(zName)) ){ | |
| 326 | - link_delete(zName); | |
| 327 | - } | |
| 328 | - if( isLink ){ | |
| 329 | - symlink_create(blob_str(&content), zName); | |
| 330 | - }else{ | |
| 331 | - blob_write_to_file(&content, zName); | |
| 332 | - } | |
| 325 | + checked_symlink_create(file_wd_size(zName)>=0, isLink, file_wd_islink(zName), &content, zName); | |
| 333 | 326 | file_wd_setexe(zName, isExe); |
| 334 | 327 | blob_reset(&content); |
| 335 | 328 | db_multi_exec("UPDATE vfile SET mtime=%lld WHERE id=%d", |
| 336 | 329 | file_wd_mtime(zName), id); |
| 337 | 330 | } |
| 338 | 331 |
| --- src/vfile.c | |
| +++ src/vfile.c | |
| @@ -320,18 +320,11 @@ | |
| 320 | if( verbose ) fossil_print("%s\n", &zName[nRepos]); |
| 321 | if( file_wd_isdir(zName) == 1 ){ |
| 322 | /*TODO(dchest): remove directories? */ |
| 323 | fossil_fatal("%s is directory, cannot overwrite\n", zName); |
| 324 | } |
| 325 | if( file_wd_size(zName)>=0 && (isLink || file_wd_islink(zName)) ){ |
| 326 | link_delete(zName); |
| 327 | } |
| 328 | if( isLink ){ |
| 329 | symlink_create(blob_str(&content), zName); |
| 330 | }else{ |
| 331 | blob_write_to_file(&content, zName); |
| 332 | } |
| 333 | file_wd_setexe(zName, isExe); |
| 334 | blob_reset(&content); |
| 335 | db_multi_exec("UPDATE vfile SET mtime=%lld WHERE id=%d", |
| 336 | file_wd_mtime(zName), id); |
| 337 | } |
| 338 |
| --- src/vfile.c | |
| +++ src/vfile.c | |
| @@ -320,18 +320,11 @@ | |
| 320 | if( verbose ) fossil_print("%s\n", &zName[nRepos]); |
| 321 | if( file_wd_isdir(zName) == 1 ){ |
| 322 | /*TODO(dchest): remove directories? */ |
| 323 | fossil_fatal("%s is directory, cannot overwrite\n", zName); |
| 324 | } |
| 325 | checked_symlink_create(file_wd_size(zName)>=0, isLink, file_wd_islink(zName), &content, zName); |
| 326 | file_wd_setexe(zName, isExe); |
| 327 | blob_reset(&content); |
| 328 | db_multi_exec("UPDATE vfile SET mtime=%lld WHERE id=%d", |
| 329 | file_wd_mtime(zName), id); |
| 330 | } |
| 331 |