Fossil SCM

Refactored symlink_create repeated block of code into a checked_symlink_create function.

sdr 2014-09-20 18:32 UTC bad-winsymlink
Commit 2d3ff7bd23b170343e613564f59f7201f5d5bcc9
+9
--- src/file.c
+++ src/file.c
@@ -241,10 +241,19 @@
241241
blob_set(&content, zTargetFile);
242242
blob_write_to_file(&content, zLinkFile);
243243
blob_reset(&content);
244244
}
245245
}
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
+}
246255
247256
/*
248257
** Copy symbolic link from zFrom to zTo.
249258
*/
250259
void symlink_copy(const char *zFrom, const char *zTo){
251260
--- 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 @@
241241
blob_read_from_file(&disk, zOPath);
242242
}
243243
content_get(rid, &a);
244244
blob_delta_apply(&a, &delta, &b);
245245
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);
254247
file_wd_setexe(zNPath, isExec);
255248
fossil_print("UPDATE %s\n", zNew);
256249
}else{
257250
int rc;
258251
if( isLink || isNewLink ){
259252
--- 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 @@
7070
if( new_exists ){
7171
fossil_print("%s %s\n", redoFlag ? "REDO" : "UNDO", zPathname);
7272
}else{
7373
fossil_print("NEW %s\n", zPathname);
7474
}
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);
8376
file_wd_setexe(zFullname, old_exe);
8477
}else{
8578
fossil_print("DELETE %s\n", zPathname);
8679
file_delete(zFullname);
8780
}
8881
--- 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 @@
808808
zFile, zFile
809809
);
810810
}else{
811811
sqlite3_int64 mtime;
812812
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);
821814
file_wd_setexe(zFull, isExe);
822815
fossil_print("REVERTED: %s\n", zFile);
823816
mtime = file_wd_mtime(zFull);
824817
db_multi_exec(
825818
"UPDATE vfile"
826819
--- 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 @@
320320
if( verbose ) fossil_print("%s\n", &zName[nRepos]);
321321
if( file_wd_isdir(zName) == 1 ){
322322
/*TODO(dchest): remove directories? */
323323
fossil_fatal("%s is directory, cannot overwrite\n", zName);
324324
}
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);
333326
file_wd_setexe(zName, isExe);
334327
blob_reset(&content);
335328
db_multi_exec("UPDATE vfile SET mtime=%lld WHERE id=%d",
336329
file_wd_mtime(zName), id);
337330
}
338331
--- 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

Keyboard Shortcuts

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