Fossil

Check-in [be3d2154]
Login

Many hyperlinks are disabled.
Use anonymous login to enable hyperlinks.

Overview
Comment:Add the --ignore option to the "add" command and have "add" honor the "ignore-glob" setting. Ticket [f270321c0f74b354f05]
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA1:be3d2154da66a4cc3d1937f44f3a551efd26ca0c
User & Date: drh 2011-01-05 18:41:18
Context
2011-01-07
16:20
Record fractional seconds for artifact times. check-in: 722d7cac user: drh tags: trunk
2011-01-05
18:55
Experimental change to try to make "export" run faster for massive repositories. Closed-Leaf check-in: c9a903c2 user: drh tags: experimental
18:41
Add the --ignore option to the "add" command and have "add" honor the "ignore-glob" setting. Ticket [f270321c0f74b354f05] check-in: be3d2154 user: drh tags: trunk
13:36
Provide a much larger palette of predefind background colors on the Checkin-Edit screen. check-in: ddf5f367 user: drh tags: trunk
Changes
Hide Diffs Unified Diffs Ignore Whitespace Patch

Changes to src/add.c.

85
86
87
88
89
90
91























92


93
94




95
96
97
98
99
100
101
...
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
...
148
149
150
151
152
153
154


155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
...
186
187
188
189
190
191
192



193
194
195
196

197


198

199
200



201
202
203
204
205
206
207
...
209
210
211
212
213
214
215






216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232

233
234
235
236
237
238
239
    zAll = blob_str(&x);
  }
  return zAll;
}


/*























** Add a single file


*/
static void add_one_file(const char *zName, int vid, Blob *pOmit){




  Blob pathname;
  const char *zPath;
  int i;
  const char *zReserved;

  file_tree_name(zName, &pathname, 1);
  zPath = blob_str(&pathname);
................................................................................
  }
  blob_reset(&pathname);
}

/*
** All content of the zDir directory to the SFILE table.
*/
void add_directory_content(const char *zDir){
  DIR *d;
  int origSize;
  struct dirent *pEntry;
  Blob path;

  blob_zero(&path);
  blob_append(&path, zDir, -1);
................................................................................
      if( pEntry->d_name[0]=='.' ){
        if( !includeDotFiles ) continue;
        if( pEntry->d_name[1]==0 ) continue;
        if( pEntry->d_name[1]=='.' && pEntry->d_name[2]==0 ) continue;
      }
      blob_appendf(&path, "/%s", pEntry->d_name);
      zPath = blob_str(&path);


      if( file_isdir(zPath)==1 ){
        add_directory_content(zPath);
      }else if( file_isfile(zPath) ){
        db_multi_exec("INSERT INTO sfile VALUES(%Q)", zPath);
      }
      blob_resize(&path, origSize);
    }
  }
  closedir(d);
  blob_reset(&path);
}

/*
** Add all content of a directory.
*/
void add_directory(const char *zDir, int vid, Blob *pOmit){
  Stmt q;
  add_directory_content(zDir);
  db_prepare(&q, "SELECT x FROM sfile ORDER BY x");
  while( db_step(&q)==SQLITE_ROW ){
    const char *zName = db_column_text(&q, 0);
    add_one_file(zName, vid, pOmit);
  }
  db_finalize(&q);
  db_multi_exec("DELETE FROM sfile");
................................................................................
**
** Make arrangements to add one or more files to the current checkout
** at the next commit.
**
** When adding files recursively, filenames that begin with "." are
** excluded by default.  To include such files, add the "--dotfiles"
** option to the command-line.



*/
void add_cmd(void){
  int i;
  int vid;

  Blob repo;




  includeDotFiles = find_option("dotfiles",0,0)!=0;
  db_must_be_within_tree();



  vid = db_lget_int("checkout",0);
  if( vid==0 ){
    fossil_panic("no checkout to add to");
  }
  db_begin_transaction();
  if( !file_tree_name(g.zRepositoryName, &repo, 0) ){
    blob_zero(&repo);
................................................................................
  db_multi_exec("CREATE TEMP TABLE sfile(x TEXT PRIMARY KEY)");
#if defined(_WIN32)
  db_multi_exec(
     "CREATE INDEX IF NOT EXISTS vfile_pathname "
     "  ON vfile(pathname COLLATE nocase)"
  );
#endif






  for(i=2; i<g.argc; i++){
    char *zName;
    int isDir;

    zName = mprintf("%/", g.argv[i]);
    isDir = file_isdir(zName);
    if( isDir==1 ){
      add_directory(zName, vid, &repo);
    }else if( isDir==0 ){
      fossil_fatal("not found: %s", zName);
    }else if( access(zName, R_OK) ){
      fossil_fatal("cannot open %s", zName);
    }else{
      add_one_file(zName, vid, &repo);
    }
    free(zName);
  }

  db_end_transaction(0);
}

/*
** Remove all contents of zDir
*/
void del_directory_content(const char *zDir){







>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
|
>
>

|
>
>
>
>







 







|







 







>
>
|
|













|

|







 







>
>
>




>

>
>

>


>
>
>







 







>
>
>
>
>
>







|









>







85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
...
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
...
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
...
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
...
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
    zAll = blob_str(&x);
  }
  return zAll;
}


/*
** The pIgnore statement is query of the form:
**
**      SELECT (:x GLOB ... OR :x GLOB ... OR ...)
**
** In other words, it is a query that returns true if the :x value
** should be ignored.  Evaluate the query and return true to ignore
** and false to not ignore.
**
** If pIgnore is NULL, then do not ignore.
*/
static int shouldBeIgnored(Stmt *pIgnore, const char *zName){
  int rc = 0;
  if( pIgnore ){
    db_bind_text(pIgnore, ":x", zName);
    db_step(pIgnore);
    rc = db_column_int(pIgnore, 0);
    db_reset(pIgnore);
  }
  return rc;
}


/*
** Add a single file named zName to the VFILE table with vid.
**
** Omit any file whose name is pOmit.
*/
static void add_one_file(
  const char *zName,   /* Name of file to add */
  int vid,             /* Add to this VFILE */
  Blob *pOmit
){
  Blob pathname;
  const char *zPath;
  int i;
  const char *zReserved;

  file_tree_name(zName, &pathname, 1);
  zPath = blob_str(&pathname);
................................................................................
  }
  blob_reset(&pathname);
}

/*
** All content of the zDir directory to the SFILE table.
*/
void add_directory_content(const char *zDir, Stmt *pIgnore){
  DIR *d;
  int origSize;
  struct dirent *pEntry;
  Blob path;

  blob_zero(&path);
  blob_append(&path, zDir, -1);
................................................................................
      if( pEntry->d_name[0]=='.' ){
        if( !includeDotFiles ) continue;
        if( pEntry->d_name[1]==0 ) continue;
        if( pEntry->d_name[1]=='.' && pEntry->d_name[2]==0 ) continue;
      }
      blob_appendf(&path, "/%s", pEntry->d_name);
      zPath = blob_str(&path);
      if( shouldBeIgnored(pIgnore, zPath) ){
        /* Noop */
      }else if( file_isdir(zPath)==1 ){
        add_directory_content(zPath, pIgnore);
      }else if( file_isfile(zPath) ){
        db_multi_exec("INSERT INTO sfile VALUES(%Q)", zPath);
      }
      blob_resize(&path, origSize);
    }
  }
  closedir(d);
  blob_reset(&path);
}

/*
** Add all content of a directory.
*/
void add_directory(const char *zDir, int vid, Blob *pOmit, Stmt *pIgnore){
  Stmt q;
  add_directory_content(zDir, pIgnore);
  db_prepare(&q, "SELECT x FROM sfile ORDER BY x");
  while( db_step(&q)==SQLITE_ROW ){
    const char *zName = db_column_text(&q, 0);
    add_one_file(zName, vid, pOmit);
  }
  db_finalize(&q);
  db_multi_exec("DELETE FROM sfile");
................................................................................
**
** Make arrangements to add one or more files to the current checkout
** at the next commit.
**
** When adding files recursively, filenames that begin with "." are
** excluded by default.  To include such files, add the "--dotfiles"
** option to the command-line.
**
** The --ignore option overrides the "ignore-glob" setting.  See
** documentation on the "setting" command for further information.
*/
void add_cmd(void){
  int i;
  int vid;
  const char *zIgnoreFlag;
  Blob repo;
  Stmt ignoreTest;     /* Test to see if a name should be ignored */
  Stmt *pIgnore;       /* Pointer to ignoreTest or to NULL */

  zIgnoreFlag = find_option("ignore",0,1);
  includeDotFiles = find_option("dotfiles",0,0)!=0;
  db_must_be_within_tree();
  if( zIgnoreFlag==0 ){
    zIgnoreFlag = db_get("ignore-glob", 0);
  }
  vid = db_lget_int("checkout",0);
  if( vid==0 ){
    fossil_panic("no checkout to add to");
  }
  db_begin_transaction();
  if( !file_tree_name(g.zRepositoryName, &repo, 0) ){
    blob_zero(&repo);
................................................................................
  db_multi_exec("CREATE TEMP TABLE sfile(x TEXT PRIMARY KEY)");
#if defined(_WIN32)
  db_multi_exec(
     "CREATE INDEX IF NOT EXISTS vfile_pathname "
     "  ON vfile(pathname COLLATE nocase)"
  );
#endif
  if( zIgnoreFlag && zIgnoreFlag[0] ){
    db_prepare(&ignoreTest, "SELECT %s", glob_expr(":x", zIgnoreFlag));
    pIgnore = &ignoreTest;
  }else{
    pIgnore = 0;
  }
  for(i=2; i<g.argc; i++){
    char *zName;
    int isDir;

    zName = mprintf("%/", g.argv[i]);
    isDir = file_isdir(zName);
    if( isDir==1 ){
      add_directory(zName, vid, &repo, pIgnore);
    }else if( isDir==0 ){
      fossil_fatal("not found: %s", zName);
    }else if( access(zName, R_OK) ){
      fossil_fatal("cannot open %s", zName);
    }else{
      add_one_file(zName, vid, &repo);
    }
    free(zName);
  }
  if( pIgnore ) db_finalize(pIgnore);
  db_end_transaction(0);
}

/*
** Remove all contents of zDir
*/
void del_directory_content(const char *zDir){