Fossil SCM
Minor optimization to status_report() to avoid building list of managed files if only unmanaged files are requested. Move unmanaged file reserved name filtering to status_report(). Ensure db_get*() calls happen after db_must_be_within_tree(). Implement extras_cmd() in terms of status_report().
Commit
d52fd18529c7faf8d1656d26cbf33edb18e6d3a9
Parent
c2b3f6b1c01ac3c…
1 file changed
+43
-54
+43
-54
| --- src/checkin.c | ||
| +++ src/checkin.c | ||
| @@ -136,28 +136,35 @@ | ||
| 136 | 136 | filename_collation(), zName, filename_collation(), |
| 137 | 137 | zName, filename_collation() |
| 138 | 138 | ); |
| 139 | 139 | } |
| 140 | 140 | |
| 141 | - /* Start building the SELECT statement. */ | |
| 141 | + /* Obtain the list of managed files if appropriate. */ | |
| 142 | 142 | blob_zero(&sql); |
| 143 | - blob_append_sql(&sql, | |
| 144 | - "SELECT pathname, deleted, chnged, rid," | |
| 145 | - " coalesce(origname!=pathname,0) AS renamed, islink, 1 AS managed" | |
| 146 | - " FROM vfile" | |
| 147 | - " WHERE is_selected(id)%s", blob_sql_text(&where)); | |
| 148 | - | |
| 149 | - /* Exclude unmodified files unless requested. */ | |
| 150 | - if( !(flags & C_UNMODIFIED) ){ | |
| 151 | - blob_append_sql(&sql, | |
| 152 | - " AND (chnged OR deleted OR rid=0 OR pathname!=origname)"); | |
| 143 | + if( flags & C_ALL ){ | |
| 144 | + /* Start with a list of all managed files. */ | |
| 145 | + blob_append_sql(&sql, | |
| 146 | + "SELECT pathname, deleted, chnged, rid," | |
| 147 | + " coalesce(origname!=pathname,0) AS renamed, islink, 1 AS managed" | |
| 148 | + " FROM vfile" | |
| 149 | + " WHERE is_selected(id)%s", blob_sql_text(&where)); | |
| 150 | + | |
| 151 | + /* Exclude unmodified files unless requested. */ | |
| 152 | + if( !(flags & C_UNMODIFIED) ){ | |
| 153 | + blob_append_sql(&sql, | |
| 154 | + " AND (chnged OR deleted OR rid=0 OR pathname!=origname)"); | |
| 155 | + } | |
| 153 | 156 | } |
| 154 | 157 | |
| 155 | 158 | /* If C_EXTRA, add unmanaged files to the query result too. */ |
| 156 | 159 | if( flags & C_EXTRA ){ |
| 157 | - blob_append_sql(&sql, " UNION ALL SELECT x AS pathname, 0, 0, 0, 0, 0, 0" | |
| 158 | - " FROM sfile WHERE 1%s", blob_sql_text(&where)); | |
| 160 | + if( blob_size(&sql) ){ | |
| 161 | + blob_append_sql(&sql, " UNION ALL"); | |
| 162 | + } | |
| 163 | + blob_append_sql(&sql, " SELECT x AS pathname, 0, 0, 0, 0, 0, 0" | |
| 164 | + " FROM sfile WHERE pathname NOT IN (%s)%s", | |
| 165 | + fossil_all_reserved_names(0), blob_sql_text(&where)); | |
| 159 | 166 | } |
| 160 | 167 | |
| 161 | 168 | /* Append an ORDER BY clause then compile the query. */ |
| 162 | 169 | blob_append_sql(&sql, " ORDER BY pathname"); |
| 163 | 170 | db_prepare(&q, "%s", blob_sql_text(&sql)); |
| @@ -420,20 +427,10 @@ | ||
| 420 | 427 | unsigned scanFlags = 0; |
| 421 | 428 | int changes = g.argv[1][0]=='c'; |
| 422 | 429 | unsigned flags = 0; |
| 423 | 430 | int vid, i; |
| 424 | 431 | |
| 425 | - /* If --ignore is not specified, use the ignore-glob setting. */ | |
| 426 | - if( !zIgnoreFlag ){ | |
| 427 | - zIgnoreFlag = db_get("ignore-glob", 0); | |
| 428 | - } | |
| 429 | - | |
| 430 | - /* Get the --dotfiles argument, or read it from the dotfiles setting. */ | |
| 431 | - if( find_option("dotfiles", 0, 0) || db_get_boolean("dotfiles", 0) ){ | |
| 432 | - scanFlags = SCAN_ALL; | |
| 433 | - } | |
| 434 | - | |
| 435 | 432 | /* Load affirmative flag options. */ |
| 436 | 433 | for( i=0; i<count(flagDefs); ++i ){ |
| 437 | 434 | if( (!flagDefs[i].changesOnly || changes) |
| 438 | 435 | && find_option(flagDefs[i].option, 0, 0) ){ |
| 439 | 436 | flags |= flagDefs[i].mask; |
| @@ -471,24 +468,32 @@ | ||
| 471 | 468 | |
| 472 | 469 | /* Relative path flag determination is done by a shared function. */ |
| 473 | 470 | if( determine_cwd_relative_option() ){ |
| 474 | 471 | flags |= C_RELPATH; |
| 475 | 472 | } |
| 473 | + | |
| 474 | + /* If --ignore is not specified, use the ignore-glob setting. */ | |
| 475 | + if( !zIgnoreFlag ){ | |
| 476 | + zIgnoreFlag = db_get("ignore-glob", 0); | |
| 477 | + } | |
| 478 | + | |
| 479 | + /* Get the --dotfiles argument, or read it from the dotfiles setting. */ | |
| 480 | + if( find_option("dotfiles", 0, 0) || db_get_boolean("dotfiles", 0) ){ | |
| 481 | + scanFlags = SCAN_ALL; | |
| 482 | + } | |
| 476 | 483 | |
| 477 | 484 | /* We should be done with options. */ |
| 478 | 485 | verify_all_options(); |
| 479 | 486 | |
| 480 | 487 | /* Check for changed files. */ |
| 481 | 488 | vfile_check_signature(vid, useSha1sum ? CKSIG_SHA1 : 0); |
| 482 | 489 | |
| 483 | - /* Search for unmanaged files if requested. Exclude reserved files. */ | |
| 490 | + /* Search for unmanaged files if requested. */ | |
| 484 | 491 | if( flags & C_EXTRA ){ |
| 485 | 492 | Glob *pIgnore = glob_create(zIgnoreFlag); |
| 486 | 493 | locate_unmanaged_files(g.argc-2, g.argv+2, scanFlags, pIgnore); |
| 487 | 494 | glob_free(pIgnore); |
| 488 | - db_multi_exec("DELETE FROM sfile WHERE x IN (%s)", | |
| 489 | - fossil_all_reserved_names(0)); | |
| 490 | 495 | } |
| 491 | 496 | |
| 492 | 497 | /* The status command prints general information before the change list. */ |
| 493 | 498 | if( !changes ){ |
| 494 | 499 | fossil_print("repository: %s\n", db_repository_filename()); |
| @@ -768,22 +773,23 @@ | ||
| 768 | 773 | ** directory. |
| 769 | 774 | ** |
| 770 | 775 | ** See also: changes, clean, status |
| 771 | 776 | */ |
| 772 | 777 | void extras_cmd(void){ |
| 773 | - Stmt q; | |
| 778 | + Blob report = BLOB_INITIALIZER; | |
| 774 | 779 | const char *zIgnoreFlag = find_option("ignore",0,1); |
| 775 | 780 | unsigned scanFlags = find_option("dotfiles",0,0)!=0 ? SCAN_ALL : 0; |
| 781 | + unsigned flags = C_EXTRA; | |
| 776 | 782 | int showHdr = find_option("header",0,0)!=0; |
| 777 | - int cwdRelative = 0; | |
| 778 | 783 | Glob *pIgnore; |
| 779 | - Blob rewrittenPathname; | |
| 780 | - const char *zPathname, *zDisplayName; | |
| 781 | 784 | |
| 782 | 785 | if( find_option("temp",0,0)!=0 ) scanFlags |= SCAN_TEMP; |
| 783 | 786 | db_must_be_within_tree(); |
| 784 | - cwdRelative = determine_cwd_relative_option(); | |
| 787 | + | |
| 788 | + if( determine_cwd_relative_option() ){ | |
| 789 | + flags |= C_RELPATH; | |
| 790 | + } | |
| 785 | 791 | |
| 786 | 792 | if( db_get_boolean("dotfiles", 0) ) scanFlags |= SCAN_ALL; |
| 787 | 793 | |
| 788 | 794 | /* We should be done with options.. */ |
| 789 | 795 | verify_all_options(); |
| @@ -792,39 +798,22 @@ | ||
| 792 | 798 | zIgnoreFlag = db_get("ignore-glob", 0); |
| 793 | 799 | } |
| 794 | 800 | pIgnore = glob_create(zIgnoreFlag); |
| 795 | 801 | locate_unmanaged_files(g.argc-2, g.argv+2, scanFlags, pIgnore); |
| 796 | 802 | glob_free(pIgnore); |
| 797 | - db_prepare(&q, | |
| 798 | - "SELECT x FROM sfile" | |
| 799 | - " WHERE x NOT IN (%s)" | |
| 800 | - " ORDER BY 1", | |
| 801 | - fossil_all_reserved_names(0) | |
| 802 | - ); | |
| 803 | - db_multi_exec("DELETE FROM sfile WHERE x IN (SELECT pathname FROM vfile)"); | |
| 804 | - blob_zero(&rewrittenPathname); | |
| 805 | 803 | g.allowSymlinks = 1; /* Report on symbolic links */ |
| 806 | - while( db_step(&q)==SQLITE_ROW ){ | |
| 807 | - zDisplayName = zPathname = db_column_text(&q, 0); | |
| 808 | - if( cwdRelative ){ | |
| 809 | - char *zFullName = mprintf("%s%s", g.zLocalRoot, zPathname); | |
| 810 | - file_relative_name(zFullName, &rewrittenPathname, 0); | |
| 811 | - free(zFullName); | |
| 812 | - zDisplayName = blob_str(&rewrittenPathname); | |
| 813 | - if( zDisplayName[0]=='.' && zDisplayName[1]=='/' ){ | |
| 814 | - zDisplayName += 2; /* no unnecessary ./ prefix */ | |
| 815 | - } | |
| 816 | - } | |
| 804 | + | |
| 805 | + blob_zero(&report); | |
| 806 | + status_report(&report, flags); | |
| 807 | + if( blob_size(&report) ){ | |
| 817 | 808 | if( showHdr ){ |
| 818 | - showHdr = 0; | |
| 819 | 809 | fossil_print("Extras for %s at %s:\n", db_get("project-name","???"), |
| 820 | 810 | g.zLocalRoot); |
| 821 | 811 | } |
| 822 | - fossil_print("%s\n", zDisplayName); | |
| 812 | + blob_write_to_file(&report, "-"); | |
| 823 | 813 | } |
| 824 | - blob_reset(&rewrittenPathname); | |
| 825 | - db_finalize(&q); | |
| 814 | + blob_reset(&report); | |
| 826 | 815 | } |
| 827 | 816 | |
| 828 | 817 | /* |
| 829 | 818 | ** COMMAND: clean |
| 830 | 819 | ** |
| 831 | 820 |
| --- src/checkin.c | |
| +++ src/checkin.c | |
| @@ -136,28 +136,35 @@ | |
| 136 | filename_collation(), zName, filename_collation(), |
| 137 | zName, filename_collation() |
| 138 | ); |
| 139 | } |
| 140 | |
| 141 | /* Start building the SELECT statement. */ |
| 142 | blob_zero(&sql); |
| 143 | blob_append_sql(&sql, |
| 144 | "SELECT pathname, deleted, chnged, rid," |
| 145 | " coalesce(origname!=pathname,0) AS renamed, islink, 1 AS managed" |
| 146 | " FROM vfile" |
| 147 | " WHERE is_selected(id)%s", blob_sql_text(&where)); |
| 148 | |
| 149 | /* Exclude unmodified files unless requested. */ |
| 150 | if( !(flags & C_UNMODIFIED) ){ |
| 151 | blob_append_sql(&sql, |
| 152 | " AND (chnged OR deleted OR rid=0 OR pathname!=origname)"); |
| 153 | } |
| 154 | |
| 155 | /* If C_EXTRA, add unmanaged files to the query result too. */ |
| 156 | if( flags & C_EXTRA ){ |
| 157 | blob_append_sql(&sql, " UNION ALL SELECT x AS pathname, 0, 0, 0, 0, 0, 0" |
| 158 | " FROM sfile WHERE 1%s", blob_sql_text(&where)); |
| 159 | } |
| 160 | |
| 161 | /* Append an ORDER BY clause then compile the query. */ |
| 162 | blob_append_sql(&sql, " ORDER BY pathname"); |
| 163 | db_prepare(&q, "%s", blob_sql_text(&sql)); |
| @@ -420,20 +427,10 @@ | |
| 420 | unsigned scanFlags = 0; |
| 421 | int changes = g.argv[1][0]=='c'; |
| 422 | unsigned flags = 0; |
| 423 | int vid, i; |
| 424 | |
| 425 | /* If --ignore is not specified, use the ignore-glob setting. */ |
| 426 | if( !zIgnoreFlag ){ |
| 427 | zIgnoreFlag = db_get("ignore-glob", 0); |
| 428 | } |
| 429 | |
| 430 | /* Get the --dotfiles argument, or read it from the dotfiles setting. */ |
| 431 | if( find_option("dotfiles", 0, 0) || db_get_boolean("dotfiles", 0) ){ |
| 432 | scanFlags = SCAN_ALL; |
| 433 | } |
| 434 | |
| 435 | /* Load affirmative flag options. */ |
| 436 | for( i=0; i<count(flagDefs); ++i ){ |
| 437 | if( (!flagDefs[i].changesOnly || changes) |
| 438 | && find_option(flagDefs[i].option, 0, 0) ){ |
| 439 | flags |= flagDefs[i].mask; |
| @@ -471,24 +468,32 @@ | |
| 471 | |
| 472 | /* Relative path flag determination is done by a shared function. */ |
| 473 | if( determine_cwd_relative_option() ){ |
| 474 | flags |= C_RELPATH; |
| 475 | } |
| 476 | |
| 477 | /* We should be done with options. */ |
| 478 | verify_all_options(); |
| 479 | |
| 480 | /* Check for changed files. */ |
| 481 | vfile_check_signature(vid, useSha1sum ? CKSIG_SHA1 : 0); |
| 482 | |
| 483 | /* Search for unmanaged files if requested. Exclude reserved files. */ |
| 484 | if( flags & C_EXTRA ){ |
| 485 | Glob *pIgnore = glob_create(zIgnoreFlag); |
| 486 | locate_unmanaged_files(g.argc-2, g.argv+2, scanFlags, pIgnore); |
| 487 | glob_free(pIgnore); |
| 488 | db_multi_exec("DELETE FROM sfile WHERE x IN (%s)", |
| 489 | fossil_all_reserved_names(0)); |
| 490 | } |
| 491 | |
| 492 | /* The status command prints general information before the change list. */ |
| 493 | if( !changes ){ |
| 494 | fossil_print("repository: %s\n", db_repository_filename()); |
| @@ -768,22 +773,23 @@ | |
| 768 | ** directory. |
| 769 | ** |
| 770 | ** See also: changes, clean, status |
| 771 | */ |
| 772 | void extras_cmd(void){ |
| 773 | Stmt q; |
| 774 | const char *zIgnoreFlag = find_option("ignore",0,1); |
| 775 | unsigned scanFlags = find_option("dotfiles",0,0)!=0 ? SCAN_ALL : 0; |
| 776 | int showHdr = find_option("header",0,0)!=0; |
| 777 | int cwdRelative = 0; |
| 778 | Glob *pIgnore; |
| 779 | Blob rewrittenPathname; |
| 780 | const char *zPathname, *zDisplayName; |
| 781 | |
| 782 | if( find_option("temp",0,0)!=0 ) scanFlags |= SCAN_TEMP; |
| 783 | db_must_be_within_tree(); |
| 784 | cwdRelative = determine_cwd_relative_option(); |
| 785 | |
| 786 | if( db_get_boolean("dotfiles", 0) ) scanFlags |= SCAN_ALL; |
| 787 | |
| 788 | /* We should be done with options.. */ |
| 789 | verify_all_options(); |
| @@ -792,39 +798,22 @@ | |
| 792 | zIgnoreFlag = db_get("ignore-glob", 0); |
| 793 | } |
| 794 | pIgnore = glob_create(zIgnoreFlag); |
| 795 | locate_unmanaged_files(g.argc-2, g.argv+2, scanFlags, pIgnore); |
| 796 | glob_free(pIgnore); |
| 797 | db_prepare(&q, |
| 798 | "SELECT x FROM sfile" |
| 799 | " WHERE x NOT IN (%s)" |
| 800 | " ORDER BY 1", |
| 801 | fossil_all_reserved_names(0) |
| 802 | ); |
| 803 | db_multi_exec("DELETE FROM sfile WHERE x IN (SELECT pathname FROM vfile)"); |
| 804 | blob_zero(&rewrittenPathname); |
| 805 | g.allowSymlinks = 1; /* Report on symbolic links */ |
| 806 | while( db_step(&q)==SQLITE_ROW ){ |
| 807 | zDisplayName = zPathname = db_column_text(&q, 0); |
| 808 | if( cwdRelative ){ |
| 809 | char *zFullName = mprintf("%s%s", g.zLocalRoot, zPathname); |
| 810 | file_relative_name(zFullName, &rewrittenPathname, 0); |
| 811 | free(zFullName); |
| 812 | zDisplayName = blob_str(&rewrittenPathname); |
| 813 | if( zDisplayName[0]=='.' && zDisplayName[1]=='/' ){ |
| 814 | zDisplayName += 2; /* no unnecessary ./ prefix */ |
| 815 | } |
| 816 | } |
| 817 | if( showHdr ){ |
| 818 | showHdr = 0; |
| 819 | fossil_print("Extras for %s at %s:\n", db_get("project-name","???"), |
| 820 | g.zLocalRoot); |
| 821 | } |
| 822 | fossil_print("%s\n", zDisplayName); |
| 823 | } |
| 824 | blob_reset(&rewrittenPathname); |
| 825 | db_finalize(&q); |
| 826 | } |
| 827 | |
| 828 | /* |
| 829 | ** COMMAND: clean |
| 830 | ** |
| 831 |
| --- src/checkin.c | |
| +++ src/checkin.c | |
| @@ -136,28 +136,35 @@ | |
| 136 | filename_collation(), zName, filename_collation(), |
| 137 | zName, filename_collation() |
| 138 | ); |
| 139 | } |
| 140 | |
| 141 | /* Obtain the list of managed files if appropriate. */ |
| 142 | blob_zero(&sql); |
| 143 | if( flags & C_ALL ){ |
| 144 | /* Start with a list of all managed files. */ |
| 145 | blob_append_sql(&sql, |
| 146 | "SELECT pathname, deleted, chnged, rid," |
| 147 | " coalesce(origname!=pathname,0) AS renamed, islink, 1 AS managed" |
| 148 | " FROM vfile" |
| 149 | " WHERE is_selected(id)%s", blob_sql_text(&where)); |
| 150 | |
| 151 | /* Exclude unmodified files unless requested. */ |
| 152 | if( !(flags & C_UNMODIFIED) ){ |
| 153 | blob_append_sql(&sql, |
| 154 | " AND (chnged OR deleted OR rid=0 OR pathname!=origname)"); |
| 155 | } |
| 156 | } |
| 157 | |
| 158 | /* If C_EXTRA, add unmanaged files to the query result too. */ |
| 159 | if( flags & C_EXTRA ){ |
| 160 | if( blob_size(&sql) ){ |
| 161 | blob_append_sql(&sql, " UNION ALL"); |
| 162 | } |
| 163 | blob_append_sql(&sql, " SELECT x AS pathname, 0, 0, 0, 0, 0, 0" |
| 164 | " FROM sfile WHERE pathname NOT IN (%s)%s", |
| 165 | fossil_all_reserved_names(0), blob_sql_text(&where)); |
| 166 | } |
| 167 | |
| 168 | /* Append an ORDER BY clause then compile the query. */ |
| 169 | blob_append_sql(&sql, " ORDER BY pathname"); |
| 170 | db_prepare(&q, "%s", blob_sql_text(&sql)); |
| @@ -420,20 +427,10 @@ | |
| 427 | unsigned scanFlags = 0; |
| 428 | int changes = g.argv[1][0]=='c'; |
| 429 | unsigned flags = 0; |
| 430 | int vid, i; |
| 431 | |
| 432 | /* Load affirmative flag options. */ |
| 433 | for( i=0; i<count(flagDefs); ++i ){ |
| 434 | if( (!flagDefs[i].changesOnly || changes) |
| 435 | && find_option(flagDefs[i].option, 0, 0) ){ |
| 436 | flags |= flagDefs[i].mask; |
| @@ -471,24 +468,32 @@ | |
| 468 | |
| 469 | /* Relative path flag determination is done by a shared function. */ |
| 470 | if( determine_cwd_relative_option() ){ |
| 471 | flags |= C_RELPATH; |
| 472 | } |
| 473 | |
| 474 | /* If --ignore is not specified, use the ignore-glob setting. */ |
| 475 | if( !zIgnoreFlag ){ |
| 476 | zIgnoreFlag = db_get("ignore-glob", 0); |
| 477 | } |
| 478 | |
| 479 | /* Get the --dotfiles argument, or read it from the dotfiles setting. */ |
| 480 | if( find_option("dotfiles", 0, 0) || db_get_boolean("dotfiles", 0) ){ |
| 481 | scanFlags = SCAN_ALL; |
| 482 | } |
| 483 | |
| 484 | /* We should be done with options. */ |
| 485 | verify_all_options(); |
| 486 | |
| 487 | /* Check for changed files. */ |
| 488 | vfile_check_signature(vid, useSha1sum ? CKSIG_SHA1 : 0); |
| 489 | |
| 490 | /* Search for unmanaged files if requested. */ |
| 491 | if( flags & C_EXTRA ){ |
| 492 | Glob *pIgnore = glob_create(zIgnoreFlag); |
| 493 | locate_unmanaged_files(g.argc-2, g.argv+2, scanFlags, pIgnore); |
| 494 | glob_free(pIgnore); |
| 495 | } |
| 496 | |
| 497 | /* The status command prints general information before the change list. */ |
| 498 | if( !changes ){ |
| 499 | fossil_print("repository: %s\n", db_repository_filename()); |
| @@ -768,22 +773,23 @@ | |
| 773 | ** directory. |
| 774 | ** |
| 775 | ** See also: changes, clean, status |
| 776 | */ |
| 777 | void extras_cmd(void){ |
| 778 | Blob report = BLOB_INITIALIZER; |
| 779 | const char *zIgnoreFlag = find_option("ignore",0,1); |
| 780 | unsigned scanFlags = find_option("dotfiles",0,0)!=0 ? SCAN_ALL : 0; |
| 781 | unsigned flags = C_EXTRA; |
| 782 | int showHdr = find_option("header",0,0)!=0; |
| 783 | Glob *pIgnore; |
| 784 | |
| 785 | if( find_option("temp",0,0)!=0 ) scanFlags |= SCAN_TEMP; |
| 786 | db_must_be_within_tree(); |
| 787 | |
| 788 | if( determine_cwd_relative_option() ){ |
| 789 | flags |= C_RELPATH; |
| 790 | } |
| 791 | |
| 792 | if( db_get_boolean("dotfiles", 0) ) scanFlags |= SCAN_ALL; |
| 793 | |
| 794 | /* We should be done with options.. */ |
| 795 | verify_all_options(); |
| @@ -792,39 +798,22 @@ | |
| 798 | zIgnoreFlag = db_get("ignore-glob", 0); |
| 799 | } |
| 800 | pIgnore = glob_create(zIgnoreFlag); |
| 801 | locate_unmanaged_files(g.argc-2, g.argv+2, scanFlags, pIgnore); |
| 802 | glob_free(pIgnore); |
| 803 | g.allowSymlinks = 1; /* Report on symbolic links */ |
| 804 | |
| 805 | blob_zero(&report); |
| 806 | status_report(&report, flags); |
| 807 | if( blob_size(&report) ){ |
| 808 | if( showHdr ){ |
| 809 | fossil_print("Extras for %s at %s:\n", db_get("project-name","???"), |
| 810 | g.zLocalRoot); |
| 811 | } |
| 812 | blob_write_to_file(&report, "-"); |
| 813 | } |
| 814 | blob_reset(&report); |
| 815 | } |
| 816 | |
| 817 | /* |
| 818 | ** COMMAND: clean |
| 819 | ** |
| 820 |