Fossil SCM

Allow the "fossil commit" command to accept directories as command-line arguments and commit all files contained underneath those directories.

drh 2013-06-21 15:19 trunk
Commit c8253f4066cbc562b835419ba6b1b0928d88373a
1 file changed +44 -11
+44 -11
--- src/checkin.c
+++ src/checkin.c
@@ -45,10 +45,11 @@
4545
const char *zTreeName;
4646
int i, nRoot;
4747
4848
blob_zero(&where);
4949
nRoot = (int)strlen(g.zLocalRoot);
50
+ blob_zero(&where);
5051
for(i=2; i<g.argc; i++) {
5152
Blob fname;
5253
file_canonical_name(g.argv[i], &fname, 0);
5354
zTreeName = blob_str(&fname)+nRoot;
5455
blob_appendf(&where, " %s (pathname=%Q %s) "
@@ -112,10 +113,12 @@
112113
}else{
113114
blob_appendf(report, "EDITED %s\n", zDisplayName);
114115
}
115116
}else if( isRenamed ){
116117
blob_appendf(report, "RENAMED %s\n", zDisplayName);
118
+ }else{
119
+ report->nUsed -= nPrefix;
117120
}
118121
free(zFullName);
119122
}
120123
blob_reset(&rewrittenPathname);
121124
db_finalize(&q);
@@ -734,30 +737,60 @@
734737
**
735738
** Returns 1 if there was a warning, 0 otherwise.
736739
*/
737740
int select_commit_files(void){
738741
int result = 0;
742
+ assert( g.aCommitFile==0 );
739743
if( g.argc>2 ){
740744
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;
744750
751
+ zCollate = filename_collation();
752
+ blob_zero(&fname);
753
+ bag_init(&toCommit);
745754
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 ){
751781
fossil_warning("fossil knows nothing about: %s", g.argv[ii]);
752782
result = 1;
753
- }else{
754
- g.aCommitFile[jj++] = iId;
755783
}
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;
757789
}
758790
g.aCommitFile[jj] = 0;
791
+ bag_clear(&toCommit);
759792
}
760793
return result;
761794
}
762795
763796
/*
764797
--- 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

Keyboard Shortcuts

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