Fossil SCM
Allow the "fossil commit" command to accept directories as command-line arguments and commit all files contained underneath those directories.
Commit
c8253f4066cbc562b835419ba6b1b0928d88373a
Parent
d09e37387857ef4…
1 file changed
+44
-11
+44
-11
| --- src/checkin.c | ||
| +++ src/checkin.c | ||
| @@ -45,10 +45,11 @@ | ||
| 45 | 45 | const char *zTreeName; |
| 46 | 46 | int i, nRoot; |
| 47 | 47 | |
| 48 | 48 | blob_zero(&where); |
| 49 | 49 | nRoot = (int)strlen(g.zLocalRoot); |
| 50 | + blob_zero(&where); | |
| 50 | 51 | for(i=2; i<g.argc; i++) { |
| 51 | 52 | Blob fname; |
| 52 | 53 | file_canonical_name(g.argv[i], &fname, 0); |
| 53 | 54 | zTreeName = blob_str(&fname)+nRoot; |
| 54 | 55 | blob_appendf(&where, " %s (pathname=%Q %s) " |
| @@ -112,10 +113,12 @@ | ||
| 112 | 113 | }else{ |
| 113 | 114 | blob_appendf(report, "EDITED %s\n", zDisplayName); |
| 114 | 115 | } |
| 115 | 116 | }else if( isRenamed ){ |
| 116 | 117 | blob_appendf(report, "RENAMED %s\n", zDisplayName); |
| 118 | + }else{ | |
| 119 | + report->nUsed -= nPrefix; | |
| 117 | 120 | } |
| 118 | 121 | free(zFullName); |
| 119 | 122 | } |
| 120 | 123 | blob_reset(&rewrittenPathname); |
| 121 | 124 | db_finalize(&q); |
| @@ -734,30 +737,60 @@ | ||
| 734 | 737 | ** |
| 735 | 738 | ** Returns 1 if there was a warning, 0 otherwise. |
| 736 | 739 | */ |
| 737 | 740 | int select_commit_files(void){ |
| 738 | 741 | int result = 0; |
| 742 | + assert( g.aCommitFile==0 ); | |
| 739 | 743 | if( g.argc>2 ){ |
| 740 | 744 | int ii, jj=0; |
| 741 | - Blob b; | |
| 742 | - blob_zero(&b); | |
| 743 | - g.aCommitFile = fossil_malloc(sizeof(int)*(g.argc-1)); | |
| 745 | + Blob fname; | |
| 746 | + int isDir; | |
| 747 | + Stmt q; | |
| 748 | + const char *zCollate; | |
| 749 | + Bag toCommit; | |
| 744 | 750 | |
| 751 | + zCollate = filename_collation(); | |
| 752 | + blob_zero(&fname); | |
| 753 | + bag_init(&toCommit); | |
| 745 | 754 | for(ii=2; ii<g.argc; ii++){ |
| 746 | - int iId; | |
| 747 | - file_tree_name(g.argv[ii], &b, 1); | |
| 748 | - iId = db_int(-1, "SELECT id FROM vfile WHERE pathname=%Q %s", | |
| 749 | - blob_str(&b), filename_collation() ); | |
| 750 | - if( iId<0 ){ | |
| 755 | + int cnt = 0; | |
| 756 | + file_tree_name(g.argv[ii], &fname, 1); | |
| 757 | + if( fossil_strcmp(blob_str(&fname),".")==0 ){ | |
| 758 | + bag_clear(&toCommit); | |
| 759 | + return result; | |
| 760 | + } | |
| 761 | + isDir = file_isdir(g.argv[ii]); | |
| 762 | + if( isDir==1 ){ | |
| 763 | + db_prepare(&q, | |
| 764 | + "SELECT id FROM vfile WHERE pathname>'%q/' %s AND pathname<'%q0'", | |
| 765 | + blob_str(&fname), zCollate, blob_str(&fname), zCollate); | |
| 766 | + }else if( isDir==2 ){ | |
| 767 | + db_prepare(&q, | |
| 768 | + "SELECT id FROM vfile WHERE pathname=%Q", | |
| 769 | + blob_str(&fname), zCollate); | |
| 770 | + }else{ | |
| 771 | + fossil_warning("not found: %s", g.argv[ii]); | |
| 772 | + result = 1; | |
| 773 | + continue; | |
| 774 | + } | |
| 775 | + while( db_step(&q)==SQLITE_ROW ){ | |
| 776 | + cnt++; | |
| 777 | + bag_insert(&toCommit, db_column_int(&q, 0)); | |
| 778 | + } | |
| 779 | + db_finalize(&q); | |
| 780 | + if( cnt==0 ){ | |
| 751 | 781 | fossil_warning("fossil knows nothing about: %s", g.argv[ii]); |
| 752 | 782 | result = 1; |
| 753 | - }else{ | |
| 754 | - g.aCommitFile[jj++] = iId; | |
| 755 | 783 | } |
| 756 | - blob_reset(&b); | |
| 784 | + blob_reset(&fname); | |
| 785 | + } | |
| 786 | + g.aCommitFile = fossil_malloc( (bag_count(&toCommit)+1) * sizeof(g.aCommitFile[0]) ); | |
| 787 | + for(ii=bag_first(&toCommit); ii>0; ii=bag_next(&toCommit, ii)){ | |
| 788 | + g.aCommitFile[jj++] = ii; | |
| 757 | 789 | } |
| 758 | 790 | g.aCommitFile[jj] = 0; |
| 791 | + bag_clear(&toCommit); | |
| 759 | 792 | } |
| 760 | 793 | return result; |
| 761 | 794 | } |
| 762 | 795 | |
| 763 | 796 | /* |
| 764 | 797 |
| --- src/checkin.c | |
| +++ src/checkin.c | |
| @@ -45,10 +45,11 @@ | |
| 45 | const char *zTreeName; |
| 46 | int i, nRoot; |
| 47 | |
| 48 | blob_zero(&where); |
| 49 | nRoot = (int)strlen(g.zLocalRoot); |
| 50 | for(i=2; i<g.argc; i++) { |
| 51 | Blob fname; |
| 52 | file_canonical_name(g.argv[i], &fname, 0); |
| 53 | zTreeName = blob_str(&fname)+nRoot; |
| 54 | blob_appendf(&where, " %s (pathname=%Q %s) " |
| @@ -112,10 +113,12 @@ | |
| 112 | }else{ |
| 113 | blob_appendf(report, "EDITED %s\n", zDisplayName); |
| 114 | } |
| 115 | }else if( isRenamed ){ |
| 116 | blob_appendf(report, "RENAMED %s\n", zDisplayName); |
| 117 | } |
| 118 | free(zFullName); |
| 119 | } |
| 120 | blob_reset(&rewrittenPathname); |
| 121 | db_finalize(&q); |
| @@ -734,30 +737,60 @@ | |
| 734 | ** |
| 735 | ** Returns 1 if there was a warning, 0 otherwise. |
| 736 | */ |
| 737 | int select_commit_files(void){ |
| 738 | int result = 0; |
| 739 | if( g.argc>2 ){ |
| 740 | int ii, jj=0; |
| 741 | Blob b; |
| 742 | blob_zero(&b); |
| 743 | g.aCommitFile = fossil_malloc(sizeof(int)*(g.argc-1)); |
| 744 | |
| 745 | for(ii=2; ii<g.argc; ii++){ |
| 746 | int iId; |
| 747 | file_tree_name(g.argv[ii], &b, 1); |
| 748 | iId = db_int(-1, "SELECT id FROM vfile WHERE pathname=%Q %s", |
| 749 | blob_str(&b), filename_collation() ); |
| 750 | if( iId<0 ){ |
| 751 | fossil_warning("fossil knows nothing about: %s", g.argv[ii]); |
| 752 | result = 1; |
| 753 | }else{ |
| 754 | g.aCommitFile[jj++] = iId; |
| 755 | } |
| 756 | blob_reset(&b); |
| 757 | } |
| 758 | g.aCommitFile[jj] = 0; |
| 759 | } |
| 760 | return result; |
| 761 | } |
| 762 | |
| 763 | /* |
| 764 |
| --- src/checkin.c | |
| +++ src/checkin.c | |
| @@ -45,10 +45,11 @@ | |
| 45 | const char *zTreeName; |
| 46 | int i, nRoot; |
| 47 | |
| 48 | blob_zero(&where); |
| 49 | nRoot = (int)strlen(g.zLocalRoot); |
| 50 | blob_zero(&where); |
| 51 | for(i=2; i<g.argc; i++) { |
| 52 | Blob fname; |
| 53 | file_canonical_name(g.argv[i], &fname, 0); |
| 54 | zTreeName = blob_str(&fname)+nRoot; |
| 55 | blob_appendf(&where, " %s (pathname=%Q %s) " |
| @@ -112,10 +113,12 @@ | |
| 113 | }else{ |
| 114 | blob_appendf(report, "EDITED %s\n", zDisplayName); |
| 115 | } |
| 116 | }else if( isRenamed ){ |
| 117 | blob_appendf(report, "RENAMED %s\n", zDisplayName); |
| 118 | }else{ |
| 119 | report->nUsed -= nPrefix; |
| 120 | } |
| 121 | free(zFullName); |
| 122 | } |
| 123 | blob_reset(&rewrittenPathname); |
| 124 | db_finalize(&q); |
| @@ -734,30 +737,60 @@ | |
| 737 | ** |
| 738 | ** Returns 1 if there was a warning, 0 otherwise. |
| 739 | */ |
| 740 | int select_commit_files(void){ |
| 741 | int result = 0; |
| 742 | assert( g.aCommitFile==0 ); |
| 743 | if( g.argc>2 ){ |
| 744 | int ii, jj=0; |
| 745 | Blob fname; |
| 746 | int isDir; |
| 747 | Stmt q; |
| 748 | const char *zCollate; |
| 749 | Bag toCommit; |
| 750 | |
| 751 | zCollate = filename_collation(); |
| 752 | blob_zero(&fname); |
| 753 | bag_init(&toCommit); |
| 754 | for(ii=2; ii<g.argc; ii++){ |
| 755 | int cnt = 0; |
| 756 | file_tree_name(g.argv[ii], &fname, 1); |
| 757 | if( fossil_strcmp(blob_str(&fname),".")==0 ){ |
| 758 | bag_clear(&toCommit); |
| 759 | return result; |
| 760 | } |
| 761 | isDir = file_isdir(g.argv[ii]); |
| 762 | if( isDir==1 ){ |
| 763 | db_prepare(&q, |
| 764 | "SELECT id FROM vfile WHERE pathname>'%q/' %s AND pathname<'%q0'", |
| 765 | blob_str(&fname), zCollate, blob_str(&fname), zCollate); |
| 766 | }else if( isDir==2 ){ |
| 767 | db_prepare(&q, |
| 768 | "SELECT id FROM vfile WHERE pathname=%Q", |
| 769 | blob_str(&fname), zCollate); |
| 770 | }else{ |
| 771 | fossil_warning("not found: %s", g.argv[ii]); |
| 772 | result = 1; |
| 773 | continue; |
| 774 | } |
| 775 | while( db_step(&q)==SQLITE_ROW ){ |
| 776 | cnt++; |
| 777 | bag_insert(&toCommit, db_column_int(&q, 0)); |
| 778 | } |
| 779 | db_finalize(&q); |
| 780 | if( cnt==0 ){ |
| 781 | fossil_warning("fossil knows nothing about: %s", g.argv[ii]); |
| 782 | result = 1; |
| 783 | } |
| 784 | blob_reset(&fname); |
| 785 | } |
| 786 | g.aCommitFile = fossil_malloc( (bag_count(&toCommit)+1) * sizeof(g.aCommitFile[0]) ); |
| 787 | for(ii=bag_first(&toCommit); ii>0; ii=bag_next(&toCommit, ii)){ |
| 788 | g.aCommitFile[jj++] = ii; |
| 789 | } |
| 790 | g.aCommitFile[jj] = 0; |
| 791 | bag_clear(&toCommit); |
| 792 | } |
| 793 | return result; |
| 794 | } |
| 795 | |
| 796 | /* |
| 797 |