Fossil SCM

Enhance the new TH1 artifact command with more flexible lookup semantics.

mistachkin 2014-06-16 18:49 trunk
Commit 00e4fedd85751b3fe08a188990b6dbebf1147be4
3 files changed +29 -2 +8 -4 +21 -1
+29 -2
--- src/info.c
+++ src/info.c
@@ -1560,16 +1560,43 @@
15601560
@ <blockquote><pre>
15611561
hexdump(&content);
15621562
@ </pre></blockquote>
15631563
style_footer();
15641564
}
1565
+
1566
+/*
1567
+** Attempt to lookup the specified checkin and file name into an rid.
1568
+*/
1569
+int artifact_from_ci_and_filename(
1570
+ const char *zCI,
1571
+ const char *zFilename
1572
+){
1573
+ int cirid;
1574
+ Manifest *pManifest;
1575
+ ManifestFile *pFile;
1576
+
1577
+ if( zCI==0 ) return 0;
1578
+ if( zFilename==0 ) return 0;
1579
+ cirid = name_to_rid(zCI);
1580
+ pManifest = manifest_get(cirid, CFTYPE_MANIFEST, 0);
1581
+ if( pManifest==0 ) return 0;
1582
+ manifest_file_rewind(pManifest);
1583
+ while( (pFile = manifest_file_next(pManifest,0))!=0 ){
1584
+ if( fossil_strcmp(zFilename, pFile->zName)==0 ){
1585
+ int rid = db_int(0, "SELECT rid FROM blob WHERE uuid=%Q", pFile->zUuid);
1586
+ manifest_destroy(pManifest);
1587
+ return rid;
1588
+ }
1589
+ }
1590
+ return 0;
1591
+}
15651592
15661593
/*
15671594
** Look for "ci" and "filename" query parameters. If found, try to
15681595
** use them to extract the record ID of an artifact for the file.
15691596
*/
1570
-int artifact_from_ci_and_filename(void){
1597
+int artifact_from_ci_and_filename_www(void){
15711598
const char *zFilename;
15721599
const char *zCI;
15731600
int cirid;
15741601
Manifest *pManifest;
15751602
ManifestFile *pFile;
@@ -1673,11 +1700,11 @@
16731700
int objType;
16741701
int asText;
16751702
const char *zUuid;
16761703
16771704
if( P("ci") && P("filename") ){
1678
- rid = artifact_from_ci_and_filename();
1705
+ rid = artifact_from_ci_and_filename_www();
16791706
}
16801707
if( rid==0 ){
16811708
rid = name_to_rid_www("name");
16821709
}
16831710
16841711
--- src/info.c
+++ src/info.c
@@ -1560,16 +1560,43 @@
1560 @ <blockquote><pre>
1561 hexdump(&content);
1562 @ </pre></blockquote>
1563 style_footer();
1564 }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1565
1566 /*
1567 ** Look for "ci" and "filename" query parameters. If found, try to
1568 ** use them to extract the record ID of an artifact for the file.
1569 */
1570 int artifact_from_ci_and_filename(void){
1571 const char *zFilename;
1572 const char *zCI;
1573 int cirid;
1574 Manifest *pManifest;
1575 ManifestFile *pFile;
@@ -1673,11 +1700,11 @@
1673 int objType;
1674 int asText;
1675 const char *zUuid;
1676
1677 if( P("ci") && P("filename") ){
1678 rid = artifact_from_ci_and_filename();
1679 }
1680 if( rid==0 ){
1681 rid = name_to_rid_www("name");
1682 }
1683
1684
--- src/info.c
+++ src/info.c
@@ -1560,16 +1560,43 @@
1560 @ <blockquote><pre>
1561 hexdump(&content);
1562 @ </pre></blockquote>
1563 style_footer();
1564 }
1565
1566 /*
1567 ** Attempt to lookup the specified checkin and file name into an rid.
1568 */
1569 int artifact_from_ci_and_filename(
1570 const char *zCI,
1571 const char *zFilename
1572 ){
1573 int cirid;
1574 Manifest *pManifest;
1575 ManifestFile *pFile;
1576
1577 if( zCI==0 ) return 0;
1578 if( zFilename==0 ) return 0;
1579 cirid = name_to_rid(zCI);
1580 pManifest = manifest_get(cirid, CFTYPE_MANIFEST, 0);
1581 if( pManifest==0 ) return 0;
1582 manifest_file_rewind(pManifest);
1583 while( (pFile = manifest_file_next(pManifest,0))!=0 ){
1584 if( fossil_strcmp(zFilename, pFile->zName)==0 ){
1585 int rid = db_int(0, "SELECT rid FROM blob WHERE uuid=%Q", pFile->zUuid);
1586 manifest_destroy(pManifest);
1587 return rid;
1588 }
1589 }
1590 return 0;
1591 }
1592
1593 /*
1594 ** Look for "ci" and "filename" query parameters. If found, try to
1595 ** use them to extract the record ID of an artifact for the file.
1596 */
1597 int artifact_from_ci_and_filename_www(void){
1598 const char *zFilename;
1599 const char *zCI;
1600 int cirid;
1601 Manifest *pManifest;
1602 ManifestFile *pFile;
@@ -1673,11 +1700,11 @@
1700 int objType;
1701 int asText;
1702 const char *zUuid;
1703
1704 if( P("ci") && P("filename") ){
1705 rid = artifact_from_ci_and_filename_www();
1706 }
1707 if( rid==0 ){
1708 rid = name_to_rid_www("name");
1709 }
1710
1711
+8 -4
--- src/th_main.c
+++ src/th_main.c
@@ -785,11 +785,11 @@
785785
return TH_ERROR;
786786
}
787787
}
788788
789789
/*
790
-** TH1 command: artifact ID
790
+** TH1 command: artifact ID ?FILENAME?
791791
**
792792
** Attempts to locate the specified artifact and return its contents. An
793793
** error is generated if the repository is not open or the artifact cannot
794794
** be found.
795795
*/
@@ -798,17 +798,21 @@
798798
void *p,
799799
int argc,
800800
const char **argv,
801801
int *argl
802802
){
803
- if( argc!=2 ){
804
- return Th_WrongNumArgs(interp, "artifact ID");
803
+ if( argc!=2 && argc!=3 ){
804
+ return Th_WrongNumArgs(interp, "artifact ID ?FILENAME?");
805805
}
806806
if( Th_IsRepositoryOpen() ){
807807
int rid;
808808
Blob content;
809
- rid = name_to_rid(argv[1]);
809
+ if( argc==3 ){
810
+ rid = artifact_from_ci_and_filename(argv[1], argv[2]);
811
+ }else{
812
+ rid = name_to_rid(argv[1]);
813
+ }
810814
if( rid!=0 && content_get(rid, &content) ){
811815
Th_SetResult(interp, blob_str(&content), blob_size(&content));
812816
blob_reset(&content);
813817
return TH_OK;
814818
}else{
815819
--- src/th_main.c
+++ src/th_main.c
@@ -785,11 +785,11 @@
785 return TH_ERROR;
786 }
787 }
788
789 /*
790 ** TH1 command: artifact ID
791 **
792 ** Attempts to locate the specified artifact and return its contents. An
793 ** error is generated if the repository is not open or the artifact cannot
794 ** be found.
795 */
@@ -798,17 +798,21 @@
798 void *p,
799 int argc,
800 const char **argv,
801 int *argl
802 ){
803 if( argc!=2 ){
804 return Th_WrongNumArgs(interp, "artifact ID");
805 }
806 if( Th_IsRepositoryOpen() ){
807 int rid;
808 Blob content;
809 rid = name_to_rid(argv[1]);
 
 
 
 
810 if( rid!=0 && content_get(rid, &content) ){
811 Th_SetResult(interp, blob_str(&content), blob_size(&content));
812 blob_reset(&content);
813 return TH_OK;
814 }else{
815
--- src/th_main.c
+++ src/th_main.c
@@ -785,11 +785,11 @@
785 return TH_ERROR;
786 }
787 }
788
789 /*
790 ** TH1 command: artifact ID ?FILENAME?
791 **
792 ** Attempts to locate the specified artifact and return its contents. An
793 ** error is generated if the repository is not open or the artifact cannot
794 ** be found.
795 */
@@ -798,17 +798,21 @@
798 void *p,
799 int argc,
800 const char **argv,
801 int *argl
802 ){
803 if( argc!=2 && argc!=3 ){
804 return Th_WrongNumArgs(interp, "artifact ID ?FILENAME?");
805 }
806 if( Th_IsRepositoryOpen() ){
807 int rid;
808 Blob content;
809 if( argc==3 ){
810 rid = artifact_from_ci_and_filename(argv[1], argv[2]);
811 }else{
812 rid = name_to_rid(argv[1]);
813 }
814 if( rid!=0 && content_get(rid, &content) ){
815 Th_SetResult(interp, blob_str(&content), blob_size(&content));
816 blob_reset(&content);
817 return TH_OK;
818 }else{
819
+21 -1
--- test/th1.test
+++ test/th1.test
@@ -635,11 +635,11 @@
635635
636636
###############################################################################
637637
638638
fossil test-th-eval "artifact"
639639
test th1-artifact-1 {$RESULT eq \
640
- {TH_ERROR: wrong # args: should be "artifact ID"}}
640
+ {TH_ERROR: wrong # args: should be "artifact ID ?FILENAME?"}}
641641
642642
###############################################################################
643643
644644
fossil test-th-eval "artifact tip"
645645
test th1-artifact-2 {$RESULT eq {TH_ERROR: repository unavailable}}
@@ -656,5 +656,25 @@
656656
657657
###############################################################################
658658
659659
fossil test-th-eval --th-open-config "artifact 0000000000"
660660
test th1-artifact-5 {$RESULT eq {TH_ERROR: artifact not found}}
661
+
662
+###############################################################################
663
+
664
+fossil test-th-eval "artifact tip test/th1.test"
665
+test th1-artifact-6 {$RESULT eq {TH_ERROR: repository unavailable}}
666
+
667
+###############################################################################
668
+
669
+fossil test-th-eval --th-open-config "artifact tip test/th1.test"
670
+test th1-artifact-7 {[regexp -- {th1-artifact-7} $RESULT]}
671
+
672
+###############################################################################
673
+
674
+fossil test-th-eval "artifact 0000000000 test/th1.test"
675
+test th1-artifact-8 {$RESULT eq {TH_ERROR: repository unavailable}}
676
+
677
+###############################################################################
678
+
679
+fossil test-th-eval --th-open-config "artifact 0000000000 test/th1.test"
680
+test th1-artifact-9 {$RESULT eq {TH_ERROR: artifact not found}}
661681
--- test/th1.test
+++ test/th1.test
@@ -635,11 +635,11 @@
635
636 ###############################################################################
637
638 fossil test-th-eval "artifact"
639 test th1-artifact-1 {$RESULT eq \
640 {TH_ERROR: wrong # args: should be "artifact ID"}}
641
642 ###############################################################################
643
644 fossil test-th-eval "artifact tip"
645 test th1-artifact-2 {$RESULT eq {TH_ERROR: repository unavailable}}
@@ -656,5 +656,25 @@
656
657 ###############################################################################
658
659 fossil test-th-eval --th-open-config "artifact 0000000000"
660 test th1-artifact-5 {$RESULT eq {TH_ERROR: artifact not found}}
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
661
--- test/th1.test
+++ test/th1.test
@@ -635,11 +635,11 @@
635
636 ###############################################################################
637
638 fossil test-th-eval "artifact"
639 test th1-artifact-1 {$RESULT eq \
640 {TH_ERROR: wrong # args: should be "artifact ID ?FILENAME?"}}
641
642 ###############################################################################
643
644 fossil test-th-eval "artifact tip"
645 test th1-artifact-2 {$RESULT eq {TH_ERROR: repository unavailable}}
@@ -656,5 +656,25 @@
656
657 ###############################################################################
658
659 fossil test-th-eval --th-open-config "artifact 0000000000"
660 test th1-artifact-5 {$RESULT eq {TH_ERROR: artifact not found}}
661
662 ###############################################################################
663
664 fossil test-th-eval "artifact tip test/th1.test"
665 test th1-artifact-6 {$RESULT eq {TH_ERROR: repository unavailable}}
666
667 ###############################################################################
668
669 fossil test-th-eval --th-open-config "artifact tip test/th1.test"
670 test th1-artifact-7 {[regexp -- {th1-artifact-7} $RESULT]}
671
672 ###############################################################################
673
674 fossil test-th-eval "artifact 0000000000 test/th1.test"
675 test th1-artifact-8 {$RESULT eq {TH_ERROR: repository unavailable}}
676
677 ###############################################################################
678
679 fossil test-th-eval --th-open-config "artifact 0000000000 test/th1.test"
680 test th1-artifact-9 {$RESULT eq {TH_ERROR: artifact not found}}
681

Keyboard Shortcuts

Open search /
Next entry (timeline) j
Previous entry (timeline) k
Open focused entry Enter
Show this help ?
Toggle theme Top nav button