Fossil

Check-in [3c39caac39]
Login

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

Overview
Comment:Fix the "revert" command so that it restores the correct execute permission to the file. Ticket [baf9b6b11e08c1]
Downloads: Tarball | ZIP archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA1: 3c39caac39b3d89e149accf25f7727c252e09e7d
User & Date: drh 2011-02-27 21:45:36.127
Context
2011-02-27
23:31
Change the ZIP file generator so that it sets the execute bit approprately. Ticket [baf9b6b11e08c1d]. check-in: b57bc473b0 user: drh tags: trunk
22:22
Untested changes trying to get execute permission to be set correctly following "update", "merge", "stash", etc. Ticket [baf9b6b11e08c1d]. This is a big mess and is going to take some time to get right. check-in: 081aefde56 user: drh tags: exe-permission-fix
21:45
Fix the "revert" command so that it restores the correct execute permission to the file. Ticket [baf9b6b11e08c1] check-in: 3c39caac39 user: drh tags: trunk
21:08
Merge the --private sync enhancement into the trunk. check-in: 8b8cc4f1b7 user: drh tags: trunk
Changes
Unified Diff Ignore Whitespace Patch
Changes to src/diffcmd.c.
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
  const char *zFrom,        /* Name of file */
  const char *zDiffCmd,     /* Use this "diff" command */
  int ignoreEolWs           /* Ignore whitespace changes at end of lines */
){
  Blob fname;
  Blob content;
  file_tree_name(g.argv[2], &fname, 1);
  historical_version_of_file(zFrom, blob_str(&fname), &content, 0);
  diff_file(&content, g.argv[2], g.argv[2], zDiffCmd, ignoreEolWs);
  blob_reset(&content);
  blob_reset(&fname);
}

/*
** Run a diff between the version zFrom and files on disk.  zFrom might







|







184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
  const char *zFrom,        /* Name of file */
  const char *zDiffCmd,     /* Use this "diff" command */
  int ignoreEolWs           /* Ignore whitespace changes at end of lines */
){
  Blob fname;
  Blob content;
  file_tree_name(g.argv[2], &fname, 1);
  historical_version_of_file(zFrom, blob_str(&fname), &content, 0, 0);
  diff_file(&content, g.argv[2], g.argv[2], zDiffCmd, ignoreEolWs);
  blob_reset(&content);
  blob_reset(&fname);
}

/*
** Run a diff between the version zFrom and files on disk.  zFrom might
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
  int ignoreEolWs
){
  char *zName;
  Blob fname;
  Blob v1, v2;
  file_tree_name(g.argv[2], &fname, 1);
  zName = blob_str(&fname);
  historical_version_of_file(zFrom, zName, &v1, 0);
  historical_version_of_file(zTo, zName, &v2, 0);
  diff_file_mem(&v1, &v2, zName, zDiffCmd, ignoreEolWs);
  blob_reset(&v1);
  blob_reset(&v2);
  blob_reset(&fname);
}

/*







|
|







306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
  int ignoreEolWs
){
  char *zName;
  Blob fname;
  Blob v1, v2;
  file_tree_name(g.argv[2], &fname, 1);
  zName = blob_str(&fname);
  historical_version_of_file(zFrom, zName, &v1, 0, 0);
  historical_version_of_file(zTo, zName, &v2, 0, 0);
  diff_file_mem(&v1, &v2, zName, zDiffCmd, ignoreEolWs);
  blob_reset(&v1);
  blob_reset(&v2);
  blob_reset(&fname);
}

/*
Changes to src/finfo.c.
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
  }else if( find_option("print","p",0) ){
    Blob record;
    Blob fname;
    const char *zRevision = find_option("revision", "r", 1);

    file_tree_name(g.argv[2], &fname, 1);
    if( zRevision ){
      historical_version_of_file(zRevision, blob_str(&fname), &record, 0);
    }else{
      int rid = db_int(0, "SELECT rid FROM vfile WHERE pathname=%B", &fname);
      if( rid==0 ){
        fossil_fatal("no history for file: %b", &fname);
      }
      content_get(rid, &record);
    }







|







98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
  }else if( find_option("print","p",0) ){
    Blob record;
    Blob fname;
    const char *zRevision = find_option("revision", "r", 1);

    file_tree_name(g.argv[2], &fname, 1);
    if( zRevision ){
      historical_version_of_file(zRevision, blob_str(&fname), &record, 0, 0);
    }else{
      int rid = db_int(0, "SELECT rid FROM vfile WHERE pathname=%B", &fname);
      if( rid==0 ){
        fossil_fatal("no history for file: %b", &fname);
      }
      content_get(rid, &record);
    }
Changes to src/update.c.
447
448
449
450
451
452
453

454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475

476
477
478
479
480
481
482
483
484
485
** Get the contents of a file within the checking "revision".  If
** revision==NULL then get the file content for the current checkout.
*/
int historical_version_of_file(
  const char *revision,    /* The checkin containing the file */
  const char *file,        /* Full treename of the file */
  Blob *content,           /* Put the content here */

  int errCode              /* Error code if file not found.  Panic if 0. */
){
  Manifest *pManifest;
  ManifestFile *pFile;
  int rid=0;
  
  if( revision ){
    rid = name_to_rid(revision);
  }else{
    rid = db_lget_int("checkout", 0);
  }
  if( !is_a_version(rid) ){
    if( errCode>0 ) return errCode;
    fossil_fatal("no such checkin: %s", revision);
  }
  pManifest = manifest_get(rid, CFTYPE_MANIFEST);
  
  if( pManifest ){
    manifest_file_rewind(pManifest);
    while( (pFile = manifest_file_next(pManifest,0))!=0 ){
      if( fossil_strcmp(pFile->zName, file)==0 ){
        rid = uuid_to_rid(pFile->zUuid, 0);

        manifest_destroy(pManifest);
        return content_get(rid, content);
      }
    }
    manifest_destroy(pManifest);
    if( errCode<=0 ){
      fossil_fatal("file %s does not exist in checkin: %s", file, revision);
    }
  }else if( errCode<=0 ){
    if( revision==0 ){







>


















<
|
|
|
>
|
|
<







447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472

473
474
475
476
477
478

479
480
481
482
483
484
485
** Get the contents of a file within the checking "revision".  If
** revision==NULL then get the file content for the current checkout.
*/
int historical_version_of_file(
  const char *revision,    /* The checkin containing the file */
  const char *file,        /* Full treename of the file */
  Blob *content,           /* Put the content here */
  int *pIsExe,             /* Set to true if file is executable */
  int errCode              /* Error code if file not found.  Panic if 0. */
){
  Manifest *pManifest;
  ManifestFile *pFile;
  int rid=0;
  
  if( revision ){
    rid = name_to_rid(revision);
  }else{
    rid = db_lget_int("checkout", 0);
  }
  if( !is_a_version(rid) ){
    if( errCode>0 ) return errCode;
    fossil_fatal("no such checkin: %s", revision);
  }
  pManifest = manifest_get(rid, CFTYPE_MANIFEST);
  
  if( pManifest ){

    pFile = manifest_file_seek(pManifest, file);
    if( pFile ){
      rid = uuid_to_rid(pFile->zUuid, 0);
      if( pIsExe ) *pIsExe = manifest_file_mperm(pFile);
      manifest_destroy(pManifest);
      return content_get(rid, content);

    }
    manifest_destroy(pManifest);
    if( errCode<=0 ){
      fossil_fatal("file %s does not exist in checkin: %s", file, revision);
    }
  }else if( errCode<=0 ){
    if( revision==0 ){
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
*/
void revert_cmd(void){
  const char *zFile;
  const char *zRevision;
  Blob record;
  int i;
  int errCode;
  int rid = 0;
  Stmt q;

  undo_capture_command_line();  
  zRevision = find_option("revision", "r", 1);
  verify_all_options();
  
  if( g.argc<2 ){







<







507
508
509
510
511
512
513

514
515
516
517
518
519
520
*/
void revert_cmd(void){
  const char *zFile;
  const char *zRevision;
  Blob record;
  int i;
  int errCode;

  Stmt q;

  undo_capture_command_line();  
  zRevision = find_option("revision", "r", 1);
  verify_all_options();
  
  if( g.argc<2 ){
547
548
549
550
551
552
553




554

555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573

574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
      "SELECT pathname"
      "  FROM vfile "
      " WHERE chnged OR deleted OR rid=0 OR pathname!=origname;"
    );
  }
  blob_zero(&record);
  db_prepare(&q, "SELECT name FROM torevert");




  while( db_step(&q)==SQLITE_ROW ){

    zFile = db_column_text(&q, 0);
    if( zRevision!=0 ){
      errCode = historical_version_of_file(zRevision, zFile, &record, 2);
    }else{
      rid = db_int(0, "SELECT rid FROM vfile WHERE pathname=%Q", zFile);
      if( rid==0 ){
        errCode = 2;
      }else{
        content_get(rid, &record);
        errCode = 0;
      }
    }

    if( errCode==2 ){
      fossil_warning("file not in repository: %s", zFile);
    }else{
      char *zFull = mprintf("%/%/", g.zLocalRoot, zFile);
      undo_save(zFile);
      blob_write_to_file(&record, zFull);

      printf("REVERTED: %s\n", zFile);
      if( zRevision==0 ){
        sqlite3_int64 mtime = file_mtime(zFull);
        db_multi_exec(
           "UPDATE vfile"
           "   SET mtime=%lld, chnged=0, deleted=0,"
           "       pathname=coalesce(origname,pathname), origname=NULL"     
           " WHERE pathname=%Q",
           mtime, zFile
        );
      }
      free(zFull);
    }
    blob_reset(&record);
  }
  db_finalize(&q);
  undo_finish();
  db_end_transaction(0);
}







>
>
>
>

>

<
|
<
<
<
<
<
<
<
<
<
<






>





|


|










546
547
548
549
550
551
552
553
554
555
556
557
558
559

560










561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
      "SELECT pathname"
      "  FROM vfile "
      " WHERE chnged OR deleted OR rid=0 OR pathname!=origname;"
    );
  }
  blob_zero(&record);
  db_prepare(&q, "SELECT name FROM torevert");
  if( zRevision==0 ){
    int vid = db_lget_int("checkout", 0);
    zRevision = db_text(0, "SELECT uuid FROM blob WHERE rid=%d", vid);
  }
  while( db_step(&q)==SQLITE_ROW ){
    int isExe = 0;
    zFile = db_column_text(&q, 0);

    errCode = historical_version_of_file(zRevision, zFile, &record, &isExe,2);










    if( errCode==2 ){
      fossil_warning("file not in repository: %s", zFile);
    }else{
      char *zFull = mprintf("%/%/", g.zLocalRoot, zFile);
      undo_save(zFile);
      blob_write_to_file(&record, zFull);
      file_setexe(zFull, isExe);
      printf("REVERTED: %s\n", zFile);
      if( zRevision==0 ){
        sqlite3_int64 mtime = file_mtime(zFull);
        db_multi_exec(
           "UPDATE vfile"
           "   SET mtime=%lld, chnged=0, deleted=0, isexe=%d,"
           "       pathname=coalesce(origname,pathname), origname=NULL"     
           " WHERE pathname=%Q",
           mtime, isExe, zFile
        );
      }
      free(zFull);
    }
    blob_reset(&record);
  }
  db_finalize(&q);
  undo_finish();
  db_end_transaction(0);
}