523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
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
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
|
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
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
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
|
-
-
-
-
+
+
+
+
+
-
+
+
+
-
-
+
+
+
-
-
-
+
+
+
+
+
-
-
+
+
+
-
+
+
+
-
-
+
+
+
+
+
-
-
-
+
+
+
+
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
-
+
+
+
+
-
-
+
+
+
|
eflg |= MFESTFLG_TAGS;
}
if( eflg & (MFESTFLG_RAW|MFESTFLG_UUID) ){
if( eflg & MFESTFLG_RAW ){
blob_append(&filename, "manifest", -1);
zName = blob_str(&filename);
}
if( eflg & MFESTFLG_RAW ) {
sterilize_manifest(&mfile, CFTYPE_MANIFEST);
tar_add_file(zName, &mfile, 0, mTime);
if( listFlag ) fossil_print("%s\n", zName);
if( pTar ){
sterilize_manifest(&mfile, CFTYPE_MANIFEST);
tar_add_file(zName, &mfile, 0, mTime);
}
}
}
blob_reset(&mfile);
if( eflg & MFESTFLG_UUID ){
blob_append(&hash, "\n", 1);
blob_resize(&filename, nPrefix);
blob_append(&filename, "manifest.uuid", -1);
zName = blob_str(&filename);
if( listFlag ) fossil_print("%s\n", zName);
if( pTar ){
blob_append(&hash, "\n", 1);
tar_add_file(zName, &hash, 0, mTime);
}
tar_add_file(zName, &hash, 0, mTime);
}
}
if( eflg & MFESTFLG_TAGS ){
Blob tagslist;
blob_zero(&tagslist);
get_checkin_taglist(rid, &tagslist);
blob_resize(&filename, nPrefix);
blob_append(&filename, "manifest.tags", -1);
zName = blob_str(&filename);
if( listFlag ) fossil_print("%s\n", zName);
if( pTar ){
Blob tagslist;
blob_zero(&tagslist);
get_checkin_taglist(rid, &tagslist);
tar_add_file(zName, &tagslist, 0, mTime);
blob_reset(&tagslist);
tar_add_file(zName, &tagslist, 0, mTime);
blob_reset(&tagslist);
}
}
}
manifest_file_rewind(pManifest);
while( (pFile = manifest_file_next(pManifest,0))!=0 ){
int fid;
if( pInclude!=0 && !glob_match(pInclude, pFile->zName) ) continue;
if( glob_match(pExclude, pFile->zName) ) continue;
fid = uuid_to_rid(pFile->zUuid, 0);
if( fid ){
content_get(fid, &file);
blob_resize(&filename, nPrefix);
blob_append(&filename, pFile->zName, -1);
zName = blob_str(&filename);
if( listFlag ) fossil_print("%s\n", zName);
if( pTar ){
content_get(fid, &file);
tar_add_file(zName, &file, manifest_file_mperm(pFile), mTime);
blob_reset(&file);
tar_add_file(zName, &file, manifest_file_mperm(pFile), mTime);
blob_reset(&file);
}
}
}
}else{
blob_append(&filename, blob_str(&hash), 16);
zName = blob_str(&filename);
if( listFlag ) fossil_print("%s\n", zName);
if( pTar ){
mTime = db_int64(0, "SELECT (julianday('now') - 2440587.5)*86400.0;");
tar_begin(mTime);
tar_add_file(zName, &mfile, 0, mTime);
mTime = db_int64(0, "SELECT (julianday('now') - 2440587.5)*86400.0;");
tar_begin(mTime);
tar_add_file(zName, &mfile, 0, mTime);
}
}
manifest_destroy(pManifest);
blob_reset(&mfile);
blob_reset(&hash);
blob_reset(&filename);
tar_finish(pTar);
if( pTar ) tar_finish(pTar);
}
/*
** COMMAND: tarball*
**
** Usage: %fossil tarball VERSION OUTPUTFILE [OPTIONS]
**
** Generate a compressed tarball for a specified version. If the --name
** option is used, its argument becomes the name of the top-level directory
** in the resulting tarball. If --name is omitted, the top-level directory
** name is derived from the project name, the check-in date and time, and
** the artifact ID of the check-in.
**
** The GLOBLIST argument to --exclude and --include can be a comma-separated
** list of glob patterns, where each glob pattern may optionally be enclosed
** in "..." or '...' so that it may contain commas. If a file matches both
** --include and --exclude then it is excluded.
**
** If OUTPUTFILE is an empty string or "/dev/null" then no tarball is
** actually generated. This feature can be used in combination with
** the --list option to get a list of the filename that would be in the
** tarball had it actually been generated. Note that --list shows only
** filenames. "tar tzf" shows both filesnames and subdirectory names.
**
** Options:
** -X|--exclude GLOBLIST Comma-separated list of GLOBs of files to exclude
** --include GLOBLIST Comma-separated list of GLOBs of files to include
** -l|--list Show archive content on stdout
** --name DIRECTORYNAME The name of the top-level directory in the archive
** -R REPOSITORY Specify a Fossil repository
*/
void tarball_cmd(void){
int rid;
Blob tarball;
const char *zName;
Glob *pInclude = 0;
Glob *pExclude = 0;
const char *zInclude;
const char *zExclude;
int listFlag = 0;
const char *zOut;
zName = find_option("name", 0, 1);
zExclude = find_option("exclude", "X", 1);
if( zExclude ) pExclude = glob_create(zExclude);
zInclude = find_option("include", 0, 1);
if( zInclude ) pInclude = glob_create(zInclude);
db_find_and_open_repository(0, 0);
listFlag = find_option("list","l",0)!=0;
/* We should be done with options.. */
verify_all_options();
if( g.argc!=4 ){
usage("VERSION OUTPUTFILE");
}
g.zOpenRevision = g.argv[2];
rid = name_to_typed_rid(g.argv[2], "ci");
if( rid==0 ){
fossil_fatal("Check-in not found: %s", g.argv[2]);
return;
}
zOut = g.argv[3];
if( fossil_strcmp("/dev/null",zOut)==0 || fossil_strcmp("",zOut)==0 ){
zOut = 0;
}
if( zName==0 ){
zName = db_text("default-name",
"SELECT replace(%Q,' ','_') "
" || strftime('_%%Y-%%m-%%d_%%H%%M%%S_', event.mtime) "
" || substr(blob.uuid, 1, 10)"
" FROM event, blob"
" WHERE event.objid=%d"
" AND blob.rid=%d",
db_get("project-name", "unnamed"), rid, rid
);
}
tarball_of_checkin(rid, &tarball, zName, pInclude, pExclude);
tarball_of_checkin(rid, zOut ? &tarball : 0,
zName, pInclude, pExclude, listFlag);
glob_free(pInclude);
glob_free(pExclude);
if( listFlag ) fflush(stdout);
if( zOut ){
blob_write_to_file(&tarball, g.argv[3]);
blob_reset(&tarball);
blob_write_to_file(&tarball, zOut);
blob_reset(&tarball);
}
}
/*
** Check to see if the input string is of the form:
**
** checkin-name/filename.ext
**
|