Hello,

I finally came up with something to make import work with:

    git fast-export -M -C ...

Below is the tentative patch that seems to work on my tests.  The good
thing is that even though Fossil does not follows history across
renames, at least now the rename operation is visible and both source
and destination timelines are now linked.  For repositories imported
from git, that is.

Please accept my apologies if I failed to follow the conventions.
Comments and testing will be very welcomed.


Index: src/import.c
==================================================================
--- src/import.c
+++ src/import.c
@@ -107,10 +107,11 @@
   gg.nMerge = 0;
   for(i=0; i<gg.nFile; i++){
     fossil_free(gg.aFile[i].zName);
     fossil_free(gg.aFile[i].zUuid);
     fossil_free(gg.aFile[i].zPrior);
+    gg.aFile[i].zPrior = 0;
   }
   memset(gg.aFile, 0, gg.nFile*sizeof(gg.aFile[0]));
   gg.nFile = 0;
   if( freeAll ){
     fossil_free(gg.zPrevBranch);
@@ -243,17 +244,22 @@
   for(i=0; i<gg.nFile; i++){
     const char *zUuid = gg.aFile[i].zUuid;
     if( zUuid==0 ) continue;
     blob_appendf(&record, "F %F %s", gg.aFile[i].zName, zUuid);
     if( gg.aFile[i].isExe ){
-      blob_append(&record, " x\n", 3);
+      blob_append(&record, " x", 2);
     }else if( gg.aFile[i].isLink ){
-      blob_append(&record, " l\n", 3);
+      blob_append(&record, " l", 2);
       gg.hasLinks = 1;
-    }else{
-      blob_append(&record, "\n", 1);
+    }
+    if( gg.aFile[i].zPrior ){
+      if( !gg.aFile[i].isExe && !gg.aFile[i].isLink ){
+        blob_append(&record, " w", 2);
+      }
+      blob_appendf(&record, " %F", gg.aFile[i].zPrior);
     }
+    blob_append(&record, "\n", 1);
   }
   if( gg.zFrom ){
     blob_appendf(&record, "P %s", gg.zFrom);
     for(i=0; i<gg.nMerge; i++){
       blob_appendf(&record, " %s", gg.azMerge[i]);
@@ -636,10 +642,11 @@
       i = 0;
       while( (pFile = import_find_file(zName, &i, gg.nFile))!=0 ){
         if( pFile->isFrom==0 ) continue;
         fossil_free(pFile->zName);
         fossil_free(pFile->zPrior);
+        pFile->zPrior = 0;
         fossil_free(pFile->zUuid);
         *pFile = gg.aFile[--gg.nFile];
         i--;
       }
     }else
@@ -651,51 +658,36 @@
       zTo = rest_of_line(&z);
       i = 0;
       mx = gg.nFile;
       nFrom = strlen(zFrom);
       while( (pFile = import_find_file(zFrom, &i, mx))!=0 ){
-        if( pFile->isFrom==0 ) continue;
         pNew = import_add_file();
         pFile = &gg.aFile[i-1];
         if( strlen(pFile->zName)>nFrom ){
           pNew->zName = mprintf("%s%s", zTo, pFile->zName[nFrom]);
         }else{
-          pNew->zName = fossil_strdup(pFile->zName);
+          pNew->zName = fossil_strdup(zTo);
         }
         pNew->isExe = pFile->isExe;
         pNew->isLink = pFile->isLink;
         pNew->zUuid = fossil_strdup(pFile->zUuid);
         pNew->isFrom = 0;
       }
     }else
     if( memcmp(zLine, "R ", 2)==0 ){
-      int nFrom;
       import_prior_files();
       z = &zLine[2];
       zFrom = next_token(&z);
       zTo = rest_of_line(&z);
       i = 0;
-      nFrom = strlen(zFrom);
       while( (pFile = import_find_file(zFrom, &i, gg.nFile))!=0 ){
         if( pFile->isFrom==0 ) continue;
-        pNew = import_add_file();
         pFile = &gg.aFile[i-1];
-        if( strlen(pFile->zName)>nFrom ){
-          pNew->zName = mprintf("%s%s", zTo, pFile->zName[nFrom]);
-        }else{
-          pNew->zName = fossil_strdup(pFile->zName);
-        }
-        pNew->zPrior = pFile->zName;
-        pNew->isExe = pFile->isExe;
-        pNew->isLink = pFile->isLink;
-        pNew->zUuid = pFile->zUuid;
-        pNew->isFrom = 0;
-        gg.nFile--;
-        *pFile = *pNew;
-        memset(pNew, 0, sizeof(*pNew));
+        pFile->zPrior = pFile->zName;
+        pFile->zName = fossil_strdup(zTo);
+        pFile->isFrom = 0;
       }
-      fossil_fatal("cannot handle R records, use --full-tree");
     }else
     if( memcmp(zLine, "deleteall", 9)==0 ){
       gg.fromLoaded = 1;
     }else
     if( memcmp(zLine, "N ", 2)==0 ){


-- 
Isaac Jurado

"The noblest pleasure is the joy of understanding."
                                  Leonardo da Vinci
_______________________________________________
fossil-users mailing list
fossil-users@lists.fossil-scm.org
http://lists.fossil-scm.org:8080/cgi-bin/mailman/listinfo/fossil-users

Reply via email to