Fossil

Check-in [a3471a5e]
Login

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

Overview
Comment:The mirror command is now able to export all of Fossil itself, though tags are still not exported.
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | mirror-cmd
Files: files | file ages | folders
SHA3-256:a3471a5eef0b4764e316f15d478d990d0b176956e68857db03a94d999b398413
User & Date: drh 2019-03-14 20:16:09
Context
2019-03-15
11:48
Render any phantom or shunned artifacts as an empty file. check-in: 2487f505 user: drh tags: mirror-cmd
2019-03-14
20:16
The mirror command is now able to export all of Fossil itself, though tags are still not exported. check-in: a3471a5e user: drh tags: mirror-cmd
19:43
Fix the export so that it is able to handle phantom check-ins. check-in: 4a480954 user: drh tags: mirror-cmd
Changes
Hide Diffs Unified Diffs Ignore Whitespace Patch

Changes to src/export.c.

865
866
867
868
869
870
871







































872
873
874
875
876
877
878
...
946
947
948
949
950
951
952
953
954
955

956
957
958


959
960
961
962
963
964
965
....
1010
1011
1012
1013
1014
1015
1016
1017
1018

1019
1020
1021
1022
1023
1024
1025
....
1055
1056
1057
1058
1059
1060
1061

1062
1063
1064
1065

1066

1067
1068
1069
1070
1071
1072
1073
      zu[i] = '_';
    }else if( zu[i]=='.' && (zu[i+1]==0 || zu[i+1]=='.'
                             || (i>0 && zu[i-1]=='.')) ){
      zu[i] = '_';
    }
  }
}








































/*
** Transfer a tag over to the mirror.  "rid" is the BLOB.RID value for
** the record that describes the tag.
**
** The Git tag mechanism is very limited compared to Fossil.  Many Fossil
** tags cannot be exported to Git.  If this tag cannot be exported, then
................................................................................
*/
static void mirror_send_checkin(
  FILE *xCmd,           /* Write fast-import text on this pipe */
  int rid,              /* BLOB.RID for the check-in to export */
  const char *zUuid,    /* BLOB.UUID for the check-in to export */
  int *pnLimit          /* Stop when the counter reaches zero */
){
  Manifest *pMan;
  int i, iParent;
  Stmt q;

  char *zBranch;
  int iMark;
  Blob sql;



  pMan = manifest_get(rid, CFTYPE_MANIFEST, 0);
  if( pMan==0 ){
    /* Must be a phantom.  Return without doing anything, and in particular
    ** without creating a mark for this check-in. */
    return;
  }
................................................................................
  fossil_free(zBranch);
  iMark = mirror_find_mark(zUuid, 1);
  fprintf(xCmd, "mark :%d\n", iMark);
  fprintf(xCmd, "committer %s <%s@noemail.net> %lld +0000\n",
     pMan->zUser, pMan->zUser, 
     (sqlite3_int64)((pMan->rDate-2440587.5)*86400.0)
  );
  fprintf(xCmd, "data %d\n", (int)strlen(pMan->zComment));
  fprintf(xCmd, "%s\n", pMan->zComment);

  iParent = -1;  /* Which ancestor is the primary parent */
  for(i=0; i<pMan->nParent; i++){
    int iOther = mirror_find_mark(pMan->azParent[i], 0);
    if( iOther==0 ) continue;
    if( iParent<0 ){
      iParent = i;
      fprintf(xCmd, "from :%d\n", iOther);
................................................................................
  );
  blob_reset(&sql);
  while( db_step(&q)==SQLITE_ROW ){
    const char *zFilename = db_column_text(&q,0);
    const char *zMode = db_column_text(&q,1);
    int iMark = db_column_int(&q,2);
    const char *zGitMode = "100644";

    if( zMode ){
      if( strchr(zMode,'x') ) zGitMode = "100755";
      if( strchr(zMode,'l') ) zGitMode = "120000";
    }

    fprintf(xCmd,"M %s :%d %s\n", zGitMode, iMark, zFilename);

  }
  db_finalize(&q);

  /* The check-in is finished, so decrement the counter */
  (*pnLimit)--;
}








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







 







|
|
|
>
|
<
|
>
>







 







|
|
>







 







>




>
|
>







865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
...
985
986
987
988
989
990
991
992
993
994
995
996

997
998
999
1000
1001
1002
1003
1004
1005
1006
....
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
....
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
      zu[i] = '_';
    }else if( zu[i]=='.' && (zu[i+1]==0 || zu[i+1]=='.'
                             || (i>0 && zu[i-1]=='.')) ){
      zu[i] = '_';
    }
  }
}

/*
** Quote a filename as a C-style string using \\ and \" if necessary.
** If quoting is not necessary, just return a copy of the input string.
**
** The return value is a held in memory obtained from fossil_malloc()
** and must be freed by the caller.
*/
static char *mirror_quote_filename_if_needed(const char *zIn){
  int i, j;
  char c;
  int nSpecial = 0;
  char *zOut;
  for(i=0; (c = zIn[i])!=0; i++){
    if( c=='\\' || c=='"' || c=='\n' ){
      nSpecial++;
    }
  }
  if( nSpecial==0 ){
    return fossil_strdup(zIn);
  }
  zOut = fossil_malloc( i+nSpecial+3 );
  zOut[0] = '"';
  for(i=0, j=1; (c = zIn[i])!=0; i++){
    if( c=='\\' || c=='"' || c=='\n' ){
      zOut[j++] = '\\';
      if( c=='\n' ){
        zOut[j++] = 'n';
      }else{
        zOut[j++] = c;
      }
    }else{
      zOut[j++] = c;
    }
  }
  zOut[j++] = '"';
  zOut[j] = 0;
  return zOut;
}

/*
** Transfer a tag over to the mirror.  "rid" is the BLOB.RID value for
** the record that describes the tag.
**
** The Git tag mechanism is very limited compared to Fossil.  Many Fossil
** tags cannot be exported to Git.  If this tag cannot be exported, then
................................................................................
*/
static void mirror_send_checkin(
  FILE *xCmd,           /* Write fast-import text on this pipe */
  int rid,              /* BLOB.RID for the check-in to export */
  const char *zUuid,    /* BLOB.UUID for the check-in to export */
  int *pnLimit          /* Stop when the counter reaches zero */
){
  Manifest *pMan;       /* The check-in to be output */
  int i;                /* Loop counter */
  int iParent;          /* Which immediate ancestor is primary.  -1 for none */
  Stmt q;               /* An SQL query */
  char *zBranch;        /* The branch of the check-in */

  int iMark;            /* The mark for the check-in */
  Blob sql;             /* String of SQL for part of the query */
  char *zCom;           /* The check-in comment */

  pMan = manifest_get(rid, CFTYPE_MANIFEST, 0);
  if( pMan==0 ){
    /* Must be a phantom.  Return without doing anything, and in particular
    ** without creating a mark for this check-in. */
    return;
  }
................................................................................
  fossil_free(zBranch);
  iMark = mirror_find_mark(zUuid, 1);
  fprintf(xCmd, "mark :%d\n", iMark);
  fprintf(xCmd, "committer %s <%s@noemail.net> %lld +0000\n",
     pMan->zUser, pMan->zUser, 
     (sqlite3_int64)((pMan->rDate-2440587.5)*86400.0)
  );
  zCom = pMan->zComment;
  if( zCom==0 ) zCom = "(no comment)";
  fprintf(xCmd, "data %d\n%s\n", (int)strlen(zCom), zCom);
  iParent = -1;  /* Which ancestor is the primary parent */
  for(i=0; i<pMan->nParent; i++){
    int iOther = mirror_find_mark(pMan->azParent[i], 0);
    if( iOther==0 ) continue;
    if( iParent<0 ){
      iParent = i;
      fprintf(xCmd, "from :%d\n", iOther);
................................................................................
  );
  blob_reset(&sql);
  while( db_step(&q)==SQLITE_ROW ){
    const char *zFilename = db_column_text(&q,0);
    const char *zMode = db_column_text(&q,1);
    int iMark = db_column_int(&q,2);
    const char *zGitMode = "100644";
    char *zFNQuoted = 0;
    if( zMode ){
      if( strchr(zMode,'x') ) zGitMode = "100755";
      if( strchr(zMode,'l') ) zGitMode = "120000";
    }
    zFNQuoted = mirror_quote_filename_if_needed(zFilename);
    fprintf(xCmd,"M %s :%d %s\n", zGitMode, iMark, zFNQuoted);
    fossil_free(zFNQuoted);
  }
  db_finalize(&q);

  /* The check-in is finished, so decrement the counter */
  (*pnLimit)--;
}