Many hyperlinks are disabled.
Use anonymous login
to enable hyperlinks.
Overview
Comment: | Add options for drawing the file tree with Unicode symbols or ASCII characters (Windows defaults to the latter, all others to the former). |
---|---|
Downloads: | Tarball | ZIP archive | SQL archive |
Timelines: | family | ancestors | descendants | both | trunk |
Files: | files | file ages | folders |
SHA3-256: |
635fa090d10a20436e281e040c3a50f6 |
User & Date: | danield 2024-04-29 15:25:20.954 |
Context
2024-04-29
| ||
21:33 | Code cleaning after the previous check-in. No functional changes. ... (check-in: b705d756cf user: danield tags: trunk) | |
15:25 | Add options for drawing the file tree with Unicode symbols or ASCII characters (Windows defaults to the latter, all others to the former). ... (check-in: 635fa090d1 user: danield tags: trunk) | |
03:04 | Add the "fossil tree" command and the --tree option to "fossil ls" and "fossil extras". ... (check-in: dd72a96111 user: drh tags: trunk) | |
Changes
Changes to src/checkin.c.
︙ | ︙ | |||
644 645 646 647 648 649 650 | ** Print a section of a filelist hierarchy graph. This is a helper ** routine for print_filelist_as_tree() below. */ static const char *print_filelist_section( const char *zIn, /* List of filenames, separated by \n */ const char *zLast, /* Last filename in the list to print */ const char *zPrefix, /* Prefix so put before each output line */ | | > > > > > > > > > > > > > > | > | | | | | | | 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 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 | ** Print a section of a filelist hierarchy graph. This is a helper ** routine for print_filelist_as_tree() below. */ static const char *print_filelist_section( const char *zIn, /* List of filenames, separated by \n */ const char *zLast, /* Last filename in the list to print */ const char *zPrefix, /* Prefix so put before each output line */ int nDir, /* Ignore this many characters of directory name */ int treeFmt /* 1 = use Unicode symbols, 2 = use ASCII chars */ ){ const char *treeEntry = "|-- "; const char *treeLastE = "`-- "; const char *treeContu = "| "; const char *treeBlank = " "; if( treeFmt == 1 ){ treeEntry = "\342\224\234\342\224\200\342\224\200 "; treeLastE = "\342\224\224\342\224\200\342\224\200 "; treeContu = "\342\224\202 "; } while( zIn<=zLast ){ int i; // const char *treeContu = (treeFmt == 1) ? "\342\224\202 " : "| "; // const char *treeEntry = (treeFmt == 1) ? "\342\224\234\342\224\200\342\224\200 " : "|-- "; // const char *treeLastE = (treeFmt == 1) ? "\342\224\224\342\224\200\342\224\200 " : "`-- "; // const char *treeBlank = " "; for(i=nDir; zIn[i]!='\n' && zIn[i]!='/'; i++){} if( zIn[i]=='/' ){ char *zSubPrefix; const char *zSubLast = last_line(zIn, i+1); zSubPrefix = mprintf("%s%s", zPrefix, zSubLast==zLast ? treeBlank : treeContu); fossil_print("%s%s%.*s\n", zPrefix, zSubLast==zLast ? treeLastE : treeEntry, i-nDir, &zIn[nDir]); zIn = print_filelist_section(zIn, zSubLast, zSubPrefix, i+1, treeFmt); fossil_free(zSubPrefix); }else{ fossil_print("%s%s%.*s\n", zPrefix, zIn==zLast ? treeLastE : treeEntry, i-nDir, &zIn[nDir]); zIn = next_line(zIn); } } return zIn; } /* ** Input blob pList is a list of filenames, one filename per line, ** in sorted order and with / directory separators. Output this list ** as a tree in a manner similar to the "tree" command on Linux. */ static void print_filelist_as_tree(Blob *pList, int treeFmt){ char *zAll; const char *zLast; fossil_print("%s\n", g.zLocalRoot); zAll = blob_str(pList); if( zAll[0] ){ zLast = last_line(zAll, 0); print_filelist_section(zAll, zLast, "", 0, treeFmt); } } /* ** Take care of -r version of ls command */ static void ls_cmd_rev( |
︙ | ︙ | |||
758 759 760 761 762 763 764 | fossil_print("%s %s\n", zTime, zFile); }else{ fossil_print("%s\n", zFile); } } db_finalize(&q); if( treeFmt ){ | | | 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 | fossil_print("%s %s\n", zTime, zFile); }else{ fossil_print("%s\n", zFile); } } db_finalize(&q); if( treeFmt ){ print_filelist_as_tree(&out, treeFmt); blob_reset(&out); } } /* ** COMMAND: ls ** |
︙ | ︙ | |||
790 791 792 793 794 795 796 | ** ** The -t option changes the sort order. Without -t, files are sorted by ** path and name (case insensitive sort if -r). If neither --age nor -r ** are used, -t sorts by modification time, otherwise by commit time. ** ** Options: ** --age Show when each file was committed | | | | | | > > > > > > > > > > > | 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 | ** ** The -t option changes the sort order. Without -t, files are sorted by ** path and name (case insensitive sort if -r). If neither --age nor -r ** are used, -t sorts by modification time, otherwise by commit time. ** ** Options: ** --age Show when each file was committed ** -a|--ascii-tree Use ASCII characters when drawing the tree ** --hash With -v, verify file status using hashing ** rather than relying on file sizes and mtimes ** -r VERSION The specific check-in to list ** -R|--repository REPO Extract info from repository REPO ** -t Sort output in time order ** --tree Tree format ** -u|--unicode-tree Use Unicode symbols when drawing the tree ** -v|--verbose Provide extra information about each file ** ** See also: [[changes]], [[extras]], [[status]], [[tree]] */ void ls_cmd(void){ int vid; Stmt q; int verboseFlag; int showAge; int treeFmt; int asciiTree; int unicodeTree; int timeOrder; char *zOrderBy = "pathname"; Blob where; int i; int useHash = 0; const char *zName; const char *zRev; verboseFlag = find_option("verbose","v", 0)!=0; if( !verboseFlag ){ verboseFlag = find_option("l","l", 0)!=0; /* deprecated */ } showAge = find_option("age",0,0)!=0; zRev = find_option("r","r",1); timeOrder = find_option("t","t",0)!=0; if( verboseFlag ){ useHash = find_option("hash",0,0)!=0; } treeFmt = find_option("tree",0,0)!=0; asciiTree = find_option("ascii-tree","a",0)!=0; unicodeTree = find_option("unicode-tree","u",0)!=0; if( treeFmt ){ if( zRev==0 ) zRev = "current"; #ifdef _WIN32 treeFmt = 2; #endif if( unicodeTree ) treeFmt = 1; if( asciiTree ) treeFmt = 2; } if( zRev!=0 ){ db_find_and_open_repository(0, 0); verify_all_options(); ls_cmd_rev(zRev,verboseFlag,showAge,timeOrder,treeFmt); return; |
︙ | ︙ | |||
943 944 945 946 947 948 949 950 951 952 953 954 955 956 | ** Usage: %fossil tree ?OPTIONS? ?PATHS ...? ** ** List all files in the current check-out in after the fashion of the ** "tree" command. If PATHS is included, only the named files ** (or their children if directories) are shown. ** ** Options: ** -r VERSION The specific check-in to list ** -R|--repository REPO Extract info from repository REPO ** ** See also: [[ls]] */ void tree_cmd(void){ const char *zRev; | > > | > > > > > > > | | 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 | ** Usage: %fossil tree ?OPTIONS? ?PATHS ...? ** ** List all files in the current check-out in after the fashion of the ** "tree" command. If PATHS is included, only the named files ** (or their children if directories) are shown. ** ** Options: ** -a|--ascii-tree Use ASCII characters when drawing the tree ** -r VERSION The specific check-in to list ** -R|--repository REPO Extract info from repository REPO ** -u|--unicode-tree Use Unicode symbols when drawing the tree ** ** See also: [[ls]] */ void tree_cmd(void){ const char *zRev; int treeFmt = 1; int asciiTree = find_option("ascii-tree","a",0)!=0; int unicodeTree = find_option("unicode-tree","u",0)!=0; #ifdef _WIN32 treeFmt = 2; #endif if( unicodeTree ) treeFmt = 1; if( asciiTree ) treeFmt = 2; zRev = find_option("r","r",1); if( zRev==0 ) zRev = "current"; db_find_and_open_repository(0, 0); verify_all_options(); ls_cmd_rev(zRev, 0, 0, 0, treeFmt); } /* ** COMMAND: extras ** ** Usage: %fossil extras ?OPTIONS? ?PATH1 ...? ** |
︙ | ︙ | |||
979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 | ** option, whose CSG argument is a comma-separated list of glob patterns. ** ** Pathnames are displayed according to the "relative-paths" setting, ** unless overridden by the --abs-paths or --rel-paths options. ** ** Options: ** --abs-paths Display absolute pathnames ** --case-sensitive BOOL Override case-sensitive setting ** --dotfiles Include files beginning with a dot (".") ** --header Identify the repository if there are extras ** --ignore CSG Ignore files matching patterns from the argument ** --rel-paths Display pathnames relative to the current working ** directory ** --tree Show output in the tree format ** ** See also: [[changes]], [[clean]], [[status]] */ void extras_cmd(void){ Blob report = BLOB_INITIALIZER; const char *zIgnoreFlag = find_option("ignore",0,1); unsigned scanFlags = find_option("dotfiles",0,0)!=0 ? SCAN_ALL : 0; unsigned flags = C_EXTRA; int showHdr = find_option("header",0,0)!=0; int treeFmt = find_option("tree",0,0)!=0; Glob *pIgnore; if( find_option("temp",0,0)!=0 ) scanFlags |= SCAN_TEMP; db_must_be_within_tree(); if( determine_cwd_relative_option() ){ flags |= C_RELPATH; } if( db_get_boolean("dotfiles", 0) ) scanFlags |= SCAN_ALL; if( treeFmt ){ flags &= ~C_RELPATH; } /* We should be done with options.. */ verify_all_options(); if( zIgnoreFlag==0 ){ zIgnoreFlag = db_get("ignore-glob", 0); } pIgnore = glob_create(zIgnoreFlag); locate_unmanaged_files(g.argc-2, g.argv+2, scanFlags, pIgnore); glob_free(pIgnore); blob_zero(&report); status_report(&report, flags); if( blob_size(&report) ){ if( showHdr ){ fossil_print("Extras for %s at %s:\n", db_get("project-name","<unnamed>"), g.zLocalRoot); } if( treeFmt ){ | > > > > > > > > > | | 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 | ** option, whose CSG argument is a comma-separated list of glob patterns. ** ** Pathnames are displayed according to the "relative-paths" setting, ** unless overridden by the --abs-paths or --rel-paths options. ** ** Options: ** --abs-paths Display absolute pathnames ** -a|--ascii-tree Use ASCII characters when drawing the tree ** --case-sensitive BOOL Override case-sensitive setting ** --dotfiles Include files beginning with a dot (".") ** --header Identify the repository if there are extras ** --ignore CSG Ignore files matching patterns from the argument ** --rel-paths Display pathnames relative to the current working ** directory ** --tree Show output in the tree format ** -u|--unicode-tree Use Unicode symbols when drawing the tree ** ** See also: [[changes]], [[clean]], [[status]] */ void extras_cmd(void){ Blob report = BLOB_INITIALIZER; const char *zIgnoreFlag = find_option("ignore",0,1); unsigned scanFlags = find_option("dotfiles",0,0)!=0 ? SCAN_ALL : 0; unsigned flags = C_EXTRA; int showHdr = find_option("header",0,0)!=0; int treeFmt = find_option("tree",0,0)!=0; int asciiTree = find_option("ascii-tree","a",0)!=0; int unicodeTree = find_option("unicode-tree","u",0)!=0; Glob *pIgnore; if( find_option("temp",0,0)!=0 ) scanFlags |= SCAN_TEMP; db_must_be_within_tree(); if( determine_cwd_relative_option() ){ flags |= C_RELPATH; } if( db_get_boolean("dotfiles", 0) ) scanFlags |= SCAN_ALL; if( treeFmt ){ flags &= ~C_RELPATH; #ifdef _WIN32 treeFmt = 2; #endif if( unicodeTree ) treeFmt = 1; if( asciiTree ) treeFmt = 2; } /* We should be done with options.. */ verify_all_options(); if( zIgnoreFlag==0 ){ zIgnoreFlag = db_get("ignore-glob", 0); } pIgnore = glob_create(zIgnoreFlag); locate_unmanaged_files(g.argc-2, g.argv+2, scanFlags, pIgnore); glob_free(pIgnore); blob_zero(&report); status_report(&report, flags); if( blob_size(&report) ){ if( showHdr ){ fossil_print("Extras for %s at %s:\n", db_get("project-name","<unnamed>"), g.zLocalRoot); } if( treeFmt ){ print_filelist_as_tree(&report, treeFmt); }else{ blob_write_to_file(&report, "-"); } } blob_reset(&report); } |
︙ | ︙ |