Fossil

Check-in [50705503]
Login

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

Overview
Comment:Add --rename-master option to import --git instead of forcing a naming convention.
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | roy-export
Files: files | file ages | folders
SHA1:50705503d94438068c5691162e38dbf0585362b5
User & Date: roy.marples 2017-02-10 22:04:06
Context
2017-02-10
22:07
Set the main-branch config option to the trunk name we're using. check-in: 9501d941 user: roy.marples tags: roy-export
22:04
Add --rename-master option to import --git instead of forcing a naming convention. check-in: 50705503 user: roy.marples tags: roy-export
20:28
Add --rename-trunk option to export instead of forcing a naming convention. check-in: bc443729 user: roy.marples tags: roy-export
Changes
Hide Diffs Side-by-Side Diffs Ignore Whitespace Patch

Changes to src/import.c.

   511    511       }
   512    512       zName[i++] = c;
   513    513     }
   514    514     zName[i] = 0;
   515    515   }
   516    516   
   517    517   
          518  +static struct{
          519  +  const char *zMasterName;    /* Name of master branch */
          520  +} ggit;
          521  +
   518    522   /*
   519    523   ** Read the git-fast-import format from pIn and insert the corresponding
   520    524   ** content into the database.
   521    525   */
   522    526   static void git_fast_import(FILE *pIn){
   523    527     ImportFile *pFile, *pNew;
   524    528     int i, mx;
................................................................................
   534    538     while( fgets(zLine, sizeof(zLine), pIn) ){
   535    539       if( zLine[0]=='\n' || zLine[0]=='#' ) continue;
   536    540       if( strncmp(zLine, "blob", 4)==0 ){
   537    541         gg.xFinish();
   538    542         gg.xFinish = finish_blob;
   539    543       }else
   540    544       if( strncmp(zLine, "commit ", 7)==0 ){
          545  +      const char *zRefName;
   541    546         gg.xFinish();
   542    547         gg.xFinish = finish_commit;
   543    548         trim_newline(&zLine[7]);
   544         -      z = &zLine[7];
          549  +      zRefName = &zLine[7];
   545    550   
   546    551         /* The argument to the "commit" line might match either of these
   547    552         ** patterns:
   548    553         **
   549    554         **   (A)  refs/heads/BRANCHNAME
   550    555         **   (B)  refs/tags/TAGNAME
   551    556         **
................................................................................
   557    562         ** tag to the new commit.  However, if there are multiple instances
   558    563         ** of pattern B with the same TAGNAME, then only put the tag on the
   559    564         ** last commit that holds that tag.
   560    565         **
   561    566         ** None of the above is explained in the git-fast-export
   562    567         ** documentation.  We had to figure it out via trial and error.
   563    568         */
   564         -      for(i=5; i<strlen(z) && z[i]!='/'; i++){}
   565         -      gg.tagCommit = strncmp(&z[5], "tags", 4)==0;  /* True for pattern B */
   566         -      if( z[i+1]!=0 ) z += i+1;
   567         -      if( fossil_strcmp(z, "master")==0 ) z = "trunk";
   568         -      gg.zBranch = fossil_strdup(z);
          569  +      for(i=5; i<strlen(zRefName) && zRefName[i]!='/'; i++){}
          570  +      gg.tagCommit = strncmp(&zRefName[5], "tags", 4)==0;  /* True for pattern B */
          571  +      if( zRefName[i+1]!=0 ) zRefName += i+1;
          572  +      if( fossil_strcmp(zRefName, "master")==0 ) zRefName = ggit.zMasterName;
          573  +      gg.zBranch = fossil_strdup(zRefName);
   569    574         gg.fromLoaded = 0;
   570    575       }else
   571    576       if( strncmp(zLine, "tag ", 4)==0 ){
   572    577         gg.xFinish();
   573    578         gg.xFinish = finish_tag;
   574    579         trim_newline(&zLine[4]);
   575    580         gg.zTag = fossil_strdup(&zLine[4]);
................................................................................
  1543   1548   ** argument.  If no input file is supplied the interchange format
  1544   1549   ** data is read from standard input.
  1545   1550   **
  1546   1551   ** The following formats are currently understood by this command
  1547   1552   **
  1548   1553   **   --git        Import from the git-fast-export file format (default)
  1549   1554   **                Options:
  1550         -**                  --import-marks FILE Restore marks table from FILE
  1551         -**                  --export-marks FILE Save marks table to FILE
         1555  +**                  --import-marks  FILE Restore marks table from FILE
         1556  +**                  --export-marks  FILE Save marks table to FILE
         1557  +**                  --rename-master NAME Renames the master branch to NAME
  1552   1558   **
  1553   1559   **   --svn        Import from the svnadmin-dump file format.  The default
  1554   1560   **                behaviour (unless overridden by --flat) is to treat 3
  1555   1561   **                folders in the SVN root as special, following the
  1556   1562   **                common layout of SVN repositories.  These are (by
  1557   1563   **                default) trunk/, branches/ and tags/.  The SVN --deltas
  1558   1564   **                format is supported but not required.
................................................................................
  1666   1672       gsvn.zBranches = find_option("branches", 0, 1);
  1667   1673       gsvn.zTags = find_option("tags", 0, 1);
  1668   1674       gsvn.revFlag = find_option("rev-tags", 0, 0)
  1669   1675                   || (incrFlag && !find_option("no-rev-tags", 0, 0));
  1670   1676     }else if( gitFlag ){
  1671   1677       markfile_in = find_option("import-marks", 0, 1);
  1672   1678       markfile_out = find_option("export-marks", 0, 1);
         1679  +    if( !(ggit.zMasterName = find_option("rename-master", 0, 1)) ){
         1680  +      ggit.zMasterName = "master";
         1681  +    }
  1673   1682     }
  1674   1683     verify_all_options();
  1675   1684   
  1676   1685     if( g.argc!=3 && g.argc!=4 ){
  1677   1686       usage("--git|--svn ?OPTIONS? NEW-REPOSITORY ?INPUT-FILE?");
  1678   1687     }
  1679   1688     if( g.argc==4 ){