Fossil

Check-in [8d8e529a]
Login

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

Overview
Comment:An attempt to factor out the opendir() family of routines and provide portable alternatives, fossil_opendir(). This simplistic first attempt works on non-windows platforms, but the build fails on windows.
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | msvc-broken
Files: files | file ages | folders
SHA1: 8d8e529aa9a6295ee138cf510b94b4878aacb0e1
User & Date: drh 2012-08-29 16:51:45
Context
2012-08-29
20:27
make it link on msvc. Doesn't run yet. check-in: bd43f1c2 user: jan.nijtmans tags: msvc-broken
16:51
An attempt to factor out the opendir() family of routines and provide portable alternatives, fossil_opendir(). This simplistic first attempt works on non-windows platforms, but the build fails on windows. check-in: 8d8e529a user: drh tags: msvc-broken
13:57
Allow UTF-8 characters in sources. translate.exe will translate it to ASCII check-in: 9f6abc59 user: jan.nijtmans tags: msvc-broken
Changes
Hide Diffs Unified Diffs Ignore Whitespace Patch

Changes to src/file.c.

1000
1001
1002
1003
1004
1005
1006
























1007
1008
1009
1010
1011
1012
1013
  }else{
    blob_read_from_file(&onDisk, zName);
  }
  rc = blob_compare(&onDisk, pContent);
  blob_reset(&onDisk);
  return rc==0;
}


























/**************************************************************************
** The following routines translate between MBCS and UTF8 on windows.
** Since everything is always UTF8 on unix, these routines are no-ops
** there.
*/







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







1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
  }else{
    blob_read_from_file(&onDisk, zName);
  }
  rc = blob_compare(&onDisk, pContent);
  blob_reset(&onDisk);
  return rc==0;
}

/*
** Portable unicode implementation of opendir()
*/
#if INTERFACE

#if defined(_WIN32)
# include <wdirent.h>
# define FOSSIL_DIR WDIR
# define fossil_dirent wdirent
# define fossil_opendir wopendir
# define fossil_readdir wreaddir
# define fossil_closedir wclosedir
#else
# include <dirent.h>
# define FOSSIL_DIR DIR
# define fossil_dirent dirent
# define fossil_opendir opendir
# define fossil_readdir readdir
# define fossil_closedir closedir
#endif

#endif /* INTERFACE */



/**************************************************************************
** The following routines translate between MBCS and UTF8 on windows.
** Since everything is always UTF8 on unix, these routines are no-ops
** there.
*/

Changes to src/rebuild.c.

16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
...
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
...
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
*******************************************************************************
**
** This file contains code used to rebuild the database.
*/
#include "config.h"
#include "rebuild.h"
#include <assert.h>
#include <dirent.h>
#include <errno.h>

#ifndef _WIN32
#define _WDIR DIR
#define _wdirent dirent
#define _wopendir opendir
#define _wreaddir readdir
#define _wclosedir closedir
#define wchar_t char
#endif

/*
** Make changes to the stable part of the schema (the part that is not
** simply deleted and reconstructed on a rebuild) to bring the schema
** up to the latest.
*/
static const char zSchemaUpdates1[] =
@ -- Index on the delta table
................................................................................
}

/*
** Recursively read all files from the directory zPath and install
** every file read as a new artifact in the repository.
*/
void recon_read_dir(char *zPath){
  _WDIR *d;
  struct _wdirent *pEntry;
  Blob aContent; /* content of the just read artifact */
  static int nFileRead = 0;
  wchar_t *zMbcsPath;
  char *zUtf8Name;

  zMbcsPath = fossil_utf8_to_unicode(zPath);
  d = _wopendir(zMbcsPath);
  if( d ){
    while( (pEntry=_wreaddir(d))!=0 ){
      Blob path;
      char *zSubpath;

      if( pEntry->d_name[0]=='.' ){
        continue;
      }
      zUtf8Name = fossil_unicode_to_utf8(pEntry->d_name);
................................................................................
      content_put(&aContent);
      blob_reset(&path);
      blob_reset(&aContent);
      free(zSubpath);
      fossil_print("\r%d", ++nFileRead);
      fflush(stdout);
    }
    _wclosedir(d);
  }else {
    fossil_panic("encountered error %d while trying to open \"%s\".",
                  errno, g.argv[3]);
  }
  fossil_mbcs_free(zMbcsPath);
}

/*
** COMMAND: reconstruct*
**
** Usage: %fossil reconstruct FILENAME DIRECTORY
**







<


<
<
<
<
<
<
<
<
<







 







|
|


|


|
|

|







 







|




|







16
17
18
19
20
21
22

23
24









25
26
27
28
29
30
31
...
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
...
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
*******************************************************************************
**
** This file contains code used to rebuild the database.
*/
#include "config.h"
#include "rebuild.h"
#include <assert.h>

#include <errno.h>










/*
** Make changes to the stable part of the schema (the part that is not
** simply deleted and reconstructed on a rebuild) to bring the schema
** up to the latest.
*/
static const char zSchemaUpdates1[] =
@ -- Index on the delta table
................................................................................
}

/*
** Recursively read all files from the directory zPath and install
** every file read as a new artifact in the repository.
*/
void recon_read_dir(char *zPath){
  FOSSIL_DIR *d;
  struct fossil_dirent *pEntry;
  Blob aContent; /* content of the just read artifact */
  static int nFileRead = 0;
  void *zUnicodePath;
  char *zUtf8Name;

  zUnicodePath = fossil_utf8_to_unicode(zPath);
  d = fossil_opendir(zUnicodePath);
  if( d ){
    while( (pEntry=fossil_readdir(d))!=0 ){
      Blob path;
      char *zSubpath;

      if( pEntry->d_name[0]=='.' ){
        continue;
      }
      zUtf8Name = fossil_unicode_to_utf8(pEntry->d_name);
................................................................................
      content_put(&aContent);
      blob_reset(&path);
      blob_reset(&aContent);
      free(zSubpath);
      fossil_print("\r%d", ++nFileRead);
      fflush(stdout);
    }
    fossil_closedir(d);
  }else {
    fossil_panic("encountered error %d while trying to open \"%s\".",
                  errno, g.argv[3]);
  }
  fossil_mbcs_free(zUnicodePath);
}

/*
** COMMAND: reconstruct*
**
** Usage: %fossil reconstruct FILENAME DIRECTORY
**

Changes to src/vfile.c.

17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
...
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
...
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
...
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
**
** Procedures for managing the VFILE table.
*/
#include "config.h"
#include "vfile.h"
#include <assert.h>
#include <sys/types.h>
#if defined(__DMC__)
#include "dirent.h"
#else
#include <dirent.h>
#endif

#ifndef _WIN32
#define _WDIR DIR
#define _wdirent dirent
#define _wopendir opendir
#define _wreaddir readdir
#define _wclosedir closedir
#define wchar_t char
#endif

/*
** The input is guaranteed to be a 40-character well-formed UUID.
** Find its rid.
*/
int fast_uuid_to_rid(const char *zUuid){
  static Stmt q;
................................................................................
** Files whose names begin with "." are omitted unless allFlag is true.
**
** Any files or directories that match the glob pattern pIgnore are 
** excluded from the scan.  Name matching occurs after the first
** nPrefix characters are elided from the filename.
*/
void vfile_scan(Blob *pPath, int nPrefix, int allFlag, Glob *pIgnore){
  _WDIR *d;
  int origSize;
  const char *zDir;
  struct _wdirent *pEntry;
  int skipAll = 0;
  static Stmt ins;
  static int depth = 0;
  wchar_t *zMbcs;

  origSize = blob_size(pPath);
  if( pIgnore ){
    blob_appendf(pPath, "/");
    if( glob_match(pIgnore, &blob_str(pPath)[nPrefix+1]) ) skipAll = 1;
    blob_resize(pPath, origSize);
  }
................................................................................
       "  WHERE NOT EXISTS(SELECT 1 FROM vfile WHERE pathname=:file)"
    );
  }
  depth++;

  zDir = blob_str(pPath);
  zMbcs = fossil_utf8_to_unicode(zDir);
  d = _wopendir(zMbcs);
  if( d ){
    while( (pEntry=_wreaddir(d))!=0 ){
      char *zPath;
      char *zUtf8;
      if( pEntry->d_name[0]=='.' ){
        if( !allFlag ) continue;
        if( pEntry->d_name[1]==0 ) continue;
        if( pEntry->d_name[1]=='.' && pEntry->d_name[2]==0 ) continue;
      }
................................................................................
      }else if( file_wd_isfile_or_link(zPath) ){
        db_bind_text(&ins, ":file", &zPath[nPrefix+1]);
        db_step(&ins);
        db_reset(&ins);
      }
      blob_resize(pPath, origSize);
    }
    _wclosedir(d);
  }
  fossil_mbcs_free(zMbcs);

  depth--;
  if( depth==0 ){
    db_finalize(&ins);
  }







<
<
<
<
<
<
<
<
<
<
<
<
<
<







 







|


|



|







 







|

|







 







|







17
18
19
20
21
22
23














24
25
26
27
28
29
30
...
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
...
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
...
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
**
** Procedures for managing the VFILE table.
*/
#include "config.h"
#include "vfile.h"
#include <assert.h>
#include <sys/types.h>















/*
** The input is guaranteed to be a 40-character well-formed UUID.
** Find its rid.
*/
int fast_uuid_to_rid(const char *zUuid){
  static Stmt q;
................................................................................
** Files whose names begin with "." are omitted unless allFlag is true.
**
** Any files or directories that match the glob pattern pIgnore are 
** excluded from the scan.  Name matching occurs after the first
** nPrefix characters are elided from the filename.
*/
void vfile_scan(Blob *pPath, int nPrefix, int allFlag, Glob *pIgnore){
  FOSSIL_DIR *d;
  int origSize;
  const char *zDir;
  struct fossil_dirent *pEntry;
  int skipAll = 0;
  static Stmt ins;
  static int depth = 0;
  void *zMbcs;

  origSize = blob_size(pPath);
  if( pIgnore ){
    blob_appendf(pPath, "/");
    if( glob_match(pIgnore, &blob_str(pPath)[nPrefix+1]) ) skipAll = 1;
    blob_resize(pPath, origSize);
  }
................................................................................
       "  WHERE NOT EXISTS(SELECT 1 FROM vfile WHERE pathname=:file)"
    );
  }
  depth++;

  zDir = blob_str(pPath);
  zMbcs = fossil_utf8_to_unicode(zDir);
  d = fossil_opendir(zMbcs);
  if( d ){
    while( (pEntry=fossil_readdir(d))!=0 ){
      char *zPath;
      char *zUtf8;
      if( pEntry->d_name[0]=='.' ){
        if( !allFlag ) continue;
        if( pEntry->d_name[1]==0 ) continue;
        if( pEntry->d_name[1]=='.' && pEntry->d_name[2]==0 ) continue;
      }
................................................................................
      }else if( file_wd_isfile_or_link(zPath) ){
        db_bind_text(&ins, ":file", &zPath[nPrefix+1]);
        db_step(&ins);
        db_reset(&ins);
      }
      blob_resize(pPath, origSize);
    }
    fossil_closedir(d);
  }
  fossil_mbcs_free(zMbcs);

  depth--;
  if( depth==0 ){
    db_finalize(&ins);
  }