Fossil

Check-in [8c4e72e223]
Login

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

Overview
Comment:Enhance the "fossil add" command so that when a directory is named, all contents of that directory are added recursively. Ticket [e02ffabcdaaaf606099ac09227833ba282fdaace]
Downloads: Tarball | ZIP archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA1: 8c4e72e22320d3de04ffcd9fe63b63b98d946db8
User & Date: drh 2008-12-07 18:11:09.000
References
2008-12-07
18:13 Ticket [04a259be40] operations upon all files status still Open with 1 other change ... (artifact: c885a96353 user: drh)
18:12 Fixed ticket [e02ffabcda]: recursive add plus 2 other changes ... (artifact: 274dabb8aa user: drh)
Context
2008-12-07
18:48
The server now issues error messages in the synchronization protocol when a database error occurs during sync. Ticket [39f3294e213111a51e93d02fef6faa0062979619] ... (check-in: 2be82dcc2a user: drh tags: trunk)
18:11
Enhance the "fossil add" command so that when a directory is named, all contents of that directory are added recursively. Ticket [e02ffabcdaaaf606099ac09227833ba282fdaace] ... (check-in: 8c4e72e223 user: drh tags: trunk)
2008-12-06
18:02
Add the ability to detect file changes using only the mtime. This is turned on using the "fossil setting mtime-changes ON" command. It is off by default, but it does make many operations go much faster, especially on large repositories, so we might want to start turning it on by default. ... (check-in: 2dffce041d user: drh tags: trunk)
Changes
Unified Diff Ignore Whitespace Patch
Changes to src/add.c.
23
24
25
26
27
28
29

30













































































31
32
33
34
35
36
37
**
** This file contains code used to check-out versions of the project
** from the local repository.
*/
#include "config.h"
#include "add.h"
#include <assert.h>
















































































/*
** COMMAND: add
**
** Usage: %fossil add FILE...
**
** Make arrangements to add one or more files to the current checkout 







>

>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>







23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
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
**
** This file contains code used to check-out versions of the project
** from the local repository.
*/
#include "config.h"
#include "add.h"
#include <assert.h>
#include <dirent.h>

    
/*
** Add a single file
*/
static void add_one_file(const char *zName, int vid, Blob *pOmit){
  Blob pathname;
  const char *zPath;
      
  file_tree_name(zName, &pathname, 1);
  zPath = blob_str(&pathname);
  if( strcmp(zPath, "manifest")==0
   || strcmp(zPath, "_FOSSIL_")==0
   || strcmp(zPath, "manifest.uuid")==0
   || blob_compare(&pathname, pOmit)==0
  ){
    fossil_warning("cannot add %s", zPath);
  }else{
    if( !file_is_simple_pathname(zPath) ){
      fossil_fatal("filename contains illegal characters: %s", zPath);
    }
    if( db_exists("SELECT 1 FROM vfile WHERE pathname=%Q", zPath) ){
      db_multi_exec("UPDATE vfile SET deleted=0 WHERE pathname=%Q", zPath);
    }else{
      db_multi_exec(
        "INSERT INTO vfile(vid,deleted,rid,mrid,pathname)"
        "VALUES(%d,0,0,0,%Q)", vid, zPath);
    }
    printf("ADDED  %s\n", zPath);
  }
  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);
  origSize = blob_size(&path);
  d = opendir(zDir);
  if( d ){
    while( (pEntry=readdir(d))!=0 ){
      char *zPath;
      if( pEntry->d_name[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");
}

/*
** COMMAND: add
**
** Usage: %fossil add FILE...
**
** Make arrangements to add one or more files to the current checkout 
47
48
49
50
51
52
53

54
55
56
57
58
59
60
61
62

63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
  if( vid==0 ){
    fossil_panic("no checkout to add to");
  }
  db_begin_transaction();
  if( !file_tree_name(g.zRepositoryName, &repo, 0) ){
    blob_zero(&repo);
  }

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

    zName = mprintf("%/", g.argv[i]);
    isDir = file_isdir(zName);
    if( isDir==1 ) continue;

    if( isDir==0 ){
      fossil_fatal("not found: %s", zName);
    }
    if( isDir==2 && access(zName, R_OK) ){
      fossil_fatal("cannot open %s", zName);
    }
    file_tree_name(zName, &pathname, 1);
    zPath = blob_str(&pathname);
    if( strcmp(zPath, "manifest")==0
     || strcmp(zPath, "_FOSSIL_")==0
     || strcmp(zPath, "manifest.uuid")==0
     || blob_compare(&pathname, &repo)==0
    ){
      fossil_warning("cannot add %s", zPath);
    }else{
      if( !file_is_simple_pathname(zPath) ){
        fossil_fatal("filename contains illegal characters: %s", zPath);
      }
      if( db_exists("SELECT 1 FROM vfile WHERE pathname=%Q", zPath) ){
        db_multi_exec("UPDATE vfile SET deleted=0 WHERE pathname=%Q", zPath);
      }else{
        db_multi_exec(
          "INSERT INTO vfile(vid,deleted,rid,mrid,pathname)"
          "VALUES(%d,0,0,0,%Q)", vid, zPath);
      }
    }
    blob_reset(&pathname);
    free(zName);
  }
  db_end_transaction(0);
}

/*
** COMMAND: rm







>


<
<




|
>
|

<
|

<
<
<
<
<
<
<
<
<

<
<
<
<
<
<
<
<
|
|
<
<







125
126
127
128
129
130
131
132
133
134


135
136
137
138
139
140
141
142

143
144









145








146
147


148
149
150
151
152
153
154
  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)");
  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);
}

/*
** COMMAND: rm