Fossil

Diff
Login

Differences From Artifact [fc54d7cdae]:

To Artifact [9e7f15d053]:


364
365
366
367
368
369
370
371
372
373
374

375

376


377










378
379
380
381











382
383
384
385
386
387
388
389
390
391


392
393
394
395
396

397
398


399
400
401
402
403
404
405
** Get a token from a line of text.  Return a pointer to the first
** character of the token and zero-terminate the token.  Make
** *pzIn point to the first character past the end of the zero
** terminator, or at the zero-terminator at EOL.
*/
static char *next_token(char **pzIn){
  char *z = *pzIn;
  int i;
  if( z[0]==0 ) return z;
  for(i=0; z[i] && z[i]!=' ' && z[i]!='\n'; i++){}
  if( z[i] ){

    z[i] = 0;

    *pzIn = &z[i+1];


  }else{










    *pzIn = &z[i];
  }
  return z;
}












/*
** Return a token that is all text up to (but omitting) the next \n
** or \r\n.
*/
static char *rest_of_line(char **pzIn){
  char *z = *pzIn;
  int i;
  if( z[0]==0 ) return z;
  for(i=0; z[i] && z[i]!='\r' && z[i]!='\n'; i++){}


  if( z[i] ){
    if( z[i]=='\r' && z[i+1]=='\n' ){
      z[i] = 0;
      i++;
    }else{

      z[i] = 0;
    }


    *pzIn = &z[i+1];
  }else{
    *pzIn = &z[i];
  }
  return z;
}








|

<
|
>
|
>
|
>
>
|
>
>
>
>
>
>
>
>
>
>
|
<
|
<
>
>
>
>
>
>
>
>
>
>
>
|
<
<
<
<
<
|
<
<
<
>
>
|
<
<
<
|
>
|
|
>
>







364
365
366
367
368
369
370
371
372

373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391

392

393
394
395
396
397
398
399
400
401
402
403
404





405



406
407
408



409
410
411
412
413
414
415
416
417
418
419
420
421
** Get a token from a line of text.  Return a pointer to the first
** character of the token and zero-terminate the token.  Make
** *pzIn point to the first character past the end of the zero
** terminator, or at the zero-terminator at EOL.
*/
static char *next_token(char **pzIn){
  char *z = *pzIn;
  int i, j;
  if( z[0]==0 ) return z;

  if( z[0]=='"' ){
    /* Quoted path name */
    z++;
    for(i=0, j=0; z[i] && z[i]!='"' && z[i]!='\n'; i++, j++){
      if( z[i]=='\\' && z[i+1] ){
        char v, c = z[++i];
        switch( c ){
          case 0:
          case '"':  c = '"';  break;
          case '\\': c = '\\'; break;
          case 'a':  c = '\a'; break;
          case 'b':  c = '\b'; break;
          case 'f':  c = '\f'; break;
          case 'n':  c = '\n'; break;
          case 'r':  c = '\r'; break;
          case 't':  c = '\t'; break;
          case 'v':  c = '\v'; break;
          case '0': case '1': case '2': case '3':
            v = (c - '0') << 6;

            c = z[++i];

            if( c < '0' || c > '7' )
              fossil_fatal("Invalid octal digit '%c' in sequence", c);
            v |= (c - '0') << 3;
            c = z[++i];
            if( c < '0' || c > '7' )
              fossil_fatal("Invalid octal digit '%c' in sequence", c);
            v |= (c - '0');
            c = v;
            break;
          default:
            fossil_fatal("Unrecognized escape sequence \"\\%c\"", c);
        }





        z[j] = c;



      }
    }
    if( z[i]=='"' ) z[i++] = 0;



  }else{
    /* Unquoted path name or generic token */
    for(i=0; z[i] && z[i]!=' ' && z[i]!='\n'; i++){}
  }
  if( z[i] ){
    z[i] = 0;
    *pzIn = &z[i+1];
  }else{
    *pzIn = &z[i];
  }
  return z;
}

514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
      return &gg.aFile[i];
    }
    i++;
  }
  return 0;
}

/*
** Dequote a fast-export filename.  Filenames are normally unquoted.  But
** if the contain some obscure special characters, quotes might be added.
*/
static void dequote_git_filename(char *zName){
  int n, i, j;
  if( zName==0 || zName[0]!='"' ) return;
  n = (int)strlen(zName);
  if( zName[n-1]!='"' ) return;
  for(i=0, j=1; j<n-1; j++){
    char c = zName[j];
    if( c=='\\' ) c = zName[++j];
    zName[i++] = c;
  }
  zName[i] = 0;
}


/*
** Read the git-fast-import format from pIn and insert the corresponding
** content into the database.
*/
static void git_fast_import(FILE *pIn){
  ImportFile *pFile, *pNew;







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







530
531
532
533
534
535
536

















537
538
539
540
541
542
543
      return &gg.aFile[i];
    }
    i++;
  }
  return 0;
}



















/*
** Read the git-fast-import format from pIn and insert the corresponding
** content into the database.
*/
static void git_fast_import(FILE *pIn){
  ImportFile *pFile, *pNew;
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
      if( gg.azMerge[gg.nMerge] ) gg.nMerge++;
    }else
    if( memcmp(zLine, "M ", 2)==0 ){
      import_prior_files();
      z = &zLine[2];
      zPerm = next_token(&z);
      zUuid = next_token(&z);
      zName = rest_of_line(&z);
      dequote_git_filename(zName);
      i = 0;
      pFile = import_find_file(zName, &i, gg.nFile);
      if( pFile==0 ){
        pFile = import_add_file();
        pFile->zName = fossil_strdup(zName);
        gg.nFileEffective++;
      }







|
<







673
674
675
676
677
678
679
680

681
682
683
684
685
686
687
      if( gg.azMerge[gg.nMerge] ) gg.nMerge++;
    }else
    if( memcmp(zLine, "M ", 2)==0 ){
      import_prior_files();
      z = &zLine[2];
      zPerm = next_token(&z);
      zUuid = next_token(&z);
      zName = next_token(&z);

      i = 0;
      pFile = import_find_file(zName, &i, gg.nFile);
      if( pFile==0 ){
        pFile = import_add_file();
        pFile->zName = fossil_strdup(zName);
        gg.nFileEffective++;
      }
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
      */
      gg.nChanged += 1 - pFile->hasChanged;
      pFile->hasChanged = 1;
    }else
    if( memcmp(zLine, "D ", 2)==0 ){
      import_prior_files();
      z = &zLine[2];
      zName = rest_of_line(&z);
      dequote_git_filename(zName);
      i = 0;
      pFile = import_find_file(zName, &i, gg.nFile);
      if( pFile!=0 ){
        /* Do not remove the item from gg.aFile, just mark as deleted */
        fossil_free(pFile->zUuid);
        pFile->zUuid = 0;
        gg.nChanged += 1 - pFile->hasChanged;
        pFile->hasChanged = 1;
        gg.nFileEffective--;
      }
    }else
    if( memcmp(zLine, "C ", 2)==0 ){
      import_prior_files();
      z = &zLine[2];
      zFrom = next_token(&z);
      zTo = rest_of_line(&z);
      i = 0;
      pFile = import_find_file(zFrom, &i, gg.nFile);
      if( pFile!=0 ){
        int j = 0;
        pNew = import_find_file(zTo, &j, gg.nFile);
        if( pNew==0 ){
          pNew = import_add_file();







|
<















|







696
697
698
699
700
701
702
703

704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
      */
      gg.nChanged += 1 - pFile->hasChanged;
      pFile->hasChanged = 1;
    }else
    if( memcmp(zLine, "D ", 2)==0 ){
      import_prior_files();
      z = &zLine[2];
      zName = next_token(&z);

      i = 0;
      pFile = import_find_file(zName, &i, gg.nFile);
      if( pFile!=0 ){
        /* Do not remove the item from gg.aFile, just mark as deleted */
        fossil_free(pFile->zUuid);
        pFile->zUuid = 0;
        gg.nChanged += 1 - pFile->hasChanged;
        pFile->hasChanged = 1;
        gg.nFileEffective--;
      }
    }else
    if( memcmp(zLine, "C ", 2)==0 ){
      import_prior_files();
      z = &zLine[2];
      zFrom = next_token(&z);
      zTo = next_token(&z);
      i = 0;
      pFile = import_find_file(zFrom, &i, gg.nFile);
      if( pFile!=0 ){
        int j = 0;
        pNew = import_find_file(zTo, &j, gg.nFile);
        if( pNew==0 ){
          pNew = import_add_file();
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
        pNew->hasChanged = 1;
      }
    }else
    if( memcmp(zLine, "R ", 2)==0 ){
      import_prior_files();
      z = &zLine[2];
      zFrom = next_token(&z);
      zTo = rest_of_line(&z);
      i = 0;
      pFile = import_find_file(zFrom, &i, gg.nFile);
      if( pFile!=0 ){
        /*
        ** File renames in delta manifests require two "F" cards: one to
        ** delete the old file (without UUID) and another with the rename
        ** (with prior name equals to the name in the other card).







|







737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
        pNew->hasChanged = 1;
      }
    }else
    if( memcmp(zLine, "R ", 2)==0 ){
      import_prior_files();
      z = &zLine[2];
      zFrom = next_token(&z);
      zTo = next_token(&z);
      i = 0;
      pFile = import_find_file(zFrom, &i, gg.nFile);
      if( pFile!=0 ){
        /*
        ** File renames in delta manifests require two "F" cards: one to
        ** delete the old file (without UUID) and another with the rename
        ** (with prior name equals to the name in the other card).