Fossil SCM

catch up with trunk. Remove C++ style comments from http_ssl.c.

martin.weber 2011-09-06 20:12 UTC msw-hack merge
Commit 0f1c41bc20f8856376cdd65e3355fe399c0361bb
+7
--- auto.def
+++ auto.def
@@ -134,10 +134,17 @@
134134
define FOSSIL_ENABLE_SSL
135135
define-append EXTRA_CFLAGS $cflags
136136
define-append EXTRA_LDFLAGS $ldflags
137137
define-append LIBS -lssl -lcrypto
138138
msg-result "HTTP support enabled"
139
+
140
+ # Silence OpenSSL deprecation warnings on Mac OS X 10.7.
141
+ if {[string match *-darwin* [get-define host]]} {
142
+ if {[cctest -cflags {-Wdeprecated-declarations}]} {
143
+ define-append EXTRA_CFLAGS -Wdeprecated-declarations
144
+ }
145
+ }
139146
} else {
140147
user-error "OpenSSL not found. Consider --with-openssl=none to disable HTTPS support"
141148
}
142149
}
143150
144151
--- auto.def
+++ auto.def
@@ -134,10 +134,17 @@
134 define FOSSIL_ENABLE_SSL
135 define-append EXTRA_CFLAGS $cflags
136 define-append EXTRA_LDFLAGS $ldflags
137 define-append LIBS -lssl -lcrypto
138 msg-result "HTTP support enabled"
 
 
 
 
 
 
 
139 } else {
140 user-error "OpenSSL not found. Consider --with-openssl=none to disable HTTPS support"
141 }
142 }
143
144
--- auto.def
+++ auto.def
@@ -134,10 +134,17 @@
134 define FOSSIL_ENABLE_SSL
135 define-append EXTRA_CFLAGS $cflags
136 define-append EXTRA_LDFLAGS $ldflags
137 define-append LIBS -lssl -lcrypto
138 msg-result "HTTP support enabled"
139
140 # Silence OpenSSL deprecation warnings on Mac OS X 10.7.
141 if {[string match *-darwin* [get-define host]]} {
142 if {[cctest -cflags {-Wdeprecated-declarations}]} {
143 define-append EXTRA_CFLAGS -Wdeprecated-declarations
144 }
145 }
146 } else {
147 user-error "OpenSSL not found. Consider --with-openssl=none to disable HTTPS support"
148 }
149 }
150
151
--- autosetup/autosetup
+++ autosetup/autosetup
@@ -1,11 +1,11 @@
11
#!/bin/sh
22
# Copyright (c) 2006-2011 WorkWare Systems http://www.workware.net.au/
33
# All rights reserved
44
# vim:se syntax=tcl:
55
# \
6
-dir=`dirname "$0"`; exec `"$dir/find-tclsh" || echo false` "$0" "$@"
6
+dir=`dirname "$0"`; exec "`$dir/find-tclsh`" "$0" "$@"
77
88
set autosetup(version) 0.6.2
99
1010
# Can be set to 1 to debug early-init problems
1111
set autosetup(debug) 0
@@ -182,11 +182,11 @@
182182
183183
# @opt-bool option ...
184184
#
185185
# Check each of the named, boolean options and return 1 if any of them have
186186
# been set by the user.
187
-#
187
+#
188188
proc opt-bool {args} {
189189
option-check-names {*}$args
190190
opt_bool ::useropts {*}$args
191191
}
192192
@@ -198,11 +198,11 @@
198198
# If only a single value is required, use something like:
199199
#
200200
## lindex [opt-val $names] end
201201
#
202202
# If no options were set, $default is returned (exactly, not as a list).
203
-#
203
+#
204204
proc opt-val {names {default ""}} {
205205
option-check-names {*}$names
206206
join [opt_val ::useropts $names $default]
207207
}
208208
@@ -396,11 +396,11 @@
396396
# These options are not displayed with --help and can be useful for internal options or as aliases.
397397
#
398398
# For example, --disable-lfs is an alias for --disable=largefile:
399399
#
400400
## lfs=1 largefile=1 => "Disable large file support"
401
-#
401
+#
402402
proc options {optlist} {
403403
# Allow options as a list or args
404404
options-add $optlist "Local Options:"
405405
406406
if {$::autosetup(showhelp)} {
@@ -434,11 +434,11 @@
434434
return $alias
435435
}
436436
}
437437
438438
# @define name ?value=1?
439
-#
439
+#
440440
# Defines the named variable to the given value.
441441
# These (name, value) pairs represent the results of the configuration check
442442
# and are available to be checked, modified and substituted.
443443
#
444444
proc define {name {value 1}} {
@@ -564,10 +564,40 @@
564564
foreach arg $argv {
565565
lappend args [quote-if-needed $arg]
566566
}
567567
join $args
568568
}
569
+
570
+# @suffix suf list
571
+#
572
+# Takes a list and returns a new list with $suf appended
573
+# to each element
574
+#
575
+## suffix .c {a b c} => {a.c b.c c.c}
576
+#
577
+proc suffix {suf list} {
578
+ set result {}
579
+ foreach p $list {
580
+ lappend result $p$suf
581
+ }
582
+ return $result
583
+}
584
+
585
+# @prefix pre list
586
+#
587
+# Takes a list and returns a new list with $pre prepended
588
+# to each element
589
+#
590
+## prefix jim- {a.c b.c} => {jim-a.c jim-b.c}
591
+#
592
+proc prefix {pre list} {
593
+ set result {}
594
+ foreach p $list {
595
+ lappend result $pre$p
596
+ }
597
+ return $result
598
+}
569599
570600
# @find-executable name
571601
#
572602
# Searches the path for an executable with the given name.
573603
# Note that the name may include some parameters, e.g. "cc -mbig-endian",
@@ -999,21 +1029,24 @@
9991029
10001030
# Simple getopt module
10011031
10021032
# Parse everything out of the argv list which looks like an option
10031033
# Knows about --enable-thing and --disable-thing as alternatives for --thing=0 or --thing=1
1034
+# Everything which doesn't look like an option, or is after --, is left unchanged
10041035
proc getopt {argvname} {
10051036
upvar $argvname argv
1037
+ set nargv {}
10061038
10071039
for {set i 0} {$i < [llength $argv]} {incr i} {
10081040
set arg [lindex $argv $i]
10091041
10101042
#dputs arg=$arg
10111043
10121044
if {$arg eq "--"} {
10131045
# End of options
10141046
incr i
1047
+ lappend nargv {*}[lrange $argv $i end]
10151048
break
10161049
}
10171050
10181051
if {[regexp {^--([^=][^=]+)=(.*)$} $arg -> name value]} {
10191052
lappend opts($name) $value
@@ -1023,18 +1056,18 @@
10231056
} else {
10241057
set value 1
10251058
}
10261059
lappend opts($name) $value
10271060
} else {
1028
- break
1061
+ lappend nargv $arg
10291062
}
10301063
}
10311064
1032
- #puts "getopt: argv=[join $argv] => [join [lrange $argv $i end]]"
1065
+ #puts "getopt: argv=[join $argv] => [join $nargv]"
10331066
#parray opts
10341067
1035
- set argv [lrange $argv $i end]
1068
+ set argv $nargv
10361069
10371070
return [array get opts]
10381071
}
10391072
10401073
proc opt_val {optarrayname options {default {}}} {
@@ -1264,11 +1297,11 @@
12641297
writefile configure "#!/bin/sh\nWRAPPER=\"\$0\" exec $::autosetup(dir)/autosetup \"\$@\"\n"
12651298
} else {
12661299
writefile configure \
12671300
{#!/bin/sh
12681301
dir="`dirname "$0"`/autosetup"
1269
-WRAPPER="$0" exec `"$dir/find-tclsh" || echo false` "$dir/autosetup" "$@"
1302
+WRAPPER="$0" exec "`$dir/find-tclsh`" "$dir/autosetup" "$@"
12701303
}
12711304
}
12721305
catch {exec chmod 755 configure}
12731306
}
12741307
if {![file exists auto.def]} {
@@ -1279,11 +1312,11 @@
12791312
12801313
# Add any user options here
12811314
options {
12821315
}
12831316
1284
-make-autoconf-h config.h
1317
+make-config-header config.h
12851318
make-template Makefile.in
12861319
}
12871320
}
12881321
if {![file exists Makefile.in]} {
12891322
puts "Note: I don't see Makefile.in. You will probably need to create one."
@@ -1511,11 +1544,11 @@
15111544
string map {\\ /} [env $name {*}$args]
15121545
}
15131546
# Jim uses system() for exec under mingw, so
15141547
# we need to fetch the output ourselves
15151548
proc exec-with-stderr {args} {
1516
- set tmpfile /tmp/autosetup.[format %05x [rand 10000]].tmp
1549
+ set tmpfile auto[format %04x [rand 10000]].tmp
15171550
set rc [catch [list exec {*}$args >$tmpfile 2>&1] result]
15181551
set result [readfile $tmpfile]
15191552
file delete $tmpfile
15201553
return -code $rc $result
15211554
}
15221555
--- autosetup/autosetup
+++ autosetup/autosetup
@@ -1,11 +1,11 @@
1 #!/bin/sh
2 # Copyright (c) 2006-2011 WorkWare Systems http://www.workware.net.au/
3 # All rights reserved
4 # vim:se syntax=tcl:
5 # \
6 dir=`dirname "$0"`; exec `"$dir/find-tclsh" || echo false` "$0" "$@"
7
8 set autosetup(version) 0.6.2
9
10 # Can be set to 1 to debug early-init problems
11 set autosetup(debug) 0
@@ -182,11 +182,11 @@
182
183 # @opt-bool option ...
184 #
185 # Check each of the named, boolean options and return 1 if any of them have
186 # been set by the user.
187 #
188 proc opt-bool {args} {
189 option-check-names {*}$args
190 opt_bool ::useropts {*}$args
191 }
192
@@ -198,11 +198,11 @@
198 # If only a single value is required, use something like:
199 #
200 ## lindex [opt-val $names] end
201 #
202 # If no options were set, $default is returned (exactly, not as a list).
203 #
204 proc opt-val {names {default ""}} {
205 option-check-names {*}$names
206 join [opt_val ::useropts $names $default]
207 }
208
@@ -396,11 +396,11 @@
396 # These options are not displayed with --help and can be useful for internal options or as aliases.
397 #
398 # For example, --disable-lfs is an alias for --disable=largefile:
399 #
400 ## lfs=1 largefile=1 => "Disable large file support"
401 #
402 proc options {optlist} {
403 # Allow options as a list or args
404 options-add $optlist "Local Options:"
405
406 if {$::autosetup(showhelp)} {
@@ -434,11 +434,11 @@
434 return $alias
435 }
436 }
437
438 # @define name ?value=1?
439 #
440 # Defines the named variable to the given value.
441 # These (name, value) pairs represent the results of the configuration check
442 # and are available to be checked, modified and substituted.
443 #
444 proc define {name {value 1}} {
@@ -564,10 +564,40 @@
564 foreach arg $argv {
565 lappend args [quote-if-needed $arg]
566 }
567 join $args
568 }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
569
570 # @find-executable name
571 #
572 # Searches the path for an executable with the given name.
573 # Note that the name may include some parameters, e.g. "cc -mbig-endian",
@@ -999,21 +1029,24 @@
999
1000 # Simple getopt module
1001
1002 # Parse everything out of the argv list which looks like an option
1003 # Knows about --enable-thing and --disable-thing as alternatives for --thing=0 or --thing=1
 
1004 proc getopt {argvname} {
1005 upvar $argvname argv
 
1006
1007 for {set i 0} {$i < [llength $argv]} {incr i} {
1008 set arg [lindex $argv $i]
1009
1010 #dputs arg=$arg
1011
1012 if {$arg eq "--"} {
1013 # End of options
1014 incr i
 
1015 break
1016 }
1017
1018 if {[regexp {^--([^=][^=]+)=(.*)$} $arg -> name value]} {
1019 lappend opts($name) $value
@@ -1023,18 +1056,18 @@
1023 } else {
1024 set value 1
1025 }
1026 lappend opts($name) $value
1027 } else {
1028 break
1029 }
1030 }
1031
1032 #puts "getopt: argv=[join $argv] => [join [lrange $argv $i end]]"
1033 #parray opts
1034
1035 set argv [lrange $argv $i end]
1036
1037 return [array get opts]
1038 }
1039
1040 proc opt_val {optarrayname options {default {}}} {
@@ -1264,11 +1297,11 @@
1264 writefile configure "#!/bin/sh\nWRAPPER=\"\$0\" exec $::autosetup(dir)/autosetup \"\$@\"\n"
1265 } else {
1266 writefile configure \
1267 {#!/bin/sh
1268 dir="`dirname "$0"`/autosetup"
1269 WRAPPER="$0" exec `"$dir/find-tclsh" || echo false` "$dir/autosetup" "$@"
1270 }
1271 }
1272 catch {exec chmod 755 configure}
1273 }
1274 if {![file exists auto.def]} {
@@ -1279,11 +1312,11 @@
1279
1280 # Add any user options here
1281 options {
1282 }
1283
1284 make-autoconf-h config.h
1285 make-template Makefile.in
1286 }
1287 }
1288 if {![file exists Makefile.in]} {
1289 puts "Note: I don't see Makefile.in. You will probably need to create one."
@@ -1511,11 +1544,11 @@
1511 string map {\\ /} [env $name {*}$args]
1512 }
1513 # Jim uses system() for exec under mingw, so
1514 # we need to fetch the output ourselves
1515 proc exec-with-stderr {args} {
1516 set tmpfile /tmp/autosetup.[format %05x [rand 10000]].tmp
1517 set rc [catch [list exec {*}$args >$tmpfile 2>&1] result]
1518 set result [readfile $tmpfile]
1519 file delete $tmpfile
1520 return -code $rc $result
1521 }
1522
--- autosetup/autosetup
+++ autosetup/autosetup
@@ -1,11 +1,11 @@
1 #!/bin/sh
2 # Copyright (c) 2006-2011 WorkWare Systems http://www.workware.net.au/
3 # All rights reserved
4 # vim:se syntax=tcl:
5 # \
6 dir=`dirname "$0"`; exec "`$dir/find-tclsh`" "$0" "$@"
7
8 set autosetup(version) 0.6.2
9
10 # Can be set to 1 to debug early-init problems
11 set autosetup(debug) 0
@@ -182,11 +182,11 @@
182
183 # @opt-bool option ...
184 #
185 # Check each of the named, boolean options and return 1 if any of them have
186 # been set by the user.
187 #
188 proc opt-bool {args} {
189 option-check-names {*}$args
190 opt_bool ::useropts {*}$args
191 }
192
@@ -198,11 +198,11 @@
198 # If only a single value is required, use something like:
199 #
200 ## lindex [opt-val $names] end
201 #
202 # If no options were set, $default is returned (exactly, not as a list).
203 #
204 proc opt-val {names {default ""}} {
205 option-check-names {*}$names
206 join [opt_val ::useropts $names $default]
207 }
208
@@ -396,11 +396,11 @@
396 # These options are not displayed with --help and can be useful for internal options or as aliases.
397 #
398 # For example, --disable-lfs is an alias for --disable=largefile:
399 #
400 ## lfs=1 largefile=1 => "Disable large file support"
401 #
402 proc options {optlist} {
403 # Allow options as a list or args
404 options-add $optlist "Local Options:"
405
406 if {$::autosetup(showhelp)} {
@@ -434,11 +434,11 @@
434 return $alias
435 }
436 }
437
438 # @define name ?value=1?
439 #
440 # Defines the named variable to the given value.
441 # These (name, value) pairs represent the results of the configuration check
442 # and are available to be checked, modified and substituted.
443 #
444 proc define {name {value 1}} {
@@ -564,10 +564,40 @@
564 foreach arg $argv {
565 lappend args [quote-if-needed $arg]
566 }
567 join $args
568 }
569
570 # @suffix suf list
571 #
572 # Takes a list and returns a new list with $suf appended
573 # to each element
574 #
575 ## suffix .c {a b c} => {a.c b.c c.c}
576 #
577 proc suffix {suf list} {
578 set result {}
579 foreach p $list {
580 lappend result $p$suf
581 }
582 return $result
583 }
584
585 # @prefix pre list
586 #
587 # Takes a list and returns a new list with $pre prepended
588 # to each element
589 #
590 ## prefix jim- {a.c b.c} => {jim-a.c jim-b.c}
591 #
592 proc prefix {pre list} {
593 set result {}
594 foreach p $list {
595 lappend result $pre$p
596 }
597 return $result
598 }
599
600 # @find-executable name
601 #
602 # Searches the path for an executable with the given name.
603 # Note that the name may include some parameters, e.g. "cc -mbig-endian",
@@ -999,21 +1029,24 @@
1029
1030 # Simple getopt module
1031
1032 # Parse everything out of the argv list which looks like an option
1033 # Knows about --enable-thing and --disable-thing as alternatives for --thing=0 or --thing=1
1034 # Everything which doesn't look like an option, or is after --, is left unchanged
1035 proc getopt {argvname} {
1036 upvar $argvname argv
1037 set nargv {}
1038
1039 for {set i 0} {$i < [llength $argv]} {incr i} {
1040 set arg [lindex $argv $i]
1041
1042 #dputs arg=$arg
1043
1044 if {$arg eq "--"} {
1045 # End of options
1046 incr i
1047 lappend nargv {*}[lrange $argv $i end]
1048 break
1049 }
1050
1051 if {[regexp {^--([^=][^=]+)=(.*)$} $arg -> name value]} {
1052 lappend opts($name) $value
@@ -1023,18 +1056,18 @@
1056 } else {
1057 set value 1
1058 }
1059 lappend opts($name) $value
1060 } else {
1061 lappend nargv $arg
1062 }
1063 }
1064
1065 #puts "getopt: argv=[join $argv] => [join $nargv]"
1066 #parray opts
1067
1068 set argv $nargv
1069
1070 return [array get opts]
1071 }
1072
1073 proc opt_val {optarrayname options {default {}}} {
@@ -1264,11 +1297,11 @@
1297 writefile configure "#!/bin/sh\nWRAPPER=\"\$0\" exec $::autosetup(dir)/autosetup \"\$@\"\n"
1298 } else {
1299 writefile configure \
1300 {#!/bin/sh
1301 dir="`dirname "$0"`/autosetup"
1302 WRAPPER="$0" exec "`$dir/find-tclsh`" "$dir/autosetup" "$@"
1303 }
1304 }
1305 catch {exec chmod 755 configure}
1306 }
1307 if {![file exists auto.def]} {
@@ -1279,11 +1312,11 @@
1312
1313 # Add any user options here
1314 options {
1315 }
1316
1317 make-config-header config.h
1318 make-template Makefile.in
1319 }
1320 }
1321 if {![file exists Makefile.in]} {
1322 puts "Note: I don't see Makefile.in. You will probably need to create one."
@@ -1511,11 +1544,11 @@
1544 string map {\\ /} [env $name {*}$args]
1545 }
1546 # Jim uses system() for exec under mingw, so
1547 # we need to fetch the output ourselves
1548 proc exec-with-stderr {args} {
1549 set tmpfile auto[format %04x [rand 10000]].tmp
1550 set rc [catch [list exec {*}$args >$tmpfile 2>&1] result]
1551 set result [readfile $tmpfile]
1552 file delete $tmpfile
1553 return -code $rc $result
1554 }
1555
--- autosetup/cc-lib.tcl
+++ autosetup/cc-lib.tcl
@@ -48,21 +48,21 @@
4848
cc-check-includes sys/types.h sys/param.h
4949
set rc 0
5050
msg-checking "Checking endian..."
5151
cc-with {-includes {sys/types.h sys/param.h}} {
5252
if {[cctest -code {
53
- #if! defined(BIG_ENDIAN) || !defined(BYTE_ORDER)
53
+ #if !defined(BIG_ENDIAN) || !defined(BYTE_ORDER)
5454
#error unknown
5555
#elif BYTE_ORDER != BIG_ENDIAN
5656
#error little
5757
#endif
5858
}]} {
5959
define-feature big-endian
6060
msg-result "big"
6161
set rc 1
6262
} elseif {[cctest -code {
63
- #if! defined(LITTLE_ENDIAN) || !defined(BYTE_ORDER)
63
+ #if !defined(LITTLE_ENDIAN) || !defined(BYTE_ORDER)
6464
#error unknown
6565
#elif BYTE_ORDER != LITTLE_ENDIAN
6666
#error big
6767
#endif
6868
}]} {
6969
--- autosetup/cc-lib.tcl
+++ autosetup/cc-lib.tcl
@@ -48,21 +48,21 @@
48 cc-check-includes sys/types.h sys/param.h
49 set rc 0
50 msg-checking "Checking endian..."
51 cc-with {-includes {sys/types.h sys/param.h}} {
52 if {[cctest -code {
53 #if! defined(BIG_ENDIAN) || !defined(BYTE_ORDER)
54 #error unknown
55 #elif BYTE_ORDER != BIG_ENDIAN
56 #error little
57 #endif
58 }]} {
59 define-feature big-endian
60 msg-result "big"
61 set rc 1
62 } elseif {[cctest -code {
63 #if! defined(LITTLE_ENDIAN) || !defined(BYTE_ORDER)
64 #error unknown
65 #elif BYTE_ORDER != LITTLE_ENDIAN
66 #error big
67 #endif
68 }]} {
69
--- autosetup/cc-lib.tcl
+++ autosetup/cc-lib.tcl
@@ -48,21 +48,21 @@
48 cc-check-includes sys/types.h sys/param.h
49 set rc 0
50 msg-checking "Checking endian..."
51 cc-with {-includes {sys/types.h sys/param.h}} {
52 if {[cctest -code {
53 #if !defined(BIG_ENDIAN) || !defined(BYTE_ORDER)
54 #error unknown
55 #elif BYTE_ORDER != BIG_ENDIAN
56 #error little
57 #endif
58 }]} {
59 define-feature big-endian
60 msg-result "big"
61 set rc 1
62 } elseif {[cctest -code {
63 #if !defined(LITTLE_ENDIAN) || !defined(BYTE_ORDER)
64 #error unknown
65 #elif BYTE_ORDER != LITTLE_ENDIAN
66 #error big
67 #endif
68 }]} {
69
--- autosetup/cc-shared.tcl
+++ autosetup/cc-shared.tcl
@@ -35,14 +35,29 @@
3535
}
3636
*-*-cygwin {
3737
define SH_LDFLAGS -shared
3838
define SHOBJ_LDFLAGS -shared
3939
}
40
+ *-*-solaris* {
41
+ # XXX: These haven't been fully tested.
42
+ #define SH_LINKFLAGS -Wl,-export-dynamic
43
+ define SH_CFLAGS -Kpic
44
+ define SHOBJ_CFLAGS -Kpic
45
+ define SHOBJ_LDFLAGS "-G"
46
+ }
47
+ *-*-hpux {
48
+ # XXX: These haven't been tested
49
+ define SH_LINKFLAGS -Wl,+s
50
+ define SH_CFLAGS +z
51
+ define SHOBJ_CFLAGS "+O3 +z"
52
+ define SHOBJ_LDFLAGS -b
53
+ define LD_LIBRARY_PATH SHLIB_PATH
54
+ }
4055
* {
4156
# Generic Unix settings
4257
define SH_LINKFLAGS -rdynamic
43
- define SH_CFLAGS -fPIC
58
+ define SH_CFLAGS -fpic
4459
define SH_LDFLAGS -shared
45
- define SHOBJ_CFLAGS -fPIC
60
+ define SHOBJ_CFLAGS -fpic
4661
define SHOBJ_LDFLAGS "-shared -nostartfiles"
4762
}
4863
}
4964
--- autosetup/cc-shared.tcl
+++ autosetup/cc-shared.tcl
@@ -35,14 +35,29 @@
35 }
36 *-*-cygwin {
37 define SH_LDFLAGS -shared
38 define SHOBJ_LDFLAGS -shared
39 }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
40 * {
41 # Generic Unix settings
42 define SH_LINKFLAGS -rdynamic
43 define SH_CFLAGS -fPIC
44 define SH_LDFLAGS -shared
45 define SHOBJ_CFLAGS -fPIC
46 define SHOBJ_LDFLAGS "-shared -nostartfiles"
47 }
48 }
49
--- autosetup/cc-shared.tcl
+++ autosetup/cc-shared.tcl
@@ -35,14 +35,29 @@
35 }
36 *-*-cygwin {
37 define SH_LDFLAGS -shared
38 define SHOBJ_LDFLAGS -shared
39 }
40 *-*-solaris* {
41 # XXX: These haven't been fully tested.
42 #define SH_LINKFLAGS -Wl,-export-dynamic
43 define SH_CFLAGS -Kpic
44 define SHOBJ_CFLAGS -Kpic
45 define SHOBJ_LDFLAGS "-G"
46 }
47 *-*-hpux {
48 # XXX: These haven't been tested
49 define SH_LINKFLAGS -Wl,+s
50 define SH_CFLAGS +z
51 define SHOBJ_CFLAGS "+O3 +z"
52 define SHOBJ_LDFLAGS -b
53 define LD_LIBRARY_PATH SHLIB_PATH
54 }
55 * {
56 # Generic Unix settings
57 define SH_LINKFLAGS -rdynamic
58 define SH_CFLAGS -fpic
59 define SH_LDFLAGS -shared
60 define SHOBJ_CFLAGS -fpic
61 define SHOBJ_LDFLAGS "-shared -nostartfiles"
62 }
63 }
64
--- autosetup/cc.tcl
+++ autosetup/cc.tcl
@@ -331,17 +331,11 @@
331331
# simply replaces the existing value.
332332
#
333333
# Returns the previous settings
334334
proc cc-update-settings {args} {
335335
set prev [cc-get-settings]
336
- array set new $prev
337
-
338
- foreach {name value} $args {
339
- set new($name) $value
340
- }
341
- cc-store-settings $new
342
-
336
+ cc-store-settings [dict merge $prev $args]
343337
return $prev
344338
}
345339
346340
# @cc-with settings ?{ script }?
347341
#
@@ -416,11 +410,11 @@
416410
#
417411
# Any failures are recorded in 'config.log'
418412
#
419413
proc cctest {args} {
420414
set src conftest__.c
421
- set tmp conftest__.o
415
+ set tmp conftest__
422416
423417
# Easiest way to merge in the settings
424418
cc-with $args {
425419
array set opts [cc-get-settings]
426420
}
@@ -468,10 +462,11 @@
468462
autosetup-error "cctest called with unknown language: $opts(-lang)"
469463
}
470464
}
471465
472466
if {!$opts(-link)} {
467
+ set tmp conftest__.o
473468
lappend cmdline -c
474469
}
475470
lappend cmdline {*}$opts(-cflags)
476471
477472
switch -glob -- [get-define host] {
478473
--- autosetup/cc.tcl
+++ autosetup/cc.tcl
@@ -331,17 +331,11 @@
331 # simply replaces the existing value.
332 #
333 # Returns the previous settings
334 proc cc-update-settings {args} {
335 set prev [cc-get-settings]
336 array set new $prev
337
338 foreach {name value} $args {
339 set new($name) $value
340 }
341 cc-store-settings $new
342
343 return $prev
344 }
345
346 # @cc-with settings ?{ script }?
347 #
@@ -416,11 +410,11 @@
416 #
417 # Any failures are recorded in 'config.log'
418 #
419 proc cctest {args} {
420 set src conftest__.c
421 set tmp conftest__.o
422
423 # Easiest way to merge in the settings
424 cc-with $args {
425 array set opts [cc-get-settings]
426 }
@@ -468,10 +462,11 @@
468 autosetup-error "cctest called with unknown language: $opts(-lang)"
469 }
470 }
471
472 if {!$opts(-link)} {
 
473 lappend cmdline -c
474 }
475 lappend cmdline {*}$opts(-cflags)
476
477 switch -glob -- [get-define host] {
478
--- autosetup/cc.tcl
+++ autosetup/cc.tcl
@@ -331,17 +331,11 @@
331 # simply replaces the existing value.
332 #
333 # Returns the previous settings
334 proc cc-update-settings {args} {
335 set prev [cc-get-settings]
336 cc-store-settings [dict merge $prev $args]
 
 
 
 
 
 
337 return $prev
338 }
339
340 # @cc-with settings ?{ script }?
341 #
@@ -416,11 +410,11 @@
410 #
411 # Any failures are recorded in 'config.log'
412 #
413 proc cctest {args} {
414 set src conftest__.c
415 set tmp conftest__
416
417 # Easiest way to merge in the settings
418 cc-with $args {
419 array set opts [cc-get-settings]
420 }
@@ -468,10 +462,11 @@
462 autosetup-error "cctest called with unknown language: $opts(-lang)"
463 }
464 }
465
466 if {!$opts(-link)} {
467 set tmp conftest__.o
468 lappend cmdline -c
469 }
470 lappend cmdline {*}$opts(-cflags)
471
472 switch -glob -- [get-define host] {
473
--- autosetup/system.tcl
+++ autosetup/system.tcl
@@ -6,28 +6,32 @@
66
# This module supports common system interrogation and options
77
# such as --host, --build, --prefix, and setting srcdir, builddir, and EXEXT.
88
#
99
# It also support the 'feature' naming convention, where searching
1010
# for a feature such as sys/type.h defines HAVE_SYS_TYPES_H
11
-
12
-# Note that the hidden options are supported for autoconf compatibility
13
-
11
+#
1412
module-options {
1513
host:host-alias => {a complete or partial cpu-vendor-opsys for the system where
1614
the application will run (defaults to the same value as --build)}
1715
build:build-alias => {a complete or partial cpu-vendor-opsys for the system
1816
where the application will be built (defaults to the
1917
result of running config.guess)}
2018
prefix:dir => {the target directory for the build (defaults to /usr/local)}
2119
20
+ # These (hidden) options are supported for autoconf/automake compatibility
21
+ exec-prefix:
22
+ bindir:
23
+ sbindir:
2224
includedir:
2325
mandir:
2426
infodir:
2527
libexecdir:
28
+ datadir:
29
+ libdir:
2630
sysconfdir:
31
+ sharedstatedir:
2732
localstatedir:
28
-
2933
maintainer-mode=0
3034
dependency-tracking=0
3135
}
3236
3337
# Returns 1 if exists, or 0 if not
@@ -107,10 +111,28 @@
107111
#
108112
# The special value @srcdir@ is subsituted with the relative
109113
# path to the source directory from the directory where the output
110114
# file is created. Use @top_srcdir@ for the absolute path.
111115
#
116
+# Conditional sections may be specified as follows:
117
+## @if name == value
118
+## lines
119
+## @else
120
+## lines
121
+## @endif
122
+#
123
+# Where 'name' is a defined variable name and @else is optional.
124
+# If the expression does not match, all lines through '@endif' are ignored.
125
+#
126
+# The alternative forms may also be used:
127
+## @if name
128
+## @if name != value
129
+#
130
+# Where the first form is true if the variable is defined, but not empty or 0
131
+#
132
+# Currently these expressions can't be nested.
133
+#
112134
proc make-template {template {out {}}} {
113135
set infile [file join $::autosetup(srcdir) $template]
114136
115137
if {![file exists $infile]} {
116138
user-error "Template $template is missing"
@@ -136,11 +158,43 @@
136158
137159
set mapping {}
138160
foreach {n v} [array get ::define] {
139161
lappend mapping @$n@ $v
140162
}
141
- writefile $out [string map $mapping [readfile $infile]]\n
163
+ set result {}
164
+ foreach line [split [readfile $infile] \n] {
165
+ if {[info exists cond]} {
166
+ set l [string trimright $line]
167
+ if {$l eq "@endif"} {
168
+ unset cond
169
+ continue
170
+ }
171
+ if {$l eq "@else"} {
172
+ set cond [expr {!$cond}]
173
+ continue
174
+ }
175
+ if {$cond} {
176
+ lappend result $line
177
+ }
178
+ continue
179
+ }
180
+ if {[regexp {^@if\s+(\w+)(.*)} $line -> name expression]} {
181
+ lassign $expression equal value
182
+ set varval [get-define $name ""]
183
+ if {$equal eq ""} {
184
+ set cond [expr {$varval ni {"" 0}}]
185
+ } else {
186
+ set cond [expr {$varval eq $value}]
187
+ if {$equal ne "=="} {
188
+ set cond [expr {!$cond}]
189
+ }
190
+ }
191
+ continue
192
+ }
193
+ lappend result $line
194
+ }
195
+ writefile $out [string map $mapping [join $result \n]]\n
142196
143197
msg-result "Created [relative-path $out] from [relative-path $template]"
144198
}
145199
146200
# build/host tuples and cross-compilation prefix
@@ -171,23 +225,27 @@
171225
define builddir $autosetup(builddir)
172226
define srcdir $autosetup(srcdir)
173227
# Allow this to come from the environment
174228
define top_srcdir [get-env top_srcdir [get-define srcdir]]
175229
176
-# And less common ones too
177
-define exec_prefix \${prefix}
178
-define bindir \${exec_prefix}/bin
179
-define sbindir \${exec_prefix}/sbin
180
-define libexecdir [get-env libexecdir \${exec_prefix}/libexec]
181
-define datadir \${prefix}/share
182
-define sysconfdir [get-env sysconfdir \${prefix}/etc]
183
-define sharedstatedir \${prefix}/com
184
-define localstatedir [get-env localstatedir \${prefix}/var]
185
-define libdir \${exec_prefix}/lib
186
-define infodir [get-env infodir \${prefix}/share/info]
187
-define mandir [get-env mandir \${prefix}/share/man]
188
-define includedir [get-env includdir \${prefix}/include]
230
+# autoconf supports all of these
231
+define exec_prefix [opt-val exec-prefix [get-env exec-prefix \${prefix}]]
232
+foreach {name defpath} {
233
+ bindir \${exec_prefix}/bin
234
+ sbindir \${exec_prefix}/sbin
235
+ libexecdir \${exec_prefix}/libexec
236
+ libdir \${exec_prefix}/lib
237
+ datadir \${prefix}/share
238
+ sysconfdir \${prefix}/etc
239
+ sharedstatedir \${prefix}/com
240
+ localstatedir \${prefix}/var
241
+ infodir \${prefix}/share/info
242
+ mandir \${prefix}/share/man
243
+ includedir \${prefix}/include
244
+} {
245
+ define $name [opt-val $name [get-env $name $defpath]]
246
+}
189247
190248
define SHELL [get-env SHELL [find-an-executable sh bash ksh]]
191249
192250
# Windows vs. non-Windows
193251
switch -glob -- [get-define host] {
194252
--- autosetup/system.tcl
+++ autosetup/system.tcl
@@ -6,28 +6,32 @@
6 # This module supports common system interrogation and options
7 # such as --host, --build, --prefix, and setting srcdir, builddir, and EXEXT.
8 #
9 # It also support the 'feature' naming convention, where searching
10 # for a feature such as sys/type.h defines HAVE_SYS_TYPES_H
11
12 # Note that the hidden options are supported for autoconf compatibility
13
14 module-options {
15 host:host-alias => {a complete or partial cpu-vendor-opsys for the system where
16 the application will run (defaults to the same value as --build)}
17 build:build-alias => {a complete or partial cpu-vendor-opsys for the system
18 where the application will be built (defaults to the
19 result of running config.guess)}
20 prefix:dir => {the target directory for the build (defaults to /usr/local)}
21
 
 
 
 
22 includedir:
23 mandir:
24 infodir:
25 libexecdir:
 
 
26 sysconfdir:
 
27 localstatedir:
28
29 maintainer-mode=0
30 dependency-tracking=0
31 }
32
33 # Returns 1 if exists, or 0 if not
@@ -107,10 +111,28 @@
107 #
108 # The special value @srcdir@ is subsituted with the relative
109 # path to the source directory from the directory where the output
110 # file is created. Use @top_srcdir@ for the absolute path.
111 #
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
112 proc make-template {template {out {}}} {
113 set infile [file join $::autosetup(srcdir) $template]
114
115 if {![file exists $infile]} {
116 user-error "Template $template is missing"
@@ -136,11 +158,43 @@
136
137 set mapping {}
138 foreach {n v} [array get ::define] {
139 lappend mapping @$n@ $v
140 }
141 writefile $out [string map $mapping [readfile $infile]]\n
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
142
143 msg-result "Created [relative-path $out] from [relative-path $template]"
144 }
145
146 # build/host tuples and cross-compilation prefix
@@ -171,23 +225,27 @@
171 define builddir $autosetup(builddir)
172 define srcdir $autosetup(srcdir)
173 # Allow this to come from the environment
174 define top_srcdir [get-env top_srcdir [get-define srcdir]]
175
176 # And less common ones too
177 define exec_prefix \${prefix}
178 define bindir \${exec_prefix}/bin
179 define sbindir \${exec_prefix}/sbin
180 define libexecdir [get-env libexecdir \${exec_prefix}/libexec]
181 define datadir \${prefix}/share
182 define sysconfdir [get-env sysconfdir \${prefix}/etc]
183 define sharedstatedir \${prefix}/com
184 define localstatedir [get-env localstatedir \${prefix}/var]
185 define libdir \${exec_prefix}/lib
186 define infodir [get-env infodir \${prefix}/share/info]
187 define mandir [get-env mandir \${prefix}/share/man]
188 define includedir [get-env includdir \${prefix}/include]
 
 
 
 
189
190 define SHELL [get-env SHELL [find-an-executable sh bash ksh]]
191
192 # Windows vs. non-Windows
193 switch -glob -- [get-define host] {
194
--- autosetup/system.tcl
+++ autosetup/system.tcl
@@ -6,28 +6,32 @@
6 # This module supports common system interrogation and options
7 # such as --host, --build, --prefix, and setting srcdir, builddir, and EXEXT.
8 #
9 # It also support the 'feature' naming convention, where searching
10 # for a feature such as sys/type.h defines HAVE_SYS_TYPES_H
11 #
 
 
12 module-options {
13 host:host-alias => {a complete or partial cpu-vendor-opsys for the system where
14 the application will run (defaults to the same value as --build)}
15 build:build-alias => {a complete or partial cpu-vendor-opsys for the system
16 where the application will be built (defaults to the
17 result of running config.guess)}
18 prefix:dir => {the target directory for the build (defaults to /usr/local)}
19
20 # These (hidden) options are supported for autoconf/automake compatibility
21 exec-prefix:
22 bindir:
23 sbindir:
24 includedir:
25 mandir:
26 infodir:
27 libexecdir:
28 datadir:
29 libdir:
30 sysconfdir:
31 sharedstatedir:
32 localstatedir:
 
33 maintainer-mode=0
34 dependency-tracking=0
35 }
36
37 # Returns 1 if exists, or 0 if not
@@ -107,10 +111,28 @@
111 #
112 # The special value @srcdir@ is subsituted with the relative
113 # path to the source directory from the directory where the output
114 # file is created. Use @top_srcdir@ for the absolute path.
115 #
116 # Conditional sections may be specified as follows:
117 ## @if name == value
118 ## lines
119 ## @else
120 ## lines
121 ## @endif
122 #
123 # Where 'name' is a defined variable name and @else is optional.
124 # If the expression does not match, all lines through '@endif' are ignored.
125 #
126 # The alternative forms may also be used:
127 ## @if name
128 ## @if name != value
129 #
130 # Where the first form is true if the variable is defined, but not empty or 0
131 #
132 # Currently these expressions can't be nested.
133 #
134 proc make-template {template {out {}}} {
135 set infile [file join $::autosetup(srcdir) $template]
136
137 if {![file exists $infile]} {
138 user-error "Template $template is missing"
@@ -136,11 +158,43 @@
158
159 set mapping {}
160 foreach {n v} [array get ::define] {
161 lappend mapping @$n@ $v
162 }
163 set result {}
164 foreach line [split [readfile $infile] \n] {
165 if {[info exists cond]} {
166 set l [string trimright $line]
167 if {$l eq "@endif"} {
168 unset cond
169 continue
170 }
171 if {$l eq "@else"} {
172 set cond [expr {!$cond}]
173 continue
174 }
175 if {$cond} {
176 lappend result $line
177 }
178 continue
179 }
180 if {[regexp {^@if\s+(\w+)(.*)} $line -> name expression]} {
181 lassign $expression equal value
182 set varval [get-define $name ""]
183 if {$equal eq ""} {
184 set cond [expr {$varval ni {"" 0}}]
185 } else {
186 set cond [expr {$varval eq $value}]
187 if {$equal ne "=="} {
188 set cond [expr {!$cond}]
189 }
190 }
191 continue
192 }
193 lappend result $line
194 }
195 writefile $out [string map $mapping [join $result \n]]\n
196
197 msg-result "Created [relative-path $out] from [relative-path $template]"
198 }
199
200 # build/host tuples and cross-compilation prefix
@@ -171,23 +225,27 @@
225 define builddir $autosetup(builddir)
226 define srcdir $autosetup(srcdir)
227 # Allow this to come from the environment
228 define top_srcdir [get-env top_srcdir [get-define srcdir]]
229
230 # autoconf supports all of these
231 define exec_prefix [opt-val exec-prefix [get-env exec-prefix \${prefix}]]
232 foreach {name defpath} {
233 bindir \${exec_prefix}/bin
234 sbindir \${exec_prefix}/sbin
235 libexecdir \${exec_prefix}/libexec
236 libdir \${exec_prefix}/lib
237 datadir \${prefix}/share
238 sysconfdir \${prefix}/etc
239 sharedstatedir \${prefix}/com
240 localstatedir \${prefix}/var
241 infodir \${prefix}/share/info
242 mandir \${prefix}/share/man
243 includedir \${prefix}/include
244 } {
245 define $name [opt-val $name [get-env $name $defpath]]
246 }
247
248 define SHELL [get-env SHELL [find-an-executable sh bash ksh]]
249
250 # Windows vs. non-Windows
251 switch -glob -- [get-define host] {
252
+1 -1
--- configure
+++ configure
@@ -1,3 +1,3 @@
11
#!/bin/sh
22
dir="`dirname "$0"`/autosetup"
3
-WRAPPER="$0" exec `"$dir/find-tclsh" || echo false` "$dir/autosetup" "$@"
3
+WRAPPER="$0" exec "`$dir/find-tclsh`" "$dir/autosetup" "$@"
44
--- configure
+++ configure
@@ -1,3 +1,3 @@
1 #!/bin/sh
2 dir="`dirname "$0"`/autosetup"
3 WRAPPER="$0" exec `"$dir/find-tclsh" || echo false` "$dir/autosetup" "$@"
4
--- configure
+++ configure
@@ -1,3 +1,3 @@
1 #!/bin/sh
2 dir="`dirname "$0"`/autosetup"
3 WRAPPER="$0" exec "`$dir/find-tclsh`" "$dir/autosetup" "$@"
4
+4 -4
--- src/add.c
+++ src/add.c
@@ -106,13 +106,13 @@
106106
db_multi_exec("UPDATE vfile SET deleted=0"
107107
" WHERE pathname=%Q COLLATE %s", zPath, zCollate);
108108
}else{
109109
char *zFullname = mprintf("%s%s", g.zLocalRoot, zPath);
110110
db_multi_exec(
111
- "INSERT INTO vfile(vid,deleted,rid,mrid,pathname,isexe)"
112
- "VALUES(%d,0,0,0,%Q,%d)",
113
- vid, zPath, file_isexe(zFullname));
111
+ "INSERT INTO vfile(vid,deleted,rid,mrid,pathname,isexe,islink)"
112
+ "VALUES(%d,0,0,0,%Q,%d,%d)",
113
+ vid, zPath, file_isexe(zFullname), file_islink(zFullname));
114114
fossil_free(zFullname);
115115
}
116116
if( db_changes() ){
117117
fossil_print("ADDED %s\n", zPath);
118118
return 1;
@@ -426,11 +426,11 @@
426426
const char * zFile;
427427
const char * zPath;
428428
429429
zFile = db_column_text(&q, 0);
430430
zPath = db_column_text(&q, 1);
431
- if( !file_isfile(zPath) ){
431
+ if( !file_isfile_or_link(zPath) ){
432432
if( !isTest ){
433433
db_multi_exec("UPDATE vfile SET deleted=1 WHERE pathname=%Q", zFile);
434434
}
435435
fossil_print("DELETED %s\n", zFile);
436436
nDelete++;
437437
--- src/add.c
+++ src/add.c
@@ -106,13 +106,13 @@
106 db_multi_exec("UPDATE vfile SET deleted=0"
107 " WHERE pathname=%Q COLLATE %s", zPath, zCollate);
108 }else{
109 char *zFullname = mprintf("%s%s", g.zLocalRoot, zPath);
110 db_multi_exec(
111 "INSERT INTO vfile(vid,deleted,rid,mrid,pathname,isexe)"
112 "VALUES(%d,0,0,0,%Q,%d)",
113 vid, zPath, file_isexe(zFullname));
114 fossil_free(zFullname);
115 }
116 if( db_changes() ){
117 fossil_print("ADDED %s\n", zPath);
118 return 1;
@@ -426,11 +426,11 @@
426 const char * zFile;
427 const char * zPath;
428
429 zFile = db_column_text(&q, 0);
430 zPath = db_column_text(&q, 1);
431 if( !file_isfile(zPath) ){
432 if( !isTest ){
433 db_multi_exec("UPDATE vfile SET deleted=1 WHERE pathname=%Q", zFile);
434 }
435 fossil_print("DELETED %s\n", zFile);
436 nDelete++;
437
--- src/add.c
+++ src/add.c
@@ -106,13 +106,13 @@
106 db_multi_exec("UPDATE vfile SET deleted=0"
107 " WHERE pathname=%Q COLLATE %s", zPath, zCollate);
108 }else{
109 char *zFullname = mprintf("%s%s", g.zLocalRoot, zPath);
110 db_multi_exec(
111 "INSERT INTO vfile(vid,deleted,rid,mrid,pathname,isexe,islink)"
112 "VALUES(%d,0,0,0,%Q,%d,%d)",
113 vid, zPath, file_isexe(zFullname), file_islink(zFullname));
114 fossil_free(zFullname);
115 }
116 if( db_changes() ){
117 fossil_print("ADDED %s\n", zPath);
118 return 1;
@@ -426,11 +426,11 @@
426 const char * zFile;
427 const char * zPath;
428
429 zFile = db_column_text(&q, 0);
430 zPath = db_column_text(&q, 1);
431 if( !file_isfile_or_link(zPath) ){
432 if( !isTest ){
433 db_multi_exec("UPDATE vfile SET deleted=1 WHERE pathname=%Q", zFile);
434 }
435 fossil_print("DELETED %s\n", zFile);
436 nDelete++;
437
+1 -1
--- src/bisect.c
+++ src/bisect.c
@@ -42,11 +42,11 @@
4242
}
4343
bisect.good = db_lget_int("bisect-good", 0);
4444
if( bisect.good==0 ){
4545
fossil_fatal("no \"good\" version has been identified");
4646
}
47
- p = path_shortest(bisect.good, bisect.bad, bisect_option("direct-only"));
47
+ p = path_shortest(bisect.good, bisect.bad, bisect_option("direct-only"), 0);
4848
if( p==0 ){
4949
char *zBad = db_text(0, "SELECT uuid FROM blob WHERE rid=%d", bisect.bad);
5050
char *zGood = db_text(0, "SELECT uuid FROM blob WHERE rid=%d", bisect.good);
5151
fossil_fatal("no path from good ([%S]) to bad ([%S]) or back",
5252
zGood, zBad);
5353
--- src/bisect.c
+++ src/bisect.c
@@ -42,11 +42,11 @@
42 }
43 bisect.good = db_lget_int("bisect-good", 0);
44 if( bisect.good==0 ){
45 fossil_fatal("no \"good\" version has been identified");
46 }
47 p = path_shortest(bisect.good, bisect.bad, bisect_option("direct-only"));
48 if( p==0 ){
49 char *zBad = db_text(0, "SELECT uuid FROM blob WHERE rid=%d", bisect.bad);
50 char *zGood = db_text(0, "SELECT uuid FROM blob WHERE rid=%d", bisect.good);
51 fossil_fatal("no path from good ([%S]) to bad ([%S]) or back",
52 zGood, zBad);
53
--- src/bisect.c
+++ src/bisect.c
@@ -42,11 +42,11 @@
42 }
43 bisect.good = db_lget_int("bisect-good", 0);
44 if( bisect.good==0 ){
45 fossil_fatal("no \"good\" version has been identified");
46 }
47 p = path_shortest(bisect.good, bisect.bad, bisect_option("direct-only"), 0);
48 if( p==0 ){
49 char *zBad = db_text(0, "SELECT uuid FROM blob WHERE rid=%d", bisect.bad);
50 char *zGood = db_text(0, "SELECT uuid FROM blob WHERE rid=%d", bisect.good);
51 fossil_fatal("no path from good ([%S]) to bad ([%S]) or back",
52 zGood, zBad);
53
+26
--- src/blob.c
+++ src/blob.c
@@ -701,10 +701,36 @@
701701
if( got<size ){
702702
blob_resize(pBlob, got);
703703
}
704704
return got;
705705
}
706
+
707
+/*
708
+** Reads symlink destination path and puts int into blob.
709
+** Any prior content of the blob is discarded, not freed.
710
+**
711
+** Returns length of destination path.
712
+**
713
+** On windows, zeros blob and returns 0.
714
+*/
715
+int blob_read_link(Blob *pBlob, const char *zFilename){
716
+#if !defined(_WIN32)
717
+ char zBuf[1024];
718
+ ssize_t len = readlink(zFilename, zBuf, 1023);
719
+ if( len < 0 ){
720
+ fossil_panic("cannot read symbolic link %s", zFilename);
721
+ }
722
+ zBuf[len] = 0; /* null-terminate */
723
+ blob_zero(pBlob);
724
+ blob_appendf(pBlob, "%s", zBuf);
725
+ return len;
726
+#else
727
+ blob_zero(pBlob);
728
+ return 0;
729
+#endif
730
+}
731
+
706732
707733
/*
708734
** Write the content of a blob into a file.
709735
**
710736
** If the filename is blank or "-" then write to standard output.
711737
--- src/blob.c
+++ src/blob.c
@@ -701,10 +701,36 @@
701 if( got<size ){
702 blob_resize(pBlob, got);
703 }
704 return got;
705 }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
706
707 /*
708 ** Write the content of a blob into a file.
709 **
710 ** If the filename is blank or "-" then write to standard output.
711
--- src/blob.c
+++ src/blob.c
@@ -701,10 +701,36 @@
701 if( got<size ){
702 blob_resize(pBlob, got);
703 }
704 return got;
705 }
706
707 /*
708 ** Reads symlink destination path and puts int into blob.
709 ** Any prior content of the blob is discarded, not freed.
710 **
711 ** Returns length of destination path.
712 **
713 ** On windows, zeros blob and returns 0.
714 */
715 int blob_read_link(Blob *pBlob, const char *zFilename){
716 #if !defined(_WIN32)
717 char zBuf[1024];
718 ssize_t len = readlink(zFilename, zBuf, 1023);
719 if( len < 0 ){
720 fossil_panic("cannot read symbolic link %s", zFilename);
721 }
722 zBuf[len] = 0; /* null-terminate */
723 blob_zero(pBlob);
724 blob_appendf(pBlob, "%s", zBuf);
725 return len;
726 #else
727 blob_zero(pBlob);
728 return 0;
729 #endif
730 }
731
732
733 /*
734 ** Write the content of a blob into a file.
735 **
736 ** If the filename is blank or "-" then write to standard output.
737
+21 -3
--- src/branch.c
+++ src/branch.c
@@ -281,13 +281,18 @@
281281
void brlist_page(void){
282282
Stmt q;
283283
int cnt;
284284
int showClosed = P("closed")!=0;
285285
int showAll = P("all")!=0;
286
+ int colorTest = P("colortest")!=0;
286287
287288
login_check_credentials();
288289
if( !g.okRead ){ login_needed(); return; }
290
+ if( colorTest ){
291
+ showClosed = 0;
292
+ showAll = 1;
293
+ }
289294
290295
style_header(showClosed ? "Closed Branches" :
291296
showAll ? "All Branches" : "Open Branches");
292297
style_submenu_element("Timeline", "Timeline", "brtimeline");
293298
if( showClosed ){
@@ -298,10 +303,15 @@
298303
style_submenu_element("Open","Open","brlist");
299304
}else{
300305
style_submenu_element("All", "All", "brlist?all");
301306
style_submenu_element("Closed","Closed","brlist?closed");
302307
}
308
+ if( !colorTest ){
309
+ style_submenu_element("Color-Test", "Color-Test", "brlist?colortest");
310
+ }else{
311
+ style_submenu_element("All", "All", "brlist?all");
312
+ }
303313
login_anonymous_available();
304314
style_sidebox_begin("Nomenclature:", "33%");
305315
@ <ol>
306316
@ <li> An <div class="sideboxDescribed"><a href="brlist">
307317
@ open branch</a></div> is a branch that has one or
@@ -320,20 +330,28 @@
320330
prepareBranchQuery(&q, showAll, showClosed);
321331
cnt = 0;
322332
while( db_step(&q)==SQLITE_ROW ){
323333
const char *zBr = db_column_text(&q, 0);
324334
if( cnt==0 ){
325
- if( showClosed ){
335
+ if( colorTest ){
336
+ @ <h2>Default background colors for all branches:</h2>
337
+ }else if( showAll ){
338
+ @ <h2>All Branches:</h2>
339
+ }else if( showClosed ){
326340
@ <h2>Closed Branches:</h2>
327341
}else{
328342
@ <h2>Open Branches:</h2>
329343
}
330344
@ <ul>
331345
cnt++;
332346
}
333
- if( g.okHistory ){
334
- @ <li><a href="%s(g.zTop)/timeline?r=%T(zBr)">%h(zBr)</a></li>
347
+ if( colorTest ){
348
+ const char *zColor = hash_color(zBr);
349
+ @ <li><span style="background-color: %s(zColor)">
350
+ @ %h(zBr) &rarr; %s(zColor)</span></li>
351
+ }else if( g.okHistory ){
352
+ @ <li><a href="%s(g.zTop)/timeline?r=%T(zBr)")>%h(zBr)</a></li>
335353
}else{
336354
@ <li><b>%h(zBr)</b></li>
337355
}
338356
}
339357
if( cnt ){
340358
--- src/branch.c
+++ src/branch.c
@@ -281,13 +281,18 @@
281 void brlist_page(void){
282 Stmt q;
283 int cnt;
284 int showClosed = P("closed")!=0;
285 int showAll = P("all")!=0;
 
286
287 login_check_credentials();
288 if( !g.okRead ){ login_needed(); return; }
 
 
 
 
289
290 style_header(showClosed ? "Closed Branches" :
291 showAll ? "All Branches" : "Open Branches");
292 style_submenu_element("Timeline", "Timeline", "brtimeline");
293 if( showClosed ){
@@ -298,10 +303,15 @@
298 style_submenu_element("Open","Open","brlist");
299 }else{
300 style_submenu_element("All", "All", "brlist?all");
301 style_submenu_element("Closed","Closed","brlist?closed");
302 }
 
 
 
 
 
303 login_anonymous_available();
304 style_sidebox_begin("Nomenclature:", "33%");
305 @ <ol>
306 @ <li> An <div class="sideboxDescribed"><a href="brlist">
307 @ open branch</a></div> is a branch that has one or
@@ -320,20 +330,28 @@
320 prepareBranchQuery(&q, showAll, showClosed);
321 cnt = 0;
322 while( db_step(&q)==SQLITE_ROW ){
323 const char *zBr = db_column_text(&q, 0);
324 if( cnt==0 ){
325 if( showClosed ){
 
 
 
 
326 @ <h2>Closed Branches:</h2>
327 }else{
328 @ <h2>Open Branches:</h2>
329 }
330 @ <ul>
331 cnt++;
332 }
333 if( g.okHistory ){
334 @ <li><a href="%s(g.zTop)/timeline?r=%T(zBr)">%h(zBr)</a></li>
 
 
 
 
335 }else{
336 @ <li><b>%h(zBr)</b></li>
337 }
338 }
339 if( cnt ){
340
--- src/branch.c
+++ src/branch.c
@@ -281,13 +281,18 @@
281 void brlist_page(void){
282 Stmt q;
283 int cnt;
284 int showClosed = P("closed")!=0;
285 int showAll = P("all")!=0;
286 int colorTest = P("colortest")!=0;
287
288 login_check_credentials();
289 if( !g.okRead ){ login_needed(); return; }
290 if( colorTest ){
291 showClosed = 0;
292 showAll = 1;
293 }
294
295 style_header(showClosed ? "Closed Branches" :
296 showAll ? "All Branches" : "Open Branches");
297 style_submenu_element("Timeline", "Timeline", "brtimeline");
298 if( showClosed ){
@@ -298,10 +303,15 @@
303 style_submenu_element("Open","Open","brlist");
304 }else{
305 style_submenu_element("All", "All", "brlist?all");
306 style_submenu_element("Closed","Closed","brlist?closed");
307 }
308 if( !colorTest ){
309 style_submenu_element("Color-Test", "Color-Test", "brlist?colortest");
310 }else{
311 style_submenu_element("All", "All", "brlist?all");
312 }
313 login_anonymous_available();
314 style_sidebox_begin("Nomenclature:", "33%");
315 @ <ol>
316 @ <li> An <div class="sideboxDescribed"><a href="brlist">
317 @ open branch</a></div> is a branch that has one or
@@ -320,20 +330,28 @@
330 prepareBranchQuery(&q, showAll, showClosed);
331 cnt = 0;
332 while( db_step(&q)==SQLITE_ROW ){
333 const char *zBr = db_column_text(&q, 0);
334 if( cnt==0 ){
335 if( colorTest ){
336 @ <h2>Default background colors for all branches:</h2>
337 }else if( showAll ){
338 @ <h2>All Branches:</h2>
339 }else if( showClosed ){
340 @ <h2>Closed Branches:</h2>
341 }else{
342 @ <h2>Open Branches:</h2>
343 }
344 @ <ul>
345 cnt++;
346 }
347 if( colorTest ){
348 const char *zColor = hash_color(zBr);
349 @ <li><span style="background-color: %s(zColor)">
350 @ %h(zBr) &rarr; %s(zColor)</span></li>
351 }else if( g.okHistory ){
352 @ <li><a href="%s(g.zTop)/timeline?r=%T(zBr)")>%h(zBr)</a></li>
353 }else{
354 @ <li><b>%h(zBr)</b></li>
355 }
356 }
357 if( cnt ){
358
+18 -5
--- src/checkin.c
+++ src/checkin.c
@@ -64,11 +64,11 @@
6464
}
6565
}
6666
blob_append(report, zPrefix, nPrefix);
6767
if( isDeleted ){
6868
blob_appendf(report, "DELETED %s\n", zDisplayName);
69
- }else if( !file_isfile(zFullName) ){
69
+ }else if( !file_isfile_or_link(zFullName) ){
7070
if( file_access(zFullName, 0)==0 ){
7171
blob_appendf(report, "NOT_A_FILE %s\n", zDisplayName);
7272
if( missingIsFatal ){
7373
fossil_warning("not a file: %s", zDisplayName);
7474
nErr++;
@@ -227,11 +227,11 @@
227227
fossil_print("%s\n", zPathname);
228228
}else if( isNew ){
229229
fossil_print("ADDED %s\n", zPathname);
230230
}else if( isDeleted ){
231231
fossil_print("DELETED %s\n", zPathname);
232
- }else if( !file_isfile(zFullName) ){
232
+ }else if( !file_isfile_or_link(zFullName) ){
233233
if( file_access(zFullName, 0)==0 ){
234234
fossil_print("NOT_A_FILE %s\n", zPathname);
235235
}else{
236236
fossil_print("MISSING %s\n", zPathname);
237237
}
@@ -635,11 +635,11 @@
635635
blob_appendf(pOut, "C %F\n", blob_str(pComment));
636636
zDate = date_in_standard_format(zDateOvrd ? zDateOvrd : "now");
637637
blob_appendf(pOut, "D %s\n", zDate);
638638
zDate[10] = ' ';
639639
db_prepare(&q,
640
- "SELECT pathname, uuid, origname, blob.rid, isexe,"
640
+ "SELECT pathname, uuid, origname, blob.rid, isexe, islink,"
641641
" file_is_selected(vfile.id)"
642642
" FROM vfile JOIN blob ON vfile.mrid=blob.rid"
643643
" WHERE (NOT deleted OR NOT file_is_selected(vfile.id))"
644644
" AND vfile.vid=%d"
645645
" ORDER BY 1", vid);
@@ -650,11 +650,12 @@
650650
const char *zName = db_column_text(&q, 0);
651651
const char *zUuid = db_column_text(&q, 1);
652652
const char *zOrig = db_column_text(&q, 2);
653653
int frid = db_column_int(&q, 3);
654654
int isexe = db_column_int(&q, 4);
655
- int isSelected = db_column_int(&q, 5);
655
+ int isLink = db_column_int(&q, 5);
656
+ int isSelected = db_column_int(&q, 6);
656657
const char *zPerm;
657658
int cmp;
658659
#if !defined(_WIN32)
659660
/* For unix, extract the "executable" permission bit directly from
660661
** the filesystem. On windows, the "executable" bit is retained
@@ -661,13 +662,20 @@
661662
** unchanged from the original.
662663
*/
663664
blob_resize(&filename, nBasename);
664665
blob_append(&filename, zName, -1);
665666
isexe = file_isexe(blob_str(&filename));
667
+
668
+ /* For unix, check if the file on the filesystem is symlink.
669
+ ** On windows, the bit is retained unchanged from original.
670
+ */
671
+ isLink = file_islink(blob_str(&filename));
666672
#endif
667673
if( isexe ){
668674
zPerm = " x";
675
+ }else if( isLink ){
676
+ zPerm = " l"; /* note: symlinks don't have executable bit on unix */
669677
}else{
670678
zPerm = "";
671679
}
672680
if( !g.markPrivate ) content_make_public(frid);
673681
while( pFile && fossil_strcmp(pFile->zName,zName)<0 ){
@@ -1063,11 +1071,16 @@
10631071
zFullname = db_column_text(&q, 1);
10641072
rid = db_column_int(&q, 2);
10651073
crnlOk = db_column_int(&q, 3);
10661074
10671075
blob_zero(&content);
1068
- blob_read_from_file(&content, zFullname);
1076
+ if( file_islink(zFullname) ){
1077
+ /* Instead of file content, put link destination path */
1078
+ blob_read_link(&content, zFullname);
1079
+ }else{
1080
+ blob_read_from_file(&content, zFullname);
1081
+ }
10691082
if( !crnlOk ) cr_warning(&content, zFullname);
10701083
nrid = content_put(&content);
10711084
blob_reset(&content);
10721085
if( rid>0 ){
10731086
content_deltify(rid, nrid, 0);
10741087
--- src/checkin.c
+++ src/checkin.c
@@ -64,11 +64,11 @@
64 }
65 }
66 blob_append(report, zPrefix, nPrefix);
67 if( isDeleted ){
68 blob_appendf(report, "DELETED %s\n", zDisplayName);
69 }else if( !file_isfile(zFullName) ){
70 if( file_access(zFullName, 0)==0 ){
71 blob_appendf(report, "NOT_A_FILE %s\n", zDisplayName);
72 if( missingIsFatal ){
73 fossil_warning("not a file: %s", zDisplayName);
74 nErr++;
@@ -227,11 +227,11 @@
227 fossil_print("%s\n", zPathname);
228 }else if( isNew ){
229 fossil_print("ADDED %s\n", zPathname);
230 }else if( isDeleted ){
231 fossil_print("DELETED %s\n", zPathname);
232 }else if( !file_isfile(zFullName) ){
233 if( file_access(zFullName, 0)==0 ){
234 fossil_print("NOT_A_FILE %s\n", zPathname);
235 }else{
236 fossil_print("MISSING %s\n", zPathname);
237 }
@@ -635,11 +635,11 @@
635 blob_appendf(pOut, "C %F\n", blob_str(pComment));
636 zDate = date_in_standard_format(zDateOvrd ? zDateOvrd : "now");
637 blob_appendf(pOut, "D %s\n", zDate);
638 zDate[10] = ' ';
639 db_prepare(&q,
640 "SELECT pathname, uuid, origname, blob.rid, isexe,"
641 " file_is_selected(vfile.id)"
642 " FROM vfile JOIN blob ON vfile.mrid=blob.rid"
643 " WHERE (NOT deleted OR NOT file_is_selected(vfile.id))"
644 " AND vfile.vid=%d"
645 " ORDER BY 1", vid);
@@ -650,11 +650,12 @@
650 const char *zName = db_column_text(&q, 0);
651 const char *zUuid = db_column_text(&q, 1);
652 const char *zOrig = db_column_text(&q, 2);
653 int frid = db_column_int(&q, 3);
654 int isexe = db_column_int(&q, 4);
655 int isSelected = db_column_int(&q, 5);
 
656 const char *zPerm;
657 int cmp;
658 #if !defined(_WIN32)
659 /* For unix, extract the "executable" permission bit directly from
660 ** the filesystem. On windows, the "executable" bit is retained
@@ -661,13 +662,20 @@
661 ** unchanged from the original.
662 */
663 blob_resize(&filename, nBasename);
664 blob_append(&filename, zName, -1);
665 isexe = file_isexe(blob_str(&filename));
 
 
 
 
 
666 #endif
667 if( isexe ){
668 zPerm = " x";
 
 
669 }else{
670 zPerm = "";
671 }
672 if( !g.markPrivate ) content_make_public(frid);
673 while( pFile && fossil_strcmp(pFile->zName,zName)<0 ){
@@ -1063,11 +1071,16 @@
1063 zFullname = db_column_text(&q, 1);
1064 rid = db_column_int(&q, 2);
1065 crnlOk = db_column_int(&q, 3);
1066
1067 blob_zero(&content);
1068 blob_read_from_file(&content, zFullname);
 
 
 
 
 
1069 if( !crnlOk ) cr_warning(&content, zFullname);
1070 nrid = content_put(&content);
1071 blob_reset(&content);
1072 if( rid>0 ){
1073 content_deltify(rid, nrid, 0);
1074
--- src/checkin.c
+++ src/checkin.c
@@ -64,11 +64,11 @@
64 }
65 }
66 blob_append(report, zPrefix, nPrefix);
67 if( isDeleted ){
68 blob_appendf(report, "DELETED %s\n", zDisplayName);
69 }else if( !file_isfile_or_link(zFullName) ){
70 if( file_access(zFullName, 0)==0 ){
71 blob_appendf(report, "NOT_A_FILE %s\n", zDisplayName);
72 if( missingIsFatal ){
73 fossil_warning("not a file: %s", zDisplayName);
74 nErr++;
@@ -227,11 +227,11 @@
227 fossil_print("%s\n", zPathname);
228 }else if( isNew ){
229 fossil_print("ADDED %s\n", zPathname);
230 }else if( isDeleted ){
231 fossil_print("DELETED %s\n", zPathname);
232 }else if( !file_isfile_or_link(zFullName) ){
233 if( file_access(zFullName, 0)==0 ){
234 fossil_print("NOT_A_FILE %s\n", zPathname);
235 }else{
236 fossil_print("MISSING %s\n", zPathname);
237 }
@@ -635,11 +635,11 @@
635 blob_appendf(pOut, "C %F\n", blob_str(pComment));
636 zDate = date_in_standard_format(zDateOvrd ? zDateOvrd : "now");
637 blob_appendf(pOut, "D %s\n", zDate);
638 zDate[10] = ' ';
639 db_prepare(&q,
640 "SELECT pathname, uuid, origname, blob.rid, isexe, islink,"
641 " file_is_selected(vfile.id)"
642 " FROM vfile JOIN blob ON vfile.mrid=blob.rid"
643 " WHERE (NOT deleted OR NOT file_is_selected(vfile.id))"
644 " AND vfile.vid=%d"
645 " ORDER BY 1", vid);
@@ -650,11 +650,12 @@
650 const char *zName = db_column_text(&q, 0);
651 const char *zUuid = db_column_text(&q, 1);
652 const char *zOrig = db_column_text(&q, 2);
653 int frid = db_column_int(&q, 3);
654 int isexe = db_column_int(&q, 4);
655 int isLink = db_column_int(&q, 5);
656 int isSelected = db_column_int(&q, 6);
657 const char *zPerm;
658 int cmp;
659 #if !defined(_WIN32)
660 /* For unix, extract the "executable" permission bit directly from
661 ** the filesystem. On windows, the "executable" bit is retained
@@ -661,13 +662,20 @@
662 ** unchanged from the original.
663 */
664 blob_resize(&filename, nBasename);
665 blob_append(&filename, zName, -1);
666 isexe = file_isexe(blob_str(&filename));
667
668 /* For unix, check if the file on the filesystem is symlink.
669 ** On windows, the bit is retained unchanged from original.
670 */
671 isLink = file_islink(blob_str(&filename));
672 #endif
673 if( isexe ){
674 zPerm = " x";
675 }else if( isLink ){
676 zPerm = " l"; /* note: symlinks don't have executable bit on unix */
677 }else{
678 zPerm = "";
679 }
680 if( !g.markPrivate ) content_make_public(frid);
681 while( pFile && fossil_strcmp(pFile->zName,zName)<0 ){
@@ -1063,11 +1071,16 @@
1071 zFullname = db_column_text(&q, 1);
1072 rid = db_column_int(&q, 2);
1073 crnlOk = db_column_int(&q, 3);
1074
1075 blob_zero(&content);
1076 if( file_islink(zFullname) ){
1077 /* Instead of file content, put link destination path */
1078 blob_read_link(&content, zFullname);
1079 }else{
1080 blob_read_from_file(&content, zFullname);
1081 }
1082 if( !crnlOk ) cr_warning(&content, zFullname);
1083 nrid = content_put(&content);
1084 blob_reset(&content);
1085 if( rid>0 ){
1086 content_deltify(rid, nrid, 0);
1087
+2 -1
--- src/checkout.c
+++ src/checkout.c
@@ -92,11 +92,12 @@
9292
db_reset(&s);
9393
}
9494
9595
/*
9696
** Set or clear the execute permission bit (as appropriate) for all
97
-** files in the current check-out.
97
+** files in the current check-out, and replace files that have
98
+** symlink bit with actual symlinks.
9899
*/
99100
void checkout_set_all_exe(int vid){
100101
Blob filename;
101102
int baseLen;
102103
Manifest *pManifest;
103104
--- src/checkout.c
+++ src/checkout.c
@@ -92,11 +92,12 @@
92 db_reset(&s);
93 }
94
95 /*
96 ** Set or clear the execute permission bit (as appropriate) for all
97 ** files in the current check-out.
 
98 */
99 void checkout_set_all_exe(int vid){
100 Blob filename;
101 int baseLen;
102 Manifest *pManifest;
103
--- src/checkout.c
+++ src/checkout.c
@@ -92,11 +92,12 @@
92 db_reset(&s);
93 }
94
95 /*
96 ** Set or clear the execute permission bit (as appropriate) for all
97 ** files in the current check-out, and replace files that have
98 ** symlink bit with actual symlinks.
99 */
100 void checkout_set_all_exe(int vid){
101 Blob filename;
102 int baseLen;
103 Manifest *pManifest;
104
+1 -1
--- src/configure.c
+++ src/configure.c
@@ -726,11 +726,11 @@
726726
727727
728728
/*
729729
** COMMAND: configuration
730730
**
731
-** Usage: %fossil configure METHOD ... ?-R|--repository REPOSITORY?
731
+** Usage: %fossil configuration METHOD ... ?-R|--repository REPOSITORY?
732732
**
733733
** Where METHOD is one of: export import merge pull push reset. All methods
734734
** accept the -R or --repository option to specific a repository.
735735
**
736736
** %fossil configuration export AREA FILENAME
737737
--- src/configure.c
+++ src/configure.c
@@ -726,11 +726,11 @@
726
727
728 /*
729 ** COMMAND: configuration
730 **
731 ** Usage: %fossil configure METHOD ... ?-R|--repository REPOSITORY?
732 **
733 ** Where METHOD is one of: export import merge pull push reset. All methods
734 ** accept the -R or --repository option to specific a repository.
735 **
736 ** %fossil configuration export AREA FILENAME
737
--- src/configure.c
+++ src/configure.c
@@ -726,11 +726,11 @@
726
727
728 /*
729 ** COMMAND: configuration
730 **
731 ** Usage: %fossil configuration METHOD ... ?-R|--repository REPOSITORY?
732 **
733 ** Where METHOD is one of: export import merge pull push reset. All methods
734 ** accept the -R or --repository option to specific a repository.
735 **
736 ** %fossil configuration export AREA FILENAME
737
+51 -34
--- src/db.c
+++ src/db.c
@@ -736,18 +736,35 @@
736736
}
737737
g.configOpen = 1;
738738
free(zDbName);
739739
}
740740
741
+
742
+/*
743
+ * * Returns TRUE if zTable exists in the local database.
744
+ */
745
+static int db_local_table_exists(const char *zTable){
746
+ return db_exists("SELECT 1 FROM %s.sqlite_master"
747
+ " WHERE name=='%s'",
748
+ db_name("localdb"), zTable);
749
+}
750
+
751
+/*
752
+** Returns TRUE if zColumn exists in zTable in the local database.
753
+*/
754
+static int db_local_column_exists(const char *zTable, const char *zColumn){
755
+ return db_exists("SELECT 1 FROM %s.sqlite_master"
756
+ " WHERE name=='%s' AND sql GLOB '* %s *'",
757
+ db_name("localdb"), zTable, zColumn);
758
+}
759
+
741760
/*
742761
** If zDbName is a valid local database file, open it and return
743762
** true. If it is not a valid local database file, return 0.
744763
*/
745764
static int isValidLocalDb(const char *zDbName){
746765
i64 lsize;
747
- int rc;
748
- sqlite3_stmt *pStmt;
749766
750767
if( file_access(zDbName, F_OK) ) return 0;
751768
lsize = file_size(zDbName);
752769
if( lsize%1024!=0 || lsize<4096 ) return 0;
753770
db_open_or_attach(zDbName, "localdb");
@@ -757,40 +774,31 @@
757774
758775
/* If the "isexe" column is missing from the vfile table, then
759776
** add it now. This code added on 2010-03-06. After all users have
760777
** upgraded, this code can be safely deleted.
761778
*/
762
- rc = sqlite3_prepare(g.db, "SELECT isexe FROM vfile", -1, &pStmt, 0);
763
- nPrepare++;
764
- sqlite3_finalize(pStmt);
765
- if( rc==SQLITE_ERROR ){
766
- sqlite3_exec(g.db, "ALTER TABLE vfile ADD COLUMN isexe BOOLEAN", 0, 0, 0);
767
- }
768
-
769
-#if 0
770
- /* If the "mtime" column is missing from the vfile table, then
771
- ** add it now. This code added on 2008-12-06. After all users have
772
- ** upgraded, this code can be safely deleted.
773
- */
774
- rc = sqlite3_prepare(g.db, "SELECT mtime FROM vfile", -1, &pStmt, 0);
775
- sqlite3_finalize(pStmt);
776
- if( rc==SQLITE_ERROR ){
777
- sqlite3_exec(g.db, "ALTER TABLE vfile ADD COLUMN mtime INTEGER", 0, 0, 0);
778
- }
779
-#endif
780
-
781
-#if 0
782
- /* If the "origname" column is missing from the vfile table, then
783
- ** add it now. This code added on 2008-11-09. After all users have
784
- ** upgraded, this code can be safely deleted.
785
- */
786
- rc = sqlite3_prepare(g.db, "SELECT origname FROM vfile", -1, &pStmt, 0);
787
- sqlite3_finalize(pStmt);
788
- if( rc==SQLITE_ERROR ){
789
- sqlite3_exec(g.db, "ALTER TABLE vfile ADD COLUMN origname TEXT", 0, 0, 0);
790
- }
791
-#endif
779
+ if( !db_local_column_exists("vfile", "isexe") )
780
+ db_multi_exec("ALTER TABLE vfile ADD COLUMN isexe BOOLEAN DEFAULT 0");
781
+
782
+ /* If "islink"/"isLink" columns are missing from tables, then
783
+ ** add them now. This code added on 2011-01-17 and 2011-08-27.
784
+ ** After all users have upgraded, this code can be safely deleted.
785
+ */
786
+ if( !db_local_column_exists("vfile", "islink") )
787
+ db_multi_exec("ALTER TABLE vfile ADD COLUMN islink BOOLEAN DEFAULT 0");
788
+
789
+ if( !db_local_column_exists("stashfile", "isLink") &&
790
+ db_local_table_exists("stashfile") )
791
+ db_multi_exec("ALTER TABLE stashfile ADD COLUMN isLink BOOLEAN DEFAULT 0");
792
+
793
+ if( !db_local_column_exists("undo", "isLink") &&
794
+ db_local_table_exists("undo") )
795
+ db_multi_exec("ALTER TABLE undo ADD COLUMN isLink BOOLEAN DEFAULT 0");
796
+
797
+ if( !db_local_column_exists("undo_vfile", "islink") &&
798
+ db_local_table_exists("undo_vfile") )
799
+ db_multi_exec("ALTER TABLE undo_vfile ADD COLUMN islink BOOLEAN DEFAULT 0");
792800
793801
return 1;
794802
}
795803
796804
/*
@@ -866,10 +874,12 @@
866874
}
867875
}
868876
db_open_or_attach(zDbName, "repository");
869877
g.repositoryOpen = 1;
870878
g.zRepositoryName = mprintf("%s", zDbName);
879
+ /* Cache "allow-symlinks" option, because we'll need it on every stat call */
880
+ g.allowSymlinks = db_get_boolean("allow-symlinks", 0);
871881
}
872882
873883
/*
874884
** Flags for the db_find_and_open_repository() function.
875885
*/
@@ -1426,11 +1436,11 @@
14261436
}
14271437
cacheEntry = cacheEntry->next;
14281438
}
14291439
/* Attempt to read value from file in checkout if there wasn't a cache hit
14301440
** and a checkout is open. */
1431
- if( cacheEntry==0 && db_open_local() ){
1441
+ if( cacheEntry==0 ){
14321442
Blob versionedPathname;
14331443
char *zVersionedPathname;
14341444
blob_zero(&versionedPathname);
14351445
blob_appendf(&versionedPathname, "%s/.fossil-settings/%s",
14361446
g.zLocalRoot, zName);
@@ -1500,11 +1510,11 @@
15001510
if( z==0 && g.configOpen ){
15011511
db_swap_connections();
15021512
z = db_text(0, "SELECT value FROM global_config WHERE name=%Q", zName);
15031513
db_swap_connections();
15041514
}
1505
- if( ctrlSetting!=0 && ctrlSetting->versionable ){
1515
+ if( ctrlSetting!=0 && ctrlSetting->versionable && g.localOpen ){
15061516
/* This is a versionable setting, try and get the info from a checked out file */
15071517
z = db_get_do_versionable(zName, z);
15081518
}
15091519
if( z==0 ){
15101520
z = zDefault;
@@ -1747,10 +1757,11 @@
17471757
char const *def; /* Default value */
17481758
};
17491759
#endif /* INTERFACE */
17501760
struct stControlSettings const ctrlSettings[] = {
17511761
{ "access-log", 0, 0, 0, "off" },
1762
+ { "allow-symlinks",0, 0, 0, "off" },
17521763
{ "auto-captcha", "autocaptcha", 0, 0, "on" },
17531764
{ "auto-shun", 0, 0, 0, "on" },
17541765
{ "autosync", 0, 0, 0, "on" },
17551766
{ "binary-glob", 0, 32, 1, "" },
17561767
{ "clearsign", 0, 0, 0, "off" },
@@ -1799,10 +1810,16 @@
17991810
** file named .fossil-settings/PROPERTY in the checked out files, if that
18001811
** file exists.
18011812
**
18021813
** The "unset" command clears a property setting.
18031814
**
1815
+**
1816
+** allow-symlinks If enabled, don't follow symlinks, and instead treat
1817
+** them as symlinks on Unix. Has no effect on Windows
1818
+** (existing links in repository created on Unix become
1819
+** plain-text files with link destination path inside).
1820
+** Default: off
18041821
**
18051822
** auto-captcha If enabled, the Login page provides a button to
18061823
** fill in the captcha password. Default: on
18071824
**
18081825
** auto-shun If enabled, automatically pull the shunning list
18091826
--- src/db.c
+++ src/db.c
@@ -736,18 +736,35 @@
736 }
737 g.configOpen = 1;
738 free(zDbName);
739 }
740
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
741 /*
742 ** If zDbName is a valid local database file, open it and return
743 ** true. If it is not a valid local database file, return 0.
744 */
745 static int isValidLocalDb(const char *zDbName){
746 i64 lsize;
747 int rc;
748 sqlite3_stmt *pStmt;
749
750 if( file_access(zDbName, F_OK) ) return 0;
751 lsize = file_size(zDbName);
752 if( lsize%1024!=0 || lsize<4096 ) return 0;
753 db_open_or_attach(zDbName, "localdb");
@@ -757,40 +774,31 @@
757
758 /* If the "isexe" column is missing from the vfile table, then
759 ** add it now. This code added on 2010-03-06. After all users have
760 ** upgraded, this code can be safely deleted.
761 */
762 rc = sqlite3_prepare(g.db, "SELECT isexe FROM vfile", -1, &pStmt, 0);
763 nPrepare++;
764 sqlite3_finalize(pStmt);
765 if( rc==SQLITE_ERROR ){
766 sqlite3_exec(g.db, "ALTER TABLE vfile ADD COLUMN isexe BOOLEAN", 0, 0, 0);
767 }
768
769 #if 0
770 /* If the "mtime" column is missing from the vfile table, then
771 ** add it now. This code added on 2008-12-06. After all users have
772 ** upgraded, this code can be safely deleted.
773 */
774 rc = sqlite3_prepare(g.db, "SELECT mtime FROM vfile", -1, &pStmt, 0);
775 sqlite3_finalize(pStmt);
776 if( rc==SQLITE_ERROR ){
777 sqlite3_exec(g.db, "ALTER TABLE vfile ADD COLUMN mtime INTEGER", 0, 0, 0);
778 }
779 #endif
780
781 #if 0
782 /* If the "origname" column is missing from the vfile table, then
783 ** add it now. This code added on 2008-11-09. After all users have
784 ** upgraded, this code can be safely deleted.
785 */
786 rc = sqlite3_prepare(g.db, "SELECT origname FROM vfile", -1, &pStmt, 0);
787 sqlite3_finalize(pStmt);
788 if( rc==SQLITE_ERROR ){
789 sqlite3_exec(g.db, "ALTER TABLE vfile ADD COLUMN origname TEXT", 0, 0, 0);
790 }
791 #endif
792
793 return 1;
794 }
795
796 /*
@@ -866,10 +874,12 @@
866 }
867 }
868 db_open_or_attach(zDbName, "repository");
869 g.repositoryOpen = 1;
870 g.zRepositoryName = mprintf("%s", zDbName);
 
 
871 }
872
873 /*
874 ** Flags for the db_find_and_open_repository() function.
875 */
@@ -1426,11 +1436,11 @@
1426 }
1427 cacheEntry = cacheEntry->next;
1428 }
1429 /* Attempt to read value from file in checkout if there wasn't a cache hit
1430 ** and a checkout is open. */
1431 if( cacheEntry==0 && db_open_local() ){
1432 Blob versionedPathname;
1433 char *zVersionedPathname;
1434 blob_zero(&versionedPathname);
1435 blob_appendf(&versionedPathname, "%s/.fossil-settings/%s",
1436 g.zLocalRoot, zName);
@@ -1500,11 +1510,11 @@
1500 if( z==0 && g.configOpen ){
1501 db_swap_connections();
1502 z = db_text(0, "SELECT value FROM global_config WHERE name=%Q", zName);
1503 db_swap_connections();
1504 }
1505 if( ctrlSetting!=0 && ctrlSetting->versionable ){
1506 /* This is a versionable setting, try and get the info from a checked out file */
1507 z = db_get_do_versionable(zName, z);
1508 }
1509 if( z==0 ){
1510 z = zDefault;
@@ -1747,10 +1757,11 @@
1747 char const *def; /* Default value */
1748 };
1749 #endif /* INTERFACE */
1750 struct stControlSettings const ctrlSettings[] = {
1751 { "access-log", 0, 0, 0, "off" },
 
1752 { "auto-captcha", "autocaptcha", 0, 0, "on" },
1753 { "auto-shun", 0, 0, 0, "on" },
1754 { "autosync", 0, 0, 0, "on" },
1755 { "binary-glob", 0, 32, 1, "" },
1756 { "clearsign", 0, 0, 0, "off" },
@@ -1799,10 +1810,16 @@
1799 ** file named .fossil-settings/PROPERTY in the checked out files, if that
1800 ** file exists.
1801 **
1802 ** The "unset" command clears a property setting.
1803 **
 
 
 
 
 
 
1804 **
1805 ** auto-captcha If enabled, the Login page provides a button to
1806 ** fill in the captcha password. Default: on
1807 **
1808 ** auto-shun If enabled, automatically pull the shunning list
1809
--- src/db.c
+++ src/db.c
@@ -736,18 +736,35 @@
736 }
737 g.configOpen = 1;
738 free(zDbName);
739 }
740
741
742 /*
743 * * Returns TRUE if zTable exists in the local database.
744 */
745 static int db_local_table_exists(const char *zTable){
746 return db_exists("SELECT 1 FROM %s.sqlite_master"
747 " WHERE name=='%s'",
748 db_name("localdb"), zTable);
749 }
750
751 /*
752 ** Returns TRUE if zColumn exists in zTable in the local database.
753 */
754 static int db_local_column_exists(const char *zTable, const char *zColumn){
755 return db_exists("SELECT 1 FROM %s.sqlite_master"
756 " WHERE name=='%s' AND sql GLOB '* %s *'",
757 db_name("localdb"), zTable, zColumn);
758 }
759
760 /*
761 ** If zDbName is a valid local database file, open it and return
762 ** true. If it is not a valid local database file, return 0.
763 */
764 static int isValidLocalDb(const char *zDbName){
765 i64 lsize;
 
 
766
767 if( file_access(zDbName, F_OK) ) return 0;
768 lsize = file_size(zDbName);
769 if( lsize%1024!=0 || lsize<4096 ) return 0;
770 db_open_or_attach(zDbName, "localdb");
@@ -757,40 +774,31 @@
774
775 /* If the "isexe" column is missing from the vfile table, then
776 ** add it now. This code added on 2010-03-06. After all users have
777 ** upgraded, this code can be safely deleted.
778 */
779 if( !db_local_column_exists("vfile", "isexe") )
780 db_multi_exec("ALTER TABLE vfile ADD COLUMN isexe BOOLEAN DEFAULT 0");
781
782 /* If "islink"/"isLink" columns are missing from tables, then
783 ** add them now. This code added on 2011-01-17 and 2011-08-27.
784 ** After all users have upgraded, this code can be safely deleted.
785 */
786 if( !db_local_column_exists("vfile", "islink") )
787 db_multi_exec("ALTER TABLE vfile ADD COLUMN islink BOOLEAN DEFAULT 0");
788
789 if( !db_local_column_exists("stashfile", "isLink") &&
790 db_local_table_exists("stashfile") )
791 db_multi_exec("ALTER TABLE stashfile ADD COLUMN isLink BOOLEAN DEFAULT 0");
792
793 if( !db_local_column_exists("undo", "isLink") &&
794 db_local_table_exists("undo") )
795 db_multi_exec("ALTER TABLE undo ADD COLUMN isLink BOOLEAN DEFAULT 0");
796
797 if( !db_local_column_exists("undo_vfile", "islink") &&
798 db_local_table_exists("undo_vfile") )
799 db_multi_exec("ALTER TABLE undo_vfile ADD COLUMN islink BOOLEAN DEFAULT 0");
 
 
 
 
 
 
 
 
 
800
801 return 1;
802 }
803
804 /*
@@ -866,10 +874,12 @@
874 }
875 }
876 db_open_or_attach(zDbName, "repository");
877 g.repositoryOpen = 1;
878 g.zRepositoryName = mprintf("%s", zDbName);
879 /* Cache "allow-symlinks" option, because we'll need it on every stat call */
880 g.allowSymlinks = db_get_boolean("allow-symlinks", 0);
881 }
882
883 /*
884 ** Flags for the db_find_and_open_repository() function.
885 */
@@ -1426,11 +1436,11 @@
1436 }
1437 cacheEntry = cacheEntry->next;
1438 }
1439 /* Attempt to read value from file in checkout if there wasn't a cache hit
1440 ** and a checkout is open. */
1441 if( cacheEntry==0 ){
1442 Blob versionedPathname;
1443 char *zVersionedPathname;
1444 blob_zero(&versionedPathname);
1445 blob_appendf(&versionedPathname, "%s/.fossil-settings/%s",
1446 g.zLocalRoot, zName);
@@ -1500,11 +1510,11 @@
1510 if( z==0 && g.configOpen ){
1511 db_swap_connections();
1512 z = db_text(0, "SELECT value FROM global_config WHERE name=%Q", zName);
1513 db_swap_connections();
1514 }
1515 if( ctrlSetting!=0 && ctrlSetting->versionable && g.localOpen ){
1516 /* This is a versionable setting, try and get the info from a checked out file */
1517 z = db_get_do_versionable(zName, z);
1518 }
1519 if( z==0 ){
1520 z = zDefault;
@@ -1747,10 +1757,11 @@
1757 char const *def; /* Default value */
1758 };
1759 #endif /* INTERFACE */
1760 struct stControlSettings const ctrlSettings[] = {
1761 { "access-log", 0, 0, 0, "off" },
1762 { "allow-symlinks",0, 0, 0, "off" },
1763 { "auto-captcha", "autocaptcha", 0, 0, "on" },
1764 { "auto-shun", 0, 0, 0, "on" },
1765 { "autosync", 0, 0, 0, "on" },
1766 { "binary-glob", 0, 32, 1, "" },
1767 { "clearsign", 0, 0, 0, "off" },
@@ -1799,10 +1810,16 @@
1810 ** file named .fossil-settings/PROPERTY in the checked out files, if that
1811 ** file exists.
1812 **
1813 ** The "unset" command clears a property setting.
1814 **
1815 **
1816 ** allow-symlinks If enabled, don't follow symlinks, and instead treat
1817 ** them as symlinks on Unix. Has no effect on Windows
1818 ** (existing links in repository created on Unix become
1819 ** plain-text files with link destination path inside).
1820 ** Default: off
1821 **
1822 ** auto-captcha If enabled, the Login page provides a button to
1823 ** fill in the captcha password. Default: on
1824 **
1825 ** auto-shun If enabled, automatically pull the shunning list
1826
+32 -10
--- src/diffcmd.c
+++ src/diffcmd.c
@@ -74,11 +74,15 @@
7474
/* Read content of zFile2 into memory */
7575
blob_zero(&file2);
7676
if( file_size(zFile2)<0 ){
7777
zName2 = "/dev/null";
7878
}else{
79
- blob_read_from_file(&file2, zFile2);
79
+ if( file_islink(zFile2) ){
80
+ blob_read_link(&file2, zFile2);
81
+ }else{
82
+ blob_read_from_file(&file2, zFile2);
83
+ }
8084
zName2 = zName;
8185
}
8286
8387
/* Compute and output the differences */
8488
blob_zero(&out);
@@ -186,13 +190,18 @@
186190
int ignoreEolWs, /* Ignore whitespace changes at end of lines */
187191
const char *zFileTreeName
188192
){
189193
Blob fname;
190194
Blob content;
195
+ int isLink;
191196
file_tree_name(zFileTreeName, &fname, 1);
192
- historical_version_of_file(zFrom, blob_str(&fname), &content, 0, 0);
193
- diff_file(&content, zFileTreeName, zFileTreeName, zDiffCmd, ignoreEolWs);
197
+ historical_version_of_file(zFrom, blob_str(&fname), &content, &isLink, 0, 0);
198
+ if( !isLink != !file_islink(zFrom) ){
199
+ diff_printf("cannot compute difference between symlink and regular file\n");
200
+ }else{
201
+ diff_file(&content, zFileTreeName, zFileTreeName, zDiffCmd, ignoreEolWs);
202
+ }
194203
blob_reset(&content);
195204
blob_reset(&fname);
196205
}
197206
198207
/*
@@ -222,32 +231,32 @@
222231
if( !is_a_version(rid) ){
223232
fossil_fatal("no such check-in: %s", zFrom);
224233
}
225234
load_vfile_from_rid(rid);
226235
blob_appendf(&sql,
227
- "SELECT v2.pathname, v2.deleted, v2.chnged, v2.rid==0, v1.rid"
236
+ "SELECT v2.pathname, v2.deleted, v2.chnged, v2.rid==0, v1.rid, v1.islink"
228237
" FROM vfile v1, vfile v2 "
229238
" WHERE v1.pathname=v2.pathname AND v1.vid=%d AND v2.vid=%d"
230239
" AND (v2.deleted OR v2.chnged OR v1.mrid!=v2.rid)"
231240
"UNION "
232
- "SELECT pathname, 1, 0, 0, 0"
241
+ "SELECT pathname, 1, 0, 0, 0, islink"
233242
" FROM vfile v1"
234243
" WHERE v1.vid=%d"
235244
" AND NOT EXISTS(SELECT 1 FROM vfile v2"
236245
" WHERE v2.vid=%d AND v2.pathname=v1.pathname)"
237246
"UNION "
238
- "SELECT pathname, 0, 0, 1, 0"
247
+ "SELECT pathname, 0, 0, 1, 0, islink"
239248
" FROM vfile v2"
240249
" WHERE v2.vid=%d"
241250
" AND NOT EXISTS(SELECT 1 FROM vfile v1"
242251
" WHERE v1.vid=%d AND v1.pathname=v2.pathname)"
243252
" ORDER BY 1",
244253
rid, vid, rid, vid, vid, rid
245254
);
246255
}else{
247256
blob_appendf(&sql,
248
- "SELECT pathname, deleted, chnged , rid==0, rid"
257
+ "SELECT pathname, deleted, chnged , rid==0, rid, islink"
249258
" FROM vfile"
250259
" WHERE vid=%d"
251260
" AND (deleted OR chnged OR rid==0)"
252261
" ORDER BY pathname",
253262
vid
@@ -258,10 +267,11 @@
258267
const char *zPathname = db_column_text(&q,0);
259268
int isDeleted = db_column_int(&q, 1);
260269
int isChnged = db_column_int(&q,2);
261270
int isNew = db_column_int(&q,3);
262271
int srcid = db_column_int(&q, 4);
272
+ int isLink = db_column_int(&q, 5);
263273
char *zFullName = mprintf("%s%s", g.zLocalRoot, zPathname);
264274
char *zToFree = zFullName;
265275
int showDiff = 1;
266276
if( isDeleted ){
267277
diff_printf("DELETED %s\n", zPathname);
@@ -278,10 +288,16 @@
278288
srcid = 0;
279289
if( !asNewFile ){ showDiff = 0; }
280290
}
281291
if( showDiff ){
282292
Blob content;
293
+ if( !isLink != !file_islink(zFullName) ){
294
+ diff_print_index(zPathname);
295
+ diff_printf("--- %s\n+++ %s\n", zPathname, zPathname);
296
+ diff_printf("cannot compute difference between symlink and regular file\n");
297
+ continue;
298
+ }
283299
if( srcid>0 ){
284300
content_get(srcid, &content);
285301
}else{
286302
blob_zero(&content);
287303
}
@@ -307,15 +323,21 @@
307323
const char *zFileTreeName
308324
){
309325
char *zName;
310326
Blob fname;
311327
Blob v1, v2;
328
+ int isLink1, isLink2;
312329
file_tree_name(zFileTreeName, &fname, 1);
313330
zName = blob_str(&fname);
314
- historical_version_of_file(zFrom, zName, &v1, 0, 0);
315
- historical_version_of_file(zTo, zName, &v2, 0, 0);
316
- diff_file_mem(&v1, &v2, zName, zDiffCmd, ignoreEolWs);
331
+ historical_version_of_file(zFrom, zName, &v1, &isLink1, 0, 0);
332
+ historical_version_of_file(zTo, zName, &v2, &isLink2, 0, 0);
333
+ if( isLink1 != isLink2 ){
334
+ diff_printf("--- %s\n+++ %s\n", zName, zName);
335
+ diff_printf("cannot compute difference between symlink and regular file\n");
336
+ }else{
337
+ diff_file_mem(&v1, &v2, zName, zDiffCmd, ignoreEolWs);
338
+ }
317339
blob_reset(&v1);
318340
blob_reset(&v2);
319341
blob_reset(&fname);
320342
}
321343
322344
--- src/diffcmd.c
+++ src/diffcmd.c
@@ -74,11 +74,15 @@
74 /* Read content of zFile2 into memory */
75 blob_zero(&file2);
76 if( file_size(zFile2)<0 ){
77 zName2 = "/dev/null";
78 }else{
79 blob_read_from_file(&file2, zFile2);
 
 
 
 
80 zName2 = zName;
81 }
82
83 /* Compute and output the differences */
84 blob_zero(&out);
@@ -186,13 +190,18 @@
186 int ignoreEolWs, /* Ignore whitespace changes at end of lines */
187 const char *zFileTreeName
188 ){
189 Blob fname;
190 Blob content;
 
191 file_tree_name(zFileTreeName, &fname, 1);
192 historical_version_of_file(zFrom, blob_str(&fname), &content, 0, 0);
193 diff_file(&content, zFileTreeName, zFileTreeName, zDiffCmd, ignoreEolWs);
 
 
 
 
194 blob_reset(&content);
195 blob_reset(&fname);
196 }
197
198 /*
@@ -222,32 +231,32 @@
222 if( !is_a_version(rid) ){
223 fossil_fatal("no such check-in: %s", zFrom);
224 }
225 load_vfile_from_rid(rid);
226 blob_appendf(&sql,
227 "SELECT v2.pathname, v2.deleted, v2.chnged, v2.rid==0, v1.rid"
228 " FROM vfile v1, vfile v2 "
229 " WHERE v1.pathname=v2.pathname AND v1.vid=%d AND v2.vid=%d"
230 " AND (v2.deleted OR v2.chnged OR v1.mrid!=v2.rid)"
231 "UNION "
232 "SELECT pathname, 1, 0, 0, 0"
233 " FROM vfile v1"
234 " WHERE v1.vid=%d"
235 " AND NOT EXISTS(SELECT 1 FROM vfile v2"
236 " WHERE v2.vid=%d AND v2.pathname=v1.pathname)"
237 "UNION "
238 "SELECT pathname, 0, 0, 1, 0"
239 " FROM vfile v2"
240 " WHERE v2.vid=%d"
241 " AND NOT EXISTS(SELECT 1 FROM vfile v1"
242 " WHERE v1.vid=%d AND v1.pathname=v2.pathname)"
243 " ORDER BY 1",
244 rid, vid, rid, vid, vid, rid
245 );
246 }else{
247 blob_appendf(&sql,
248 "SELECT pathname, deleted, chnged , rid==0, rid"
249 " FROM vfile"
250 " WHERE vid=%d"
251 " AND (deleted OR chnged OR rid==0)"
252 " ORDER BY pathname",
253 vid
@@ -258,10 +267,11 @@
258 const char *zPathname = db_column_text(&q,0);
259 int isDeleted = db_column_int(&q, 1);
260 int isChnged = db_column_int(&q,2);
261 int isNew = db_column_int(&q,3);
262 int srcid = db_column_int(&q, 4);
 
263 char *zFullName = mprintf("%s%s", g.zLocalRoot, zPathname);
264 char *zToFree = zFullName;
265 int showDiff = 1;
266 if( isDeleted ){
267 diff_printf("DELETED %s\n", zPathname);
@@ -278,10 +288,16 @@
278 srcid = 0;
279 if( !asNewFile ){ showDiff = 0; }
280 }
281 if( showDiff ){
282 Blob content;
 
 
 
 
 
 
283 if( srcid>0 ){
284 content_get(srcid, &content);
285 }else{
286 blob_zero(&content);
287 }
@@ -307,15 +323,21 @@
307 const char *zFileTreeName
308 ){
309 char *zName;
310 Blob fname;
311 Blob v1, v2;
 
312 file_tree_name(zFileTreeName, &fname, 1);
313 zName = blob_str(&fname);
314 historical_version_of_file(zFrom, zName, &v1, 0, 0);
315 historical_version_of_file(zTo, zName, &v2, 0, 0);
316 diff_file_mem(&v1, &v2, zName, zDiffCmd, ignoreEolWs);
 
 
 
 
 
317 blob_reset(&v1);
318 blob_reset(&v2);
319 blob_reset(&fname);
320 }
321
322
--- src/diffcmd.c
+++ src/diffcmd.c
@@ -74,11 +74,15 @@
74 /* Read content of zFile2 into memory */
75 blob_zero(&file2);
76 if( file_size(zFile2)<0 ){
77 zName2 = "/dev/null";
78 }else{
79 if( file_islink(zFile2) ){
80 blob_read_link(&file2, zFile2);
81 }else{
82 blob_read_from_file(&file2, zFile2);
83 }
84 zName2 = zName;
85 }
86
87 /* Compute and output the differences */
88 blob_zero(&out);
@@ -186,13 +190,18 @@
190 int ignoreEolWs, /* Ignore whitespace changes at end of lines */
191 const char *zFileTreeName
192 ){
193 Blob fname;
194 Blob content;
195 int isLink;
196 file_tree_name(zFileTreeName, &fname, 1);
197 historical_version_of_file(zFrom, blob_str(&fname), &content, &isLink, 0, 0);
198 if( !isLink != !file_islink(zFrom) ){
199 diff_printf("cannot compute difference between symlink and regular file\n");
200 }else{
201 diff_file(&content, zFileTreeName, zFileTreeName, zDiffCmd, ignoreEolWs);
202 }
203 blob_reset(&content);
204 blob_reset(&fname);
205 }
206
207 /*
@@ -222,32 +231,32 @@
231 if( !is_a_version(rid) ){
232 fossil_fatal("no such check-in: %s", zFrom);
233 }
234 load_vfile_from_rid(rid);
235 blob_appendf(&sql,
236 "SELECT v2.pathname, v2.deleted, v2.chnged, v2.rid==0, v1.rid, v1.islink"
237 " FROM vfile v1, vfile v2 "
238 " WHERE v1.pathname=v2.pathname AND v1.vid=%d AND v2.vid=%d"
239 " AND (v2.deleted OR v2.chnged OR v1.mrid!=v2.rid)"
240 "UNION "
241 "SELECT pathname, 1, 0, 0, 0, islink"
242 " FROM vfile v1"
243 " WHERE v1.vid=%d"
244 " AND NOT EXISTS(SELECT 1 FROM vfile v2"
245 " WHERE v2.vid=%d AND v2.pathname=v1.pathname)"
246 "UNION "
247 "SELECT pathname, 0, 0, 1, 0, islink"
248 " FROM vfile v2"
249 " WHERE v2.vid=%d"
250 " AND NOT EXISTS(SELECT 1 FROM vfile v1"
251 " WHERE v1.vid=%d AND v1.pathname=v2.pathname)"
252 " ORDER BY 1",
253 rid, vid, rid, vid, vid, rid
254 );
255 }else{
256 blob_appendf(&sql,
257 "SELECT pathname, deleted, chnged , rid==0, rid, islink"
258 " FROM vfile"
259 " WHERE vid=%d"
260 " AND (deleted OR chnged OR rid==0)"
261 " ORDER BY pathname",
262 vid
@@ -258,10 +267,11 @@
267 const char *zPathname = db_column_text(&q,0);
268 int isDeleted = db_column_int(&q, 1);
269 int isChnged = db_column_int(&q,2);
270 int isNew = db_column_int(&q,3);
271 int srcid = db_column_int(&q, 4);
272 int isLink = db_column_int(&q, 5);
273 char *zFullName = mprintf("%s%s", g.zLocalRoot, zPathname);
274 char *zToFree = zFullName;
275 int showDiff = 1;
276 if( isDeleted ){
277 diff_printf("DELETED %s\n", zPathname);
@@ -278,10 +288,16 @@
288 srcid = 0;
289 if( !asNewFile ){ showDiff = 0; }
290 }
291 if( showDiff ){
292 Blob content;
293 if( !isLink != !file_islink(zFullName) ){
294 diff_print_index(zPathname);
295 diff_printf("--- %s\n+++ %s\n", zPathname, zPathname);
296 diff_printf("cannot compute difference between symlink and regular file\n");
297 continue;
298 }
299 if( srcid>0 ){
300 content_get(srcid, &content);
301 }else{
302 blob_zero(&content);
303 }
@@ -307,15 +323,21 @@
323 const char *zFileTreeName
324 ){
325 char *zName;
326 Blob fname;
327 Blob v1, v2;
328 int isLink1, isLink2;
329 file_tree_name(zFileTreeName, &fname, 1);
330 zName = blob_str(&fname);
331 historical_version_of_file(zFrom, zName, &v1, &isLink1, 0, 0);
332 historical_version_of_file(zTo, zName, &v2, &isLink2, 0, 0);
333 if( isLink1 != isLink2 ){
334 diff_printf("--- %s\n+++ %s\n", zName, zName);
335 diff_printf("cannot compute difference between symlink and regular file\n");
336 }else{
337 diff_file_mem(&v1, &v2, zName, zDiffCmd, ignoreEolWs);
338 }
339 blob_reset(&v1);
340 blob_reset(&v2);
341 blob_reset(&fname);
342 }
343
344
+9 -2
--- src/export.c
+++ src/export.c
@@ -269,12 +269,19 @@
269269
const char *zName = db_column_text(&q4,0);
270270
int zNew = db_column_int(&q4,1);
271271
int mPerm = db_column_int(&q4,2);
272272
if( zNew==0)
273273
printf("D %s\n", zName);
274
- else if( bag_find(&blobs, zNew) )
275
- printf("M %s :%d %s\n", mPerm ? "100755" : "100644", BLOBMARK(zNew), zName);
274
+ else if( bag_find(&blobs, zNew) ) {
275
+ const char *zPerm;
276
+ switch( mPerm ){
277
+ case PERM_LNK: zPerm = "120000"; break;
278
+ case PERM_EXE: zPerm = "100755"; break;
279
+ default: zPerm = "100644"; break;
280
+ }
281
+ printf("M %s :%d %s\n", zPerm, BLOBMARK(zNew), zName);
282
+ }
276283
}
277284
db_finalize(&q4);
278285
db_finalize(&q3);
279286
printf("\n");
280287
}
281288
--- src/export.c
+++ src/export.c
@@ -269,12 +269,19 @@
269 const char *zName = db_column_text(&q4,0);
270 int zNew = db_column_int(&q4,1);
271 int mPerm = db_column_int(&q4,2);
272 if( zNew==0)
273 printf("D %s\n", zName);
274 else if( bag_find(&blobs, zNew) )
275 printf("M %s :%d %s\n", mPerm ? "100755" : "100644", BLOBMARK(zNew), zName);
 
 
 
 
 
 
 
276 }
277 db_finalize(&q4);
278 db_finalize(&q3);
279 printf("\n");
280 }
281
--- src/export.c
+++ src/export.c
@@ -269,12 +269,19 @@
269 const char *zName = db_column_text(&q4,0);
270 int zNew = db_column_int(&q4,1);
271 int mPerm = db_column_int(&q4,2);
272 if( zNew==0)
273 printf("D %s\n", zName);
274 else if( bag_find(&blobs, zNew) ) {
275 const char *zPerm;
276 switch( mPerm ){
277 case PERM_LNK: zPerm = "120000"; break;
278 case PERM_EXE: zPerm = "100755"; break;
279 default: zPerm = "100644"; break;
280 }
281 printf("M %s :%d %s\n", zPerm, BLOBMARK(zNew), zName);
282 }
283 }
284 db_finalize(&q4);
285 db_finalize(&q3);
286 printf("\n");
287 }
288
+123 -12
--- src/file.c
+++ src/file.c
@@ -30,16 +30,26 @@
3030
**
3131
** Use _stati64 rather than stat on windows, in order to handle files
3232
** larger than 2GB.
3333
*/
3434
#if defined(_WIN32) && defined(__MSVCRT__)
35
- static struct _stati64 fileStat;
3635
# define stat _stati64
37
-#else
38
- static struct stat fileStat;
3936
#endif
4037
static int fileStatValid = 0;
38
+static struct stat fileStat;
39
+
40
+static int fossil_stat(const char *zFilename, struct stat *buf){
41
+#if !defined(_WIN32)
42
+ if( g.allowSymlinks ){
43
+ return lstat(zFilename, buf);
44
+ }else{
45
+ return stat(zFilename, buf);
46
+ }
47
+#else
48
+ return stat(zFilename, buf);
49
+#endif
50
+}
4151
4252
/*
4353
** Fill in the fileStat variable for the file named zFilename.
4454
** If zFilename==0, then use the previous value of fileStat if
4555
** there is a previous value.
@@ -50,11 +60,11 @@
5060
int rc = 0;
5161
if( zFilename==0 ){
5262
if( fileStatValid==0 ) rc = 1;
5363
}else{
5464
char *zMbcs = fossil_utf8_to_mbcs(zFilename);
55
- if( stat(zMbcs, &fileStat)!=0 ){
65
+ if( fossil_stat(zMbcs, &fileStat)!=0 ){
5666
fileStatValid = 0;
5767
rc = 1;
5868
}else{
5969
fileStatValid = 1;
6070
rc = 0;
@@ -80,10 +90,24 @@
8090
** recently stat-ed file.
8191
*/
8292
i64 file_mtime(const char *zFilename){
8393
return getStat(zFilename) ? -1 : fileStat.st_mtime;
8494
}
95
+
96
+/*
97
+** Return TRUE if the named file is an ordinary file or symlink
98
+** and symlinks are allowed.
99
+** Return false for directories, devices, fifos, etc.
100
+*/
101
+int file_isfile_or_link(const char *zFilename){
102
+#if !defined(_WIN32)
103
+ if ( g.allowSymlinks ){
104
+ return getStat(zFilename) ? 0 : S_ISREG(fileStat.st_mode) || S_ISLNK(fileStat.st_mode);
105
+ }
106
+#endif
107
+ return getStat(zFilename) ? 0 : S_ISREG(fileStat.st_mode);
108
+}
85109
86110
/*
87111
** Return TRUE if the named file is an ordinary file. Return false
88112
** for directories, devices, fifos, symlinks, etc.
89113
*/
@@ -90,25 +114,98 @@
90114
int file_isfile(const char *zFilename){
91115
return getStat(zFilename) ? 0 : S_ISREG(fileStat.st_mode);
92116
}
93117
94118
/*
95
-** Return TRUE if the named file is an executable. Return false
96
-** for directories, devices, fifos, symlinks, etc.
119
+** Create symlink to file on Unix, or plain-text file with
120
+** symlink target if "allow-symlinks" is off or we're on Windows.
121
+**
122
+** Arguments: target file (symlink will point to it), link file
123
+**/
124
+void create_symlink(const char *zTargetFile, const char *zLinkFile){
125
+#if !defined(_WIN32)
126
+ if( g.allowSymlinks ){
127
+ int i, nName;
128
+ char *zName, zBuf[1000];
129
+
130
+ nName = strlen(zLinkFile);
131
+ if( nName>=sizeof(zBuf) ){
132
+ zName = mprintf("%s", zLinkFile);
133
+ }else{
134
+ zName = zBuf;
135
+ memcpy(zName, zLinkFile, nName+1);
136
+ }
137
+ nName = file_simplify_name(zName, nName);
138
+ for(i=1; i<nName; i++){
139
+ if( zName[i]=='/' ){
140
+ zName[i] = 0;
141
+ if( file_mkdir(zName, 1) ){
142
+ fossil_fatal_recursive("unable to create directory %s", zName);
143
+ return;
144
+ }
145
+ zName[i] = '/';
146
+ }
147
+ }
148
+ if( zName!=zBuf ) free(zName);
149
+
150
+ if( symlink(zTargetFile, zName)!=0 ){
151
+ fossil_fatal_recursive("unable to create symlink \"%s\"", zName);
152
+ }
153
+ }else
154
+#endif
155
+ {
156
+ Blob content;
157
+ blob_set(&content, zTargetFile);
158
+ blob_write_to_file(&content, zLinkFile);
159
+ blob_reset(&content);
160
+ }
161
+}
162
+
163
+/*
164
+** Return file permissions (normal, executable, or symlink):
165
+** - PERM_EXE if file is executable;
166
+** - PERM_LNK on Unix if file is symlink and allow-symlinks option is on;
167
+** - PERM_REG for all other cases (regular file, directory, fifo, etc).
97168
*/
98
-int file_isexe(const char *zFilename){
99
- if( getStat(zFilename) || !S_ISREG(fileStat.st_mode) ) return 0;
169
+int file_perm(const char *zFilename){
170
+ if( getStat(zFilename) ) return PERM_REG;
100171
#if defined(_WIN32)
101172
# if defined(__DMC__) || defined(_MSC_VER)
102173
# define S_IXUSR _S_IEXEC
103174
# endif
104
- return ((S_IXUSR)&fileStat.st_mode)!=0;
175
+ if( S_ISREG(fileStat.st_mode) && ((S_IXUSR)&fileStat.st_mode)!=0 )
176
+ return PERM_EXE;
177
+ else
178
+ return PERM_REG;
105179
#else
106
- return ((S_IXUSR|S_IXGRP|S_IXOTH)&fileStat.st_mode)!=0;
180
+ if( S_ISREG(fileStat.st_mode) &&
181
+ ((S_IXUSR|S_IXGRP|S_IXOTH)&fileStat.st_mode)!=0 )
182
+ return PERM_EXE;
183
+ else if( g.allowSymlinks && S_ISLNK(fileStat.st_mode) )
184
+ return PERM_LNK;
185
+ else
186
+ return PERM_REG;
107187
#endif
108188
}
109189
190
+/*
191
+** Return TRUE if the named file is an executable. Return false
192
+** for directories, devices, fifos, symlinks, etc.
193
+*/
194
+int file_isexe(const char *zFilename){
195
+ return file_perm(zFilename)==PERM_EXE;
196
+}
197
+
198
+/*
199
+** Return TRUE if the named file is a symlink and symlinks are allowed.
200
+** Return false for all other cases.
201
+**
202
+** On Windows, always return False.
203
+*/
204
+int file_islink(const char *zFilename){
205
+ return file_perm(zFilename)==PERM_LNK;
206
+}
110207
111208
/*
112209
** Return 1 if zFilename is a directory. Return 0 if zFilename
113210
** does not exist. Return 2 if zFilename exists but is something
114211
** other than a directory.
@@ -122,11 +219,19 @@
122219
rc = getStat(zFN);
123220
free(zFN);
124221
}else{
125222
rc = getStat(0);
126223
}
224
+#if !defined(_WIN32)
225
+ if( g.allowSymlinks ){
226
+ return rc ? 0 : (S_ISDIR(fileStat.st_mode) && !S_ISLNK(fileStat.st_mode) ? 1 : 2);
227
+ }else{
228
+ return rc ? 0 : (S_ISDIR(fileStat.st_mode) ? 1 : 2);
229
+ }
230
+#else
127231
return rc ? 0 : (S_ISDIR(fileStat.st_mode) ? 1 : 2);
232
+#endif
128233
}
129234
130235
/*
131236
** Wrapper around the access() system call.
132237
*/
@@ -199,11 +304,11 @@
199304
*/
200305
int file_setexe(const char *zFilename, int onoff){
201306
int rc = 0;
202307
#if !defined(_WIN32)
203308
struct stat buf;
204
- if( stat(zFilename, &buf)!=0 ) return 0;
309
+ if( fossil_stat(zFilename, &buf)!=0 || S_ISLNK(buf.st_mode) ) return 0;
205310
if( onoff ){
206311
int targetMode = (buf.st_mode & 0444)>>2;
207312
if( (buf.st_mode & 0111)!=targetMode ){
208313
chmod(zFilename, buf.st_mode | targetMode);
209314
rc = 1;
@@ -469,10 +574,12 @@
469574
sqlite3_snprintf(sizeof(zBuf), zBuf, "%lld", file_size(zName));
470575
fossil_print(" file_size = %s\n", zBuf);
471576
sqlite3_snprintf(sizeof(zBuf), zBuf, "%lld", file_mtime(zName));
472577
fossil_print(" file_mtime = %s\n", zBuf);
473578
fossil_print(" file_isfile = %d\n", file_isfile(zName));
579
+ fossil_print(" file_isfile_or_link = %d\n", file_isfile_or_link(zName));
580
+ fossil_print(" file_islink = %d\n", file_islink(zName));
474581
fossil_print(" file_isexe = %d\n", file_isexe(zName));
475582
fossil_print(" file_isdir = %d\n", file_isdir(zName));
476583
}
477584
}
478585
@@ -739,11 +846,15 @@
739846
Blob onDisk;
740847
741848
iSize = file_size(zName);
742849
if( iSize<0 ) return 0;
743850
if( iSize!=blob_size(pContent) ) return 0;
744
- blob_read_from_file(&onDisk, zName);
851
+ if( file_islink(zName) ){
852
+ blob_read_link(&onDisk, zName);
853
+ }else{
854
+ blob_read_from_file(&onDisk, zName);
855
+ }
745856
rc = blob_compare(&onDisk, pContent);
746857
blob_reset(&onDisk);
747858
return rc==0;
748859
}
749860
750861
--- src/file.c
+++ src/file.c
@@ -30,16 +30,26 @@
30 **
31 ** Use _stati64 rather than stat on windows, in order to handle files
32 ** larger than 2GB.
33 */
34 #if defined(_WIN32) && defined(__MSVCRT__)
35 static struct _stati64 fileStat;
36 # define stat _stati64
37 #else
38 static struct stat fileStat;
39 #endif
40 static int fileStatValid = 0;
 
 
 
 
 
 
 
 
 
 
 
 
 
41
42 /*
43 ** Fill in the fileStat variable for the file named zFilename.
44 ** If zFilename==0, then use the previous value of fileStat if
45 ** there is a previous value.
@@ -50,11 +60,11 @@
50 int rc = 0;
51 if( zFilename==0 ){
52 if( fileStatValid==0 ) rc = 1;
53 }else{
54 char *zMbcs = fossil_utf8_to_mbcs(zFilename);
55 if( stat(zMbcs, &fileStat)!=0 ){
56 fileStatValid = 0;
57 rc = 1;
58 }else{
59 fileStatValid = 1;
60 rc = 0;
@@ -80,10 +90,24 @@
80 ** recently stat-ed file.
81 */
82 i64 file_mtime(const char *zFilename){
83 return getStat(zFilename) ? -1 : fileStat.st_mtime;
84 }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
85
86 /*
87 ** Return TRUE if the named file is an ordinary file. Return false
88 ** for directories, devices, fifos, symlinks, etc.
89 */
@@ -90,25 +114,98 @@
90 int file_isfile(const char *zFilename){
91 return getStat(zFilename) ? 0 : S_ISREG(fileStat.st_mode);
92 }
93
94 /*
95 ** Return TRUE if the named file is an executable. Return false
96 ** for directories, devices, fifos, symlinks, etc.
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
97 */
98 int file_isexe(const char *zFilename){
99 if( getStat(zFilename) || !S_ISREG(fileStat.st_mode) ) return 0;
100 #if defined(_WIN32)
101 # if defined(__DMC__) || defined(_MSC_VER)
102 # define S_IXUSR _S_IEXEC
103 # endif
104 return ((S_IXUSR)&fileStat.st_mode)!=0;
 
 
 
105 #else
106 return ((S_IXUSR|S_IXGRP|S_IXOTH)&fileStat.st_mode)!=0;
 
 
 
 
 
 
107 #endif
108 }
109
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
110
111 /*
112 ** Return 1 if zFilename is a directory. Return 0 if zFilename
113 ** does not exist. Return 2 if zFilename exists but is something
114 ** other than a directory.
@@ -122,11 +219,19 @@
122 rc = getStat(zFN);
123 free(zFN);
124 }else{
125 rc = getStat(0);
126 }
 
 
 
 
 
 
 
127 return rc ? 0 : (S_ISDIR(fileStat.st_mode) ? 1 : 2);
 
128 }
129
130 /*
131 ** Wrapper around the access() system call.
132 */
@@ -199,11 +304,11 @@
199 */
200 int file_setexe(const char *zFilename, int onoff){
201 int rc = 0;
202 #if !defined(_WIN32)
203 struct stat buf;
204 if( stat(zFilename, &buf)!=0 ) return 0;
205 if( onoff ){
206 int targetMode = (buf.st_mode & 0444)>>2;
207 if( (buf.st_mode & 0111)!=targetMode ){
208 chmod(zFilename, buf.st_mode | targetMode);
209 rc = 1;
@@ -469,10 +574,12 @@
469 sqlite3_snprintf(sizeof(zBuf), zBuf, "%lld", file_size(zName));
470 fossil_print(" file_size = %s\n", zBuf);
471 sqlite3_snprintf(sizeof(zBuf), zBuf, "%lld", file_mtime(zName));
472 fossil_print(" file_mtime = %s\n", zBuf);
473 fossil_print(" file_isfile = %d\n", file_isfile(zName));
 
 
474 fossil_print(" file_isexe = %d\n", file_isexe(zName));
475 fossil_print(" file_isdir = %d\n", file_isdir(zName));
476 }
477 }
478
@@ -739,11 +846,15 @@
739 Blob onDisk;
740
741 iSize = file_size(zName);
742 if( iSize<0 ) return 0;
743 if( iSize!=blob_size(pContent) ) return 0;
744 blob_read_from_file(&onDisk, zName);
 
 
 
 
745 rc = blob_compare(&onDisk, pContent);
746 blob_reset(&onDisk);
747 return rc==0;
748 }
749
750
--- src/file.c
+++ src/file.c
@@ -30,16 +30,26 @@
30 **
31 ** Use _stati64 rather than stat on windows, in order to handle files
32 ** larger than 2GB.
33 */
34 #if defined(_WIN32) && defined(__MSVCRT__)
 
35 # define stat _stati64
 
 
36 #endif
37 static int fileStatValid = 0;
38 static struct stat fileStat;
39
40 static int fossil_stat(const char *zFilename, struct stat *buf){
41 #if !defined(_WIN32)
42 if( g.allowSymlinks ){
43 return lstat(zFilename, buf);
44 }else{
45 return stat(zFilename, buf);
46 }
47 #else
48 return stat(zFilename, buf);
49 #endif
50 }
51
52 /*
53 ** Fill in the fileStat variable for the file named zFilename.
54 ** If zFilename==0, then use the previous value of fileStat if
55 ** there is a previous value.
@@ -50,11 +60,11 @@
60 int rc = 0;
61 if( zFilename==0 ){
62 if( fileStatValid==0 ) rc = 1;
63 }else{
64 char *zMbcs = fossil_utf8_to_mbcs(zFilename);
65 if( fossil_stat(zMbcs, &fileStat)!=0 ){
66 fileStatValid = 0;
67 rc = 1;
68 }else{
69 fileStatValid = 1;
70 rc = 0;
@@ -80,10 +90,24 @@
90 ** recently stat-ed file.
91 */
92 i64 file_mtime(const char *zFilename){
93 return getStat(zFilename) ? -1 : fileStat.st_mtime;
94 }
95
96 /*
97 ** Return TRUE if the named file is an ordinary file or symlink
98 ** and symlinks are allowed.
99 ** Return false for directories, devices, fifos, etc.
100 */
101 int file_isfile_or_link(const char *zFilename){
102 #if !defined(_WIN32)
103 if ( g.allowSymlinks ){
104 return getStat(zFilename) ? 0 : S_ISREG(fileStat.st_mode) || S_ISLNK(fileStat.st_mode);
105 }
106 #endif
107 return getStat(zFilename) ? 0 : S_ISREG(fileStat.st_mode);
108 }
109
110 /*
111 ** Return TRUE if the named file is an ordinary file. Return false
112 ** for directories, devices, fifos, symlinks, etc.
113 */
@@ -90,25 +114,98 @@
114 int file_isfile(const char *zFilename){
115 return getStat(zFilename) ? 0 : S_ISREG(fileStat.st_mode);
116 }
117
118 /*
119 ** Create symlink to file on Unix, or plain-text file with
120 ** symlink target if "allow-symlinks" is off or we're on Windows.
121 **
122 ** Arguments: target file (symlink will point to it), link file
123 **/
124 void create_symlink(const char *zTargetFile, const char *zLinkFile){
125 #if !defined(_WIN32)
126 if( g.allowSymlinks ){
127 int i, nName;
128 char *zName, zBuf[1000];
129
130 nName = strlen(zLinkFile);
131 if( nName>=sizeof(zBuf) ){
132 zName = mprintf("%s", zLinkFile);
133 }else{
134 zName = zBuf;
135 memcpy(zName, zLinkFile, nName+1);
136 }
137 nName = file_simplify_name(zName, nName);
138 for(i=1; i<nName; i++){
139 if( zName[i]=='/' ){
140 zName[i] = 0;
141 if( file_mkdir(zName, 1) ){
142 fossil_fatal_recursive("unable to create directory %s", zName);
143 return;
144 }
145 zName[i] = '/';
146 }
147 }
148 if( zName!=zBuf ) free(zName);
149
150 if( symlink(zTargetFile, zName)!=0 ){
151 fossil_fatal_recursive("unable to create symlink \"%s\"", zName);
152 }
153 }else
154 #endif
155 {
156 Blob content;
157 blob_set(&content, zTargetFile);
158 blob_write_to_file(&content, zLinkFile);
159 blob_reset(&content);
160 }
161 }
162
163 /*
164 ** Return file permissions (normal, executable, or symlink):
165 ** - PERM_EXE if file is executable;
166 ** - PERM_LNK on Unix if file is symlink and allow-symlinks option is on;
167 ** - PERM_REG for all other cases (regular file, directory, fifo, etc).
168 */
169 int file_perm(const char *zFilename){
170 if( getStat(zFilename) ) return PERM_REG;
171 #if defined(_WIN32)
172 # if defined(__DMC__) || defined(_MSC_VER)
173 # define S_IXUSR _S_IEXEC
174 # endif
175 if( S_ISREG(fileStat.st_mode) && ((S_IXUSR)&fileStat.st_mode)!=0 )
176 return PERM_EXE;
177 else
178 return PERM_REG;
179 #else
180 if( S_ISREG(fileStat.st_mode) &&
181 ((S_IXUSR|S_IXGRP|S_IXOTH)&fileStat.st_mode)!=0 )
182 return PERM_EXE;
183 else if( g.allowSymlinks && S_ISLNK(fileStat.st_mode) )
184 return PERM_LNK;
185 else
186 return PERM_REG;
187 #endif
188 }
189
190 /*
191 ** Return TRUE if the named file is an executable. Return false
192 ** for directories, devices, fifos, symlinks, etc.
193 */
194 int file_isexe(const char *zFilename){
195 return file_perm(zFilename)==PERM_EXE;
196 }
197
198 /*
199 ** Return TRUE if the named file is a symlink and symlinks are allowed.
200 ** Return false for all other cases.
201 **
202 ** On Windows, always return False.
203 */
204 int file_islink(const char *zFilename){
205 return file_perm(zFilename)==PERM_LNK;
206 }
207
208 /*
209 ** Return 1 if zFilename is a directory. Return 0 if zFilename
210 ** does not exist. Return 2 if zFilename exists but is something
211 ** other than a directory.
@@ -122,11 +219,19 @@
219 rc = getStat(zFN);
220 free(zFN);
221 }else{
222 rc = getStat(0);
223 }
224 #if !defined(_WIN32)
225 if( g.allowSymlinks ){
226 return rc ? 0 : (S_ISDIR(fileStat.st_mode) && !S_ISLNK(fileStat.st_mode) ? 1 : 2);
227 }else{
228 return rc ? 0 : (S_ISDIR(fileStat.st_mode) ? 1 : 2);
229 }
230 #else
231 return rc ? 0 : (S_ISDIR(fileStat.st_mode) ? 1 : 2);
232 #endif
233 }
234
235 /*
236 ** Wrapper around the access() system call.
237 */
@@ -199,11 +304,11 @@
304 */
305 int file_setexe(const char *zFilename, int onoff){
306 int rc = 0;
307 #if !defined(_WIN32)
308 struct stat buf;
309 if( fossil_stat(zFilename, &buf)!=0 || S_ISLNK(buf.st_mode) ) return 0;
310 if( onoff ){
311 int targetMode = (buf.st_mode & 0444)>>2;
312 if( (buf.st_mode & 0111)!=targetMode ){
313 chmod(zFilename, buf.st_mode | targetMode);
314 rc = 1;
@@ -469,10 +574,12 @@
574 sqlite3_snprintf(sizeof(zBuf), zBuf, "%lld", file_size(zName));
575 fossil_print(" file_size = %s\n", zBuf);
576 sqlite3_snprintf(sizeof(zBuf), zBuf, "%lld", file_mtime(zName));
577 fossil_print(" file_mtime = %s\n", zBuf);
578 fossil_print(" file_isfile = %d\n", file_isfile(zName));
579 fossil_print(" file_isfile_or_link = %d\n", file_isfile_or_link(zName));
580 fossil_print(" file_islink = %d\n", file_islink(zName));
581 fossil_print(" file_isexe = %d\n", file_isexe(zName));
582 fossil_print(" file_isdir = %d\n", file_isdir(zName));
583 }
584 }
585
@@ -739,11 +846,15 @@
846 Blob onDisk;
847
848 iSize = file_size(zName);
849 if( iSize<0 ) return 0;
850 if( iSize!=blob_size(pContent) ) return 0;
851 if( file_islink(zName) ){
852 blob_read_link(&onDisk, zName);
853 }else{
854 blob_read_from_file(&onDisk, zName);
855 }
856 rc = blob_compare(&onDisk, pContent);
857 blob_reset(&onDisk);
858 return rc==0;
859 }
860
861
+1 -1
--- src/finfo.c
+++ src/finfo.c
@@ -99,11 +99,11 @@
9999
Blob fname;
100100
const char *zRevision = find_option("revision", "r", 1);
101101
102102
file_tree_name(g.argv[2], &fname, 1);
103103
if( zRevision ){
104
- historical_version_of_file(zRevision, blob_str(&fname), &record, 0, 0);
104
+ historical_version_of_file(zRevision, blob_str(&fname), &record, 0, 0, 0);
105105
}else{
106106
int rid = db_int(0, "SELECT rid FROM vfile WHERE pathname=%B", &fname);
107107
if( rid==0 ){
108108
fossil_fatal("no history for file: %b", &fname);
109109
}
110110
--- src/finfo.c
+++ src/finfo.c
@@ -99,11 +99,11 @@
99 Blob fname;
100 const char *zRevision = find_option("revision", "r", 1);
101
102 file_tree_name(g.argv[2], &fname, 1);
103 if( zRevision ){
104 historical_version_of_file(zRevision, blob_str(&fname), &record, 0, 0);
105 }else{
106 int rid = db_int(0, "SELECT rid FROM vfile WHERE pathname=%B", &fname);
107 if( rid==0 ){
108 fossil_fatal("no history for file: %b", &fname);
109 }
110
--- src/finfo.c
+++ src/finfo.c
@@ -99,11 +99,11 @@
99 Blob fname;
100 const char *zRevision = find_option("revision", "r", 1);
101
102 file_tree_name(g.argv[2], &fname, 1);
103 if( zRevision ){
104 historical_version_of_file(zRevision, blob_str(&fname), &record, 0, 0, 0);
105 }else{
106 int rid = db_int(0, "SELECT rid FROM vfile WHERE pathname=%B", &fname);
107 if( rid==0 ){
108 fossil_fatal("no history for file: %b", &fname);
109 }
110
+13 -2
--- src/http_ssl.c
+++ src/http_ssl.c
@@ -249,11 +249,11 @@
249249
int j;
250250
for( j = 0; j < mdLength; ++j ) {
251251
BIO_printf(mem, " %02x", md[j]);
252252
}
253253
}
254
- BIO_write(mem, "", 1); // null-terminate mem buffer
254
+ BIO_write(mem, "", 1); /* null-terminate mem buffer */
255255
BIO_get_mem_data(mem, &desc);
256256
257257
if( hasSavedCertificate ){
258258
warning = "WARNING: Certificate doesn't match the "
259259
"saved certificate for this host!";
@@ -280,10 +280,21 @@
280280
if( blob_str(&ans)[0]=='a' ) {
281281
ssl_save_certificate(cert);
282282
}
283283
blob_reset(&ans);
284284
}
285
+
286
+ /* Set the Global.zIpAddr variable to the server we are talking to.
287
+ ** This is used to populate the ipaddr column of the rcvfrom table,
288
+ ** if any files are received from the server.
289
+ */
290
+ {
291
+ /* IPv4 only code */
292
+ const unsigned char *ip = (const unsigned char *) BIO_get_conn_ip(iBio);
293
+ g.zIpAddr = mprintf("%d.%d.%d.%d", ip[0], ip[1], ip[2], ip[3]);
294
+ }
295
+
285296
X509_free(cert);
286297
return 0;
287298
}
288299
289300
/*
@@ -293,11 +304,11 @@
293304
BIO *mem;
294305
char *zCert, *zHost;
295306
296307
mem = BIO_new(BIO_s_mem());
297308
PEM_write_bio_X509(mem, cert);
298
- BIO_write(mem, "", 1); // null-terminate mem buffer
309
+ BIO_write(mem, "", 1); /* null-terminate mem buffer */
299310
BIO_get_mem_data(mem, &zCert);
300311
zHost = mprintf("cert:%s", g.urlName);
301312
db_set(zHost, zCert, 1);
302313
free(zHost);
303314
BIO_free(mem);
304315
--- src/http_ssl.c
+++ src/http_ssl.c
@@ -249,11 +249,11 @@
249 int j;
250 for( j = 0; j < mdLength; ++j ) {
251 BIO_printf(mem, " %02x", md[j]);
252 }
253 }
254 BIO_write(mem, "", 1); // null-terminate mem buffer
255 BIO_get_mem_data(mem, &desc);
256
257 if( hasSavedCertificate ){
258 warning = "WARNING: Certificate doesn't match the "
259 "saved certificate for this host!";
@@ -280,10 +280,21 @@
280 if( blob_str(&ans)[0]=='a' ) {
281 ssl_save_certificate(cert);
282 }
283 blob_reset(&ans);
284 }
 
 
 
 
 
 
 
 
 
 
 
285 X509_free(cert);
286 return 0;
287 }
288
289 /*
@@ -293,11 +304,11 @@
293 BIO *mem;
294 char *zCert, *zHost;
295
296 mem = BIO_new(BIO_s_mem());
297 PEM_write_bio_X509(mem, cert);
298 BIO_write(mem, "", 1); // null-terminate mem buffer
299 BIO_get_mem_data(mem, &zCert);
300 zHost = mprintf("cert:%s", g.urlName);
301 db_set(zHost, zCert, 1);
302 free(zHost);
303 BIO_free(mem);
304
--- src/http_ssl.c
+++ src/http_ssl.c
@@ -249,11 +249,11 @@
249 int j;
250 for( j = 0; j < mdLength; ++j ) {
251 BIO_printf(mem, " %02x", md[j]);
252 }
253 }
254 BIO_write(mem, "", 1); /* null-terminate mem buffer */
255 BIO_get_mem_data(mem, &desc);
256
257 if( hasSavedCertificate ){
258 warning = "WARNING: Certificate doesn't match the "
259 "saved certificate for this host!";
@@ -280,10 +280,21 @@
280 if( blob_str(&ans)[0]=='a' ) {
281 ssl_save_certificate(cert);
282 }
283 blob_reset(&ans);
284 }
285
286 /* Set the Global.zIpAddr variable to the server we are talking to.
287 ** This is used to populate the ipaddr column of the rcvfrom table,
288 ** if any files are received from the server.
289 */
290 {
291 /* IPv4 only code */
292 const unsigned char *ip = (const unsigned char *) BIO_get_conn_ip(iBio);
293 g.zIpAddr = mprintf("%d.%d.%d.%d", ip[0], ip[1], ip[2], ip[3]);
294 }
295
296 X509_free(cert);
297 return 0;
298 }
299
300 /*
@@ -293,11 +304,11 @@
304 BIO *mem;
305 char *zCert, *zHost;
306
307 mem = BIO_new(BIO_s_mem());
308 PEM_write_bio_X509(mem, cert);
309 BIO_write(mem, "", 1); /* null-terminate mem buffer */
310 BIO_get_mem_data(mem, &zCert);
311 zHost = mprintf("cert:%s", g.urlName);
312 db_set(zHost, zCert, 1);
313 free(zHost);
314 BIO_free(mem);
315
+13 -2
--- src/http_ssl.c
+++ src/http_ssl.c
@@ -249,11 +249,11 @@
249249
int j;
250250
for( j = 0; j < mdLength; ++j ) {
251251
BIO_printf(mem, " %02x", md[j]);
252252
}
253253
}
254
- BIO_write(mem, "", 1); // null-terminate mem buffer
254
+ BIO_write(mem, "", 1); /* null-terminate mem buffer */
255255
BIO_get_mem_data(mem, &desc);
256256
257257
if( hasSavedCertificate ){
258258
warning = "WARNING: Certificate doesn't match the "
259259
"saved certificate for this host!";
@@ -280,10 +280,21 @@
280280
if( blob_str(&ans)[0]=='a' ) {
281281
ssl_save_certificate(cert);
282282
}
283283
blob_reset(&ans);
284284
}
285
+
286
+ /* Set the Global.zIpAddr variable to the server we are talking to.
287
+ ** This is used to populate the ipaddr column of the rcvfrom table,
288
+ ** if any files are received from the server.
289
+ */
290
+ {
291
+ /* IPv4 only code */
292
+ const unsigned char *ip = (const unsigned char *) BIO_get_conn_ip(iBio);
293
+ g.zIpAddr = mprintf("%d.%d.%d.%d", ip[0], ip[1], ip[2], ip[3]);
294
+ }
295
+
285296
X509_free(cert);
286297
return 0;
287298
}
288299
289300
/*
@@ -293,11 +304,11 @@
293304
BIO *mem;
294305
char *zCert, *zHost;
295306
296307
mem = BIO_new(BIO_s_mem());
297308
PEM_write_bio_X509(mem, cert);
298
- BIO_write(mem, "", 1); // null-terminate mem buffer
309
+ BIO_write(mem, "", 1); /* null-terminate mem buffer */
299310
BIO_get_mem_data(mem, &zCert);
300311
zHost = mprintf("cert:%s", g.urlName);
301312
db_set(zHost, zCert, 1);
302313
free(zHost);
303314
BIO_free(mem);
304315
--- src/http_ssl.c
+++ src/http_ssl.c
@@ -249,11 +249,11 @@
249 int j;
250 for( j = 0; j < mdLength; ++j ) {
251 BIO_printf(mem, " %02x", md[j]);
252 }
253 }
254 BIO_write(mem, "", 1); // null-terminate mem buffer
255 BIO_get_mem_data(mem, &desc);
256
257 if( hasSavedCertificate ){
258 warning = "WARNING: Certificate doesn't match the "
259 "saved certificate for this host!";
@@ -280,10 +280,21 @@
280 if( blob_str(&ans)[0]=='a' ) {
281 ssl_save_certificate(cert);
282 }
283 blob_reset(&ans);
284 }
 
 
 
 
 
 
 
 
 
 
 
285 X509_free(cert);
286 return 0;
287 }
288
289 /*
@@ -293,11 +304,11 @@
293 BIO *mem;
294 char *zCert, *zHost;
295
296 mem = BIO_new(BIO_s_mem());
297 PEM_write_bio_X509(mem, cert);
298 BIO_write(mem, "", 1); // null-terminate mem buffer
299 BIO_get_mem_data(mem, &zCert);
300 zHost = mprintf("cert:%s", g.urlName);
301 db_set(zHost, zCert, 1);
302 free(zHost);
303 BIO_free(mem);
304
--- src/http_ssl.c
+++ src/http_ssl.c
@@ -249,11 +249,11 @@
249 int j;
250 for( j = 0; j < mdLength; ++j ) {
251 BIO_printf(mem, " %02x", md[j]);
252 }
253 }
254 BIO_write(mem, "", 1); /* null-terminate mem buffer */
255 BIO_get_mem_data(mem, &desc);
256
257 if( hasSavedCertificate ){
258 warning = "WARNING: Certificate doesn't match the "
259 "saved certificate for this host!";
@@ -280,10 +280,21 @@
280 if( blob_str(&ans)[0]=='a' ) {
281 ssl_save_certificate(cert);
282 }
283 blob_reset(&ans);
284 }
285
286 /* Set the Global.zIpAddr variable to the server we are talking to.
287 ** This is used to populate the ipaddr column of the rcvfrom table,
288 ** if any files are received from the server.
289 */
290 {
291 /* IPv4 only code */
292 const unsigned char *ip = (const unsigned char *) BIO_get_conn_ip(iBio);
293 g.zIpAddr = mprintf("%d.%d.%d.%d", ip[0], ip[1], ip[2], ip[3]);
294 }
295
296 X509_free(cert);
297 return 0;
298 }
299
300 /*
@@ -293,11 +304,11 @@
304 BIO *mem;
305 char *zCert, *zHost;
306
307 mem = BIO_new(BIO_s_mem());
308 PEM_write_bio_X509(mem, cert);
309 BIO_write(mem, "", 1); /* null-terminate mem buffer */
310 BIO_get_mem_data(mem, &zCert);
311 zHost = mprintf("cert:%s", g.urlName);
312 db_set(zHost, zCert, 1);
313 free(zHost);
314 BIO_free(mem);
315
+12
--- src/import.c
+++ src/import.c
@@ -30,10 +30,11 @@
3030
char *zName; /* Name of a file */
3131
char *zUuid; /* UUID of the file */
3232
char *zPrior; /* Prior name if the name was changed */
3333
char isFrom; /* True if obtained from the parent */
3434
char isExe; /* True if executable */
35
+ char isLink; /* True if symlink */
3536
};
3637
#endif
3738
3839
3940
/*
@@ -58,10 +59,11 @@
5859
char **azMerge; /* Merge values */
5960
int nFile; /* Number of aFile values */
6061
int nFileAlloc; /* Number of slots in aFile[] */
6162
ImportFile *aFile; /* Information about files in a commit */
6263
int fromLoaded; /* True zFrom content loaded into aFile[] */
64
+ int hasLinks; /* True if git repository contains symlinks */
6365
int tagCommit; /* True if the commit adds a tag */
6466
} gg;
6567
6668
/*
6769
** Duplicate a string.
@@ -242,10 +244,13 @@
242244
const char *zUuid = gg.aFile[i].zUuid;
243245
if( zUuid==0 ) continue;
244246
blob_appendf(&record, "F %F %s", gg.aFile[i].zName, zUuid);
245247
if( gg.aFile[i].isExe ){
246248
blob_append(&record, " x\n", 3);
249
+ }else if( gg.aFile[i].isLink ){
250
+ blob_append(&record, " l\n", 3);
251
+ gg.hasLinks = 1;
247252
}else{
248253
blob_append(&record, "\n", 1);
249254
}
250255
}
251256
if( gg.zFrom ){
@@ -421,10 +426,11 @@
421426
manifest_file_rewind(p);
422427
while( (pOld = manifest_file_next(p, 0))!=0 ){
423428
pNew = import_add_file();
424429
pNew->zName = fossil_strdup(pOld->zName);
425430
pNew->isExe = pOld->zPerm && strstr(pOld->zPerm, "x")!=0;
431
+ pNew->isLink = pOld->zPerm && strstr(pOld->zPerm, "l")!=0;
426432
pNew->zUuid = fossil_strdup(pOld->zUuid);
427433
pNew->isFrom = 1;
428434
}
429435
manifest_destroy(p);
430436
}
@@ -597,10 +603,11 @@
597603
if( pFile==0 ){
598604
pFile = import_add_file();
599605
pFile->zName = fossil_strdup(zName);
600606
}
601607
pFile->isExe = (fossil_strcmp(zPerm, "100755")==0);
608
+ pFile->isLink = (fossil_strcmp(zPerm, "120000")==0);
602609
fossil_free(pFile->zUuid);
603610
pFile->zUuid = resolve_committish(zUuid);
604611
pFile->isFrom = 0;
605612
}else
606613
if( memcmp(zLine, "D ", 2)==0 ){
@@ -634,10 +641,11 @@
634641
pNew->zName = mprintf("%s%s", zTo, pFile->zName[nFrom]);
635642
}else{
636643
pNew->zName = fossil_strdup(pFile->zName);
637644
}
638645
pNew->isExe = pFile->isExe;
646
+ pNew->isLink = pFile->isLink;
639647
pNew->zUuid = fossil_strdup(pFile->zUuid);
640648
pNew->isFrom = 0;
641649
}
642650
}else
643651
if( memcmp(zLine, "R ", 2)==0 ){
@@ -657,10 +665,11 @@
657665
}else{
658666
pNew->zName = fossil_strdup(pFile->zName);
659667
}
660668
pNew->zPrior = pFile->zName;
661669
pNew->isExe = pFile->isExe;
670
+ pNew->isLink = pFile->isLink;
662671
pNew->zUuid = pFile->zUuid;
663672
pNew->isFrom = 0;
664673
gg.nFile--;
665674
*pFile = *pNew;
666675
memset(pNew, 0, sizeof(*pNew));
@@ -677,10 +686,13 @@
677686
{
678687
goto malformed_line;
679688
}
680689
}
681690
gg.xFinish();
691
+ if( gg.hasLinks ){
692
+ db_set_int("allow-symlinks", 1, 0);
693
+ }
682694
import_reset(1);
683695
return;
684696
685697
malformed_line:
686698
trim_newline(zLine);
687699
--- src/import.c
+++ src/import.c
@@ -30,10 +30,11 @@
30 char *zName; /* Name of a file */
31 char *zUuid; /* UUID of the file */
32 char *zPrior; /* Prior name if the name was changed */
33 char isFrom; /* True if obtained from the parent */
34 char isExe; /* True if executable */
 
35 };
36 #endif
37
38
39 /*
@@ -58,10 +59,11 @@
58 char **azMerge; /* Merge values */
59 int nFile; /* Number of aFile values */
60 int nFileAlloc; /* Number of slots in aFile[] */
61 ImportFile *aFile; /* Information about files in a commit */
62 int fromLoaded; /* True zFrom content loaded into aFile[] */
 
63 int tagCommit; /* True if the commit adds a tag */
64 } gg;
65
66 /*
67 ** Duplicate a string.
@@ -242,10 +244,13 @@
242 const char *zUuid = gg.aFile[i].zUuid;
243 if( zUuid==0 ) continue;
244 blob_appendf(&record, "F %F %s", gg.aFile[i].zName, zUuid);
245 if( gg.aFile[i].isExe ){
246 blob_append(&record, " x\n", 3);
 
 
 
247 }else{
248 blob_append(&record, "\n", 1);
249 }
250 }
251 if( gg.zFrom ){
@@ -421,10 +426,11 @@
421 manifest_file_rewind(p);
422 while( (pOld = manifest_file_next(p, 0))!=0 ){
423 pNew = import_add_file();
424 pNew->zName = fossil_strdup(pOld->zName);
425 pNew->isExe = pOld->zPerm && strstr(pOld->zPerm, "x")!=0;
 
426 pNew->zUuid = fossil_strdup(pOld->zUuid);
427 pNew->isFrom = 1;
428 }
429 manifest_destroy(p);
430 }
@@ -597,10 +603,11 @@
597 if( pFile==0 ){
598 pFile = import_add_file();
599 pFile->zName = fossil_strdup(zName);
600 }
601 pFile->isExe = (fossil_strcmp(zPerm, "100755")==0);
 
602 fossil_free(pFile->zUuid);
603 pFile->zUuid = resolve_committish(zUuid);
604 pFile->isFrom = 0;
605 }else
606 if( memcmp(zLine, "D ", 2)==0 ){
@@ -634,10 +641,11 @@
634 pNew->zName = mprintf("%s%s", zTo, pFile->zName[nFrom]);
635 }else{
636 pNew->zName = fossil_strdup(pFile->zName);
637 }
638 pNew->isExe = pFile->isExe;
 
639 pNew->zUuid = fossil_strdup(pFile->zUuid);
640 pNew->isFrom = 0;
641 }
642 }else
643 if( memcmp(zLine, "R ", 2)==0 ){
@@ -657,10 +665,11 @@
657 }else{
658 pNew->zName = fossil_strdup(pFile->zName);
659 }
660 pNew->zPrior = pFile->zName;
661 pNew->isExe = pFile->isExe;
 
662 pNew->zUuid = pFile->zUuid;
663 pNew->isFrom = 0;
664 gg.nFile--;
665 *pFile = *pNew;
666 memset(pNew, 0, sizeof(*pNew));
@@ -677,10 +686,13 @@
677 {
678 goto malformed_line;
679 }
680 }
681 gg.xFinish();
 
 
 
682 import_reset(1);
683 return;
684
685 malformed_line:
686 trim_newline(zLine);
687
--- src/import.c
+++ src/import.c
@@ -30,10 +30,11 @@
30 char *zName; /* Name of a file */
31 char *zUuid; /* UUID of the file */
32 char *zPrior; /* Prior name if the name was changed */
33 char isFrom; /* True if obtained from the parent */
34 char isExe; /* True if executable */
35 char isLink; /* True if symlink */
36 };
37 #endif
38
39
40 /*
@@ -58,10 +59,11 @@
59 char **azMerge; /* Merge values */
60 int nFile; /* Number of aFile values */
61 int nFileAlloc; /* Number of slots in aFile[] */
62 ImportFile *aFile; /* Information about files in a commit */
63 int fromLoaded; /* True zFrom content loaded into aFile[] */
64 int hasLinks; /* True if git repository contains symlinks */
65 int tagCommit; /* True if the commit adds a tag */
66 } gg;
67
68 /*
69 ** Duplicate a string.
@@ -242,10 +244,13 @@
244 const char *zUuid = gg.aFile[i].zUuid;
245 if( zUuid==0 ) continue;
246 blob_appendf(&record, "F %F %s", gg.aFile[i].zName, zUuid);
247 if( gg.aFile[i].isExe ){
248 blob_append(&record, " x\n", 3);
249 }else if( gg.aFile[i].isLink ){
250 blob_append(&record, " l\n", 3);
251 gg.hasLinks = 1;
252 }else{
253 blob_append(&record, "\n", 1);
254 }
255 }
256 if( gg.zFrom ){
@@ -421,10 +426,11 @@
426 manifest_file_rewind(p);
427 while( (pOld = manifest_file_next(p, 0))!=0 ){
428 pNew = import_add_file();
429 pNew->zName = fossil_strdup(pOld->zName);
430 pNew->isExe = pOld->zPerm && strstr(pOld->zPerm, "x")!=0;
431 pNew->isLink = pOld->zPerm && strstr(pOld->zPerm, "l")!=0;
432 pNew->zUuid = fossil_strdup(pOld->zUuid);
433 pNew->isFrom = 1;
434 }
435 manifest_destroy(p);
436 }
@@ -597,10 +603,11 @@
603 if( pFile==0 ){
604 pFile = import_add_file();
605 pFile->zName = fossil_strdup(zName);
606 }
607 pFile->isExe = (fossil_strcmp(zPerm, "100755")==0);
608 pFile->isLink = (fossil_strcmp(zPerm, "120000")==0);
609 fossil_free(pFile->zUuid);
610 pFile->zUuid = resolve_committish(zUuid);
611 pFile->isFrom = 0;
612 }else
613 if( memcmp(zLine, "D ", 2)==0 ){
@@ -634,10 +641,11 @@
641 pNew->zName = mprintf("%s%s", zTo, pFile->zName[nFrom]);
642 }else{
643 pNew->zName = fossil_strdup(pFile->zName);
644 }
645 pNew->isExe = pFile->isExe;
646 pNew->isLink = pFile->isLink;
647 pNew->zUuid = fossil_strdup(pFile->zUuid);
648 pNew->isFrom = 0;
649 }
650 }else
651 if( memcmp(zLine, "R ", 2)==0 ){
@@ -657,10 +665,11 @@
665 }else{
666 pNew->zName = fossil_strdup(pFile->zName);
667 }
668 pNew->zPrior = pFile->zName;
669 pNew->isExe = pFile->isExe;
670 pNew->isLink = pFile->isLink;
671 pNew->zUuid = pFile->zUuid;
672 pNew->isFrom = 0;
673 gg.nFile--;
674 *pFile = *pNew;
675 memset(pNew, 0, sizeof(*pNew));
@@ -677,10 +686,13 @@
686 {
687 goto malformed_line;
688 }
689 }
690 gg.xFinish();
691 if( gg.hasLinks ){
692 db_set_int("allow-symlinks", 1, 0);
693 }
694 import_reset(1);
695 return;
696
697 malformed_line:
698 trim_newline(zLine);
699
+51 -30
--- src/info.c
+++ src/info.c
@@ -282,21 +282,22 @@
282282
const char *zName, /* Name of the file that has changed */
283283
const char *zOld, /* blob.uuid before change. NULL for added files */
284284
const char *zNew, /* blob.uuid after change. NULL for deletes */
285285
const char *zOldName, /* Prior name. NULL if no name change. */
286286
int showDiff, /* Show edit diffs if true */
287
- int mperm /* EXE permission for zNew */
287
+ int mperm /* executable or symlink permission for zNew */
288288
){
289289
if( !g.okHistory ){
290290
if( zNew==0 ){
291291
@ <p>Deleted %h(zName)</p>
292292
}else if( zOld==0 ){
293293
@ <p>Added %h(zName)</p>
294294
}else if( zOldName!=0 && fossil_strcmp(zName,zOldName)!=0 ){
295295
@ <p>Name change from %h(zOldName) to %h(zName)
296296
}else if( fossil_strcmp(zNew, zOld)==0 ){
297
- @ <p>Execute permission %s(mperm?"set":"cleared") for %h(zName)</p>
297
+ @ <p>Execute permission %s(( mperm==PERM_EXE )?"set":"cleared")
298
+ @ for %h(zName)</p>
298299
}else{
299300
@ <p>Changes to %h(zName)</p>
300301
}
301302
if( showDiff ){
302303
@ <blockquote><pre>
@@ -312,11 +313,11 @@
312313
}else if( zOldName!=0 && fossil_strcmp(zName,zOldName)!=0 ){
313314
@ <p>Name change from
314315
@ from <a href="%s(g.zTop)/finfo?name=%T(zOldName)">%h(zOldName)</a>
315316
@ to <a href="%s(g.zTop)/finfo?name=%T(zName)">%h(zName)</a>.
316317
}else{
317
- @ <p>Execute permission %s(mperm?"set":"cleared") for
318
+ @ <p>Execute permission %s(( mperm==PERM_EXE )?"set":"cleared") for
318319
@ <a href="%s(g.zTop)/finfo?name=%T(zName)">%h(zName)</a>
319320
}
320321
}else if( zOld ){
321322
@ <p>Deleted <a href="%s(g.zTop)/finfo?name=%T(zName)">%h(zName)</a>
322323
@ version <a href="%s(g.zTop)/artifact/%s(zOld)">[%S(zOld)]</a>
@@ -776,53 +777,81 @@
776777
Stmt q;
777778
int cnt = 0;
778779
int nWiki = 0;
779780
char *zUuid = db_text(0, "SELECT uuid FROM blob WHERE rid=%d", rid);
780781
782
+ char *prevName = 0;
783
+
781784
db_prepare(&q,
782785
"SELECT filename.name, datetime(event.mtime),"
783786
" coalesce(event.ecomment,event.comment),"
784787
" coalesce(event.euser,event.user),"
785
- " b.uuid"
788
+ " b.uuid, mlink.mperm,"
789
+ " coalesce((SELECT value FROM tagxref"
790
+ " WHERE tagid=%d AND tagtype>0 AND rid=mlink.mid),'trunk')"
786791
" FROM mlink, filename, event, blob a, blob b"
787792
" WHERE filename.fnid=mlink.fnid"
788793
" AND event.objid=mlink.mid"
789794
" AND a.rid=mlink.fid"
790795
" AND b.rid=mlink.mid"
791
- " AND mlink.fid=%d",
792
- rid
796
+ " AND mlink.fid=%d"
797
+ " ORDER BY filename.name, event.mtime",
798
+ TAG_BRANCH, rid
793799
);
800
+ @ <ul>
794801
while( db_step(&q)==SQLITE_ROW ){
795802
const char *zName = db_column_text(&q, 0);
796803
const char *zDate = db_column_text(&q, 1);
797804
const char *zCom = db_column_text(&q, 2);
798805
const char *zUser = db_column_text(&q, 3);
799806
const char *zVers = db_column_text(&q, 4);
800
- if( cnt>0 ){
801
- @ Also file
802
- }else{
803
- @ File
804
- }
805
- if( g.okHistory ){
806
- @ <a href="%s(g.zTop)/finfo?name=%T(zName)">%h(zName)</a>
807
- }else{
808
- @ %h(zName)
809
- }
810
- @ part of check-in
807
+ int mPerm = db_column_int(&q, 5);
808
+ const char *zBr = db_column_text(&q, 6);
809
+ if( !prevName || fossil_strcmp(zName, prevName) ) {
810
+ if( prevName ) {
811
+ @ </ul>
812
+ }
813
+ if( mPerm==PERM_LNK ){
814
+ @ <li>Symbolic link
815
+ }else if( mPerm==PERM_EXE ){
816
+ @ <li>Executable file
817
+ }else{
818
+ @ <li>File
819
+ }
820
+ if( g.okHistory ){
821
+ @ <a href="%s(g.zTop)/finfo?name=%T(zName)">%h(zName)</a>
822
+ }else{
823
+ @ %h(zName)
824
+ }
825
+ @ <ul>
826
+ prevName = fossil_strdup(zName);
827
+ }
828
+ @ <li>
829
+ hyperlink_to_date(zDate,"");
830
+ @ - part of checkin
811831
hyperlink_to_uuid(zVers);
812
- @ - %w(zCom) by
813
- hyperlink_to_user(zUser,zDate," on");
814
- hyperlink_to_date(zDate,".");
832
+ if( zBr && zBr[0] ){
833
+ if( g.okHistory ){
834
+ @ on branch <a href="%s(g.zTop)/timeline?r=%T(zBr)">%h(zBr)</a>
835
+ }else{
836
+ @ on branch %h(zBr)
837
+ }
838
+ }
839
+ @ - %w(zCom) (user:
840
+ hyperlink_to_user(zUser,zDate,"");
841
+ @ )
815842
if( g.okHistory ){
816843
@ <a href="%s(g.zTop)/annotate?checkin=%S(zVers)&filename=%T(zName)">
817844
@ [annotate]</a>
818845
}
819846
cnt++;
820847
if( pDownloadName && blob_size(pDownloadName)==0 ){
821848
blob_append(pDownloadName, zName, -1);
822849
}
823850
}
851
+ @ </ul></ul>
852
+ free(prevName);
824853
db_finalize(&q);
825854
db_prepare(&q,
826855
"SELECT substr(tagname, 6, 10000), datetime(event.mtime),"
827856
" coalesce(event.euser, event.user)"
828857
" FROM tagxref, tag, event"
@@ -988,17 +1017,13 @@
9881017
style_header("Diff");
9891018
style_submenu_element("Patch", "Patch", "%s/fdiff?v1=%T&v2=%T&patch",
9901019
g.zTop, P("v1"), P("v2"));
9911020
@ <h2>Differences From
9921021
@ Artifact <a href="%s(g.zTop)/artifact/%S(zV1)">[%S(zV1)]</a>:</h2>
993
- @ <blockquote><p>
994
- object_description(v1, 1, 0);
995
- @ </p></blockquote>
1022
+ object_description(v1, 0, 0);
9961023
@ <h2>To Artifact <a href="%s(g.zTop)/artifact/%S(zV2)">[%S(zV2)]</a>:</h2>
997
- @ <blockquote><p>
998
- object_description(v2, 1, 0);
999
- @ </p></blockquote>
1024
+ object_description(v2, 0, 0);
10001025
@ <hr />
10011026
@ <blockquote><pre>
10021027
@ %h(blob_str(&diff))
10031028
@ </pre></blockquote>
10041029
blob_reset(&diff);
@@ -1107,16 +1132,14 @@
11071132
}
11081133
}
11091134
style_header("Hex Artifact Content");
11101135
zUuid = db_text("?","SELECT uuid FROM blob WHERE rid=%d", rid);
11111136
@ <h2>Artifact %s(zUuid):</h2>
1112
- @ <blockquote><p>
11131137
blob_zero(&downloadName);
11141138
object_description(rid, 0, &downloadName);
11151139
style_submenu_element("Download", "Download",
11161140
"%s/raw/%T?name=%s", g.zTop, blob_str(&downloadName), zUuid);
1117
- @ </p></blockquote>
11181141
@ <hr />
11191142
content_get(rid, &content);
11201143
@ <blockquote><pre>
11211144
hexdump(&content);
11221145
@ </pre></blockquote>
@@ -1256,11 +1279,10 @@
12561279
}
12571280
}
12581281
style_header("Artifact Content");
12591282
zUuid = db_text("?", "SELECT uuid FROM blob WHERE rid=%d", rid);
12601283
@ <h2>Artifact %s(zUuid)</h2>
1261
- @ <blockquote><p>
12621284
blob_zero(&downloadName);
12631285
object_description(rid, 0, &downloadName);
12641286
style_submenu_element("Download", "Download",
12651287
"%s/raw/%T?name=%s", g.zTop, blob_str(&downloadName), zUuid);
12661288
zMime = mimetype_from_name(blob_str(&downloadName));
@@ -1283,11 +1305,10 @@
12831305
style_submenu_element("Text", "Text",
12841306
"%s/artifact/%s?txt=1", g.zTop, zUuid);
12851307
}
12861308
}
12871309
}
1288
- @ </p></blockquote>
12891310
@ <hr />
12901311
content_get(rid, &content);
12911312
if( renderAsWiki ){
12921313
wiki_convert(&content, 0, 0);
12931314
}else if( renderAsHtml ){
12941315
--- src/info.c
+++ src/info.c
@@ -282,21 +282,22 @@
282 const char *zName, /* Name of the file that has changed */
283 const char *zOld, /* blob.uuid before change. NULL for added files */
284 const char *zNew, /* blob.uuid after change. NULL for deletes */
285 const char *zOldName, /* Prior name. NULL if no name change. */
286 int showDiff, /* Show edit diffs if true */
287 int mperm /* EXE permission for zNew */
288 ){
289 if( !g.okHistory ){
290 if( zNew==0 ){
291 @ <p>Deleted %h(zName)</p>
292 }else if( zOld==0 ){
293 @ <p>Added %h(zName)</p>
294 }else if( zOldName!=0 && fossil_strcmp(zName,zOldName)!=0 ){
295 @ <p>Name change from %h(zOldName) to %h(zName)
296 }else if( fossil_strcmp(zNew, zOld)==0 ){
297 @ <p>Execute permission %s(mperm?"set":"cleared") for %h(zName)</p>
 
298 }else{
299 @ <p>Changes to %h(zName)</p>
300 }
301 if( showDiff ){
302 @ <blockquote><pre>
@@ -312,11 +313,11 @@
312 }else if( zOldName!=0 && fossil_strcmp(zName,zOldName)!=0 ){
313 @ <p>Name change from
314 @ from <a href="%s(g.zTop)/finfo?name=%T(zOldName)">%h(zOldName)</a>
315 @ to <a href="%s(g.zTop)/finfo?name=%T(zName)">%h(zName)</a>.
316 }else{
317 @ <p>Execute permission %s(mperm?"set":"cleared") for
318 @ <a href="%s(g.zTop)/finfo?name=%T(zName)">%h(zName)</a>
319 }
320 }else if( zOld ){
321 @ <p>Deleted <a href="%s(g.zTop)/finfo?name=%T(zName)">%h(zName)</a>
322 @ version <a href="%s(g.zTop)/artifact/%s(zOld)">[%S(zOld)]</a>
@@ -776,53 +777,81 @@
776 Stmt q;
777 int cnt = 0;
778 int nWiki = 0;
779 char *zUuid = db_text(0, "SELECT uuid FROM blob WHERE rid=%d", rid);
780
 
 
781 db_prepare(&q,
782 "SELECT filename.name, datetime(event.mtime),"
783 " coalesce(event.ecomment,event.comment),"
784 " coalesce(event.euser,event.user),"
785 " b.uuid"
 
 
786 " FROM mlink, filename, event, blob a, blob b"
787 " WHERE filename.fnid=mlink.fnid"
788 " AND event.objid=mlink.mid"
789 " AND a.rid=mlink.fid"
790 " AND b.rid=mlink.mid"
791 " AND mlink.fid=%d",
792 rid
 
793 );
 
794 while( db_step(&q)==SQLITE_ROW ){
795 const char *zName = db_column_text(&q, 0);
796 const char *zDate = db_column_text(&q, 1);
797 const char *zCom = db_column_text(&q, 2);
798 const char *zUser = db_column_text(&q, 3);
799 const char *zVers = db_column_text(&q, 4);
800 if( cnt>0 ){
801 @ Also file
802 }else{
803 @ File
804 }
805 if( g.okHistory ){
806 @ <a href="%s(g.zTop)/finfo?name=%T(zName)">%h(zName)</a>
807 }else{
808 @ %h(zName)
809 }
810 @ part of check-in
 
 
 
 
 
 
 
 
 
 
 
 
 
811 hyperlink_to_uuid(zVers);
812 @ - %w(zCom) by
813 hyperlink_to_user(zUser,zDate," on");
814 hyperlink_to_date(zDate,".");
 
 
 
 
 
 
 
815 if( g.okHistory ){
816 @ <a href="%s(g.zTop)/annotate?checkin=%S(zVers)&filename=%T(zName)">
817 @ [annotate]</a>
818 }
819 cnt++;
820 if( pDownloadName && blob_size(pDownloadName)==0 ){
821 blob_append(pDownloadName, zName, -1);
822 }
823 }
 
 
824 db_finalize(&q);
825 db_prepare(&q,
826 "SELECT substr(tagname, 6, 10000), datetime(event.mtime),"
827 " coalesce(event.euser, event.user)"
828 " FROM tagxref, tag, event"
@@ -988,17 +1017,13 @@
988 style_header("Diff");
989 style_submenu_element("Patch", "Patch", "%s/fdiff?v1=%T&v2=%T&patch",
990 g.zTop, P("v1"), P("v2"));
991 @ <h2>Differences From
992 @ Artifact <a href="%s(g.zTop)/artifact/%S(zV1)">[%S(zV1)]</a>:</h2>
993 @ <blockquote><p>
994 object_description(v1, 1, 0);
995 @ </p></blockquote>
996 @ <h2>To Artifact <a href="%s(g.zTop)/artifact/%S(zV2)">[%S(zV2)]</a>:</h2>
997 @ <blockquote><p>
998 object_description(v2, 1, 0);
999 @ </p></blockquote>
1000 @ <hr />
1001 @ <blockquote><pre>
1002 @ %h(blob_str(&diff))
1003 @ </pre></blockquote>
1004 blob_reset(&diff);
@@ -1107,16 +1132,14 @@
1107 }
1108 }
1109 style_header("Hex Artifact Content");
1110 zUuid = db_text("?","SELECT uuid FROM blob WHERE rid=%d", rid);
1111 @ <h2>Artifact %s(zUuid):</h2>
1112 @ <blockquote><p>
1113 blob_zero(&downloadName);
1114 object_description(rid, 0, &downloadName);
1115 style_submenu_element("Download", "Download",
1116 "%s/raw/%T?name=%s", g.zTop, blob_str(&downloadName), zUuid);
1117 @ </p></blockquote>
1118 @ <hr />
1119 content_get(rid, &content);
1120 @ <blockquote><pre>
1121 hexdump(&content);
1122 @ </pre></blockquote>
@@ -1256,11 +1279,10 @@
1256 }
1257 }
1258 style_header("Artifact Content");
1259 zUuid = db_text("?", "SELECT uuid FROM blob WHERE rid=%d", rid);
1260 @ <h2>Artifact %s(zUuid)</h2>
1261 @ <blockquote><p>
1262 blob_zero(&downloadName);
1263 object_description(rid, 0, &downloadName);
1264 style_submenu_element("Download", "Download",
1265 "%s/raw/%T?name=%s", g.zTop, blob_str(&downloadName), zUuid);
1266 zMime = mimetype_from_name(blob_str(&downloadName));
@@ -1283,11 +1305,10 @@
1283 style_submenu_element("Text", "Text",
1284 "%s/artifact/%s?txt=1", g.zTop, zUuid);
1285 }
1286 }
1287 }
1288 @ </p></blockquote>
1289 @ <hr />
1290 content_get(rid, &content);
1291 if( renderAsWiki ){
1292 wiki_convert(&content, 0, 0);
1293 }else if( renderAsHtml ){
1294
--- src/info.c
+++ src/info.c
@@ -282,21 +282,22 @@
282 const char *zName, /* Name of the file that has changed */
283 const char *zOld, /* blob.uuid before change. NULL for added files */
284 const char *zNew, /* blob.uuid after change. NULL for deletes */
285 const char *zOldName, /* Prior name. NULL if no name change. */
286 int showDiff, /* Show edit diffs if true */
287 int mperm /* executable or symlink permission for zNew */
288 ){
289 if( !g.okHistory ){
290 if( zNew==0 ){
291 @ <p>Deleted %h(zName)</p>
292 }else if( zOld==0 ){
293 @ <p>Added %h(zName)</p>
294 }else if( zOldName!=0 && fossil_strcmp(zName,zOldName)!=0 ){
295 @ <p>Name change from %h(zOldName) to %h(zName)
296 }else if( fossil_strcmp(zNew, zOld)==0 ){
297 @ <p>Execute permission %s(( mperm==PERM_EXE )?"set":"cleared")
298 @ for %h(zName)</p>
299 }else{
300 @ <p>Changes to %h(zName)</p>
301 }
302 if( showDiff ){
303 @ <blockquote><pre>
@@ -312,11 +313,11 @@
313 }else if( zOldName!=0 && fossil_strcmp(zName,zOldName)!=0 ){
314 @ <p>Name change from
315 @ from <a href="%s(g.zTop)/finfo?name=%T(zOldName)">%h(zOldName)</a>
316 @ to <a href="%s(g.zTop)/finfo?name=%T(zName)">%h(zName)</a>.
317 }else{
318 @ <p>Execute permission %s(( mperm==PERM_EXE )?"set":"cleared") for
319 @ <a href="%s(g.zTop)/finfo?name=%T(zName)">%h(zName)</a>
320 }
321 }else if( zOld ){
322 @ <p>Deleted <a href="%s(g.zTop)/finfo?name=%T(zName)">%h(zName)</a>
323 @ version <a href="%s(g.zTop)/artifact/%s(zOld)">[%S(zOld)]</a>
@@ -776,53 +777,81 @@
777 Stmt q;
778 int cnt = 0;
779 int nWiki = 0;
780 char *zUuid = db_text(0, "SELECT uuid FROM blob WHERE rid=%d", rid);
781
782 char *prevName = 0;
783
784 db_prepare(&q,
785 "SELECT filename.name, datetime(event.mtime),"
786 " coalesce(event.ecomment,event.comment),"
787 " coalesce(event.euser,event.user),"
788 " b.uuid, mlink.mperm,"
789 " coalesce((SELECT value FROM tagxref"
790 " WHERE tagid=%d AND tagtype>0 AND rid=mlink.mid),'trunk')"
791 " FROM mlink, filename, event, blob a, blob b"
792 " WHERE filename.fnid=mlink.fnid"
793 " AND event.objid=mlink.mid"
794 " AND a.rid=mlink.fid"
795 " AND b.rid=mlink.mid"
796 " AND mlink.fid=%d"
797 " ORDER BY filename.name, event.mtime",
798 TAG_BRANCH, rid
799 );
800 @ <ul>
801 while( db_step(&q)==SQLITE_ROW ){
802 const char *zName = db_column_text(&q, 0);
803 const char *zDate = db_column_text(&q, 1);
804 const char *zCom = db_column_text(&q, 2);
805 const char *zUser = db_column_text(&q, 3);
806 const char *zVers = db_column_text(&q, 4);
807 int mPerm = db_column_int(&q, 5);
808 const char *zBr = db_column_text(&q, 6);
809 if( !prevName || fossil_strcmp(zName, prevName) ) {
810 if( prevName ) {
811 @ </ul>
812 }
813 if( mPerm==PERM_LNK ){
814 @ <li>Symbolic link
815 }else if( mPerm==PERM_EXE ){
816 @ <li>Executable file
817 }else{
818 @ <li>File
819 }
820 if( g.okHistory ){
821 @ <a href="%s(g.zTop)/finfo?name=%T(zName)">%h(zName)</a>
822 }else{
823 @ %h(zName)
824 }
825 @ <ul>
826 prevName = fossil_strdup(zName);
827 }
828 @ <li>
829 hyperlink_to_date(zDate,"");
830 @ - part of checkin
831 hyperlink_to_uuid(zVers);
832 if( zBr && zBr[0] ){
833 if( g.okHistory ){
834 @ on branch <a href="%s(g.zTop)/timeline?r=%T(zBr)">%h(zBr)</a>
835 }else{
836 @ on branch %h(zBr)
837 }
838 }
839 @ - %w(zCom) (user:
840 hyperlink_to_user(zUser,zDate,"");
841 @ )
842 if( g.okHistory ){
843 @ <a href="%s(g.zTop)/annotate?checkin=%S(zVers)&filename=%T(zName)">
844 @ [annotate]</a>
845 }
846 cnt++;
847 if( pDownloadName && blob_size(pDownloadName)==0 ){
848 blob_append(pDownloadName, zName, -1);
849 }
850 }
851 @ </ul></ul>
852 free(prevName);
853 db_finalize(&q);
854 db_prepare(&q,
855 "SELECT substr(tagname, 6, 10000), datetime(event.mtime),"
856 " coalesce(event.euser, event.user)"
857 " FROM tagxref, tag, event"
@@ -988,17 +1017,13 @@
1017 style_header("Diff");
1018 style_submenu_element("Patch", "Patch", "%s/fdiff?v1=%T&v2=%T&patch",
1019 g.zTop, P("v1"), P("v2"));
1020 @ <h2>Differences From
1021 @ Artifact <a href="%s(g.zTop)/artifact/%S(zV1)">[%S(zV1)]</a>:</h2>
1022 object_description(v1, 0, 0);
 
 
1023 @ <h2>To Artifact <a href="%s(g.zTop)/artifact/%S(zV2)">[%S(zV2)]</a>:</h2>
1024 object_description(v2, 0, 0);
 
 
1025 @ <hr />
1026 @ <blockquote><pre>
1027 @ %h(blob_str(&diff))
1028 @ </pre></blockquote>
1029 blob_reset(&diff);
@@ -1107,16 +1132,14 @@
1132 }
1133 }
1134 style_header("Hex Artifact Content");
1135 zUuid = db_text("?","SELECT uuid FROM blob WHERE rid=%d", rid);
1136 @ <h2>Artifact %s(zUuid):</h2>
 
1137 blob_zero(&downloadName);
1138 object_description(rid, 0, &downloadName);
1139 style_submenu_element("Download", "Download",
1140 "%s/raw/%T?name=%s", g.zTop, blob_str(&downloadName), zUuid);
 
1141 @ <hr />
1142 content_get(rid, &content);
1143 @ <blockquote><pre>
1144 hexdump(&content);
1145 @ </pre></blockquote>
@@ -1256,11 +1279,10 @@
1279 }
1280 }
1281 style_header("Artifact Content");
1282 zUuid = db_text("?", "SELECT uuid FROM blob WHERE rid=%d", rid);
1283 @ <h2>Artifact %s(zUuid)</h2>
 
1284 blob_zero(&downloadName);
1285 object_description(rid, 0, &downloadName);
1286 style_submenu_element("Download", "Download",
1287 "%s/raw/%T?name=%s", g.zTop, blob_str(&downloadName), zUuid);
1288 zMime = mimetype_from_name(blob_str(&downloadName));
@@ -1283,11 +1305,10 @@
1305 style_submenu_element("Text", "Text",
1306 "%s/artifact/%s?txt=1", g.zTop, zUuid);
1307 }
1308 }
1309 }
 
1310 @ <hr />
1311 content_get(rid, &content);
1312 if( renderAsWiki ){
1313 wiki_convert(&content, 0, 0);
1314 }else if( renderAsHtml ){
1315
+2
--- src/main.c
+++ src/main.c
@@ -156,10 +156,12 @@
156156
const char *azAuxName[MX_AUX]; /* Name of each aux() or option() value */
157157
char *azAuxParam[MX_AUX]; /* Param of each aux() or option() value */
158158
const char *azAuxVal[MX_AUX]; /* Value of each aux() or option() value */
159159
const char **azAuxOpt[MX_AUX]; /* Options of each option() value */
160160
int anAuxCols[MX_AUX]; /* Number of columns for option() values */
161
+
162
+ int allowSymlinks; /* Cached "allow-symlinks" option */
161163
};
162164
163165
/*
164166
** Macro for debugging:
165167
*/
166168
--- src/main.c
+++ src/main.c
@@ -156,10 +156,12 @@
156 const char *azAuxName[MX_AUX]; /* Name of each aux() or option() value */
157 char *azAuxParam[MX_AUX]; /* Param of each aux() or option() value */
158 const char *azAuxVal[MX_AUX]; /* Value of each aux() or option() value */
159 const char **azAuxOpt[MX_AUX]; /* Options of each option() value */
160 int anAuxCols[MX_AUX]; /* Number of columns for option() values */
 
 
161 };
162
163 /*
164 ** Macro for debugging:
165 */
166
--- src/main.c
+++ src/main.c
@@ -156,10 +156,12 @@
156 const char *azAuxName[MX_AUX]; /* Name of each aux() or option() value */
157 char *azAuxParam[MX_AUX]; /* Param of each aux() or option() value */
158 const char *azAuxVal[MX_AUX]; /* Value of each aux() or option() value */
159 const char **azAuxOpt[MX_AUX]; /* Options of each option() value */
160 int anAuxCols[MX_AUX]; /* Number of columns for option() values */
161
162 int allowSymlinks; /* Cached "allow-symlinks" option */
163 };
164
165 /*
166 ** Macro for debugging:
167 */
168
+14 -4
--- src/manifest.c
+++ src/manifest.c
@@ -35,10 +35,17 @@
3535
#define CFTYPE_WIKI 4
3636
#define CFTYPE_TICKET 5
3737
#define CFTYPE_ATTACHMENT 6
3838
#define CFTYPE_EVENT 7
3939
40
+/*
41
+** File permissions used by Fossil internally.
42
+*/
43
+#define PERM_REG 0 /* regular file */
44
+#define PERM_EXE 1 /* executable */
45
+#define PERM_LNK 2 /* symlink */
46
+
4047
/*
4148
** A single F-card within a manifest
4249
*/
4350
struct ManifestFile {
4451
char *zName; /* Name of a file */
@@ -1085,13 +1092,16 @@
10851092
/*
10861093
** Compute an appropriate mlink.mperm integer for the permission string
10871094
** of a file.
10881095
*/
10891096
int manifest_file_mperm(ManifestFile *pFile){
1090
- int mperm = 0;
1091
- if( pFile && pFile->zPerm && strstr(pFile->zPerm,"x")!=0 ){
1092
- mperm = 1;
1097
+ int mperm = PERM_REG;
1098
+ if( pFile && pFile->zPerm){
1099
+ if( strstr(pFile->zPerm,"x")!=0 )
1100
+ mperm = PERM_EXE;
1101
+ else if( strstr(pFile->zPerm,"l")!=0 )
1102
+ mperm = PERM_LNK;
10931103
}
10941104
return mperm;
10951105
}
10961106
10971107
/*
@@ -1103,11 +1113,11 @@
11031113
const char *zFromUuid, /* UUID for the mlink.pid. "" to add file */
11041114
const char *zToUuid, /* UUID for the mlink.fid. "" to delele */
11051115
const char *zFilename, /* Filename */
11061116
const char *zPrior, /* Previous filename. NULL if unchanged */
11071117
int isPublic, /* True if mid is not a private manifest */
1108
- int mperm /* 1: exec */
1118
+ int mperm /* 1: exec, 2: symlink */
11091119
){
11101120
int fnid, pfnid, pid, fid;
11111121
static Stmt s1;
11121122
11131123
fnid = filename_to_fnid(zFilename);
11141124
--- src/manifest.c
+++ src/manifest.c
@@ -35,10 +35,17 @@
35 #define CFTYPE_WIKI 4
36 #define CFTYPE_TICKET 5
37 #define CFTYPE_ATTACHMENT 6
38 #define CFTYPE_EVENT 7
39
 
 
 
 
 
 
 
40 /*
41 ** A single F-card within a manifest
42 */
43 struct ManifestFile {
44 char *zName; /* Name of a file */
@@ -1085,13 +1092,16 @@
1085 /*
1086 ** Compute an appropriate mlink.mperm integer for the permission string
1087 ** of a file.
1088 */
1089 int manifest_file_mperm(ManifestFile *pFile){
1090 int mperm = 0;
1091 if( pFile && pFile->zPerm && strstr(pFile->zPerm,"x")!=0 ){
1092 mperm = 1;
 
 
 
1093 }
1094 return mperm;
1095 }
1096
1097 /*
@@ -1103,11 +1113,11 @@
1103 const char *zFromUuid, /* UUID for the mlink.pid. "" to add file */
1104 const char *zToUuid, /* UUID for the mlink.fid. "" to delele */
1105 const char *zFilename, /* Filename */
1106 const char *zPrior, /* Previous filename. NULL if unchanged */
1107 int isPublic, /* True if mid is not a private manifest */
1108 int mperm /* 1: exec */
1109 ){
1110 int fnid, pfnid, pid, fid;
1111 static Stmt s1;
1112
1113 fnid = filename_to_fnid(zFilename);
1114
--- src/manifest.c
+++ src/manifest.c
@@ -35,10 +35,17 @@
35 #define CFTYPE_WIKI 4
36 #define CFTYPE_TICKET 5
37 #define CFTYPE_ATTACHMENT 6
38 #define CFTYPE_EVENT 7
39
40 /*
41 ** File permissions used by Fossil internally.
42 */
43 #define PERM_REG 0 /* regular file */
44 #define PERM_EXE 1 /* executable */
45 #define PERM_LNK 2 /* symlink */
46
47 /*
48 ** A single F-card within a manifest
49 */
50 struct ManifestFile {
51 char *zName; /* Name of a file */
@@ -1085,13 +1092,16 @@
1092 /*
1093 ** Compute an appropriate mlink.mperm integer for the permission string
1094 ** of a file.
1095 */
1096 int manifest_file_mperm(ManifestFile *pFile){
1097 int mperm = PERM_REG;
1098 if( pFile && pFile->zPerm){
1099 if( strstr(pFile->zPerm,"x")!=0 )
1100 mperm = PERM_EXE;
1101 else if( strstr(pFile->zPerm,"l")!=0 )
1102 mperm = PERM_LNK;
1103 }
1104 return mperm;
1105 }
1106
1107 /*
@@ -1103,11 +1113,11 @@
1113 const char *zFromUuid, /* UUID for the mlink.pid. "" to add file */
1114 const char *zToUuid, /* UUID for the mlink.fid. "" to delele */
1115 const char *zFilename, /* Filename */
1116 const char *zPrior, /* Previous filename. NULL if unchanged */
1117 int isPublic, /* True if mid is not a private manifest */
1118 int mperm /* 1: exec, 2: symlink */
1119 ){
1120 int fnid, pfnid, pid, fid;
1121 static Stmt s1;
1122
1123 fnid = filename_to_fnid(zFilename);
1124
+72 -44
--- src/merge.c
+++ src/merge.c
@@ -148,10 +148,19 @@
148148
vfile_check_signature(vid, 1, 0);
149149
db_begin_transaction();
150150
if( !nochangeFlag ) undo_begin();
151151
load_vfile_from_rid(mid);
152152
load_vfile_from_rid(pid);
153
+ if( debugFlag ){
154
+ char *z;
155
+ z = db_text(0, "SELECT uuid FROM blob WHERE rid=%d", pid);
156
+ fossil_print("P=%d %z\n", pid, z);
157
+ z = db_text(0, "SELECT uuid FROM blob WHERE rid=%d", mid);
158
+ fossil_print("M=%d %z\n", mid, z);
159
+ z = db_text(0, "SELECT uuid FROM blob WHERE rid=%d", vid);
160
+ fossil_print("V=%d %z\n", vid, z);
161
+ }
153162
154163
/*
155164
** The vfile.pathname field is used to match files against each other. The
156165
** FV table contains one row for each each unique filename in
157166
** in the current checkout, the pivot, and the version being merged.
@@ -167,11 +176,13 @@
167176
" ridv INTEGER," /* Record ID for current version */
168177
" ridp INTEGER," /* Record ID for pivot */
169178
" ridm INTEGER," /* Record ID for merge */
170179
" isexe BOOLEAN," /* Execute permission enabled */
171180
" fnp TEXT," /* The filename in the pivot */
172
- " fnm TEXT" /* the filename in the merged version */
181
+ " fnm TEXT," /* the filename in the merged version */
182
+ " islinkv BOOLEAN," /* True if current version is a symlink */
183
+ " islinkm BOOLEAN" /* True if merged version in is a symlink */
173184
");",
174185
caseSensitive ? "binary" : "nocase"
175186
);
176187
177188
/* Add files found in V
@@ -185,19 +196,19 @@
185196
);
186197
187198
/*
188199
** Compute name changes from P->V
189200
*/
190
- find_filename_changes(vid, pid, &nChng, &aChng);
201
+ find_filename_changes(pid, vid, 0, &nChng, &aChng, debugFlag ? "P->V" : 0);
191202
if( nChng ){
192203
for(i=0; i<nChng; i++){
193204
char *z;
194
- z = db_text(0, "SELECT name FROM filename WHERE fnid=%d", aChng[i*2+1]);
205
+ z = db_text(0, "SELECT name FROM filename WHERE fnid=%d", aChng[i*2]);
195206
db_multi_exec(
196207
"UPDATE fv SET fnp=%Q, fnm=%Q"
197208
" WHERE fn=(SELECT name FROM filename WHERE fnid=%d)",
198
- z, z, aChng[i*2]
209
+ z, z, aChng[i*2+1]
199210
);
200211
free(z);
201212
}
202213
fossil_free(aChng);
203214
db_multi_exec("UPDATE fv SET fnm=fnp WHERE fnp!=fn");
@@ -215,11 +226,11 @@
215226
);
216227
217228
/*
218229
** Compute name changes from P->M
219230
*/
220
- find_filename_changes(pid, mid, &nChng, &aChng);
231
+ find_filename_changes(pid, mid, 0, &nChng, &aChng, debugFlag ? "P->M" : 0);
221232
if( nChng ){
222233
if( nChng>4 ) db_multi_exec("CREATE INDEX fv_fnp ON fv(fnp)");
223234
for(i=0; i<nChng; i++){
224235
db_multi_exec(
225236
"UPDATE fv SET fnm=(SELECT name FROM filename WHERE fnid=%d)"
@@ -248,26 +259,34 @@
248259
db_multi_exec(
249260
"UPDATE fv SET"
250261
" idp=coalesce((SELECT id FROM vfile WHERE vid=%d AND pathname=fnp),0),"
251262
" ridp=coalesce((SELECT rid FROM vfile WHERE vid=%d AND pathname=fnp),0),"
252263
" idm=coalesce((SELECT id FROM vfile WHERE vid=%d AND pathname=fnm),0),"
253
- " ridm=coalesce((SELECT rid FROM vfile WHERE vid=%d AND pathname=fnm),0)",
254
- pid, pid, mid, mid
264
+ " ridm=coalesce((SELECT rid FROM vfile WHERE vid=%d AND pathname=fnm),0),"
265
+ " islinkv=coalesce((SELECT islink FROM vfile"
266
+ " WHERE vid=%d AND pathname=fnm),0),"
267
+ " islinkm=coalesce((SELECT islink FROM vfile"
268
+ " WHERE vid=%d AND pathname=fnm),0)",
269
+ pid, pid, mid, mid, vid, mid
255270
);
256271
257272
if( debugFlag ){
258273
db_prepare(&q,
259
- "SELECT rowid, fn, fnp, fnm, chnged, ridv, ridp, ridm, isexe FROM fv"
274
+ "SELECT rowid, fn, fnp, fnm, chnged, ridv, ridp, ridm, "
275
+ " isexe, islinkv, islinkm FROM fv"
260276
);
261277
while( db_step(&q)==SQLITE_ROW ){
262
- fossil_print("%3d: ridv=%-4d ridp=%-4d ridm=%-4d chnged=%d isexe=%d\n",
278
+ fossil_print("%3d: ridv=%-4d ridp=%-4d ridm=%-4d chnged=%d isexe=%d "
279
+ " islinkv=%d islinkm=%d\n",
263280
db_column_int(&q, 0),
264281
db_column_int(&q, 5),
265282
db_column_int(&q, 6),
266283
db_column_int(&q, 7),
267284
db_column_int(&q, 4),
268
- db_column_int(&q, 8));
285
+ db_column_int(&q, 8),
286
+ db_column_int(&q, 9),
287
+ db_column_int(&q, 10));
269288
fossil_print(" fn = [%s]\n", db_column_text(&q, 1));
270289
fossil_print(" fnp = [%s]\n", db_column_text(&q, 2));
271290
fossil_print(" fnm = [%s]\n", db_column_text(&q, 3));
272291
}
273292
db_finalize(&q);
@@ -301,12 +320,12 @@
301320
int idm = db_column_int(&q, 0);
302321
int rowid = db_column_int(&q, 1);
303322
int idv;
304323
const char *zName;
305324
db_multi_exec(
306
- "INSERT INTO vfile(vid,chnged,deleted,rid,mrid,isexe,pathname)"
307
- " SELECT %d,3,0,rid,mrid,isexe,pathname FROM vfile WHERE id=%d",
325
+ "INSERT INTO vfile(vid,chnged,deleted,rid,mrid,isexe,islink,pathname)"
326
+ " SELECT %d,3,0,rid,mrid,isexe,islink,pathname FROM vfile WHERE id=%d",
308327
vid, idm
309328
);
310329
idv = db_last_insert_rowid();
311330
db_multi_exec("UPDATE fv SET idv=%d WHERE rowid=%d", idv, rowid);
312331
zName = db_column_text(&q, 2);
@@ -315,30 +334,32 @@
315334
undo_save(zName);
316335
vfile_to_disk(0, idm, 0, 0);
317336
}
318337
}
319338
db_finalize(&q);
320
-
339
+
321340
/*
322
- ** Find files that have changed from P->M but not P->V.
341
+ ** Find files that have changed from P->M but not P->V.
323342
** Copy the M content over into V.
324343
*/
325344
db_prepare(&q,
326
- "SELECT idv, ridm, fn FROM fv"
345
+ "SELECT idv, ridm, fn, islinkm FROM fv"
327346
" WHERE idp>0 AND idv>0 AND idm>0"
328347
" AND ridm!=ridp AND ridv=ridp AND NOT chnged"
329348
);
330349
while( db_step(&q)==SQLITE_ROW ){
331350
int idv = db_column_int(&q, 0);
332351
int ridm = db_column_int(&q, 1);
333352
const char *zName = db_column_text(&q, 2);
353
+ int islinkm = db_column_int(&q, 3);
334354
/* Copy content from idm over into idv. Overwrite idv. */
335355
fossil_print("UPDATE %s\n", zName);
336356
if( !nochangeFlag ){
337357
undo_save(zName);
338358
db_multi_exec(
339
- "UPDATE vfile SET mtime=0, mrid=%d, chnged=2 WHERE id=%d", ridm, idv
359
+ "UPDATE vfile SET mtime=0, mrid=%d, chnged=2, islink=%d "
360
+ " WHERE id=%d", ridm, islinkm, idv
340361
);
341362
vfile_to_disk(0, idv, 0, 0);
342363
}
343364
}
344365
db_finalize(&q);
@@ -345,11 +366,11 @@
345366
346367
/*
347368
** Do a three-way merge on files that have changes on both P->M and P->V.
348369
*/
349370
db_prepare(&q,
350
- "SELECT ridm, idv, ridp, ridv, %s, fn, isexe FROM fv"
371
+ "SELECT ridm, idv, ridp, ridv, %s, fn, isexe, islinkv, islinkm FROM fv"
351372
" WHERE idp>0 AND idv>0 AND idm>0"
352373
" AND ridm!=ridp AND (ridv!=ridp OR chnged)",
353374
glob_expr("fv.fn", zBinGlob)
354375
);
355376
while( db_step(&q)==SQLITE_ROW ){
@@ -358,10 +379,12 @@
358379
int ridp = db_column_int(&q, 2);
359380
int ridv = db_column_int(&q, 3);
360381
int isBinary = db_column_int(&q, 4);
361382
const char *zName = db_column_text(&q, 5);
362383
int isExe = db_column_int(&q, 6);
384
+ int islinkv = db_column_int(&q, 7);
385
+ int islinkm = db_column_int(&q, 8);
363386
int rc;
364387
char *zFullPath;
365388
Blob m, p, r;
366389
/* Do a 3-way merge of idp->idm into idp->idv. The results go into idv. */
367390
if( detailFlag ){
@@ -368,37 +391,42 @@
368391
fossil_print("MERGE %s (pivot=%d v1=%d v2=%d)\n",
369392
zName, ridp, ridm, ridv);
370393
}else{
371394
fossil_print("MERGE %s\n", zName);
372395
}
373
- undo_save(zName);
374
- zFullPath = mprintf("%s/%s", g.zLocalRoot, zName);
375
- content_get(ridp, &p);
376
- content_get(ridm, &m);
377
- if( isBinary ){
378
- rc = -1;
379
- blob_zero(&r);
380
- }else{
381
- rc = merge_3way(&p, zFullPath, &m, &r);
382
- }
383
- if( rc>=0 ){
384
- if( !nochangeFlag ){
385
- blob_write_to_file(&r, zFullPath);
386
- file_setexe(zFullPath, isExe);
387
- }
388
- db_multi_exec("UPDATE vfile SET mtime=0 WHERE id=%d", idv);
389
- if( rc>0 ){
390
- fossil_print("***** %d merge conflicts in %s\n", rc, zName);
391
- nConflict++;
392
- }
393
- }else{
394
- fossil_print("***** Cannot merge binary file %s\n", zName);
395
- nConflict++;
396
- }
397
- blob_reset(&p);
398
- blob_reset(&m);
399
- blob_reset(&r);
396
+ if( islinkv || islinkm /* || file_islink(zFullPath) */ ){
397
+ fossil_print("***** Cannot merge symlink %s\n", zName);
398
+ nConflict++;
399
+ }else{
400
+ undo_save(zName);
401
+ zFullPath = mprintf("%s/%s", g.zLocalRoot, zName);
402
+ content_get(ridp, &p);
403
+ content_get(ridm, &m);
404
+ if( isBinary ){
405
+ rc = -1;
406
+ blob_zero(&r);
407
+ }else{
408
+ rc = merge_3way(&p, zFullPath, &m, &r);
409
+ }
410
+ if( rc>=0 ){
411
+ if( !nochangeFlag ){
412
+ blob_write_to_file(&r, zFullPath);
413
+ file_setexe(zFullPath, isExe);
414
+ }
415
+ db_multi_exec("UPDATE vfile SET mtime=0 WHERE id=%d", idv);
416
+ if( rc>0 ){
417
+ fossil_print("***** %d merge conflicts in %s\n", rc, zName);
418
+ nConflict++;
419
+ }
420
+ }else{
421
+ fossil_print("***** Cannot merge binary file %s\n", zName);
422
+ nConflict++;
423
+ }
424
+ blob_reset(&p);
425
+ blob_reset(&m);
426
+ blob_reset(&r);
427
+ }
400428
db_multi_exec("INSERT OR IGNORE INTO vmerge(id,merge) VALUES(%d,%d)",
401429
idv,ridm);
402430
}
403431
db_finalize(&q);
404432
405433
--- src/merge.c
+++ src/merge.c
@@ -148,10 +148,19 @@
148 vfile_check_signature(vid, 1, 0);
149 db_begin_transaction();
150 if( !nochangeFlag ) undo_begin();
151 load_vfile_from_rid(mid);
152 load_vfile_from_rid(pid);
 
 
 
 
 
 
 
 
 
153
154 /*
155 ** The vfile.pathname field is used to match files against each other. The
156 ** FV table contains one row for each each unique filename in
157 ** in the current checkout, the pivot, and the version being merged.
@@ -167,11 +176,13 @@
167 " ridv INTEGER," /* Record ID for current version */
168 " ridp INTEGER," /* Record ID for pivot */
169 " ridm INTEGER," /* Record ID for merge */
170 " isexe BOOLEAN," /* Execute permission enabled */
171 " fnp TEXT," /* The filename in the pivot */
172 " fnm TEXT" /* the filename in the merged version */
 
 
173 ");",
174 caseSensitive ? "binary" : "nocase"
175 );
176
177 /* Add files found in V
@@ -185,19 +196,19 @@
185 );
186
187 /*
188 ** Compute name changes from P->V
189 */
190 find_filename_changes(vid, pid, &nChng, &aChng);
191 if( nChng ){
192 for(i=0; i<nChng; i++){
193 char *z;
194 z = db_text(0, "SELECT name FROM filename WHERE fnid=%d", aChng[i*2+1]);
195 db_multi_exec(
196 "UPDATE fv SET fnp=%Q, fnm=%Q"
197 " WHERE fn=(SELECT name FROM filename WHERE fnid=%d)",
198 z, z, aChng[i*2]
199 );
200 free(z);
201 }
202 fossil_free(aChng);
203 db_multi_exec("UPDATE fv SET fnm=fnp WHERE fnp!=fn");
@@ -215,11 +226,11 @@
215 );
216
217 /*
218 ** Compute name changes from P->M
219 */
220 find_filename_changes(pid, mid, &nChng, &aChng);
221 if( nChng ){
222 if( nChng>4 ) db_multi_exec("CREATE INDEX fv_fnp ON fv(fnp)");
223 for(i=0; i<nChng; i++){
224 db_multi_exec(
225 "UPDATE fv SET fnm=(SELECT name FROM filename WHERE fnid=%d)"
@@ -248,26 +259,34 @@
248 db_multi_exec(
249 "UPDATE fv SET"
250 " idp=coalesce((SELECT id FROM vfile WHERE vid=%d AND pathname=fnp),0),"
251 " ridp=coalesce((SELECT rid FROM vfile WHERE vid=%d AND pathname=fnp),0),"
252 " idm=coalesce((SELECT id FROM vfile WHERE vid=%d AND pathname=fnm),0),"
253 " ridm=coalesce((SELECT rid FROM vfile WHERE vid=%d AND pathname=fnm),0)",
254 pid, pid, mid, mid
 
 
 
 
255 );
256
257 if( debugFlag ){
258 db_prepare(&q,
259 "SELECT rowid, fn, fnp, fnm, chnged, ridv, ridp, ridm, isexe FROM fv"
 
260 );
261 while( db_step(&q)==SQLITE_ROW ){
262 fossil_print("%3d: ridv=%-4d ridp=%-4d ridm=%-4d chnged=%d isexe=%d\n",
 
263 db_column_int(&q, 0),
264 db_column_int(&q, 5),
265 db_column_int(&q, 6),
266 db_column_int(&q, 7),
267 db_column_int(&q, 4),
268 db_column_int(&q, 8));
 
 
269 fossil_print(" fn = [%s]\n", db_column_text(&q, 1));
270 fossil_print(" fnp = [%s]\n", db_column_text(&q, 2));
271 fossil_print(" fnm = [%s]\n", db_column_text(&q, 3));
272 }
273 db_finalize(&q);
@@ -301,12 +320,12 @@
301 int idm = db_column_int(&q, 0);
302 int rowid = db_column_int(&q, 1);
303 int idv;
304 const char *zName;
305 db_multi_exec(
306 "INSERT INTO vfile(vid,chnged,deleted,rid,mrid,isexe,pathname)"
307 " SELECT %d,3,0,rid,mrid,isexe,pathname FROM vfile WHERE id=%d",
308 vid, idm
309 );
310 idv = db_last_insert_rowid();
311 db_multi_exec("UPDATE fv SET idv=%d WHERE rowid=%d", idv, rowid);
312 zName = db_column_text(&q, 2);
@@ -315,30 +334,32 @@
315 undo_save(zName);
316 vfile_to_disk(0, idm, 0, 0);
317 }
318 }
319 db_finalize(&q);
320
321 /*
322 ** Find files that have changed from P->M but not P->V.
323 ** Copy the M content over into V.
324 */
325 db_prepare(&q,
326 "SELECT idv, ridm, fn FROM fv"
327 " WHERE idp>0 AND idv>0 AND idm>0"
328 " AND ridm!=ridp AND ridv=ridp AND NOT chnged"
329 );
330 while( db_step(&q)==SQLITE_ROW ){
331 int idv = db_column_int(&q, 0);
332 int ridm = db_column_int(&q, 1);
333 const char *zName = db_column_text(&q, 2);
 
334 /* Copy content from idm over into idv. Overwrite idv. */
335 fossil_print("UPDATE %s\n", zName);
336 if( !nochangeFlag ){
337 undo_save(zName);
338 db_multi_exec(
339 "UPDATE vfile SET mtime=0, mrid=%d, chnged=2 WHERE id=%d", ridm, idv
 
340 );
341 vfile_to_disk(0, idv, 0, 0);
342 }
343 }
344 db_finalize(&q);
@@ -345,11 +366,11 @@
345
346 /*
347 ** Do a three-way merge on files that have changes on both P->M and P->V.
348 */
349 db_prepare(&q,
350 "SELECT ridm, idv, ridp, ridv, %s, fn, isexe FROM fv"
351 " WHERE idp>0 AND idv>0 AND idm>0"
352 " AND ridm!=ridp AND (ridv!=ridp OR chnged)",
353 glob_expr("fv.fn", zBinGlob)
354 );
355 while( db_step(&q)==SQLITE_ROW ){
@@ -358,10 +379,12 @@
358 int ridp = db_column_int(&q, 2);
359 int ridv = db_column_int(&q, 3);
360 int isBinary = db_column_int(&q, 4);
361 const char *zName = db_column_text(&q, 5);
362 int isExe = db_column_int(&q, 6);
 
 
363 int rc;
364 char *zFullPath;
365 Blob m, p, r;
366 /* Do a 3-way merge of idp->idm into idp->idv. The results go into idv. */
367 if( detailFlag ){
@@ -368,37 +391,42 @@
368 fossil_print("MERGE %s (pivot=%d v1=%d v2=%d)\n",
369 zName, ridp, ridm, ridv);
370 }else{
371 fossil_print("MERGE %s\n", zName);
372 }
373 undo_save(zName);
374 zFullPath = mprintf("%s/%s", g.zLocalRoot, zName);
375 content_get(ridp, &p);
376 content_get(ridm, &m);
377 if( isBinary ){
378 rc = -1;
379 blob_zero(&r);
380 }else{
381 rc = merge_3way(&p, zFullPath, &m, &r);
382 }
383 if( rc>=0 ){
384 if( !nochangeFlag ){
385 blob_write_to_file(&r, zFullPath);
386 file_setexe(zFullPath, isExe);
387 }
388 db_multi_exec("UPDATE vfile SET mtime=0 WHERE id=%d", idv);
389 if( rc>0 ){
390 fossil_print("***** %d merge conflicts in %s\n", rc, zName);
391 nConflict++;
392 }
393 }else{
394 fossil_print("***** Cannot merge binary file %s\n", zName);
395 nConflict++;
396 }
397 blob_reset(&p);
398 blob_reset(&m);
399 blob_reset(&r);
 
 
 
 
 
400 db_multi_exec("INSERT OR IGNORE INTO vmerge(id,merge) VALUES(%d,%d)",
401 idv,ridm);
402 }
403 db_finalize(&q);
404
405
--- src/merge.c
+++ src/merge.c
@@ -148,10 +148,19 @@
148 vfile_check_signature(vid, 1, 0);
149 db_begin_transaction();
150 if( !nochangeFlag ) undo_begin();
151 load_vfile_from_rid(mid);
152 load_vfile_from_rid(pid);
153 if( debugFlag ){
154 char *z;
155 z = db_text(0, "SELECT uuid FROM blob WHERE rid=%d", pid);
156 fossil_print("P=%d %z\n", pid, z);
157 z = db_text(0, "SELECT uuid FROM blob WHERE rid=%d", mid);
158 fossil_print("M=%d %z\n", mid, z);
159 z = db_text(0, "SELECT uuid FROM blob WHERE rid=%d", vid);
160 fossil_print("V=%d %z\n", vid, z);
161 }
162
163 /*
164 ** The vfile.pathname field is used to match files against each other. The
165 ** FV table contains one row for each each unique filename in
166 ** in the current checkout, the pivot, and the version being merged.
@@ -167,11 +176,13 @@
176 " ridv INTEGER," /* Record ID for current version */
177 " ridp INTEGER," /* Record ID for pivot */
178 " ridm INTEGER," /* Record ID for merge */
179 " isexe BOOLEAN," /* Execute permission enabled */
180 " fnp TEXT," /* The filename in the pivot */
181 " fnm TEXT," /* the filename in the merged version */
182 " islinkv BOOLEAN," /* True if current version is a symlink */
183 " islinkm BOOLEAN" /* True if merged version in is a symlink */
184 ");",
185 caseSensitive ? "binary" : "nocase"
186 );
187
188 /* Add files found in V
@@ -185,19 +196,19 @@
196 );
197
198 /*
199 ** Compute name changes from P->V
200 */
201 find_filename_changes(pid, vid, 0, &nChng, &aChng, debugFlag ? "P->V" : 0);
202 if( nChng ){
203 for(i=0; i<nChng; i++){
204 char *z;
205 z = db_text(0, "SELECT name FROM filename WHERE fnid=%d", aChng[i*2]);
206 db_multi_exec(
207 "UPDATE fv SET fnp=%Q, fnm=%Q"
208 " WHERE fn=(SELECT name FROM filename WHERE fnid=%d)",
209 z, z, aChng[i*2+1]
210 );
211 free(z);
212 }
213 fossil_free(aChng);
214 db_multi_exec("UPDATE fv SET fnm=fnp WHERE fnp!=fn");
@@ -215,11 +226,11 @@
226 );
227
228 /*
229 ** Compute name changes from P->M
230 */
231 find_filename_changes(pid, mid, 0, &nChng, &aChng, debugFlag ? "P->M" : 0);
232 if( nChng ){
233 if( nChng>4 ) db_multi_exec("CREATE INDEX fv_fnp ON fv(fnp)");
234 for(i=0; i<nChng; i++){
235 db_multi_exec(
236 "UPDATE fv SET fnm=(SELECT name FROM filename WHERE fnid=%d)"
@@ -248,26 +259,34 @@
259 db_multi_exec(
260 "UPDATE fv SET"
261 " idp=coalesce((SELECT id FROM vfile WHERE vid=%d AND pathname=fnp),0),"
262 " ridp=coalesce((SELECT rid FROM vfile WHERE vid=%d AND pathname=fnp),0),"
263 " idm=coalesce((SELECT id FROM vfile WHERE vid=%d AND pathname=fnm),0),"
264 " ridm=coalesce((SELECT rid FROM vfile WHERE vid=%d AND pathname=fnm),0),"
265 " islinkv=coalesce((SELECT islink FROM vfile"
266 " WHERE vid=%d AND pathname=fnm),0),"
267 " islinkm=coalesce((SELECT islink FROM vfile"
268 " WHERE vid=%d AND pathname=fnm),0)",
269 pid, pid, mid, mid, vid, mid
270 );
271
272 if( debugFlag ){
273 db_prepare(&q,
274 "SELECT rowid, fn, fnp, fnm, chnged, ridv, ridp, ridm, "
275 " isexe, islinkv, islinkm FROM fv"
276 );
277 while( db_step(&q)==SQLITE_ROW ){
278 fossil_print("%3d: ridv=%-4d ridp=%-4d ridm=%-4d chnged=%d isexe=%d "
279 " islinkv=%d islinkm=%d\n",
280 db_column_int(&q, 0),
281 db_column_int(&q, 5),
282 db_column_int(&q, 6),
283 db_column_int(&q, 7),
284 db_column_int(&q, 4),
285 db_column_int(&q, 8),
286 db_column_int(&q, 9),
287 db_column_int(&q, 10));
288 fossil_print(" fn = [%s]\n", db_column_text(&q, 1));
289 fossil_print(" fnp = [%s]\n", db_column_text(&q, 2));
290 fossil_print(" fnm = [%s]\n", db_column_text(&q, 3));
291 }
292 db_finalize(&q);
@@ -301,12 +320,12 @@
320 int idm = db_column_int(&q, 0);
321 int rowid = db_column_int(&q, 1);
322 int idv;
323 const char *zName;
324 db_multi_exec(
325 "INSERT INTO vfile(vid,chnged,deleted,rid,mrid,isexe,islink,pathname)"
326 " SELECT %d,3,0,rid,mrid,isexe,islink,pathname FROM vfile WHERE id=%d",
327 vid, idm
328 );
329 idv = db_last_insert_rowid();
330 db_multi_exec("UPDATE fv SET idv=%d WHERE rowid=%d", idv, rowid);
331 zName = db_column_text(&q, 2);
@@ -315,30 +334,32 @@
334 undo_save(zName);
335 vfile_to_disk(0, idm, 0, 0);
336 }
337 }
338 db_finalize(&q);
339
340 /*
341 ** Find files that have changed from P->M but not P->V.
342 ** Copy the M content over into V.
343 */
344 db_prepare(&q,
345 "SELECT idv, ridm, fn, islinkm FROM fv"
346 " WHERE idp>0 AND idv>0 AND idm>0"
347 " AND ridm!=ridp AND ridv=ridp AND NOT chnged"
348 );
349 while( db_step(&q)==SQLITE_ROW ){
350 int idv = db_column_int(&q, 0);
351 int ridm = db_column_int(&q, 1);
352 const char *zName = db_column_text(&q, 2);
353 int islinkm = db_column_int(&q, 3);
354 /* Copy content from idm over into idv. Overwrite idv. */
355 fossil_print("UPDATE %s\n", zName);
356 if( !nochangeFlag ){
357 undo_save(zName);
358 db_multi_exec(
359 "UPDATE vfile SET mtime=0, mrid=%d, chnged=2, islink=%d "
360 " WHERE id=%d", ridm, islinkm, idv
361 );
362 vfile_to_disk(0, idv, 0, 0);
363 }
364 }
365 db_finalize(&q);
@@ -345,11 +366,11 @@
366
367 /*
368 ** Do a three-way merge on files that have changes on both P->M and P->V.
369 */
370 db_prepare(&q,
371 "SELECT ridm, idv, ridp, ridv, %s, fn, isexe, islinkv, islinkm FROM fv"
372 " WHERE idp>0 AND idv>0 AND idm>0"
373 " AND ridm!=ridp AND (ridv!=ridp OR chnged)",
374 glob_expr("fv.fn", zBinGlob)
375 );
376 while( db_step(&q)==SQLITE_ROW ){
@@ -358,10 +379,12 @@
379 int ridp = db_column_int(&q, 2);
380 int ridv = db_column_int(&q, 3);
381 int isBinary = db_column_int(&q, 4);
382 const char *zName = db_column_text(&q, 5);
383 int isExe = db_column_int(&q, 6);
384 int islinkv = db_column_int(&q, 7);
385 int islinkm = db_column_int(&q, 8);
386 int rc;
387 char *zFullPath;
388 Blob m, p, r;
389 /* Do a 3-way merge of idp->idm into idp->idv. The results go into idv. */
390 if( detailFlag ){
@@ -368,37 +391,42 @@
391 fossil_print("MERGE %s (pivot=%d v1=%d v2=%d)\n",
392 zName, ridp, ridm, ridv);
393 }else{
394 fossil_print("MERGE %s\n", zName);
395 }
396 if( islinkv || islinkm /* || file_islink(zFullPath) */ ){
397 fossil_print("***** Cannot merge symlink %s\n", zName);
398 nConflict++;
399 }else{
400 undo_save(zName);
401 zFullPath = mprintf("%s/%s", g.zLocalRoot, zName);
402 content_get(ridp, &p);
403 content_get(ridm, &m);
404 if( isBinary ){
405 rc = -1;
406 blob_zero(&r);
407 }else{
408 rc = merge_3way(&p, zFullPath, &m, &r);
409 }
410 if( rc>=0 ){
411 if( !nochangeFlag ){
412 blob_write_to_file(&r, zFullPath);
413 file_setexe(zFullPath, isExe);
414 }
415 db_multi_exec("UPDATE vfile SET mtime=0 WHERE id=%d", idv);
416 if( rc>0 ){
417 fossil_print("***** %d merge conflicts in %s\n", rc, zName);
418 nConflict++;
419 }
420 }else{
421 fossil_print("***** Cannot merge binary file %s\n", zName);
422 nConflict++;
423 }
424 blob_reset(&p);
425 blob_reset(&m);
426 blob_reset(&r);
427 }
428 db_multi_exec("INSERT OR IGNORE INTO vmerge(id,merge) VALUES(%d,%d)",
429 idv,ridm);
430 }
431 db_finalize(&q);
432
433
+94 -43
--- src/path.c
+++ src/path.c
@@ -89,14 +89,11 @@
8989
p = path.pAll;
9090
path.pAll = p->pAll;
9191
fossil_free(p);
9292
}
9393
bag_clear(&path.seen);
94
- path.pCurrent = 0;
95
- path.pAll = 0;
96
- path.pEnd = 0;
97
- path.nStep = 0;
94
+ memset(&path, 0, sizeof(&path));
9895
}
9996
10097
/*
10198
** Construct the path from path.pStart to path.pEnd in the u.pTo fields.
10299
*/
@@ -119,11 +116,16 @@
119116
** Elements of the path can be traversed by following the PathNode.u.pTo
120117
** pointer chain.
121118
**
122119
** Return NULL if no path is found.
123120
*/
124
-PathNode *path_shortest(int iFrom, int iTo, int directOnly){
121
+PathNode *path_shortest(
122
+ int iFrom, /* Path starts here */
123
+ int iTo, /* Path ends here */
124
+ int directOnly, /* No merge links if true */
125
+ int oneWayOnly /* Parent->child only if true */
126
+){
125127
Stmt s;
126128
PathNode *pPrev;
127129
PathNode *p;
128130
129131
path_reset();
@@ -130,11 +132,15 @@
130132
path.pStart = path_new_node(iFrom, 0, 0);
131133
if( iTo==iFrom ){
132134
path.pEnd = path.pStart;
133135
return path.pStart;
134136
}
135
- if( directOnly ){
137
+ if( oneWayOnly ){
138
+ db_prepare(&s,
139
+ "SELECT cid, 1 FROM plink WHERE pid=:pid "
140
+ );
141
+ }else if( directOnly ){
136142
db_prepare(&s,
137143
"SELECT cid, 1 FROM plink WHERE pid=:pid AND isprim "
138144
"UNION ALL "
139145
"SELECT pid, 0 FROM plink WHERE cid=:pid AND isprim"
140146
);
@@ -196,17 +202,19 @@
196202
int iFrom;
197203
int iTo;
198204
PathNode *p;
199205
int n;
200206
int directOnly;
207
+ int oneWay;
201208
202209
db_find_and_open_repository(0,0);
203210
directOnly = find_option("no-merge",0,0)!=0;
211
+ oneWay = find_option("one-way",0,0)!=0;
204212
if( g.argc!=4 ) usage("VERSION1 VERSION2");
205213
iFrom = name_to_rid(g.argv[2]);
206214
iTo = name_to_rid(g.argv[3]);
207
- p = path_shortest(iFrom, iTo, directOnly);
215
+ p = path_shortest(iFrom, iTo, directOnly, oneWay);
208216
if( p==0 ){
209217
fossil_fatal("no path from %s to %s", g.argv[1], g.argv[2]);
210218
}
211219
for(n=1, p=path.pStart; p; p=p->u.pTo, n++){
212220
char *z;
@@ -213,11 +221,11 @@
213221
z = db_text(0,
214222
"SELECT substr(uuid,1,12) || ' ' || datetime(mtime)"
215223
" FROM blob, event"
216224
" WHERE blob.rid=%d AND event.objid=%d AND event.type='ci'",
217225
p->rid, p->rid);
218
- fossil_print("%4d: %s", n, z);
226
+ fossil_print("%4d: %5d %s", n, p->rid, z);
219227
fossil_free(z);
220228
if( p->u.pTo ){
221229
fossil_print(" is a %s of\n",
222230
p->u.pTo->fromIsParent ? "parent" : "child");
223231
}else{
@@ -313,11 +321,11 @@
313321
z = db_text(0,
314322
"SELECT substr(uuid,1,12) || ' ' || datetime(mtime)"
315323
" FROM blob, event"
316324
" WHERE blob.rid=%d AND event.objid=%d AND event.type='ci'",
317325
p->rid, p->rid);
318
- fossil_print("%4d: %s", n, z);
326
+ fossil_print("%4d: %5d %s", n, p->rid, z);
319327
fossil_free(z);
320328
if( p->rid==iFrom ) fossil_print(" VERSION1");
321329
if( p->rid==iTo ) fossil_print(" VERSION2");
322330
if( p->rid==iPivot ) fossil_print(" PIVOT");
323331
fossil_print("\n");
@@ -340,25 +348,29 @@
340348
** Compute all file name changes that occur going from checkin iFrom
341349
** to checkin iTo.
342350
**
343351
** The number of name changes is written into *pnChng. For each name
344352
** change, two integers are allocated for *piChng. The first is the
345
-** filename.fnid for the original name and the second is for new name.
353
+** filename.fnid for the original name as seen in check-in iFrom and
354
+** the second is for new name as it is used in check-in iTo.
355
+**
346356
** Space to hold *piChng is obtained from fossil_malloc() and should
347357
** be released by the caller.
348358
**
349
-** This routine really has nothing to do with pathion. It is located
359
+** This routine really has nothing to do with path. It is located
350360
** in this path.c module in order to leverage some of the path
351361
** infrastructure.
352362
*/
353363
void find_filename_changes(
354
- int iFrom,
355
- int iTo,
356
- int *pnChng,
357
- int **aiChng
364
+ int iFrom, /* Ancestor check-in */
365
+ int iTo, /* Recent check-in */
366
+ int revOk, /* Ok to move backwards (child->parent) if true */
367
+ int *pnChng, /* Number of name changes along the path */
368
+ int **aiChng, /* Name changes */
369
+ const char *zDebug /* Generate trace output if no NULL */
358370
){
359
- PathNode *p; /* For looping over path from iFrom to iTo */
371
+ PathNode *p; /* For looping over path from iFrom to iTo */
360372
NameChange *pAll = 0; /* List of all name changes seen so far */
361373
NameChange *pChng; /* For looping through the name change list */
362374
int nChng = 0; /* Number of files whose names have changed */
363375
int *aChng; /* Two integers per name change */
364376
int i; /* Loop counter */
@@ -366,58 +378,87 @@
366378
367379
*pnChng = 0;
368380
*aiChng = 0;
369381
if( iFrom==iTo ) return;
370382
path_reset();
371
- p = path_shortest(iFrom, iTo, 1);
383
+ p = path_shortest(iFrom, iTo, 1, revOk==0);
372384
if( p==0 ) return;
373385
path_reverse_path();
374386
db_prepare(&q1,
375
- "SELECT pfnid, fnid FROM mlink WHERE mid=:mid AND pfnid>0"
387
+ "SELECT pfnid, fnid FROM mlink"
388
+ " WHERE mid=:mid AND (pfnid>0 OR fid==0)"
389
+ " ORDER BY pfnid"
376390
);
377391
for(p=path.pStart; p; p=p->u.pTo){
378392
int fnid, pfnid;
379393
if( !p->fromIsParent && (p->u.pTo==0 || p->u.pTo->fromIsParent) ){
380394
/* Skip nodes where the parent is not on the path */
381395
continue;
382396
}
383397
db_bind_int(&q1, ":mid", p->rid);
384398
while( db_step(&q1)==SQLITE_ROW ){
385
- if( p->fromIsParent ){
386
- fnid = db_column_int(&q1, 1);
387
- pfnid = db_column_int(&q1, 0);
388
- }else{
389
- fnid = db_column_int(&q1, 0);
390
- pfnid = db_column_int(&q1, 1);
399
+ fnid = db_column_int(&q1, 1);
400
+ pfnid = db_column_int(&q1, 0);
401
+ if( pfnid==0 ){
402
+ pfnid = fnid;
403
+ fnid = 0;
404
+ }
405
+ if( !p->fromIsParent ){
406
+ int t = fnid;
407
+ fnid = pfnid;
408
+ pfnid = t;
409
+ }
410
+ if( zDebug ){
411
+ fossil_print("%s at %d%s %.10z: %d[%z] -> %d[%z]\n",
412
+ zDebug, p->rid, p->fromIsParent ? ">" : "<",
413
+ db_text(0, "SELECT uuid FROM blob WHERE rid=%d", p->rid),
414
+ pfnid,
415
+ db_text(0, "SELECT name FROM filename WHERE fnid=%d", pfnid),
416
+ fnid,
417
+ db_text(0, "SELECT name FROM filename WHERE fnid=%d", fnid));
391418
}
392419
for(pChng=pAll; pChng; pChng=pChng->pNext){
393420
if( pChng->curName==pfnid ){
394421
pChng->newName = fnid;
395422
break;
396423
}
397424
}
398
- if( pChng==0 ){
425
+ if( pChng==0 && fnid>0 ){
399426
pChng = fossil_malloc( sizeof(*pChng) );
400427
pChng->pNext = pAll;
401428
pAll = pChng;
402429
pChng->origName = pfnid;
403430
pChng->curName = pfnid;
404431
pChng->newName = fnid;
405432
nChng++;
406433
}
407434
}
408
- for(pChng=pAll; pChng; pChng=pChng->pNext) pChng->curName = pChng->newName;
435
+ for(pChng=pAll; pChng; pChng=pChng->pNext){
436
+ pChng->curName = pChng->newName;
437
+ }
409438
db_reset(&q1);
410439
}
411440
db_finalize(&q1);
412441
if( nChng ){
413
- *pnChng = nChng;
414442
aChng = *aiChng = fossil_malloc( nChng*2*sizeof(int) );
415
- for(pChng=pAll, i=0; pChng; pChng=pChng->pNext, i+=2){
443
+ for(pChng=pAll, i=0; pChng; pChng=pChng->pNext){
444
+ if( pChng->newName==0 ) continue;
445
+ if( pChng->origName==0 ) continue;
446
+ if( pChng->newName==pChng->origName ) continue;
416447
aChng[i] = pChng->origName;
417448
aChng[i+1] = pChng->newName;
449
+ if( zDebug ){
450
+ fossil_print("%s summary %d[%z] -> %d[%z]\n",
451
+ zDebug,
452
+ aChng[i],
453
+ db_text(0, "SELECT name FROM filename WHERE fnid=%d", aChng[i]),
454
+ aChng[i+1],
455
+ db_text(0, "SELECT name FROM filename WHERE fnid=%d", aChng[i+1]));
456
+ }
457
+ i += 2;
418458
}
459
+ *pnChng = i/2;
419460
while( pAll ){
420461
pChng = pAll;
421462
pAll = pAll->pNext;
422463
fossil_free(pChng);
423464
}
@@ -425,32 +466,42 @@
425466
}
426467
427468
/*
428469
** COMMAND: test-name-changes
429470
**
430
-** Usage: %fossil test-name-changes VERSION1 VERSION2
471
+** Usage: %fossil test-name-changes [--debug] VERSION1 VERSION2
431472
**
432473
** Show all filename changes that occur going from VERSION1 to VERSION2
433474
*/
434475
void test_name_change(void){
435476
int iFrom;
436477
int iTo;
437478
int *aChng;
438479
int nChng;
439480
int i;
481
+ const char *zDebug = 0;
482
+ int revOk = 0;
440483
441484
db_find_and_open_repository(0,0);
442
- if( g.argc!=4 ) usage("VERSION1 VERSION2");
443
- iFrom = name_to_rid(g.argv[2]);
444
- iTo = name_to_rid(g.argv[3]);
445
- find_filename_changes(iFrom, iTo, &nChng, &aChng);
446
- for(i=0; i<nChng; i++){
447
- char *zFrom, *zTo;
448
-
449
- zFrom = db_text(0, "SELECT name FROM filename WHERE fnid=%d", aChng[i*2]);
450
- zTo = db_text(0, "SELECT name FROM filename WHERE fnid=%d", aChng[i*2+1]);
451
- fossil_print("[%s] -> [%s]\n", zFrom, zTo);
452
- fossil_free(zFrom);
453
- fossil_free(zTo);
454
- }
455
- fossil_free(aChng);
485
+ zDebug = find_option("debug",0,0)!=0 ? "debug" : 0;
486
+ revOk = find_option("bidirectional",0,0)!=0;
487
+ if( g.argc<4 ) usage("VERSION1 VERSION2");
488
+ while( g.argc>=4 ){
489
+ iFrom = name_to_rid(g.argv[2]);
490
+ iTo = name_to_rid(g.argv[3]);
491
+ find_filename_changes(iFrom, iTo, revOk, &nChng, &aChng, zDebug);
492
+ fossil_print("------ Changes for (%d) %s -> (%d) %s\n",
493
+ iFrom, g.argv[2], iTo, g.argv[3]);
494
+ for(i=0; i<nChng; i++){
495
+ char *zFrom, *zTo;
496
+
497
+ zFrom = db_text(0, "SELECT name FROM filename WHERE fnid=%d", aChng[i*2]);
498
+ zTo = db_text(0, "SELECT name FROM filename WHERE fnid=%d", aChng[i*2+1]);
499
+ fossil_print("[%s] -> [%s]\n", zFrom, zTo);
500
+ fossil_free(zFrom);
501
+ fossil_free(zTo);
502
+ }
503
+ fossil_free(aChng);
504
+ g.argv += 2;
505
+ g.argc -= 2;
506
+ }
456507
}
457508
--- src/path.c
+++ src/path.c
@@ -89,14 +89,11 @@
89 p = path.pAll;
90 path.pAll = p->pAll;
91 fossil_free(p);
92 }
93 bag_clear(&path.seen);
94 path.pCurrent = 0;
95 path.pAll = 0;
96 path.pEnd = 0;
97 path.nStep = 0;
98 }
99
100 /*
101 ** Construct the path from path.pStart to path.pEnd in the u.pTo fields.
102 */
@@ -119,11 +116,16 @@
119 ** Elements of the path can be traversed by following the PathNode.u.pTo
120 ** pointer chain.
121 **
122 ** Return NULL if no path is found.
123 */
124 PathNode *path_shortest(int iFrom, int iTo, int directOnly){
 
 
 
 
 
125 Stmt s;
126 PathNode *pPrev;
127 PathNode *p;
128
129 path_reset();
@@ -130,11 +132,15 @@
130 path.pStart = path_new_node(iFrom, 0, 0);
131 if( iTo==iFrom ){
132 path.pEnd = path.pStart;
133 return path.pStart;
134 }
135 if( directOnly ){
 
 
 
 
136 db_prepare(&s,
137 "SELECT cid, 1 FROM plink WHERE pid=:pid AND isprim "
138 "UNION ALL "
139 "SELECT pid, 0 FROM plink WHERE cid=:pid AND isprim"
140 );
@@ -196,17 +202,19 @@
196 int iFrom;
197 int iTo;
198 PathNode *p;
199 int n;
200 int directOnly;
 
201
202 db_find_and_open_repository(0,0);
203 directOnly = find_option("no-merge",0,0)!=0;
 
204 if( g.argc!=4 ) usage("VERSION1 VERSION2");
205 iFrom = name_to_rid(g.argv[2]);
206 iTo = name_to_rid(g.argv[3]);
207 p = path_shortest(iFrom, iTo, directOnly);
208 if( p==0 ){
209 fossil_fatal("no path from %s to %s", g.argv[1], g.argv[2]);
210 }
211 for(n=1, p=path.pStart; p; p=p->u.pTo, n++){
212 char *z;
@@ -213,11 +221,11 @@
213 z = db_text(0,
214 "SELECT substr(uuid,1,12) || ' ' || datetime(mtime)"
215 " FROM blob, event"
216 " WHERE blob.rid=%d AND event.objid=%d AND event.type='ci'",
217 p->rid, p->rid);
218 fossil_print("%4d: %s", n, z);
219 fossil_free(z);
220 if( p->u.pTo ){
221 fossil_print(" is a %s of\n",
222 p->u.pTo->fromIsParent ? "parent" : "child");
223 }else{
@@ -313,11 +321,11 @@
313 z = db_text(0,
314 "SELECT substr(uuid,1,12) || ' ' || datetime(mtime)"
315 " FROM blob, event"
316 " WHERE blob.rid=%d AND event.objid=%d AND event.type='ci'",
317 p->rid, p->rid);
318 fossil_print("%4d: %s", n, z);
319 fossil_free(z);
320 if( p->rid==iFrom ) fossil_print(" VERSION1");
321 if( p->rid==iTo ) fossil_print(" VERSION2");
322 if( p->rid==iPivot ) fossil_print(" PIVOT");
323 fossil_print("\n");
@@ -340,25 +348,29 @@
340 ** Compute all file name changes that occur going from checkin iFrom
341 ** to checkin iTo.
342 **
343 ** The number of name changes is written into *pnChng. For each name
344 ** change, two integers are allocated for *piChng. The first is the
345 ** filename.fnid for the original name and the second is for new name.
 
 
346 ** Space to hold *piChng is obtained from fossil_malloc() and should
347 ** be released by the caller.
348 **
349 ** This routine really has nothing to do with pathion. It is located
350 ** in this path.c module in order to leverage some of the path
351 ** infrastructure.
352 */
353 void find_filename_changes(
354 int iFrom,
355 int iTo,
356 int *pnChng,
357 int **aiChng
 
 
358 ){
359 PathNode *p; /* For looping over path from iFrom to iTo */
360 NameChange *pAll = 0; /* List of all name changes seen so far */
361 NameChange *pChng; /* For looping through the name change list */
362 int nChng = 0; /* Number of files whose names have changed */
363 int *aChng; /* Two integers per name change */
364 int i; /* Loop counter */
@@ -366,58 +378,87 @@
366
367 *pnChng = 0;
368 *aiChng = 0;
369 if( iFrom==iTo ) return;
370 path_reset();
371 p = path_shortest(iFrom, iTo, 1);
372 if( p==0 ) return;
373 path_reverse_path();
374 db_prepare(&q1,
375 "SELECT pfnid, fnid FROM mlink WHERE mid=:mid AND pfnid>0"
 
 
376 );
377 for(p=path.pStart; p; p=p->u.pTo){
378 int fnid, pfnid;
379 if( !p->fromIsParent && (p->u.pTo==0 || p->u.pTo->fromIsParent) ){
380 /* Skip nodes where the parent is not on the path */
381 continue;
382 }
383 db_bind_int(&q1, ":mid", p->rid);
384 while( db_step(&q1)==SQLITE_ROW ){
385 if( p->fromIsParent ){
386 fnid = db_column_int(&q1, 1);
387 pfnid = db_column_int(&q1, 0);
388 }else{
389 fnid = db_column_int(&q1, 0);
390 pfnid = db_column_int(&q1, 1);
 
 
 
 
 
 
 
 
 
 
 
 
 
391 }
392 for(pChng=pAll; pChng; pChng=pChng->pNext){
393 if( pChng->curName==pfnid ){
394 pChng->newName = fnid;
395 break;
396 }
397 }
398 if( pChng==0 ){
399 pChng = fossil_malloc( sizeof(*pChng) );
400 pChng->pNext = pAll;
401 pAll = pChng;
402 pChng->origName = pfnid;
403 pChng->curName = pfnid;
404 pChng->newName = fnid;
405 nChng++;
406 }
407 }
408 for(pChng=pAll; pChng; pChng=pChng->pNext) pChng->curName = pChng->newName;
 
 
409 db_reset(&q1);
410 }
411 db_finalize(&q1);
412 if( nChng ){
413 *pnChng = nChng;
414 aChng = *aiChng = fossil_malloc( nChng*2*sizeof(int) );
415 for(pChng=pAll, i=0; pChng; pChng=pChng->pNext, i+=2){
 
 
 
416 aChng[i] = pChng->origName;
417 aChng[i+1] = pChng->newName;
 
 
 
 
 
 
 
 
 
418 }
 
419 while( pAll ){
420 pChng = pAll;
421 pAll = pAll->pNext;
422 fossil_free(pChng);
423 }
@@ -425,32 +466,42 @@
425 }
426
427 /*
428 ** COMMAND: test-name-changes
429 **
430 ** Usage: %fossil test-name-changes VERSION1 VERSION2
431 **
432 ** Show all filename changes that occur going from VERSION1 to VERSION2
433 */
434 void test_name_change(void){
435 int iFrom;
436 int iTo;
437 int *aChng;
438 int nChng;
439 int i;
 
 
440
441 db_find_and_open_repository(0,0);
442 if( g.argc!=4 ) usage("VERSION1 VERSION2");
443 iFrom = name_to_rid(g.argv[2]);
444 iTo = name_to_rid(g.argv[3]);
445 find_filename_changes(iFrom, iTo, &nChng, &aChng);
446 for(i=0; i<nChng; i++){
447 char *zFrom, *zTo;
448
449 zFrom = db_text(0, "SELECT name FROM filename WHERE fnid=%d", aChng[i*2]);
450 zTo = db_text(0, "SELECT name FROM filename WHERE fnid=%d", aChng[i*2+1]);
451 fossil_print("[%s] -> [%s]\n", zFrom, zTo);
452 fossil_free(zFrom);
453 fossil_free(zTo);
454 }
455 fossil_free(aChng);
 
 
 
 
 
 
 
 
456 }
457
--- src/path.c
+++ src/path.c
@@ -89,14 +89,11 @@
89 p = path.pAll;
90 path.pAll = p->pAll;
91 fossil_free(p);
92 }
93 bag_clear(&path.seen);
94 memset(&path, 0, sizeof(&path));
 
 
 
95 }
96
97 /*
98 ** Construct the path from path.pStart to path.pEnd in the u.pTo fields.
99 */
@@ -119,11 +116,16 @@
116 ** Elements of the path can be traversed by following the PathNode.u.pTo
117 ** pointer chain.
118 **
119 ** Return NULL if no path is found.
120 */
121 PathNode *path_shortest(
122 int iFrom, /* Path starts here */
123 int iTo, /* Path ends here */
124 int directOnly, /* No merge links if true */
125 int oneWayOnly /* Parent->child only if true */
126 ){
127 Stmt s;
128 PathNode *pPrev;
129 PathNode *p;
130
131 path_reset();
@@ -130,11 +132,15 @@
132 path.pStart = path_new_node(iFrom, 0, 0);
133 if( iTo==iFrom ){
134 path.pEnd = path.pStart;
135 return path.pStart;
136 }
137 if( oneWayOnly ){
138 db_prepare(&s,
139 "SELECT cid, 1 FROM plink WHERE pid=:pid "
140 );
141 }else if( directOnly ){
142 db_prepare(&s,
143 "SELECT cid, 1 FROM plink WHERE pid=:pid AND isprim "
144 "UNION ALL "
145 "SELECT pid, 0 FROM plink WHERE cid=:pid AND isprim"
146 );
@@ -196,17 +202,19 @@
202 int iFrom;
203 int iTo;
204 PathNode *p;
205 int n;
206 int directOnly;
207 int oneWay;
208
209 db_find_and_open_repository(0,0);
210 directOnly = find_option("no-merge",0,0)!=0;
211 oneWay = find_option("one-way",0,0)!=0;
212 if( g.argc!=4 ) usage("VERSION1 VERSION2");
213 iFrom = name_to_rid(g.argv[2]);
214 iTo = name_to_rid(g.argv[3]);
215 p = path_shortest(iFrom, iTo, directOnly, oneWay);
216 if( p==0 ){
217 fossil_fatal("no path from %s to %s", g.argv[1], g.argv[2]);
218 }
219 for(n=1, p=path.pStart; p; p=p->u.pTo, n++){
220 char *z;
@@ -213,11 +221,11 @@
221 z = db_text(0,
222 "SELECT substr(uuid,1,12) || ' ' || datetime(mtime)"
223 " FROM blob, event"
224 " WHERE blob.rid=%d AND event.objid=%d AND event.type='ci'",
225 p->rid, p->rid);
226 fossil_print("%4d: %5d %s", n, p->rid, z);
227 fossil_free(z);
228 if( p->u.pTo ){
229 fossil_print(" is a %s of\n",
230 p->u.pTo->fromIsParent ? "parent" : "child");
231 }else{
@@ -313,11 +321,11 @@
321 z = db_text(0,
322 "SELECT substr(uuid,1,12) || ' ' || datetime(mtime)"
323 " FROM blob, event"
324 " WHERE blob.rid=%d AND event.objid=%d AND event.type='ci'",
325 p->rid, p->rid);
326 fossil_print("%4d: %5d %s", n, p->rid, z);
327 fossil_free(z);
328 if( p->rid==iFrom ) fossil_print(" VERSION1");
329 if( p->rid==iTo ) fossil_print(" VERSION2");
330 if( p->rid==iPivot ) fossil_print(" PIVOT");
331 fossil_print("\n");
@@ -340,25 +348,29 @@
348 ** Compute all file name changes that occur going from checkin iFrom
349 ** to checkin iTo.
350 **
351 ** The number of name changes is written into *pnChng. For each name
352 ** change, two integers are allocated for *piChng. The first is the
353 ** filename.fnid for the original name as seen in check-in iFrom and
354 ** the second is for new name as it is used in check-in iTo.
355 **
356 ** Space to hold *piChng is obtained from fossil_malloc() and should
357 ** be released by the caller.
358 **
359 ** This routine really has nothing to do with path. It is located
360 ** in this path.c module in order to leverage some of the path
361 ** infrastructure.
362 */
363 void find_filename_changes(
364 int iFrom, /* Ancestor check-in */
365 int iTo, /* Recent check-in */
366 int revOk, /* Ok to move backwards (child->parent) if true */
367 int *pnChng, /* Number of name changes along the path */
368 int **aiChng, /* Name changes */
369 const char *zDebug /* Generate trace output if no NULL */
370 ){
371 PathNode *p; /* For looping over path from iFrom to iTo */
372 NameChange *pAll = 0; /* List of all name changes seen so far */
373 NameChange *pChng; /* For looping through the name change list */
374 int nChng = 0; /* Number of files whose names have changed */
375 int *aChng; /* Two integers per name change */
376 int i; /* Loop counter */
@@ -366,58 +378,87 @@
378
379 *pnChng = 0;
380 *aiChng = 0;
381 if( iFrom==iTo ) return;
382 path_reset();
383 p = path_shortest(iFrom, iTo, 1, revOk==0);
384 if( p==0 ) return;
385 path_reverse_path();
386 db_prepare(&q1,
387 "SELECT pfnid, fnid FROM mlink"
388 " WHERE mid=:mid AND (pfnid>0 OR fid==0)"
389 " ORDER BY pfnid"
390 );
391 for(p=path.pStart; p; p=p->u.pTo){
392 int fnid, pfnid;
393 if( !p->fromIsParent && (p->u.pTo==0 || p->u.pTo->fromIsParent) ){
394 /* Skip nodes where the parent is not on the path */
395 continue;
396 }
397 db_bind_int(&q1, ":mid", p->rid);
398 while( db_step(&q1)==SQLITE_ROW ){
399 fnid = db_column_int(&q1, 1);
400 pfnid = db_column_int(&q1, 0);
401 if( pfnid==0 ){
402 pfnid = fnid;
403 fnid = 0;
404 }
405 if( !p->fromIsParent ){
406 int t = fnid;
407 fnid = pfnid;
408 pfnid = t;
409 }
410 if( zDebug ){
411 fossil_print("%s at %d%s %.10z: %d[%z] -> %d[%z]\n",
412 zDebug, p->rid, p->fromIsParent ? ">" : "<",
413 db_text(0, "SELECT uuid FROM blob WHERE rid=%d", p->rid),
414 pfnid,
415 db_text(0, "SELECT name FROM filename WHERE fnid=%d", pfnid),
416 fnid,
417 db_text(0, "SELECT name FROM filename WHERE fnid=%d", fnid));
418 }
419 for(pChng=pAll; pChng; pChng=pChng->pNext){
420 if( pChng->curName==pfnid ){
421 pChng->newName = fnid;
422 break;
423 }
424 }
425 if( pChng==0 && fnid>0 ){
426 pChng = fossil_malloc( sizeof(*pChng) );
427 pChng->pNext = pAll;
428 pAll = pChng;
429 pChng->origName = pfnid;
430 pChng->curName = pfnid;
431 pChng->newName = fnid;
432 nChng++;
433 }
434 }
435 for(pChng=pAll; pChng; pChng=pChng->pNext){
436 pChng->curName = pChng->newName;
437 }
438 db_reset(&q1);
439 }
440 db_finalize(&q1);
441 if( nChng ){
 
442 aChng = *aiChng = fossil_malloc( nChng*2*sizeof(int) );
443 for(pChng=pAll, i=0; pChng; pChng=pChng->pNext){
444 if( pChng->newName==0 ) continue;
445 if( pChng->origName==0 ) continue;
446 if( pChng->newName==pChng->origName ) continue;
447 aChng[i] = pChng->origName;
448 aChng[i+1] = pChng->newName;
449 if( zDebug ){
450 fossil_print("%s summary %d[%z] -> %d[%z]\n",
451 zDebug,
452 aChng[i],
453 db_text(0, "SELECT name FROM filename WHERE fnid=%d", aChng[i]),
454 aChng[i+1],
455 db_text(0, "SELECT name FROM filename WHERE fnid=%d", aChng[i+1]));
456 }
457 i += 2;
458 }
459 *pnChng = i/2;
460 while( pAll ){
461 pChng = pAll;
462 pAll = pAll->pNext;
463 fossil_free(pChng);
464 }
@@ -425,32 +466,42 @@
466 }
467
468 /*
469 ** COMMAND: test-name-changes
470 **
471 ** Usage: %fossil test-name-changes [--debug] VERSION1 VERSION2
472 **
473 ** Show all filename changes that occur going from VERSION1 to VERSION2
474 */
475 void test_name_change(void){
476 int iFrom;
477 int iTo;
478 int *aChng;
479 int nChng;
480 int i;
481 const char *zDebug = 0;
482 int revOk = 0;
483
484 db_find_and_open_repository(0,0);
485 zDebug = find_option("debug",0,0)!=0 ? "debug" : 0;
486 revOk = find_option("bidirectional",0,0)!=0;
487 if( g.argc<4 ) usage("VERSION1 VERSION2");
488 while( g.argc>=4 ){
489 iFrom = name_to_rid(g.argv[2]);
490 iTo = name_to_rid(g.argv[3]);
491 find_filename_changes(iFrom, iTo, revOk, &nChng, &aChng, zDebug);
492 fossil_print("------ Changes for (%d) %s -> (%d) %s\n",
493 iFrom, g.argv[2], iTo, g.argv[3]);
494 for(i=0; i<nChng; i++){
495 char *zFrom, *zTo;
496
497 zFrom = db_text(0, "SELECT name FROM filename WHERE fnid=%d", aChng[i*2]);
498 zTo = db_text(0, "SELECT name FROM filename WHERE fnid=%d", aChng[i*2+1]);
499 fossil_print("[%s] -> [%s]\n", zFrom, zTo);
500 fossil_free(zFrom);
501 fossil_free(zTo);
502 }
503 fossil_free(aChng);
504 g.argv += 2;
505 g.argc -= 2;
506 }
507 }
508
+19 -9
--- src/report.c
+++ src/report.c
@@ -198,10 +198,21 @@
198198
}
199199
}
200200
return rc;
201201
}
202202
203
+/*
204
+** Activate the query authorizer
205
+*/
206
+static void report_restrict_sql(char **pzErr){
207
+ (void)fossil_localtime(0);
208
+ sqlite3_set_authorizer(g.db, report_query_authorizer, (void*)pzErr);
209
+}
210
+static void report_unrestrict_sql(void){
211
+ sqlite3_set_authorizer(g.db, 0, 0);
212
+}
213
+
203214
204215
/*
205216
** Check the given SQL to see if is a valid query that does not
206217
** attempt to do anything dangerous. Return 0 on success and a
207218
** pointer to an error message string (obtained from malloc) if
@@ -237,11 +248,11 @@
237248
}
238249
}
239250
}
240251
241252
/* Compile the statement and check for illegal accesses or syntax errors. */
242
- sqlite3_set_authorizer(g.db, report_query_authorizer, (void*)&zErr);
253
+ report_restrict_sql(&zErr);
243254
rc = sqlite3_prepare(g.db, zSql, -1, &pStmt, &zTail);
244255
if( rc!=SQLITE_OK ){
245256
zErr = mprintf("Syntax error: %s", sqlite3_errmsg(g.db));
246257
}
247258
if( !sqlite3_stmt_readonly(pStmt) ){
@@ -248,11 +259,11 @@
248259
zErr = mprintf("SQL must not modify the database");
249260
}
250261
if( pStmt ){
251262
sqlite3_finalize(pStmt);
252263
}
253
- sqlite3_set_authorizer(g.db, 0, 0);
264
+ report_unrestrict_sql();
254265
return zErr;
255266
}
256267
257268
/*
258269
** WEBPAGE: /rptsql
@@ -963,25 +974,24 @@
963974
output_color_key(zClrKey, 1,
964975
"border=\"0\" cellpadding=\"3\" cellspacing=\"0\" class=\"report\"");
965976
@ <table border="1" cellpadding="2" cellspacing="0" class="report">
966977
sState.rn = rn;
967978
sState.nCount = 0;
968
- (void)fossil_localtime(0); /* initialize the g.fTimeFormat variable */
969
- sqlite3_set_authorizer(g.db, report_query_authorizer, (void*)&zErr1);
979
+ report_restrict_sql(&zErr1);
970980
sqlite3_exec_readonly(g.db, zSql, generate_html, &sState, &zErr2);
971
- sqlite3_set_authorizer(g.db, 0, 0);
981
+ report_unrestrict_sql();
972982
@ </table>
973983
if( zErr1 ){
974984
@ <p class="reportError">Error: %h(zErr1)</p>
975985
}else if( zErr2 ){
976986
@ <p class="reportError">Error: %h(zErr2)</p>
977987
}
978988
style_footer();
979989
}else{
980
- sqlite3_set_authorizer(g.db, report_query_authorizer, (void*)&zErr1);
990
+ report_restrict_sql(&zErr1);
981991
sqlite3_exec_readonly(g.db, zSql, output_tab_separated, &count, &zErr2);
982
- sqlite3_set_authorizer(g.db, 0, 0);
992
+ report_unrestrict_sql();
983993
cgi_set_content_type("text/plain");
984994
}
985995
}
986996
987997
/*
@@ -1137,12 +1147,12 @@
11371147
zSql = mprintf("SELECT * FROM (%s) WHERE %s",zSql,zFilter);
11381148
}
11391149
count = 0;
11401150
tktEncode = enc;
11411151
zSep = zSepIn;
1142
- sqlite3_set_authorizer(g.db, report_query_authorizer, (void*)&zErr1);
1152
+ report_restrict_sql(&zErr1);
11431153
sqlite3_exec_readonly(g.db, zSql, output_separated_file, &count, &zErr2);
1144
- sqlite3_set_authorizer(g.db, 0, 0);
1154
+ report_unrestrict_sql();
11451155
if( zFilter ){
11461156
free(zSql);
11471157
}
11481158
}
11491159
--- src/report.c
+++ src/report.c
@@ -198,10 +198,21 @@
198 }
199 }
200 return rc;
201 }
202
 
 
 
 
 
 
 
 
 
 
 
203
204 /*
205 ** Check the given SQL to see if is a valid query that does not
206 ** attempt to do anything dangerous. Return 0 on success and a
207 ** pointer to an error message string (obtained from malloc) if
@@ -237,11 +248,11 @@
237 }
238 }
239 }
240
241 /* Compile the statement and check for illegal accesses or syntax errors. */
242 sqlite3_set_authorizer(g.db, report_query_authorizer, (void*)&zErr);
243 rc = sqlite3_prepare(g.db, zSql, -1, &pStmt, &zTail);
244 if( rc!=SQLITE_OK ){
245 zErr = mprintf("Syntax error: %s", sqlite3_errmsg(g.db));
246 }
247 if( !sqlite3_stmt_readonly(pStmt) ){
@@ -248,11 +259,11 @@
248 zErr = mprintf("SQL must not modify the database");
249 }
250 if( pStmt ){
251 sqlite3_finalize(pStmt);
252 }
253 sqlite3_set_authorizer(g.db, 0, 0);
254 return zErr;
255 }
256
257 /*
258 ** WEBPAGE: /rptsql
@@ -963,25 +974,24 @@
963 output_color_key(zClrKey, 1,
964 "border=\"0\" cellpadding=\"3\" cellspacing=\"0\" class=\"report\"");
965 @ <table border="1" cellpadding="2" cellspacing="0" class="report">
966 sState.rn = rn;
967 sState.nCount = 0;
968 (void)fossil_localtime(0); /* initialize the g.fTimeFormat variable */
969 sqlite3_set_authorizer(g.db, report_query_authorizer, (void*)&zErr1);
970 sqlite3_exec_readonly(g.db, zSql, generate_html, &sState, &zErr2);
971 sqlite3_set_authorizer(g.db, 0, 0);
972 @ </table>
973 if( zErr1 ){
974 @ <p class="reportError">Error: %h(zErr1)</p>
975 }else if( zErr2 ){
976 @ <p class="reportError">Error: %h(zErr2)</p>
977 }
978 style_footer();
979 }else{
980 sqlite3_set_authorizer(g.db, report_query_authorizer, (void*)&zErr1);
981 sqlite3_exec_readonly(g.db, zSql, output_tab_separated, &count, &zErr2);
982 sqlite3_set_authorizer(g.db, 0, 0);
983 cgi_set_content_type("text/plain");
984 }
985 }
986
987 /*
@@ -1137,12 +1147,12 @@
1137 zSql = mprintf("SELECT * FROM (%s) WHERE %s",zSql,zFilter);
1138 }
1139 count = 0;
1140 tktEncode = enc;
1141 zSep = zSepIn;
1142 sqlite3_set_authorizer(g.db, report_query_authorizer, (void*)&zErr1);
1143 sqlite3_exec_readonly(g.db, zSql, output_separated_file, &count, &zErr2);
1144 sqlite3_set_authorizer(g.db, 0, 0);
1145 if( zFilter ){
1146 free(zSql);
1147 }
1148 }
1149
--- src/report.c
+++ src/report.c
@@ -198,10 +198,21 @@
198 }
199 }
200 return rc;
201 }
202
203 /*
204 ** Activate the query authorizer
205 */
206 static void report_restrict_sql(char **pzErr){
207 (void)fossil_localtime(0);
208 sqlite3_set_authorizer(g.db, report_query_authorizer, (void*)pzErr);
209 }
210 static void report_unrestrict_sql(void){
211 sqlite3_set_authorizer(g.db, 0, 0);
212 }
213
214
215 /*
216 ** Check the given SQL to see if is a valid query that does not
217 ** attempt to do anything dangerous. Return 0 on success and a
218 ** pointer to an error message string (obtained from malloc) if
@@ -237,11 +248,11 @@
248 }
249 }
250 }
251
252 /* Compile the statement and check for illegal accesses or syntax errors. */
253 report_restrict_sql(&zErr);
254 rc = sqlite3_prepare(g.db, zSql, -1, &pStmt, &zTail);
255 if( rc!=SQLITE_OK ){
256 zErr = mprintf("Syntax error: %s", sqlite3_errmsg(g.db));
257 }
258 if( !sqlite3_stmt_readonly(pStmt) ){
@@ -248,11 +259,11 @@
259 zErr = mprintf("SQL must not modify the database");
260 }
261 if( pStmt ){
262 sqlite3_finalize(pStmt);
263 }
264 report_unrestrict_sql();
265 return zErr;
266 }
267
268 /*
269 ** WEBPAGE: /rptsql
@@ -963,25 +974,24 @@
974 output_color_key(zClrKey, 1,
975 "border=\"0\" cellpadding=\"3\" cellspacing=\"0\" class=\"report\"");
976 @ <table border="1" cellpadding="2" cellspacing="0" class="report">
977 sState.rn = rn;
978 sState.nCount = 0;
979 report_restrict_sql(&zErr1);
 
980 sqlite3_exec_readonly(g.db, zSql, generate_html, &sState, &zErr2);
981 report_unrestrict_sql();
982 @ </table>
983 if( zErr1 ){
984 @ <p class="reportError">Error: %h(zErr1)</p>
985 }else if( zErr2 ){
986 @ <p class="reportError">Error: %h(zErr2)</p>
987 }
988 style_footer();
989 }else{
990 report_restrict_sql(&zErr1);
991 sqlite3_exec_readonly(g.db, zSql, output_tab_separated, &count, &zErr2);
992 report_unrestrict_sql();
993 cgi_set_content_type("text/plain");
994 }
995 }
996
997 /*
@@ -1137,12 +1147,12 @@
1147 zSql = mprintf("SELECT * FROM (%s) WHERE %s",zSql,zFilter);
1148 }
1149 count = 0;
1150 tktEncode = enc;
1151 zSep = zSepIn;
1152 report_restrict_sql(&zErr1);
1153 sqlite3_exec_readonly(g.db, zSql, output_separated_file, &count, &zErr2);
1154 report_unrestrict_sql();
1155 if( zFilter ){
1156 free(zSql);
1157 }
1158 }
1159
--- src/schema.c
+++ src/schema.c
@@ -461,10 +461,11 @@
461461
@ id INTEGER PRIMARY KEY, -- ID of the checked out file
462462
@ vid INTEGER REFERENCES blob, -- The baseline this file is part of.
463463
@ chnged INT DEFAULT 0, -- 0:unchnged 1:edited 2:m-chng 3:m-add
464464
@ deleted BOOLEAN DEFAULT 0, -- True if deleted
465465
@ isexe BOOLEAN, -- True if file should be executable
466
+@ islink BOOLEAN, -- True if file should be symlink
466467
@ rid INTEGER, -- Originally from this repository record
467468
@ mrid INTEGER, -- Based on this record due to a merge
468469
@ mtime INTEGER, -- Mtime of file on disk. sec since 1970
469470
@ pathname TEXT, -- Full pathname relative to root
470471
@ origname TEXT, -- Original pathname. NULL if unchanged
471472
--- src/schema.c
+++ src/schema.c
@@ -461,10 +461,11 @@
461 @ id INTEGER PRIMARY KEY, -- ID of the checked out file
462 @ vid INTEGER REFERENCES blob, -- The baseline this file is part of.
463 @ chnged INT DEFAULT 0, -- 0:unchnged 1:edited 2:m-chng 3:m-add
464 @ deleted BOOLEAN DEFAULT 0, -- True if deleted
465 @ isexe BOOLEAN, -- True if file should be executable
 
466 @ rid INTEGER, -- Originally from this repository record
467 @ mrid INTEGER, -- Based on this record due to a merge
468 @ mtime INTEGER, -- Mtime of file on disk. sec since 1970
469 @ pathname TEXT, -- Full pathname relative to root
470 @ origname TEXT, -- Original pathname. NULL if unchanged
471
--- src/schema.c
+++ src/schema.c
@@ -461,10 +461,11 @@
461 @ id INTEGER PRIMARY KEY, -- ID of the checked out file
462 @ vid INTEGER REFERENCES blob, -- The baseline this file is part of.
463 @ chnged INT DEFAULT 0, -- 0:unchnged 1:edited 2:m-chng 3:m-add
464 @ deleted BOOLEAN DEFAULT 0, -- True if deleted
465 @ isexe BOOLEAN, -- True if file should be executable
466 @ islink BOOLEAN, -- True if file should be symlink
467 @ rid INTEGER, -- Originally from this repository record
468 @ mrid INTEGER, -- Based on this record due to a merge
469 @ mtime INTEGER, -- Mtime of file on disk. sec since 1970
470 @ pathname TEXT, -- Full pathname relative to root
471 @ origname TEXT, -- Original pathname. NULL if unchanged
472
--- src/setup.c
+++ src/setup.c
@@ -1050,10 +1050,11 @@
10501050
if( !g.okSetup ){
10511051
login_needed();
10521052
}
10531053
10541054
style_header("Settings");
1055
+ db_open_local();
10551056
db_begin_transaction();
10561057
@ <p>This page provides a simple interface to the "fossil setting" command.
10571058
@ See the "fossil help setting" output below for further information on
10581059
@ the meaning of each setting.</p><hr />
10591060
@ <form action="%s(g.zTop)/setup_settings" method="post"><div>
10601061
--- src/setup.c
+++ src/setup.c
@@ -1050,10 +1050,11 @@
1050 if( !g.okSetup ){
1051 login_needed();
1052 }
1053
1054 style_header("Settings");
 
1055 db_begin_transaction();
1056 @ <p>This page provides a simple interface to the "fossil setting" command.
1057 @ See the "fossil help setting" output below for further information on
1058 @ the meaning of each setting.</p><hr />
1059 @ <form action="%s(g.zTop)/setup_settings" method="post"><div>
1060
--- src/setup.c
+++ src/setup.c
@@ -1050,10 +1050,11 @@
1050 if( !g.okSetup ){
1051 login_needed();
1052 }
1053
1054 style_header("Settings");
1055 db_open_local();
1056 db_begin_transaction();
1057 @ <p>This page provides a simple interface to the "fossil setting" command.
1058 @ See the "fossil help setting" output below for further information on
1059 @ the meaning of each setting.</p><hr />
1060 @ <form action="%s(g.zTop)/setup_settings" method="post"><div>
1061
+60 -34
--- src/sha1.c
+++ src/sha1.c
@@ -27,60 +27,79 @@
2727
* blk0() and blk() perform the initial expand.
2828
* I got the idea of expanding during the round function from SSLeay
2929
*
3030
* blk0le() for little-endian and blk0be() for big-endian.
3131
*/
32
-#define rol(value, bits) (((value) << (bits)) | ((value) >> (32 - (bits))))
33
-#define blk0le(i) (block->l[i] = (rol(block->l[i],24)&0xFF00FF00) \
34
- |(rol(block->l[i],8)&0x00FF00FF))
35
-#define blk0be(i) block->l[i]
36
-#define blk(i) (block->l[i&15] = rol(block->l[(i+13)&15]^block->l[(i+8)&15] \
37
- ^block->l[(i+2)&15]^block->l[i&15],1))
32
+#if __GNUC__ && (defined(__i386__) || defined(__x86_64__))
33
+/*
34
+ * GCC by itself only generates left rotates. Use right rotates if
35
+ * possible to be kinder to dinky implementations with iterative rotate
36
+ * instructions.
37
+ */
38
+#define SHA_ROT(op, x, k) \
39
+ ({ unsigned int y; asm(op " %1,%0" : "=r" (y) : "I" (k), "0" (x)); y; })
40
+#define rol(x,k) SHA_ROT("roll", x, k)
41
+#define ror(x,k) SHA_ROT("rorl", x, k)
42
+
43
+#else
44
+/* Generic C equivalent */
45
+#define SHA_ROT(x,l,r) ((x) << (l) | (x) >> (r))
46
+#define rol(x,k) SHA_ROT(x,k,32-(k))
47
+#define ror(x,k) SHA_ROT(x,32-(k),k)
48
+#endif
49
+
50
+
51
+#define blk0le(i) (block[i] = (ror(block[i],8)&0xFF00FF00) \
52
+ |(rol(block[i],8)&0x00FF00FF))
53
+#define blk0be(i) block[i]
54
+#define blk(i) (block[i&15] = rol(block[(i+13)&15]^block[(i+8)&15] \
55
+ ^block[(i+2)&15]^block[i&15],1))
3856
3957
/*
4058
* (R0+R1), R2, R3, R4 are the different operations (rounds) used in SHA1
4159
*
4260
* Rl0() for little-endian and Rb0() for big-endian. Endianness is
4361
* determined at run-time.
4462
*/
4563
#define Rl0(v,w,x,y,z,i) \
46
- z+=((w&(x^y))^y)+blk0le(i)+0x5A827999+rol(v,5);w=rol(w,30);
64
+ z+=((w&(x^y))^y)+blk0le(i)+0x5A827999+rol(v,5);w=ror(w,2);
4765
#define Rb0(v,w,x,y,z,i) \
48
- z+=((w&(x^y))^y)+blk0be(i)+0x5A827999+rol(v,5);w=rol(w,30);
66
+ z+=((w&(x^y))^y)+blk0be(i)+0x5A827999+rol(v,5);w=ror(w,2);
4967
#define R1(v,w,x,y,z,i) \
50
- z+=((w&(x^y))^y)+blk(i)+0x5A827999+rol(v,5);w=rol(w,30);
68
+ z+=((w&(x^y))^y)+blk(i)+0x5A827999+rol(v,5);w=ror(w,2);
5169
#define R2(v,w,x,y,z,i) \
52
- z+=(w^x^y)+blk(i)+0x6ED9EBA1+rol(v,5);w=rol(w,30);
70
+ z+=(w^x^y)+blk(i)+0x6ED9EBA1+rol(v,5);w=ror(w,2);
5371
#define R3(v,w,x,y,z,i) \
54
- z+=(((w|x)&y)|(w&x))+blk(i)+0x8F1BBCDC+rol(v,5);w=rol(w,30);
72
+ z+=(((w|x)&y)|(w&x))+blk(i)+0x8F1BBCDC+rol(v,5);w=ror(w,2);
5573
#define R4(v,w,x,y,z,i) \
56
- z+=(w^x^y)+blk(i)+0xCA62C1D6+rol(v,5);w=rol(w,30);
57
-
58
-typedef union {
59
- unsigned char c[64];
60
- unsigned int l[16];
61
-} CHAR64LONG16;
74
+ z+=(w^x^y)+blk(i)+0xCA62C1D6+rol(v,5);w=ror(w,2);
6275
6376
/*
6477
* Hash a single 512-bit block. This is the core of the algorithm.
6578
*/
79
+#define a qq[0]
80
+#define b qq[1]
81
+#define c qq[2]
82
+#define d qq[3]
83
+#define e qq[4]
84
+
6685
void SHA1Transform(unsigned int state[5], const unsigned char buffer[64])
6786
{
68
- unsigned int a, b, c, d, e;
69
- CHAR64LONG16 *block;
87
+ unsigned int qq[5]; // a, b, c, d, e;
7088
static int one = 1;
71
- CHAR64LONG16 workspace;
72
-
73
- block = &workspace;
74
- (void)memcpy(block, buffer, 64);
89
+ unsigned int block[16];
90
+ memcpy(block, buffer, 64);
91
+ memcpy(qq,state,5*sizeof(unsigned int));
7592
7693
/* Copy context->state[] to working vars */
94
+ /*
7795
a = state[0];
7896
b = state[1];
7997
c = state[2];
8098
d = state[3];
8199
e = state[4];
100
+ */
82101
83102
/* 4 rounds of 20 operations each. Loop unrolled. */
84103
if( 1 == *(unsigned char*)&one ){
85104
Rl0(a,b,c,d,e, 0); Rl0(e,a,b,c,d, 1); Rl0(d,e,a,b,c, 2); Rl0(c,d,e,a,b, 3);
86105
Rl0(b,c,d,e,a, 4); Rl0(a,b,c,d,e, 5); Rl0(e,a,b,c,d, 6); Rl0(d,e,a,b,c, 7);
@@ -113,13 +132,10 @@
113132
state[0] += a;
114133
state[1] += b;
115134
state[2] += c;
116135
state[3] += d;
117136
state[4] += e;
118
-
119
- /* Wipe variables */
120
- a = b = c = d = e = 0;
121137
}
122138
123139
124140
/*
125141
* SHA1Init - Initialize new context
@@ -192,18 +208,17 @@
192208
** digest is stored in the first 20 bytes. zBuf should
193209
** be "char zBuf[41]".
194210
*/
195211
static void DigestToBase16(unsigned char *digest, char *zBuf){
196212
static char const zEncode[] = "0123456789abcdef";
197
- int i, j;
198
-
199
- for(j=i=0; i<20; i++){
200
- int a = digest[i];
201
- zBuf[j++] = zEncode[(a>>4)&0xf];
202
- zBuf[j++] = zEncode[a & 0xf];
203
- }
204
- zBuf[j] = 0;
213
+ int ix;
214
+
215
+ for(ix=0; ix<20; ix++){
216
+ *zBuf++ = zEncode[(*digest>>4)&0xf];
217
+ *zBuf++ = zEncode[*digest++ & 0xf];
218
+ }
219
+ *zBuf = '\0';
205220
}
206221
207222
/*
208223
** The state of a incremental SHA1 checksum computation. Only one
209224
** such computation can be underway at a time, of course.
@@ -265,10 +280,21 @@
265280
int sha1sum_file(const char *zFilename, Blob *pCksum){
266281
FILE *in;
267282
SHA1Context ctx;
268283
unsigned char zResult[20];
269284
char zBuf[10240];
285
+
286
+ if( file_islink(zFilename) ){
287
+ /* Instead of file content, return sha1 of link destination path */
288
+ Blob destinationPath;
289
+ int rc;
290
+
291
+ blob_read_link(&destinationPath, zFilename);
292
+ rc = sha1sum_blob(&destinationPath, pCksum);
293
+ blob_reset(&destinationPath);
294
+ return rc;
295
+ }
270296
271297
in = fossil_fopen(zFilename,"rb");
272298
if( in==0 ){
273299
return 1;
274300
}
275301
--- src/sha1.c
+++ src/sha1.c
@@ -27,60 +27,79 @@
27 * blk0() and blk() perform the initial expand.
28 * I got the idea of expanding during the round function from SSLeay
29 *
30 * blk0le() for little-endian and blk0be() for big-endian.
31 */
32 #define rol(value, bits) (((value) << (bits)) | ((value) >> (32 - (bits))))
33 #define blk0le(i) (block->l[i] = (rol(block->l[i],24)&0xFF00FF00) \
34 |(rol(block->l[i],8)&0x00FF00FF))
35 #define blk0be(i) block->l[i]
36 #define blk(i) (block->l[i&15] = rol(block->l[(i+13)&15]^block->l[(i+8)&15] \
37 ^block->l[(i+2)&15]^block->l[i&15],1))
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
38
39 /*
40 * (R0+R1), R2, R3, R4 are the different operations (rounds) used in SHA1
41 *
42 * Rl0() for little-endian and Rb0() for big-endian. Endianness is
43 * determined at run-time.
44 */
45 #define Rl0(v,w,x,y,z,i) \
46 z+=((w&(x^y))^y)+blk0le(i)+0x5A827999+rol(v,5);w=rol(w,30);
47 #define Rb0(v,w,x,y,z,i) \
48 z+=((w&(x^y))^y)+blk0be(i)+0x5A827999+rol(v,5);w=rol(w,30);
49 #define R1(v,w,x,y,z,i) \
50 z+=((w&(x^y))^y)+blk(i)+0x5A827999+rol(v,5);w=rol(w,30);
51 #define R2(v,w,x,y,z,i) \
52 z+=(w^x^y)+blk(i)+0x6ED9EBA1+rol(v,5);w=rol(w,30);
53 #define R3(v,w,x,y,z,i) \
54 z+=(((w|x)&y)|(w&x))+blk(i)+0x8F1BBCDC+rol(v,5);w=rol(w,30);
55 #define R4(v,w,x,y,z,i) \
56 z+=(w^x^y)+blk(i)+0xCA62C1D6+rol(v,5);w=rol(w,30);
57
58 typedef union {
59 unsigned char c[64];
60 unsigned int l[16];
61 } CHAR64LONG16;
62
63 /*
64 * Hash a single 512-bit block. This is the core of the algorithm.
65 */
 
 
 
 
 
 
66 void SHA1Transform(unsigned int state[5], const unsigned char buffer[64])
67 {
68 unsigned int a, b, c, d, e;
69 CHAR64LONG16 *block;
70 static int one = 1;
71 CHAR64LONG16 workspace;
72
73 block = &workspace;
74 (void)memcpy(block, buffer, 64);
75
76 /* Copy context->state[] to working vars */
 
77 a = state[0];
78 b = state[1];
79 c = state[2];
80 d = state[3];
81 e = state[4];
 
82
83 /* 4 rounds of 20 operations each. Loop unrolled. */
84 if( 1 == *(unsigned char*)&one ){
85 Rl0(a,b,c,d,e, 0); Rl0(e,a,b,c,d, 1); Rl0(d,e,a,b,c, 2); Rl0(c,d,e,a,b, 3);
86 Rl0(b,c,d,e,a, 4); Rl0(a,b,c,d,e, 5); Rl0(e,a,b,c,d, 6); Rl0(d,e,a,b,c, 7);
@@ -113,13 +132,10 @@
113 state[0] += a;
114 state[1] += b;
115 state[2] += c;
116 state[3] += d;
117 state[4] += e;
118
119 /* Wipe variables */
120 a = b = c = d = e = 0;
121 }
122
123
124 /*
125 * SHA1Init - Initialize new context
@@ -192,18 +208,17 @@
192 ** digest is stored in the first 20 bytes. zBuf should
193 ** be "char zBuf[41]".
194 */
195 static void DigestToBase16(unsigned char *digest, char *zBuf){
196 static char const zEncode[] = "0123456789abcdef";
197 int i, j;
198
199 for(j=i=0; i<20; i++){
200 int a = digest[i];
201 zBuf[j++] = zEncode[(a>>4)&0xf];
202 zBuf[j++] = zEncode[a & 0xf];
203 }
204 zBuf[j] = 0;
205 }
206
207 /*
208 ** The state of a incremental SHA1 checksum computation. Only one
209 ** such computation can be underway at a time, of course.
@@ -265,10 +280,21 @@
265 int sha1sum_file(const char *zFilename, Blob *pCksum){
266 FILE *in;
267 SHA1Context ctx;
268 unsigned char zResult[20];
269 char zBuf[10240];
 
 
 
 
 
 
 
 
 
 
 
270
271 in = fossil_fopen(zFilename,"rb");
272 if( in==0 ){
273 return 1;
274 }
275
--- src/sha1.c
+++ src/sha1.c
@@ -27,60 +27,79 @@
27 * blk0() and blk() perform the initial expand.
28 * I got the idea of expanding during the round function from SSLeay
29 *
30 * blk0le() for little-endian and blk0be() for big-endian.
31 */
32 #if __GNUC__ && (defined(__i386__) || defined(__x86_64__))
33 /*
34 * GCC by itself only generates left rotates. Use right rotates if
35 * possible to be kinder to dinky implementations with iterative rotate
36 * instructions.
37 */
38 #define SHA_ROT(op, x, k) \
39 ({ unsigned int y; asm(op " %1,%0" : "=r" (y) : "I" (k), "0" (x)); y; })
40 #define rol(x,k) SHA_ROT("roll", x, k)
41 #define ror(x,k) SHA_ROT("rorl", x, k)
42
43 #else
44 /* Generic C equivalent */
45 #define SHA_ROT(x,l,r) ((x) << (l) | (x) >> (r))
46 #define rol(x,k) SHA_ROT(x,k,32-(k))
47 #define ror(x,k) SHA_ROT(x,32-(k),k)
48 #endif
49
50
51 #define blk0le(i) (block[i] = (ror(block[i],8)&0xFF00FF00) \
52 |(rol(block[i],8)&0x00FF00FF))
53 #define blk0be(i) block[i]
54 #define blk(i) (block[i&15] = rol(block[(i+13)&15]^block[(i+8)&15] \
55 ^block[(i+2)&15]^block[i&15],1))
56
57 /*
58 * (R0+R1), R2, R3, R4 are the different operations (rounds) used in SHA1
59 *
60 * Rl0() for little-endian and Rb0() for big-endian. Endianness is
61 * determined at run-time.
62 */
63 #define Rl0(v,w,x,y,z,i) \
64 z+=((w&(x^y))^y)+blk0le(i)+0x5A827999+rol(v,5);w=ror(w,2);
65 #define Rb0(v,w,x,y,z,i) \
66 z+=((w&(x^y))^y)+blk0be(i)+0x5A827999+rol(v,5);w=ror(w,2);
67 #define R1(v,w,x,y,z,i) \
68 z+=((w&(x^y))^y)+blk(i)+0x5A827999+rol(v,5);w=ror(w,2);
69 #define R2(v,w,x,y,z,i) \
70 z+=(w^x^y)+blk(i)+0x6ED9EBA1+rol(v,5);w=ror(w,2);
71 #define R3(v,w,x,y,z,i) \
72 z+=(((w|x)&y)|(w&x))+blk(i)+0x8F1BBCDC+rol(v,5);w=ror(w,2);
73 #define R4(v,w,x,y,z,i) \
74 z+=(w^x^y)+blk(i)+0xCA62C1D6+rol(v,5);w=ror(w,2);
 
 
 
 
 
75
76 /*
77 * Hash a single 512-bit block. This is the core of the algorithm.
78 */
79 #define a qq[0]
80 #define b qq[1]
81 #define c qq[2]
82 #define d qq[3]
83 #define e qq[4]
84
85 void SHA1Transform(unsigned int state[5], const unsigned char buffer[64])
86 {
87 unsigned int qq[5]; // a, b, c, d, e;
 
88 static int one = 1;
89 unsigned int block[16];
90 memcpy(block, buffer, 64);
91 memcpy(qq,state,5*sizeof(unsigned int));
 
92
93 /* Copy context->state[] to working vars */
94 /*
95 a = state[0];
96 b = state[1];
97 c = state[2];
98 d = state[3];
99 e = state[4];
100 */
101
102 /* 4 rounds of 20 operations each. Loop unrolled. */
103 if( 1 == *(unsigned char*)&one ){
104 Rl0(a,b,c,d,e, 0); Rl0(e,a,b,c,d, 1); Rl0(d,e,a,b,c, 2); Rl0(c,d,e,a,b, 3);
105 Rl0(b,c,d,e,a, 4); Rl0(a,b,c,d,e, 5); Rl0(e,a,b,c,d, 6); Rl0(d,e,a,b,c, 7);
@@ -113,13 +132,10 @@
132 state[0] += a;
133 state[1] += b;
134 state[2] += c;
135 state[3] += d;
136 state[4] += e;
 
 
 
137 }
138
139
140 /*
141 * SHA1Init - Initialize new context
@@ -192,18 +208,17 @@
208 ** digest is stored in the first 20 bytes. zBuf should
209 ** be "char zBuf[41]".
210 */
211 static void DigestToBase16(unsigned char *digest, char *zBuf){
212 static char const zEncode[] = "0123456789abcdef";
213 int ix;
214
215 for(ix=0; ix<20; ix++){
216 *zBuf++ = zEncode[(*digest>>4)&0xf];
217 *zBuf++ = zEncode[*digest++ & 0xf];
218 }
219 *zBuf = '\0';
 
220 }
221
222 /*
223 ** The state of a incremental SHA1 checksum computation. Only one
224 ** such computation can be underway at a time, of course.
@@ -265,10 +280,21 @@
280 int sha1sum_file(const char *zFilename, Blob *pCksum){
281 FILE *in;
282 SHA1Context ctx;
283 unsigned char zResult[20];
284 char zBuf[10240];
285
286 if( file_islink(zFilename) ){
287 /* Instead of file content, return sha1 of link destination path */
288 Blob destinationPath;
289 int rc;
290
291 blob_read_link(&destinationPath, zFilename);
292 rc = sha1sum_blob(&destinationPath, pCksum);
293 blob_reset(&destinationPath);
294 return rc;
295 }
296
297 in = fossil_fopen(zFilename,"rb");
298 if( in==0 ){
299 return 1;
300 }
301
+3546 -2193
--- src/sqlite3.c
+++ src/sqlite3.c
@@ -385,23 +385,29 @@
385385
/*
386386
** Exactly one of the following macros must be defined in order to
387387
** specify which memory allocation subsystem to use.
388388
**
389389
** SQLITE_SYSTEM_MALLOC // Use normal system malloc()
390
+** SQLITE_WIN32_MALLOC // Use Win32 native heap API
390391
** SQLITE_MEMDEBUG // Debugging version of system malloc()
392
+**
393
+** On Windows, if the SQLITE_WIN32_MALLOC_VALIDATE macro is defined and the
394
+** assert() macro is enabled, each call into the Win32 native heap subsystem
395
+** will cause HeapValidate to be called. If heap validation should fail, an
396
+** assertion will be triggered.
391397
**
392398
** (Historical note: There used to be several other options, but we've
393399
** pared it down to just these two.)
394400
**
395401
** If none of the above are defined, then set SQLITE_SYSTEM_MALLOC as
396402
** the default.
397403
*/
398
-#if defined(SQLITE_SYSTEM_MALLOC)+defined(SQLITE_MEMDEBUG)>1
404
+#if defined(SQLITE_SYSTEM_MALLOC)+defined(SQLITE_WIN32_MALLOC)+defined(SQLITE_MEMDEBUG)>1
399405
# error "At most one of the following compile-time configuration options\
400
- is allows: SQLITE_SYSTEM_MALLOC, SQLITE_MEMDEBUG"
406
+ is allows: SQLITE_SYSTEM_MALLOC, SQLITE_WIN32_MALLOC, SQLITE_MEMDEBUG"
401407
#endif
402
-#if defined(SQLITE_SYSTEM_MALLOC)+defined(SQLITE_MEMDEBUG)==0
408
+#if defined(SQLITE_SYSTEM_MALLOC)+defined(SQLITE_WIN32_MALLOC)+defined(SQLITE_MEMDEBUG)==0
403409
# define SQLITE_SYSTEM_MALLOC 1
404410
#endif
405411
406412
/*
407413
** If SQLITE_MALLOC_SOFT_LIMIT is not zero, then try to keep the
@@ -650,11 +656,11 @@
650656
** [sqlite3_libversion_number()], [sqlite3_sourceid()],
651657
** [sqlite_version()] and [sqlite_source_id()].
652658
*/
653659
#define SQLITE_VERSION "3.7.8"
654660
#define SQLITE_VERSION_NUMBER 3007008
655
-#define SQLITE_SOURCE_ID "2011-08-16 02:07:04 9650d7962804d61f56cac944ff9bb2c7bc111957"
661
+#define SQLITE_SOURCE_ID "2011-09-04 01:27:00 6b657ae75035eb10b0ad640998d3c9eadfdffa6e"
656662
657663
/*
658664
** CAPI3REF: Run-Time Library Version Numbers
659665
** KEYWORDS: sqlite3_version, sqlite3_sourceid
660666
**
@@ -1751,20 +1757,14 @@
17511757
** also used during testing of SQLite in order to specify an alternative
17521758
** memory allocator that simulates memory out-of-memory conditions in
17531759
** order to verify that SQLite recovers gracefully from such
17541760
** conditions.
17551761
**
1756
-** The xMalloc and xFree methods must work like the
1757
-** malloc() and free() functions from the standard C library.
1758
-** The xRealloc method must work like realloc() from the standard C library
1759
-** with the exception that if the second argument to xRealloc is zero,
1760
-** xRealloc must be a no-op - it must not perform any allocation or
1761
-** deallocation. ^SQLite guarantees that the second argument to
1762
+** The xMalloc, xRealloc, and xFree methods must work like the
1763
+** malloc(), realloc() and free() functions from the standard C library.
1764
+** ^SQLite guarantees that the second argument to
17621765
** xRealloc is always a value returned by a prior call to xRoundup.
1763
-** And so in cases where xRoundup always returns a positive number,
1764
-** xRealloc can perform exactly as the standard library realloc() and
1765
-** still be in compliance with this specification.
17661766
**
17671767
** xSize should return the allocated size of a memory allocation
17681768
** previously obtained from xMalloc or xRealloc. The allocated size
17691769
** is always at least as big as the requested size but may be larger.
17701770
**
@@ -3397,11 +3397,11 @@
33973397
** a schema change, on the first [sqlite3_step()] call following any change
33983398
** to the [sqlite3_bind_text | bindings] of that [parameter].
33993399
** ^The specific value of WHERE-clause [parameter] might influence the
34003400
** choice of query plan if the parameter is the left-hand side of a [LIKE]
34013401
** or [GLOB] operator or if the parameter is compared to an indexed column
3402
-** and the [SQLITE_ENABLE_STAT3] compile-time option is enabled.
3402
+** and the [SQLITE_ENABLE_STAT2] compile-time option is enabled.
34033403
** the
34043404
** </li>
34053405
** </ol>
34063406
*/
34073407
SQLITE_API int sqlite3_prepare(
@@ -7711,22 +7711,10 @@
77117711
** is 0x00000000ffffffff. But because of quirks of some compilers, we
77127712
** have to specify the value in the less intuitive manner shown:
77137713
*/
77147714
#define SQLITE_MAX_U32 ((((u64)1)<<32)-1)
77157715
7716
-/*
7717
-** The datatype used to store estimates of the number of rows in a
7718
-** table or index. This is an unsigned integer type. For 99.9% of
7719
-** the world, a 32-bit integer is sufficient. But a 64-bit integer
7720
-** can be used at compile-time if desired.
7721
-*/
7722
-#ifdef SQLITE_64BIT_STATS
7723
- typedef u64 tRowcnt; /* 64-bit only if requested at compile-time */
7724
-#else
7725
- typedef u32 tRowcnt; /* 32-bit is the default */
7726
-#endif
7727
-
77287716
/*
77297717
** Macros to determine whether the machine is big or little endian,
77307718
** evaluated at runtime.
77317719
*/
77327720
#ifdef SQLITE_AMALGAMATION
@@ -8188,10 +8176,11 @@
81888176
** or VDBE. The VDBE implements an abstract machine that runs a
81898177
** simple program to access and modify the underlying database.
81908178
*/
81918179
#ifndef _SQLITE_VDBE_H_
81928180
#define _SQLITE_VDBE_H_
8181
+/* #include <stdio.h> */
81938182
81948183
/*
81958184
** A single VDBE is an opaque structure named "Vdbe". Only routines
81968185
** in the source file sqliteVdbe.c are allowed to see the insides
81978186
** of this structure.
@@ -8231,10 +8220,11 @@
82318220
Mem *pMem; /* Used when p4type is P4_MEM */
82328221
VTable *pVtab; /* Used when p4type is P4_VTAB */
82338222
KeyInfo *pKeyInfo; /* Used when p4type is P4_KEYINFO */
82348223
int *ai; /* Used when p4type is P4_INTARRAY */
82358224
SubProgram *pProgram; /* Used when p4type is P4_SUBPROGRAM */
8225
+ int (*xAdvance)(BtCursor *, int *);
82368226
} p4;
82378227
#ifdef SQLITE_DEBUG
82388228
char *zComment; /* Comment to improve readability */
82398229
#endif
82408230
#ifdef VDBE_PROFILE
@@ -8286,10 +8276,11 @@
82868276
#define P4_REAL (-12) /* P4 is a 64-bit floating point value */
82878277
#define P4_INT64 (-13) /* P4 is a 64-bit signed integer */
82888278
#define P4_INT32 (-14) /* P4 is a 32-bit signed integer */
82898279
#define P4_INTARRAY (-15) /* P4 is a vector of 32-bit integers */
82908280
#define P4_SUBPROGRAM (-18) /* P4 is a pointer to a SubProgram structure */
8281
+#define P4_ADVANCE (-19) /* P4 is a pointer to BtreeNext() or BtreePrev() */
82918282
82928283
/* When adding a P4 argument using P4_KEYINFO, a copy of the KeyInfo structure
82938284
** is made. That copy is freed when the Vdbe is finalized. But if the
82948285
** argument is P4_KEYINFO_HANDOFF, the passed in pointer is used. It still
82958286
** gets freed when the Vdbe is finalized so it still should be obtained
@@ -8401,88 +8392,90 @@
84018392
#define OP_VerifyCookie 37
84028393
#define OP_OpenRead 38
84038394
#define OP_OpenWrite 39
84048395
#define OP_OpenAutoindex 40
84058396
#define OP_OpenEphemeral 41
8406
-#define OP_OpenPseudo 42
8407
-#define OP_Close 43
8408
-#define OP_SeekLt 44
8409
-#define OP_SeekLe 45
8410
-#define OP_SeekGe 46
8411
-#define OP_SeekGt 47
8412
-#define OP_Seek 48
8413
-#define OP_NotFound 49
8414
-#define OP_Found 50
8415
-#define OP_IsUnique 51
8416
-#define OP_NotExists 52
8417
-#define OP_Sequence 53
8418
-#define OP_NewRowid 54
8419
-#define OP_Insert 55
8420
-#define OP_InsertInt 56
8421
-#define OP_Delete 57
8422
-#define OP_ResetCount 58
8423
-#define OP_RowKey 59
8424
-#define OP_RowData 60
8425
-#define OP_Rowid 61
8426
-#define OP_NullRow 62
8427
-#define OP_Last 63
8428
-#define OP_Sort 64
8429
-#define OP_Rewind 65
8430
-#define OP_Prev 66
8431
-#define OP_Next 67
8432
-#define OP_IdxInsert 70
8433
-#define OP_IdxDelete 71
8434
-#define OP_IdxRowid 72
8435
-#define OP_IdxLT 81
8436
-#define OP_IdxGE 92
8437
-#define OP_Destroy 95
8438
-#define OP_Clear 96
8439
-#define OP_CreateIndex 97
8440
-#define OP_CreateTable 98
8441
-#define OP_ParseSchema 99
8442
-#define OP_LoadAnalysis 100
8443
-#define OP_DropTable 101
8444
-#define OP_DropIndex 102
8445
-#define OP_DropTrigger 103
8446
-#define OP_IntegrityCk 104
8447
-#define OP_RowSetAdd 105
8448
-#define OP_RowSetRead 106
8449
-#define OP_RowSetTest 107
8450
-#define OP_Program 108
8451
-#define OP_Param 109
8452
-#define OP_FkCounter 110
8453
-#define OP_FkIfZero 111
8454
-#define OP_MemMax 112
8455
-#define OP_IfPos 113
8456
-#define OP_IfNeg 114
8457
-#define OP_IfZero 115
8458
-#define OP_AggStep 116
8459
-#define OP_AggFinal 117
8460
-#define OP_Checkpoint 118
8461
-#define OP_JournalMode 119
8462
-#define OP_Vacuum 120
8463
-#define OP_IncrVacuum 121
8464
-#define OP_Expire 122
8465
-#define OP_TableLock 123
8466
-#define OP_VBegin 124
8467
-#define OP_VCreate 125
8468
-#define OP_VDestroy 126
8469
-#define OP_VOpen 127
8470
-#define OP_VFilter 128
8471
-#define OP_VColumn 129
8472
-#define OP_VNext 131
8473
-#define OP_VRename 132
8474
-#define OP_VUpdate 133
8475
-#define OP_Pagecount 134
8476
-#define OP_MaxPgcnt 135
8477
-#define OP_Trace 136
8478
-#define OP_Noop 137
8479
-#define OP_Explain 138
8480
-
8481
-/* The following opcode values are never used */
8482
-#define OP_NotUsed_139 139
8483
-#define OP_NotUsed_140 140
8397
+#define OP_SorterOpen 42
8398
+#define OP_OpenPseudo 43
8399
+#define OP_Close 44
8400
+#define OP_SeekLt 45
8401
+#define OP_SeekLe 46
8402
+#define OP_SeekGe 47
8403
+#define OP_SeekGt 48
8404
+#define OP_Seek 49
8405
+#define OP_NotFound 50
8406
+#define OP_Found 51
8407
+#define OP_IsUnique 52
8408
+#define OP_NotExists 53
8409
+#define OP_Sequence 54
8410
+#define OP_NewRowid 55
8411
+#define OP_Insert 56
8412
+#define OP_InsertInt 57
8413
+#define OP_Delete 58
8414
+#define OP_ResetCount 59
8415
+#define OP_SorterCompare 60
8416
+#define OP_SorterData 61
8417
+#define OP_RowKey 62
8418
+#define OP_RowData 63
8419
+#define OP_Rowid 64
8420
+#define OP_NullRow 65
8421
+#define OP_Last 66
8422
+#define OP_SorterSort 67
8423
+#define OP_Sort 70
8424
+#define OP_Rewind 71
8425
+#define OP_SorterNext 72
8426
+#define OP_Prev 81
8427
+#define OP_Next 92
8428
+#define OP_SorterInsert 95
8429
+#define OP_IdxInsert 96
8430
+#define OP_IdxDelete 97
8431
+#define OP_IdxRowid 98
8432
+#define OP_IdxLT 99
8433
+#define OP_IdxGE 100
8434
+#define OP_Destroy 101
8435
+#define OP_Clear 102
8436
+#define OP_CreateIndex 103
8437
+#define OP_CreateTable 104
8438
+#define OP_ParseSchema 105
8439
+#define OP_LoadAnalysis 106
8440
+#define OP_DropTable 107
8441
+#define OP_DropIndex 108
8442
+#define OP_DropTrigger 109
8443
+#define OP_IntegrityCk 110
8444
+#define OP_RowSetAdd 111
8445
+#define OP_RowSetRead 112
8446
+#define OP_RowSetTest 113
8447
+#define OP_Program 114
8448
+#define OP_Param 115
8449
+#define OP_FkCounter 116
8450
+#define OP_FkIfZero 117
8451
+#define OP_MemMax 118
8452
+#define OP_IfPos 119
8453
+#define OP_IfNeg 120
8454
+#define OP_IfZero 121
8455
+#define OP_AggStep 122
8456
+#define OP_AggFinal 123
8457
+#define OP_Checkpoint 124
8458
+#define OP_JournalMode 125
8459
+#define OP_Vacuum 126
8460
+#define OP_IncrVacuum 127
8461
+#define OP_Expire 128
8462
+#define OP_TableLock 129
8463
+#define OP_VBegin 131
8464
+#define OP_VCreate 132
8465
+#define OP_VDestroy 133
8466
+#define OP_VOpen 134
8467
+#define OP_VFilter 135
8468
+#define OP_VColumn 136
8469
+#define OP_VNext 137
8470
+#define OP_VRename 138
8471
+#define OP_VUpdate 139
8472
+#define OP_Pagecount 140
8473
+#define OP_MaxPgcnt 146
8474
+#define OP_Trace 147
8475
+#define OP_Noop 148
8476
+#define OP_Explain 149
84848477
84858478
84868479
/* Properties such as "out2" or "jump" that are specified in
84878480
** comments following the "case" for each opcode in the vdbe.c
84888481
** are encoded into bitvectors as follows:
@@ -8498,24 +8491,24 @@
84988491
/* 0 */ 0x00, 0x01, 0x05, 0x04, 0x04, 0x10, 0x00, 0x02,\
84998492
/* 8 */ 0x02, 0x02, 0x02, 0x02, 0x02, 0x00, 0x24, 0x24,\
85008493
/* 16 */ 0x00, 0x00, 0x00, 0x24, 0x04, 0x05, 0x04, 0x00,\
85018494
/* 24 */ 0x00, 0x01, 0x05, 0x05, 0x00, 0x00, 0x00, 0x02,\
85028495
/* 32 */ 0x00, 0x00, 0x00, 0x02, 0x10, 0x00, 0x00, 0x00,\
8503
-/* 40 */ 0x00, 0x00, 0x00, 0x00, 0x11, 0x11, 0x11, 0x11,\
8504
-/* 48 */ 0x08, 0x11, 0x11, 0x11, 0x11, 0x02, 0x02, 0x00,\
8505
-/* 56 */ 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0x00, 0x01,\
8506
-/* 64 */ 0x01, 0x01, 0x01, 0x01, 0x4c, 0x4c, 0x08, 0x00,\
8507
-/* 72 */ 0x02, 0x05, 0x05, 0x15, 0x15, 0x15, 0x15, 0x15,\
8496
+/* 40 */ 0x00, 0x00, 0x00, 0x00, 0x00, 0x11, 0x11, 0x11,\
8497
+/* 48 */ 0x11, 0x08, 0x11, 0x11, 0x11, 0x11, 0x02, 0x02,\
8498
+/* 56 */ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,\
8499
+/* 64 */ 0x02, 0x00, 0x01, 0x01, 0x4c, 0x4c, 0x01, 0x01,\
8500
+/* 72 */ 0x01, 0x05, 0x05, 0x15, 0x15, 0x15, 0x15, 0x15,\
85088501
/* 80 */ 0x15, 0x01, 0x4c, 0x4c, 0x4c, 0x4c, 0x4c, 0x4c,\
8509
-/* 88 */ 0x4c, 0x4c, 0x4c, 0x4c, 0x01, 0x24, 0x02, 0x02,\
8510
-/* 96 */ 0x00, 0x02, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00,\
8511
-/* 104 */ 0x00, 0x0c, 0x45, 0x15, 0x01, 0x02, 0x00, 0x01,\
8512
-/* 112 */ 0x08, 0x05, 0x05, 0x05, 0x00, 0x00, 0x00, 0x02,\
8513
-/* 120 */ 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,\
8514
-/* 128 */ 0x01, 0x00, 0x02, 0x01, 0x00, 0x00, 0x02, 0x02,\
8515
-/* 136 */ 0x00, 0x00, 0x00, 0x00, 0x00, 0x04, 0x04, 0x04,\
8516
-/* 144 */ 0x04, 0x04,}
8502
+/* 88 */ 0x4c, 0x4c, 0x4c, 0x4c, 0x01, 0x24, 0x02, 0x08,\
8503
+/* 96 */ 0x08, 0x00, 0x02, 0x01, 0x01, 0x02, 0x00, 0x02,\
8504
+/* 104 */ 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0c,\
8505
+/* 112 */ 0x45, 0x15, 0x01, 0x02, 0x00, 0x01, 0x08, 0x05,\
8506
+/* 120 */ 0x05, 0x05, 0x00, 0x00, 0x00, 0x02, 0x00, 0x01,\
8507
+/* 128 */ 0x00, 0x00, 0x02, 0x00, 0x00, 0x00, 0x00, 0x01,\
8508
+/* 136 */ 0x00, 0x01, 0x00, 0x00, 0x02, 0x04, 0x04, 0x04,\
8509
+/* 144 */ 0x04, 0x04, 0x02, 0x00, 0x00, 0x00,}
85178510
85188511
/************** End of opcodes.h *********************************************/
85198512
/************** Continuing where we left off in vdbe.h ***********************/
85208513
85218514
/*
@@ -8529,13 +8522,13 @@
85298522
SQLITE_PRIVATE int sqlite3VdbeAddOp3(Vdbe*,int,int,int,int);
85308523
SQLITE_PRIVATE int sqlite3VdbeAddOp4(Vdbe*,int,int,int,int,const char *zP4,int);
85318524
SQLITE_PRIVATE int sqlite3VdbeAddOp4Int(Vdbe*,int,int,int,int,int);
85328525
SQLITE_PRIVATE int sqlite3VdbeAddOpList(Vdbe*, int nOp, VdbeOpList const *aOp);
85338526
SQLITE_PRIVATE void sqlite3VdbeAddParseSchemaOp(Vdbe*,int,char*);
8534
-SQLITE_PRIVATE void sqlite3VdbeChangeP1(Vdbe*, int addr, int P1);
8535
-SQLITE_PRIVATE void sqlite3VdbeChangeP2(Vdbe*, int addr, int P2);
8536
-SQLITE_PRIVATE void sqlite3VdbeChangeP3(Vdbe*, int addr, int P3);
8527
+SQLITE_PRIVATE void sqlite3VdbeChangeP1(Vdbe*, u32 addr, int P1);
8528
+SQLITE_PRIVATE void sqlite3VdbeChangeP2(Vdbe*, u32 addr, int P2);
8529
+SQLITE_PRIVATE void sqlite3VdbeChangeP3(Vdbe*, u32 addr, int P3);
85378530
SQLITE_PRIVATE void sqlite3VdbeChangeP5(Vdbe*, u8 P5);
85388531
SQLITE_PRIVATE void sqlite3VdbeJumpHere(Vdbe*, int addr);
85398532
SQLITE_PRIVATE void sqlite3VdbeChangeToNoop(Vdbe*, int addr, int N);
85408533
SQLITE_PRIVATE void sqlite3VdbeChangeP4(Vdbe*, int addr, const char *zP4, int N);
85418534
SQLITE_PRIVATE void sqlite3VdbeUsesBtree(Vdbe*, int);
@@ -8653,10 +8646,11 @@
86538646
** NOTE: These values must match the corresponding BTREE_ values in btree.h.
86548647
*/
86558648
#define PAGER_OMIT_JOURNAL 0x0001 /* Do not use a rollback journal */
86568649
#define PAGER_NO_READLOCK 0x0002 /* Omit readlocks on readonly files */
86578650
#define PAGER_MEMORY 0x0004 /* In-memory database */
8651
+#define PAGER_SORTER 0x0020 /* Accumulator in external merge sort */
86588652
86598653
/*
86608654
** Valid values for the second argument to sqlite3PagerLockingMode().
86618655
*/
86628656
#define PAGER_LOCKINGMODE_QUERY -1
@@ -9924,11 +9918,11 @@
99249918
int iPKey; /* If not negative, use aCol[iPKey] as the primary key */
99259919
int nCol; /* Number of columns in this table */
99269920
Column *aCol; /* Information about each column */
99279921
Index *pIndex; /* List of SQL indexes on this table. */
99289922
int tnum; /* Root BTree node for this table (see note above) */
9929
- tRowcnt nRowEst; /* Estimated rows in table - from sqlite_stat1 table */
9923
+ unsigned nRowEst; /* Estimated rows in table - from sqlite_stat1 table */
99309924
Select *pSelect; /* NULL for tables. Points to definition if a view. */
99319925
u16 nRef; /* Number of pointers to this Table */
99329926
u8 tabFlags; /* Mask of TF_* values */
99339927
u8 keyConf; /* What to do in case of uniqueness conflict on iPKey */
99349928
FKey *pFKey; /* Linked list of all foreign keys in this table */
@@ -10123,43 +10117,35 @@
1012310117
*/
1012410118
struct Index {
1012510119
char *zName; /* Name of this index */
1012610120
int nColumn; /* Number of columns in the table used by this index */
1012710121
int *aiColumn; /* Which columns are used by this index. 1st is 0 */
10128
- tRowcnt *aiRowEst; /* Result of ANALYZE: Est. rows selected by each column */
10122
+ unsigned *aiRowEst; /* Result of ANALYZE: Est. rows selected by each column */
1012910123
Table *pTable; /* The SQL table being indexed */
1013010124
int tnum; /* Page containing root of this index in database file */
1013110125
u8 onError; /* OE_Abort, OE_Ignore, OE_Replace, or OE_None */
1013210126
u8 autoIndex; /* True if is automatically created (ex: by UNIQUE) */
1013310127
u8 bUnordered; /* Use this index for == or IN queries only */
10134
- u8 nSample; /* Number of elements in aSample[] */
1013510128
char *zColAff; /* String defining the affinity of each column */
1013610129
Index *pNext; /* The next index associated with the same table */
1013710130
Schema *pSchema; /* Schema containing this index */
1013810131
u8 *aSortOrder; /* Array of size Index.nColumn. True==DESC, False==ASC */
1013910132
char **azColl; /* Array of collation sequence names for index */
10140
-#ifdef SQLITE_ENABLE_STAT3
10141
- tRowcnt avgEq; /* Average nEq value for key values not in aSample */
10142
- IndexSample *aSample; /* Samples of the left-most key */
10143
-#endif
10133
+ IndexSample *aSample; /* Array of SQLITE_INDEX_SAMPLES samples */
1014410134
};
1014510135
1014610136
/*
1014710137
** Each sample stored in the sqlite_stat2 table is represented in memory
1014810138
** using a structure of this type.
1014910139
*/
1015010140
struct IndexSample {
1015110141
union {
1015210142
char *z; /* Value if eType is SQLITE_TEXT or SQLITE_BLOB */
10153
- double r; /* Value if eType is SQLITE_FLOAT */
10154
- i64 i; /* Value if eType is SQLITE_INTEGER */
10143
+ double r; /* Value if eType is SQLITE_FLOAT or SQLITE_INTEGER */
1015510144
} u;
1015610145
u8 eType; /* SQLITE_NULL, SQLITE_INTEGER ... etc. */
10157
- u16 nByte; /* Size in byte of text or blob. */
10158
- tRowcnt nEq; /* Est. number of rows where the key equals this sample */
10159
- tRowcnt nLt; /* Est. number of rows where key is less than this sample */
10160
- tRowcnt nDLt; /* Est. number of distinct keys less than this sample */
10146
+ u8 nByte; /* Size in byte of text or blob. */
1016110147
};
1016210148
1016310149
/*
1016410150
** Each token coming out of the lexer is an instance of
1016510151
** this structure. Tokens are also used as part of an expression.
@@ -10190,10 +10176,11 @@
1019010176
u8 directMode; /* Direct rendering mode means take data directly
1019110177
** from source tables rather than from accumulators */
1019210178
u8 useSortingIdx; /* In direct mode, reference the sorting index rather
1019310179
** than the source table */
1019410180
int sortingIdx; /* Cursor number of the sorting index */
10181
+ int sortingIdxPTab; /* Cursor number of pseudo-table */
1019510182
ExprList *pGroupBy; /* The group by clause */
1019610183
int nSortingColumn; /* Number of columns in the sorting index */
1019710184
struct AggInfo_col { /* For each column used in source tables */
1019810185
Table *pTab; /* Source table */
1019910186
int iTable; /* Cursor number of the source table */
@@ -10722,10 +10709,11 @@
1072210709
#define SF_Resolved 0x0002 /* Identifiers have been resolved */
1072310710
#define SF_Aggregate 0x0004 /* Contains aggregate functions */
1072410711
#define SF_UsesEphemeral 0x0008 /* Uses the OpenEphemeral opcode */
1072510712
#define SF_Expanded 0x0010 /* sqlite3SelectExpand() called on this */
1072610713
#define SF_HasTypeInfo 0x0020 /* FROM subqueries have Table metadata */
10714
+#define SF_UseSorter 0x0040 /* Sort using a sorter */
1072710715
1072810716
1072910717
/*
1073010718
** The results of a select can be distributed in several ways. The
1073110719
** "SRT" prefix means "SELECT Result Type".
@@ -11361,11 +11349,10 @@
1136111349
#else
1136211350
# define sqlite3ViewGetColumnNames(A,B) 0
1136311351
#endif
1136411352
1136511353
SQLITE_PRIVATE void sqlite3DropTable(Parse*, SrcList*, int, int);
11366
-SQLITE_PRIVATE void sqlite3CodeDropTable(Parse*, Table*, int, int);
1136711354
SQLITE_PRIVATE void sqlite3DeleteTable(sqlite3*, Table*);
1136811355
#ifndef SQLITE_OMIT_AUTOINCREMENT
1136911356
SQLITE_PRIVATE void sqlite3AutoincrementBegin(Parse *pParse);
1137011357
SQLITE_PRIVATE void sqlite3AutoincrementEnd(Parse *pParse);
1137111358
#else
@@ -11618,11 +11605,11 @@
1161811605
SQLITE_PRIVATE void sqlite3ValueSetStr(sqlite3_value*, int, const void *,u8,
1161911606
void(*)(void*));
1162011607
SQLITE_PRIVATE void sqlite3ValueFree(sqlite3_value*);
1162111608
SQLITE_PRIVATE sqlite3_value *sqlite3ValueNew(sqlite3 *);
1162211609
SQLITE_PRIVATE char *sqlite3Utf16to8(sqlite3 *, const void*, int, u8);
11623
-#ifdef SQLITE_ENABLE_STAT3
11610
+#ifdef SQLITE_ENABLE_STAT2
1162411611
SQLITE_PRIVATE char *sqlite3Utf8to16(sqlite3 *, u8, char *, int, int *);
1162511612
#endif
1162611613
SQLITE_PRIVATE int sqlite3ValueFromExpr(sqlite3 *, Expr *, u8, u8, sqlite3_value **);
1162711614
SQLITE_PRIVATE void sqlite3ValueApplyAffinity(sqlite3_value *, u8, u8);
1162811615
#ifndef SQLITE_AMALGAMATION
@@ -12245,13 +12232,10 @@
1224512232
"ENABLE_RTREE",
1224612233
#endif
1224712234
#ifdef SQLITE_ENABLE_STAT2
1224812235
"ENABLE_STAT2",
1224912236
#endif
12250
-#ifdef SQLITE_ENABLE_STAT3
12251
- "ENABLE_STAT3",
12252
-#endif
1225312237
#ifdef SQLITE_ENABLE_UNLOCK_NOTIFY
1225412238
"ENABLE_UNLOCK_NOTIFY",
1225512239
#endif
1225612240
#ifdef SQLITE_ENABLE_UPDATE_DELETE_LIMIT
1225712241
"ENABLE_UPDATE_DELETE_LIMIT",
@@ -12275,10 +12259,13 @@
1227512259
"INT64_TYPE",
1227612260
#endif
1227712261
#ifdef SQLITE_LOCK_TRACE
1227812262
"LOCK_TRACE",
1227912263
#endif
12264
+#ifdef SQLITE_MAX_SCHEMA_RETRY
12265
+ "MAX_SCHEMA_RETRY=" CTIMEOPT_VAL(SQLITE_MAX_SCHEMA_RETRY),
12266
+#endif
1228012267
#ifdef SQLITE_MEMDEBUG
1228112268
"MEMDEBUG",
1228212269
#endif
1228312270
#ifdef SQLITE_MIXED_ENDIAN_64BIT_FLOAT
1228412271
"MIXED_ENDIAN_64BIT_FLOAT",
@@ -12387,10 +12374,13 @@
1238712374
#ifdef SQLITE_OMIT_LOOKASIDE
1238812375
"OMIT_LOOKASIDE",
1238912376
#endif
1239012377
#ifdef SQLITE_OMIT_MEMORYDB
1239112378
"OMIT_MEMORYDB",
12379
+#endif
12380
+#ifdef SQLITE_OMIT_MERGE_SORT
12381
+ "OMIT_MERGE_SORT",
1239212382
#endif
1239312383
#ifdef SQLITE_OMIT_OR_OPTIMIZATION
1239412384
"OMIT_OR_OPTIMIZATION",
1239512385
#endif
1239612386
#ifdef SQLITE_OMIT_PAGER_PRAGMAS
@@ -12453,10 +12443,13 @@
1245312443
#ifdef SQLITE_OMIT_WSD
1245412444
"OMIT_WSD",
1245512445
#endif
1245612446
#ifdef SQLITE_OMIT_XFER_OPT
1245712447
"OMIT_XFER_OPT",
12448
+#endif
12449
+#ifdef SQLITE_PAGECACHE_BLOCKALLOC
12450
+ "PAGECACHE_BLOCKALLOC",
1245812451
#endif
1245912452
#ifdef SQLITE_PERFORMANCE_TRACE
1246012453
"PERFORMANCE_TRACE",
1246112454
#endif
1246212455
#ifdef SQLITE_PROXY_DEBUG
@@ -12574,10 +12567,13 @@
1257412567
/*
1257512568
** Boolean values
1257612569
*/
1257712570
typedef unsigned char Bool;
1257812571
12572
+/* Opaque type used by code in vdbesort.c */
12573
+typedef struct VdbeSorter VdbeSorter;
12574
+
1257912575
/*
1258012576
** A cursor is a pointer into a single BTree within a database file.
1258112577
** The cursor can seek to a BTree entry with a particular key, or
1258212578
** loop over all entries of the Btree. You can also insert new BTree
1258312579
** entries or retrieve the key or data from the entry that the cursor
@@ -12600,15 +12596,17 @@
1260012596
Bool nullRow; /* True if pointing to a row with no data */
1260112597
Bool deferredMoveto; /* A call to sqlite3BtreeMoveto() is needed */
1260212598
Bool isTable; /* True if a table requiring integer keys */
1260312599
Bool isIndex; /* True if an index containing keys only - no data */
1260412600
Bool isOrdered; /* True if the underlying table is BTREE_UNORDERED */
12601
+ Bool isSorter; /* True if a new-style sorter */
1260512602
sqlite3_vtab_cursor *pVtabCursor; /* The cursor for a virtual table */
1260612603
const sqlite3_module *pModule; /* Module for cursor pVtabCursor */
1260712604
i64 seqCount; /* Sequence counter */
1260812605
i64 movetoTarget; /* Argument to the deferred sqlite3BtreeMoveto() */
1260912606
i64 lastRowid; /* Last rowid from a Next or NextIdx operation */
12607
+ VdbeSorter *pSorter; /* Sorter object for OP_SorterOpen cursors */
1261012608
1261112609
/* Result of last sqlite3BtreeMoveto() done by an OP_NotExists or
1261212610
** OP_IsUnique opcode on this cursor. */
1261312611
int seekResult;
1261412612
@@ -12924,17 +12922,38 @@
1292412922
SQLITE_PRIVATE int sqlite3VdbeMemRealify(Mem*);
1292512923
SQLITE_PRIVATE int sqlite3VdbeMemNumerify(Mem*);
1292612924
SQLITE_PRIVATE int sqlite3VdbeMemFromBtree(BtCursor*,int,int,int,Mem*);
1292712925
SQLITE_PRIVATE void sqlite3VdbeMemRelease(Mem *p);
1292812926
SQLITE_PRIVATE void sqlite3VdbeMemReleaseExternal(Mem *p);
12927
+#define MemReleaseExt(X) \
12928
+ if((X)->flags&(MEM_Agg|MEM_Dyn|MEM_RowSet|MEM_Frame)) \
12929
+ sqlite3VdbeMemReleaseExternal(X);
1292912930
SQLITE_PRIVATE int sqlite3VdbeMemFinalize(Mem*, FuncDef*);
1293012931
SQLITE_PRIVATE const char *sqlite3OpcodeName(int);
1293112932
SQLITE_PRIVATE int sqlite3VdbeMemGrow(Mem *pMem, int n, int preserve);
1293212933
SQLITE_PRIVATE int sqlite3VdbeCloseStatement(Vdbe *, int);
1293312934
SQLITE_PRIVATE void sqlite3VdbeFrameDelete(VdbeFrame*);
1293412935
SQLITE_PRIVATE int sqlite3VdbeFrameRestore(VdbeFrame *);
1293512936
SQLITE_PRIVATE void sqlite3VdbeMemStoreType(Mem *pMem);
12937
+
12938
+#ifdef SQLITE_OMIT_MERGE_SORT
12939
+# define sqlite3VdbeSorterInit(Y,Z) SQLITE_OK
12940
+# define sqlite3VdbeSorterWrite(X,Y,Z) SQLITE_OK
12941
+# define sqlite3VdbeSorterClose(Y,Z)
12942
+# define sqlite3VdbeSorterRowkey(Y,Z) SQLITE_OK
12943
+# define sqlite3VdbeSorterRewind(X,Y,Z) SQLITE_OK
12944
+# define sqlite3VdbeSorterNext(X,Y,Z) SQLITE_OK
12945
+# define sqlite3VdbeSorterCompare(X,Y,Z) SQLITE_OK
12946
+#else
12947
+SQLITE_PRIVATE int sqlite3VdbeSorterInit(sqlite3 *, VdbeCursor *);
12948
+SQLITE_PRIVATE void sqlite3VdbeSorterClose(sqlite3 *, VdbeCursor *);
12949
+SQLITE_PRIVATE int sqlite3VdbeSorterRowkey(VdbeCursor *, Mem *);
12950
+SQLITE_PRIVATE int sqlite3VdbeSorterNext(sqlite3 *, VdbeCursor *, int *);
12951
+SQLITE_PRIVATE int sqlite3VdbeSorterRewind(sqlite3 *, VdbeCursor *, int *);
12952
+SQLITE_PRIVATE int sqlite3VdbeSorterWrite(sqlite3 *, VdbeCursor *, Mem *);
12953
+SQLITE_PRIVATE int sqlite3VdbeSorterCompare(VdbeCursor *, Mem *, int *);
12954
+#endif
1293612955
1293712956
#if !defined(SQLITE_OMIT_SHARED_CACHE) && SQLITE_THREADSAFE>0
1293812957
SQLITE_PRIVATE void sqlite3VdbeEnter(Vdbe*);
1293912958
SQLITE_PRIVATE void sqlite3VdbeLeave(Vdbe*);
1294012959
#else
@@ -13225,10 +13244,12 @@
1322513244
** Astronomical Algorithms, 2nd Edition, 1998
1322613245
** ISBM 0-943396-61-1
1322713246
** Willmann-Bell, Inc
1322813247
** Richmond, Virginia (USA)
1322913248
*/
13249
+/* #include <stdlib.h> */
13250
+/* #include <assert.h> */
1323013251
#include <time.h>
1323113252
1323213253
#ifndef SQLITE_OMIT_DATETIME_FUNCS
1323313254
1323413255
@@ -14978,10 +14999,11 @@
1497814999
extern void backtrace_symbols_fd(void*const*,int,int);
1497915000
#else
1498015001
# define backtrace(A,B) 1
1498115002
# define backtrace_symbols_fd(A,B,C)
1498215003
#endif
15004
+/* #include <stdio.h> */
1498315005
1498415006
/*
1498515007
** Each memory allocation looks like this:
1498615008
**
1498715009
** ------------------------------------------------------------------------
@@ -18081,10 +18103,11 @@
1808118103
**
1808218104
*************************************************************************
1808318105
**
1808418106
** Memory allocation functions used throughout sqlite.
1808518107
*/
18108
+/* #include <stdarg.h> */
1808618109
1808718110
/*
1808818111
** Attempt to release up to n bytes of non-essential memory currently
1808918112
** held by SQLite. An example of non-essential memory is memory used to
1809018113
** cache database pages that are not currently in use.
@@ -20058,10 +20081,11 @@
2005820081
** BOM or Byte Order Mark:
2005920082
** 0xff 0xfe little-endian utf-16 follows
2006020083
** 0xfe 0xff big-endian utf-16 follows
2006120084
**
2006220085
*/
20086
+/* #include <assert.h> */
2006320087
2006420088
#ifndef SQLITE_AMALGAMATION
2006520089
/*
2006620090
** The following constant value is used by the SQLITE_BIGENDIAN and
2006720091
** SQLITE_LITTLEENDIAN macros.
@@ -20486,11 +20510,11 @@
2048620510
** no longer required.
2048720511
**
2048820512
** If a malloc failure occurs, NULL is returned and the db.mallocFailed
2048920513
** flag set.
2049020514
*/
20491
-#ifdef SQLITE_ENABLE_STAT3
20515
+#ifdef SQLITE_ENABLE_STAT2
2049220516
SQLITE_PRIVATE char *sqlite3Utf8to16(sqlite3 *db, u8 enc, char *z, int n, int *pnOut){
2049320517
Mem m;
2049420518
memset(&m, 0, sizeof(m));
2049520519
m.db = db;
2049620520
sqlite3VdbeMemSetStr(&m, z, n, SQLITE_UTF8, SQLITE_STATIC);
@@ -20600,10 +20624,11 @@
2060020624
**
2060120625
** This file contains functions for allocating memory, comparing
2060220626
** strings, and stuff like that.
2060320627
**
2060420628
*/
20629
+/* #include <stdarg.h> */
2060520630
#ifdef SQLITE_HAVE_ISNAN
2060620631
# include <math.h>
2060720632
#endif
2060820633
2060920634
/*
@@ -21778,10 +21803,11 @@
2177821803
**
2177921804
*************************************************************************
2178021805
** This is the implementation of generic hash-tables
2178121806
** used in SQLite.
2178221807
*/
21808
+/* #include <assert.h> */
2178321809
2178421810
/* Turn bulk memory into a hash table object by initializing the
2178521811
** fields of the Hash structure.
2178621812
**
2178721813
** "pNew" is a pointer to the hash table that is to be initialized.
@@ -22088,50 +22114,50 @@
2208822114
/* 37 */ "VerifyCookie",
2208922115
/* 38 */ "OpenRead",
2209022116
/* 39 */ "OpenWrite",
2209122117
/* 40 */ "OpenAutoindex",
2209222118
/* 41 */ "OpenEphemeral",
22093
- /* 42 */ "OpenPseudo",
22094
- /* 43 */ "Close",
22095
- /* 44 */ "SeekLt",
22096
- /* 45 */ "SeekLe",
22097
- /* 46 */ "SeekGe",
22098
- /* 47 */ "SeekGt",
22099
- /* 48 */ "Seek",
22100
- /* 49 */ "NotFound",
22101
- /* 50 */ "Found",
22102
- /* 51 */ "IsUnique",
22103
- /* 52 */ "NotExists",
22104
- /* 53 */ "Sequence",
22105
- /* 54 */ "NewRowid",
22106
- /* 55 */ "Insert",
22107
- /* 56 */ "InsertInt",
22108
- /* 57 */ "Delete",
22109
- /* 58 */ "ResetCount",
22110
- /* 59 */ "RowKey",
22111
- /* 60 */ "RowData",
22112
- /* 61 */ "Rowid",
22113
- /* 62 */ "NullRow",
22114
- /* 63 */ "Last",
22115
- /* 64 */ "Sort",
22116
- /* 65 */ "Rewind",
22117
- /* 66 */ "Prev",
22118
- /* 67 */ "Next",
22119
+ /* 42 */ "SorterOpen",
22120
+ /* 43 */ "OpenPseudo",
22121
+ /* 44 */ "Close",
22122
+ /* 45 */ "SeekLt",
22123
+ /* 46 */ "SeekLe",
22124
+ /* 47 */ "SeekGe",
22125
+ /* 48 */ "SeekGt",
22126
+ /* 49 */ "Seek",
22127
+ /* 50 */ "NotFound",
22128
+ /* 51 */ "Found",
22129
+ /* 52 */ "IsUnique",
22130
+ /* 53 */ "NotExists",
22131
+ /* 54 */ "Sequence",
22132
+ /* 55 */ "NewRowid",
22133
+ /* 56 */ "Insert",
22134
+ /* 57 */ "InsertInt",
22135
+ /* 58 */ "Delete",
22136
+ /* 59 */ "ResetCount",
22137
+ /* 60 */ "SorterCompare",
22138
+ /* 61 */ "SorterData",
22139
+ /* 62 */ "RowKey",
22140
+ /* 63 */ "RowData",
22141
+ /* 64 */ "Rowid",
22142
+ /* 65 */ "NullRow",
22143
+ /* 66 */ "Last",
22144
+ /* 67 */ "SorterSort",
2211922145
/* 68 */ "Or",
2212022146
/* 69 */ "And",
22121
- /* 70 */ "IdxInsert",
22122
- /* 71 */ "IdxDelete",
22123
- /* 72 */ "IdxRowid",
22147
+ /* 70 */ "Sort",
22148
+ /* 71 */ "Rewind",
22149
+ /* 72 */ "SorterNext",
2212422150
/* 73 */ "IsNull",
2212522151
/* 74 */ "NotNull",
2212622152
/* 75 */ "Ne",
2212722153
/* 76 */ "Eq",
2212822154
/* 77 */ "Gt",
2212922155
/* 78 */ "Le",
2213022156
/* 79 */ "Lt",
2213122157
/* 80 */ "Ge",
22132
- /* 81 */ "IdxLT",
22158
+ /* 81 */ "Prev",
2213322159
/* 82 */ "BitAnd",
2213422160
/* 83 */ "BitOr",
2213522161
/* 84 */ "ShiftLeft",
2213622162
/* 85 */ "ShiftRight",
2213722163
/* 86 */ "Add",
@@ -22138,64 +22164,68 @@
2213822164
/* 87 */ "Subtract",
2213922165
/* 88 */ "Multiply",
2214022166
/* 89 */ "Divide",
2214122167
/* 90 */ "Remainder",
2214222168
/* 91 */ "Concat",
22143
- /* 92 */ "IdxGE",
22169
+ /* 92 */ "Next",
2214422170
/* 93 */ "BitNot",
2214522171
/* 94 */ "String8",
22146
- /* 95 */ "Destroy",
22147
- /* 96 */ "Clear",
22148
- /* 97 */ "CreateIndex",
22149
- /* 98 */ "CreateTable",
22150
- /* 99 */ "ParseSchema",
22151
- /* 100 */ "LoadAnalysis",
22152
- /* 101 */ "DropTable",
22153
- /* 102 */ "DropIndex",
22154
- /* 103 */ "DropTrigger",
22155
- /* 104 */ "IntegrityCk",
22156
- /* 105 */ "RowSetAdd",
22157
- /* 106 */ "RowSetRead",
22158
- /* 107 */ "RowSetTest",
22159
- /* 108 */ "Program",
22160
- /* 109 */ "Param",
22161
- /* 110 */ "FkCounter",
22162
- /* 111 */ "FkIfZero",
22163
- /* 112 */ "MemMax",
22164
- /* 113 */ "IfPos",
22165
- /* 114 */ "IfNeg",
22166
- /* 115 */ "IfZero",
22167
- /* 116 */ "AggStep",
22168
- /* 117 */ "AggFinal",
22169
- /* 118 */ "Checkpoint",
22170
- /* 119 */ "JournalMode",
22171
- /* 120 */ "Vacuum",
22172
- /* 121 */ "IncrVacuum",
22173
- /* 122 */ "Expire",
22174
- /* 123 */ "TableLock",
22175
- /* 124 */ "VBegin",
22176
- /* 125 */ "VCreate",
22177
- /* 126 */ "VDestroy",
22178
- /* 127 */ "VOpen",
22179
- /* 128 */ "VFilter",
22180
- /* 129 */ "VColumn",
22172
+ /* 95 */ "SorterInsert",
22173
+ /* 96 */ "IdxInsert",
22174
+ /* 97 */ "IdxDelete",
22175
+ /* 98 */ "IdxRowid",
22176
+ /* 99 */ "IdxLT",
22177
+ /* 100 */ "IdxGE",
22178
+ /* 101 */ "Destroy",
22179
+ /* 102 */ "Clear",
22180
+ /* 103 */ "CreateIndex",
22181
+ /* 104 */ "CreateTable",
22182
+ /* 105 */ "ParseSchema",
22183
+ /* 106 */ "LoadAnalysis",
22184
+ /* 107 */ "DropTable",
22185
+ /* 108 */ "DropIndex",
22186
+ /* 109 */ "DropTrigger",
22187
+ /* 110 */ "IntegrityCk",
22188
+ /* 111 */ "RowSetAdd",
22189
+ /* 112 */ "RowSetRead",
22190
+ /* 113 */ "RowSetTest",
22191
+ /* 114 */ "Program",
22192
+ /* 115 */ "Param",
22193
+ /* 116 */ "FkCounter",
22194
+ /* 117 */ "FkIfZero",
22195
+ /* 118 */ "MemMax",
22196
+ /* 119 */ "IfPos",
22197
+ /* 120 */ "IfNeg",
22198
+ /* 121 */ "IfZero",
22199
+ /* 122 */ "AggStep",
22200
+ /* 123 */ "AggFinal",
22201
+ /* 124 */ "Checkpoint",
22202
+ /* 125 */ "JournalMode",
22203
+ /* 126 */ "Vacuum",
22204
+ /* 127 */ "IncrVacuum",
22205
+ /* 128 */ "Expire",
22206
+ /* 129 */ "TableLock",
2218122207
/* 130 */ "Real",
22182
- /* 131 */ "VNext",
22183
- /* 132 */ "VRename",
22184
- /* 133 */ "VUpdate",
22185
- /* 134 */ "Pagecount",
22186
- /* 135 */ "MaxPgcnt",
22187
- /* 136 */ "Trace",
22188
- /* 137 */ "Noop",
22189
- /* 138 */ "Explain",
22190
- /* 139 */ "NotUsed_139",
22191
- /* 140 */ "NotUsed_140",
22208
+ /* 131 */ "VBegin",
22209
+ /* 132 */ "VCreate",
22210
+ /* 133 */ "VDestroy",
22211
+ /* 134 */ "VOpen",
22212
+ /* 135 */ "VFilter",
22213
+ /* 136 */ "VColumn",
22214
+ /* 137 */ "VNext",
22215
+ /* 138 */ "VRename",
22216
+ /* 139 */ "VUpdate",
22217
+ /* 140 */ "Pagecount",
2219222218
/* 141 */ "ToText",
2219322219
/* 142 */ "ToBlob",
2219422220
/* 143 */ "ToNumeric",
2219522221
/* 144 */ "ToInt",
2219622222
/* 145 */ "ToReal",
22223
+ /* 146 */ "MaxPgcnt",
22224
+ /* 147 */ "Trace",
22225
+ /* 148 */ "Noop",
22226
+ /* 149 */ "Explain",
2219722227
};
2219822228
return azName[i];
2219922229
}
2220022230
#endif
2220122231
@@ -22286,11 +22316,11 @@
2228622316
*/
2228722317
#ifdef MEMORY_DEBUG
2228822318
# error "The MEMORY_DEBUG macro is obsolete. Use SQLITE_DEBUG instead."
2228922319
#endif
2229022320
22291
-#ifdef SQLITE_DEBUG
22321
+#if defined(SQLITE_TEST) && defined(SQLITE_DEBUG)
2229222322
# ifndef SQLITE_DEBUG_OS_TRACE
2229322323
# define SQLITE_DEBUG_OS_TRACE 0
2229422324
# endif
2229522325
int sqlite3OSTrace = SQLITE_DEBUG_OS_TRACE;
2229622326
# define OSTRACE(X) if( sqlite3OSTrace ) sqlite3DebugPrintf X
@@ -24450,10 +24480,11 @@
2445024480
*/
2445124481
#include <sys/types.h>
2445224482
#include <sys/stat.h>
2445324483
#include <fcntl.h>
2445424484
#include <unistd.h>
24485
+/* #include <time.h> */
2445524486
#include <sys/time.h>
2445624487
#include <errno.h>
2445724488
#ifndef SQLITE_OMIT_WAL
2445824489
#include <sys/mman.h>
2445924490
#endif
@@ -24485,10 +24516,11 @@
2448524516
/*
2448624517
** If we are to be thread-safe, include the pthreads header and define
2448724518
** the SQLITE_UNIX_THREADS macro.
2448824519
*/
2448924520
#if SQLITE_THREADSAFE
24521
+/* # include <pthread.h> */
2449024522
# define SQLITE_UNIX_THREADS 1
2449124523
#endif
2449224524
2449324525
/*
2449424526
** Default permissions when creating a new file
@@ -24584,11 +24616,15 @@
2458424616
** Allowed values for the unixFile.ctrlFlags bitmask:
2458524617
*/
2458624618
#define UNIXFILE_EXCL 0x01 /* Connections from one process only */
2458724619
#define UNIXFILE_RDONLY 0x02 /* Connection is read only */
2458824620
#define UNIXFILE_PERSIST_WAL 0x04 /* Persistent WAL mode */
24589
-#define UNIXFILE_DIRSYNC 0x08 /* Directory sync needed */
24621
+#ifndef SQLITE_DISABLE_DIRSYNC
24622
+# define UNIXFILE_DIRSYNC 0x08 /* Directory sync needed */
24623
+#else
24624
+# define UNIXFILE_DIRSYNC 0x00
24625
+#endif
2459024626
2459124627
/*
2459224628
** Include code that is common to all os_*.c files
2459324629
*/
2459424630
/************** Include os_common.h in the middle of os_unix.c ***************/
@@ -24622,11 +24658,11 @@
2462224658
*/
2462324659
#ifdef MEMORY_DEBUG
2462424660
# error "The MEMORY_DEBUG macro is obsolete. Use SQLITE_DEBUG instead."
2462524661
#endif
2462624662
24627
-#ifdef SQLITE_DEBUG
24663
+#if defined(SQLITE_TEST) && defined(SQLITE_DEBUG)
2462824664
# ifndef SQLITE_DEBUG_OS_TRACE
2462924665
# define SQLITE_DEBUG_OS_TRACE 0
2463024666
# endif
2463124667
int sqlite3OSTrace = SQLITE_DEBUG_OS_TRACE;
2463224668
# define OSTRACE(X) if( sqlite3OSTrace ) sqlite3DebugPrintf X
@@ -27061,15 +27097,16 @@
2706127097
*/
2706227098
static int afpCheckReservedLock(sqlite3_file *id, int *pResOut){
2706327099
int rc = SQLITE_OK;
2706427100
int reserved = 0;
2706527101
unixFile *pFile = (unixFile*)id;
27102
+ afpLockingContext *context;
2706627103
2706727104
SimulateIOError( return SQLITE_IOERR_CHECKRESERVEDLOCK; );
2706827105
2706927106
assert( pFile );
27070
- afpLockingContext *context = (afpLockingContext *) pFile->lockingContext;
27107
+ context = (afpLockingContext *) pFile->lockingContext;
2707127108
if( context->reserved ){
2707227109
*pResOut = 1;
2707327110
return SQLITE_OK;
2707427111
}
2707527112
unixEnterMutex(); /* Because pFile->pInode is shared across threads */
@@ -27205,11 +27242,11 @@
2720527242
2720627243
/* If control gets to this point, then actually go ahead and make
2720727244
** operating system calls for the specified lock.
2720827245
*/
2720927246
if( eFileLock==SHARED_LOCK ){
27210
- int lrc1, lrc2, lrc1Errno;
27247
+ int lrc1, lrc2, lrc1Errno = 0;
2721127248
long lk, mask;
2721227249
2721327250
assert( pInode->nShared==0 );
2721427251
assert( pInode->eFileLock==0 );
2721527252
@@ -27579,21 +27616,23 @@
2757927616
#if defined(USE_PREAD)
2758027617
do{ got = osPwrite(id->h, pBuf, cnt, offset); }while( got<0 && errno==EINTR );
2758127618
#elif defined(USE_PREAD64)
2758227619
do{ got = osPwrite64(id->h, pBuf, cnt, offset);}while( got<0 && errno==EINTR);
2758327620
#else
27584
- newOffset = lseek(id->h, offset, SEEK_SET);
27585
- SimulateIOError( newOffset-- );
27586
- if( newOffset!=offset ){
27587
- if( newOffset == -1 ){
27588
- ((unixFile*)id)->lastErrno = errno;
27589
- }else{
27590
- ((unixFile*)id)->lastErrno = 0;
27591
- }
27592
- return -1;
27593
- }
27594
- do{ got = osWrite(id->h, pBuf, cnt); }while( got<0 && errno==EINTR );
27621
+ do{
27622
+ newOffset = lseek(id->h, offset, SEEK_SET);
27623
+ SimulateIOError( newOffset-- );
27624
+ if( newOffset!=offset ){
27625
+ if( newOffset == -1 ){
27626
+ ((unixFile*)id)->lastErrno = errno;
27627
+ }else{
27628
+ ((unixFile*)id)->lastErrno = 0;
27629
+ }
27630
+ return -1;
27631
+ }
27632
+ got = osWrite(id->h, pBuf, cnt);
27633
+ }while( got<0 && errno==EINTR );
2759527634
#endif
2759627635
TIMER_END;
2759727636
if( got<0 ){
2759827637
((unixFile*)id)->lastErrno = errno;
2759927638
}
@@ -27679,15 +27718,15 @@
2767927718
SQLITE_API int sqlite3_fullsync_count = 0;
2768027719
#endif
2768127720
2768227721
/*
2768327722
** We do not trust systems to provide a working fdatasync(). Some do.
27684
-** Others do no. To be safe, we will stick with the (slower) fsync().
27685
-** If you know that your system does support fdatasync() correctly,
27723
+** Others do no. To be safe, we will stick with the (slightly slower)
27724
+** fsync(). If you know that your system does support fdatasync() correctly,
2768627725
** then simply compile with -Dfdatasync=fdatasync
2768727726
*/
27688
-#if !defined(fdatasync) && !defined(__linux__)
27727
+#if !defined(fdatasync)
2768927728
# define fdatasync fsync
2769027729
#endif
2769127730
2769227731
/*
2769327732
** Define HAVE_FULLFSYNC to 0 or 1 depending on whether or not
@@ -27888,10 +27927,12 @@
2788827927
HAVE_FULLFSYNC, isFullsync));
2788927928
rc = osOpenDirectory(pFile->zPath, &dirfd);
2789027929
if( rc==SQLITE_OK && dirfd>=0 ){
2789127930
full_fsync(dirfd, 0, 0);
2789227931
robust_close(pFile, dirfd, __LINE__);
27932
+ }else if( rc==SQLITE_CANTOPEN ){
27933
+ rc = SQLITE_OK;
2789327934
}
2789427935
pFile->ctrlFlags &= ~UNIXFILE_DIRSYNC;
2789527936
}
2789627937
return rc;
2789727938
}
@@ -27971,30 +28012,22 @@
2797128012
static int proxyFileControl(sqlite3_file*,int,void*);
2797228013
#endif
2797328014
2797428015
/*
2797528016
** This function is called to handle the SQLITE_FCNTL_SIZE_HINT
27976
-** file-control operation.
27977
-**
27978
-** If the user has configured a chunk-size for this file, it could be
27979
-** that the file needs to be extended at this point. Otherwise, the
27980
-** SQLITE_FCNTL_SIZE_HINT operation is a no-op for Unix.
28017
+** file-control operation. Enlarge the database to nBytes in size
28018
+** (rounded up to the next chunk-size). If the database is already
28019
+** nBytes or larger, this routine is a no-op.
2798128020
*/
2798228021
static int fcntlSizeHint(unixFile *pFile, i64 nByte){
27983
- { /* preserve indentation of removed "if" */
28022
+ if( pFile->szChunk>0 ){
2798428023
i64 nSize; /* Required file size */
27985
- i64 szChunk; /* Chunk size */
2798628024
struct stat buf; /* Used to hold return values of fstat() */
2798728025
2798828026
if( osFstat(pFile->h, &buf) ) return SQLITE_IOERR_FSTAT;
2798928027
27990
- szChunk = pFile->szChunk;
27991
- if( szChunk==0 ){
27992
- nSize = nByte;
27993
- }else{
27994
- nSize = ((nByte+szChunk-1) / szChunk) * szChunk;
27995
- }
28028
+ nSize = ((nByte+pFile->szChunk-1) / pFile->szChunk) * pFile->szChunk;
2799628029
if( nSize>(i64)buf.st_size ){
2799728030
2799828031
#if defined(HAVE_POSIX_FALLOCATE) && HAVE_POSIX_FALLOCATE
2799928032
/* The code below is handling the return value of osFallocate()
2800028033
** correctly. posix_fallocate() is defined to "returns zero on success,
@@ -28048,11 +28081,15 @@
2804828081
case SQLITE_FCNTL_CHUNK_SIZE: {
2804928082
pFile->szChunk = *(int *)pArg;
2805028083
return SQLITE_OK;
2805128084
}
2805228085
case SQLITE_FCNTL_SIZE_HINT: {
28053
- return fcntlSizeHint(pFile, *(i64 *)pArg);
28086
+ int rc;
28087
+ SimulateIOErrorBenign(1);
28088
+ rc = fcntlSizeHint(pFile, *(i64 *)pArg);
28089
+ SimulateIOErrorBenign(0);
28090
+ return rc;
2805428091
}
2805528092
case SQLITE_FCNTL_PERSIST_WAL: {
2805628093
int bPersist = *(int*)pArg;
2805728094
if( bPersist<0 ){
2805828095
*(int*)pArg = (pFile->ctrlFlags & UNIXFILE_PERSIST_WAL)!=0;
@@ -28175,15 +28212,13 @@
2817528212
*/
2817628213
struct unixShm {
2817728214
unixShmNode *pShmNode; /* The underlying unixShmNode object */
2817828215
unixShm *pNext; /* Next unixShm with the same unixShmNode */
2817928216
u8 hasMutex; /* True if holding the unixShmNode mutex */
28217
+ u8 id; /* Id of this connection within its unixShmNode */
2818028218
u16 sharedMask; /* Mask of shared locks held */
2818128219
u16 exclMask; /* Mask of exclusive locks held */
28182
-#ifdef SQLITE_DEBUG
28183
- u8 id; /* Id of this connection within its unixShmNode */
28184
-#endif
2818528220
};
2818628221
2818728222
/*
2818828223
** Constants used for locking
2818928224
*/
@@ -29485,10 +29520,13 @@
2948529520
int isReadonly = (flags & SQLITE_OPEN_READONLY);
2948629521
int isReadWrite = (flags & SQLITE_OPEN_READWRITE);
2948729522
#if SQLITE_ENABLE_LOCKING_STYLE
2948829523
int isAutoProxy = (flags & SQLITE_OPEN_AUTOPROXY);
2948929524
#endif
29525
+#if defined(__APPLE__) || SQLITE_ENABLE_LOCKING_STYLE
29526
+ struct statfs fsInfo;
29527
+#endif
2949029528
2949129529
/* If creating a master or main-file journal, this function will open
2949229530
** a file-descriptor on the directory too. The first time unixSync()
2949329531
** is called the directory file descriptor will be fsync()ed and close()d.
2949429532
*/
@@ -29617,11 +29655,10 @@
2961729655
2961829656
noLock = eType!=SQLITE_OPEN_MAIN_DB;
2961929657
2962029658
2962129659
#if defined(__APPLE__) || SQLITE_ENABLE_LOCKING_STYLE
29622
- struct statfs fsInfo;
2962329660
if( fstatfs(fd, &fsInfo) == -1 ){
2962429661
((unixFile*)pFile)->lastErrno = errno;
2962529662
robust_close(p, fd, __LINE__);
2962629663
return SQLITE_IOERR_ACCESS;
2962729664
}
@@ -29641,11 +29678,10 @@
2964129678
/* SQLITE_FORCE_PROXY_LOCKING==1 means force always use proxy, 0 means
2964229679
** never use proxy, NULL means use proxy for non-local files only. */
2964329680
if( envforce!=NULL ){
2964429681
useProxy = atoi(envforce)>0;
2964529682
}else{
29646
- struct statfs fsInfo;
2964729683
if( statfs(zPath, &fsInfo) == -1 ){
2964829684
/* In theory, the close(fd) call is sub-optimal. If the file opened
2964929685
** with fd is a database file, and there are other connections open
2965029686
** on that file that are currently holding advisory locks on it,
2965129687
** then the call to close() will cancel those locks. In practice,
@@ -29715,10 +29751,12 @@
2971529751
#endif
2971629752
{
2971729753
rc = unixLogError(SQLITE_IOERR_DIR_FSYNC, "fsync", zPath);
2971829754
}
2971929755
robust_close(0, fd, __LINE__);
29756
+ }else if( rc==SQLITE_CANTOPEN ){
29757
+ rc = SQLITE_OK;
2972029758
}
2972129759
}
2972229760
#endif
2972329761
return rc;
2972429762
}
@@ -30380,10 +30418,12 @@
3038030418
*pError = err;
3038130419
}
3038230420
return SQLITE_IOERR;
3038330421
}
3038430422
}
30423
+#else
30424
+ UNUSED_PARAMETER(pError);
3038530425
#endif
3038630426
#ifdef SQLITE_TEST
3038730427
/* simulate multiple hosts by creating unique hostid file paths */
3038830428
if( sqlite3_hostid_num != 0){
3038930429
pHostID[0] = (char)(pHostID[0] + (char)(sqlite3_hostid_num & 0xFF));
@@ -30472,10 +30512,11 @@
3047230512
unixFile *conchFile = pCtx->conchFile;
3047330513
int rc = SQLITE_OK;
3047430514
int nTries = 0;
3047530515
struct timespec conchModTime;
3047630516
30517
+ memset(&conchModTime, 0, sizeof(conchModTime));
3047730518
do {
3047830519
rc = conchFile->pMethod->xLock((sqlite3_file*)conchFile, lockType);
3047930520
nTries ++;
3048030521
if( rc==SQLITE_BUSY ){
3048130522
/* If the lock failed (busy):
@@ -30703,15 +30744,16 @@
3070330744
conchFile->pMethod->xUnlock((sqlite3_file*)conchFile, SHARED_LOCK);
3070430745
3070530746
end_takeconch:
3070630747
OSTRACE(("TRANSPROXY: CLOSE %d\n", pFile->h));
3070730748
if( rc==SQLITE_OK && pFile->openFlags ){
30749
+ int fd;
3070830750
if( pFile->h>=0 ){
3070930751
robust_close(pFile, pFile->h, __LINE__);
3071030752
}
3071130753
pFile->h = -1;
30712
- int fd = robust_open(pCtx->dbPath, pFile->openFlags,
30754
+ fd = robust_open(pCtx->dbPath, pFile->openFlags,
3071330755
SQLITE_DEFAULT_FILE_PERMISSIONS);
3071430756
OSTRACE(("TRANSPROXY: OPEN %d\n", fd));
3071530757
if( fd>=0 ){
3071630758
pFile->h = fd;
3071730759
}else{
@@ -31393,11 +31435,11 @@
3139331435
*/
3139431436
#ifdef MEMORY_DEBUG
3139531437
# error "The MEMORY_DEBUG macro is obsolete. Use SQLITE_DEBUG instead."
3139631438
#endif
3139731439
31398
-#ifdef SQLITE_DEBUG
31440
+#if defined(SQLITE_TEST) && defined(SQLITE_DEBUG)
3139931441
# ifndef SQLITE_DEBUG_OS_TRACE
3140031442
# define SQLITE_DEBUG_OS_TRACE 0
3140131443
# endif
3140231444
int sqlite3OSTrace = SQLITE_DEBUG_OS_TRACE;
3140331445
# define OSTRACE(X) if( sqlite3OSTrace ) sqlite3DebugPrintf X
@@ -31629,10 +31671,80 @@
3162931671
winceLock local; /* Locks obtained by this instance of winFile */
3163031672
winceLock *shared; /* Global shared lock memory for the file */
3163131673
#endif
3163231674
};
3163331675
31676
+/*
31677
+ * If compiled with SQLITE_WIN32_MALLOC on Windows, we will use the
31678
+ * various Win32 API heap functions instead of our own.
31679
+ */
31680
+#ifdef SQLITE_WIN32_MALLOC
31681
+/*
31682
+ * The initial size of the Win32-specific heap. This value may be zero.
31683
+ */
31684
+#ifndef SQLITE_WIN32_HEAP_INIT_SIZE
31685
+# define SQLITE_WIN32_HEAP_INIT_SIZE ((SQLITE_DEFAULT_CACHE_SIZE) * \
31686
+ (SQLITE_DEFAULT_PAGE_SIZE) + 4194304)
31687
+#endif
31688
+
31689
+/*
31690
+ * The maximum size of the Win32-specific heap. This value may be zero.
31691
+ */
31692
+#ifndef SQLITE_WIN32_HEAP_MAX_SIZE
31693
+# define SQLITE_WIN32_HEAP_MAX_SIZE (0)
31694
+#endif
31695
+
31696
+/*
31697
+ * The extra flags to use in calls to the Win32 heap APIs. This value may be
31698
+ * zero for the default behavior.
31699
+ */
31700
+#ifndef SQLITE_WIN32_HEAP_FLAGS
31701
+# define SQLITE_WIN32_HEAP_FLAGS (0)
31702
+#endif
31703
+
31704
+/*
31705
+** The winMemData structure stores information required by the Win32-specific
31706
+** sqlite3_mem_methods implementation.
31707
+*/
31708
+typedef struct winMemData winMemData;
31709
+struct winMemData {
31710
+#ifndef NDEBUG
31711
+ u32 magic; /* Magic number to detect structure corruption. */
31712
+#endif
31713
+ HANDLE hHeap; /* The handle to our heap. */
31714
+ BOOL bOwned; /* Do we own the heap (i.e. destroy it on shutdown)? */
31715
+};
31716
+
31717
+#ifndef NDEBUG
31718
+#define WINMEM_MAGIC 0x42b2830b
31719
+#endif
31720
+
31721
+static struct winMemData win_mem_data = {
31722
+#ifndef NDEBUG
31723
+ WINMEM_MAGIC,
31724
+#endif
31725
+ NULL, FALSE
31726
+};
31727
+
31728
+#ifndef NDEBUG
31729
+#define winMemAssertMagic() assert( win_mem_data.magic==WINMEM_MAGIC )
31730
+#else
31731
+#define winMemAssertMagic()
31732
+#endif
31733
+
31734
+#define winMemGetHeap() win_mem_data.hHeap
31735
+
31736
+static void *winMemMalloc(int nBytes);
31737
+static void winMemFree(void *pPrior);
31738
+static void *winMemRealloc(void *pPrior, int nBytes);
31739
+static int winMemSize(void *p);
31740
+static int winMemRoundup(int n);
31741
+static int winMemInit(void *pAppData);
31742
+static void winMemShutdown(void *pAppData);
31743
+
31744
+SQLITE_PRIVATE const sqlite3_mem_methods *sqlite3MemGetWin32(void);
31745
+#endif /* SQLITE_WIN32_MALLOC */
3163431746
3163531747
/*
3163631748
** Forward prototypes.
3163731749
*/
3163831750
static int getSectorSize(
@@ -31681,10 +31793,192 @@
3168131793
}
3168231794
return sqlite3_os_type==2;
3168331795
}
3168431796
#endif /* SQLITE_OS_WINCE */
3168531797
31798
+#ifdef SQLITE_WIN32_MALLOC
31799
+/*
31800
+** Allocate nBytes of memory.
31801
+*/
31802
+static void *winMemMalloc(int nBytes){
31803
+ HANDLE hHeap;
31804
+ void *p;
31805
+
31806
+ winMemAssertMagic();
31807
+ hHeap = winMemGetHeap();
31808
+ assert( hHeap!=0 );
31809
+ assert( hHeap!=INVALID_HANDLE_VALUE );
31810
+#ifdef SQLITE_WIN32_MALLOC_VALIDATE
31811
+ assert ( HeapValidate(hHeap, SQLITE_WIN32_HEAP_FLAGS, NULL) );
31812
+#endif
31813
+ assert( nBytes>=0 );
31814
+ p = HeapAlloc(hHeap, SQLITE_WIN32_HEAP_FLAGS, (SIZE_T)nBytes);
31815
+ if( !p ){
31816
+ sqlite3_log(SQLITE_NOMEM, "failed to HeapAlloc %u bytes (%d), heap=%p",
31817
+ nBytes, GetLastError(), (void*)hHeap);
31818
+ }
31819
+ return p;
31820
+}
31821
+
31822
+/*
31823
+** Free memory.
31824
+*/
31825
+static void winMemFree(void *pPrior){
31826
+ HANDLE hHeap;
31827
+
31828
+ winMemAssertMagic();
31829
+ hHeap = winMemGetHeap();
31830
+ assert( hHeap!=0 );
31831
+ assert( hHeap!=INVALID_HANDLE_VALUE );
31832
+#ifdef SQLITE_WIN32_MALLOC_VALIDATE
31833
+ assert ( HeapValidate(hHeap, SQLITE_WIN32_HEAP_FLAGS, pPrior) );
31834
+#endif
31835
+ if( !pPrior ) return; /* Passing NULL to HeapFree is undefined. */
31836
+ if( !HeapFree(hHeap, SQLITE_WIN32_HEAP_FLAGS, pPrior) ){
31837
+ sqlite3_log(SQLITE_NOMEM, "failed to HeapFree block %p (%d), heap=%p",
31838
+ pPrior, GetLastError(), (void*)hHeap);
31839
+ }
31840
+}
31841
+
31842
+/*
31843
+** Change the size of an existing memory allocation
31844
+*/
31845
+static void *winMemRealloc(void *pPrior, int nBytes){
31846
+ HANDLE hHeap;
31847
+ void *p;
31848
+
31849
+ winMemAssertMagic();
31850
+ hHeap = winMemGetHeap();
31851
+ assert( hHeap!=0 );
31852
+ assert( hHeap!=INVALID_HANDLE_VALUE );
31853
+#ifdef SQLITE_WIN32_MALLOC_VALIDATE
31854
+ assert ( HeapValidate(hHeap, SQLITE_WIN32_HEAP_FLAGS, pPrior) );
31855
+#endif
31856
+ assert( nBytes>=0 );
31857
+ if( !pPrior ){
31858
+ p = HeapAlloc(hHeap, SQLITE_WIN32_HEAP_FLAGS, (SIZE_T)nBytes);
31859
+ }else{
31860
+ p = HeapReAlloc(hHeap, SQLITE_WIN32_HEAP_FLAGS, pPrior, (SIZE_T)nBytes);
31861
+ }
31862
+ if( !p ){
31863
+ sqlite3_log(SQLITE_NOMEM, "failed to %s %u bytes (%d), heap=%p",
31864
+ pPrior ? "HeapReAlloc" : "HeapAlloc", nBytes, GetLastError(),
31865
+ (void*)hHeap);
31866
+ }
31867
+ return p;
31868
+}
31869
+
31870
+/*
31871
+** Return the size of an outstanding allocation, in bytes.
31872
+*/
31873
+static int winMemSize(void *p){
31874
+ HANDLE hHeap;
31875
+ SIZE_T n;
31876
+
31877
+ winMemAssertMagic();
31878
+ hHeap = winMemGetHeap();
31879
+ assert( hHeap!=0 );
31880
+ assert( hHeap!=INVALID_HANDLE_VALUE );
31881
+#ifdef SQLITE_WIN32_MALLOC_VALIDATE
31882
+ assert ( HeapValidate(hHeap, SQLITE_WIN32_HEAP_FLAGS, NULL) );
31883
+#endif
31884
+ if( !p ) return 0;
31885
+ n = HeapSize(hHeap, SQLITE_WIN32_HEAP_FLAGS, p);
31886
+ if( n==(SIZE_T)-1 ){
31887
+ sqlite3_log(SQLITE_NOMEM, "failed to HeapSize block %p (%d), heap=%p",
31888
+ p, GetLastError(), (void*)hHeap);
31889
+ return 0;
31890
+ }
31891
+ return (int)n;
31892
+}
31893
+
31894
+/*
31895
+** Round up a request size to the next valid allocation size.
31896
+*/
31897
+static int winMemRoundup(int n){
31898
+ return n;
31899
+}
31900
+
31901
+/*
31902
+** Initialize this module.
31903
+*/
31904
+static int winMemInit(void *pAppData){
31905
+ winMemData *pWinMemData = (winMemData *)pAppData;
31906
+
31907
+ if( !pWinMemData ) return SQLITE_ERROR;
31908
+ assert( pWinMemData->magic==WINMEM_MAGIC );
31909
+ if( !pWinMemData->hHeap ){
31910
+ pWinMemData->hHeap = HeapCreate(SQLITE_WIN32_HEAP_FLAGS,
31911
+ SQLITE_WIN32_HEAP_INIT_SIZE,
31912
+ SQLITE_WIN32_HEAP_MAX_SIZE);
31913
+ if( !pWinMemData->hHeap ){
31914
+ sqlite3_log(SQLITE_NOMEM,
31915
+ "failed to HeapCreate (%d), flags=%u, initSize=%u, maxSize=%u",
31916
+ GetLastError(), SQLITE_WIN32_HEAP_FLAGS, SQLITE_WIN32_HEAP_INIT_SIZE,
31917
+ SQLITE_WIN32_HEAP_MAX_SIZE);
31918
+ return SQLITE_NOMEM;
31919
+ }
31920
+ pWinMemData->bOwned = TRUE;
31921
+ }
31922
+ assert( pWinMemData->hHeap!=0 );
31923
+ assert( pWinMemData->hHeap!=INVALID_HANDLE_VALUE );
31924
+#ifdef SQLITE_WIN32_MALLOC_VALIDATE
31925
+ assert( HeapValidate(pWinMemData->hHeap, SQLITE_WIN32_HEAP_FLAGS, NULL) );
31926
+#endif
31927
+ return SQLITE_OK;
31928
+}
31929
+
31930
+/*
31931
+** Deinitialize this module.
31932
+*/
31933
+static void winMemShutdown(void *pAppData){
31934
+ winMemData *pWinMemData = (winMemData *)pAppData;
31935
+
31936
+ if( !pWinMemData ) return;
31937
+ if( pWinMemData->hHeap ){
31938
+ assert( pWinMemData->hHeap!=INVALID_HANDLE_VALUE );
31939
+#ifdef SQLITE_WIN32_MALLOC_VALIDATE
31940
+ assert( HeapValidate(pWinMemData->hHeap, SQLITE_WIN32_HEAP_FLAGS, NULL) );
31941
+#endif
31942
+ if( pWinMemData->bOwned ){
31943
+ if( !HeapDestroy(pWinMemData->hHeap) ){
31944
+ sqlite3_log(SQLITE_NOMEM, "failed to HeapDestroy (%d), heap=%p",
31945
+ GetLastError(), (void*)pWinMemData->hHeap);
31946
+ }
31947
+ pWinMemData->bOwned = FALSE;
31948
+ }
31949
+ pWinMemData->hHeap = NULL;
31950
+ }
31951
+}
31952
+
31953
+/*
31954
+** Populate the low-level memory allocation function pointers in
31955
+** sqlite3GlobalConfig.m with pointers to the routines in this file. The
31956
+** arguments specify the block of memory to manage.
31957
+**
31958
+** This routine is only called by sqlite3_config(), and therefore
31959
+** is not required to be threadsafe (it is not).
31960
+*/
31961
+SQLITE_PRIVATE const sqlite3_mem_methods *sqlite3MemGetWin32(void){
31962
+ static const sqlite3_mem_methods winMemMethods = {
31963
+ winMemMalloc,
31964
+ winMemFree,
31965
+ winMemRealloc,
31966
+ winMemSize,
31967
+ winMemRoundup,
31968
+ winMemInit,
31969
+ winMemShutdown,
31970
+ &win_mem_data
31971
+ };
31972
+ return &winMemMethods;
31973
+}
31974
+
31975
+SQLITE_PRIVATE void sqlite3MemSetDefault(void){
31976
+ sqlite3_config(SQLITE_CONFIG_MALLOC, sqlite3MemGetWin32());
31977
+}
31978
+#endif /* SQLITE_WIN32_MALLOC */
31979
+
3168631980
/*
3168731981
** Convert a UTF-8 string to microsoft unicode (UTF-16?).
3168831982
**
3168931983
** Space to hold the returned string is obtained from malloc.
3169031984
*/
@@ -31969,10 +32263,11 @@
3196932263
*/
3197032264
/*
3197132265
** WindowsCE does not have a localtime() function. So create a
3197232266
** substitute.
3197332267
*/
32268
+/* #include <time.h> */
3197432269
struct tm *__cdecl localtime(const time_t *t)
3197532270
{
3197632271
static struct tm y;
3197732272
FILETIME uTm, lTm;
3197832273
SYSTEMTIME pTm;
@@ -32473,11 +32768,11 @@
3247332768
/* If the user has configured a chunk-size for this file, truncate the
3247432769
** file so that it consists of an integer number of chunks (i.e. the
3247532770
** actual file size after the operation may be larger than the requested
3247632771
** size).
3247732772
*/
32478
- if( pFile->szChunk ){
32773
+ if( pFile->szChunk>0 ){
3247932774
nByte = ((nByte + pFile->szChunk - 1)/pFile->szChunk) * pFile->szChunk;
3248032775
}
3248132776
3248232777
/* SetEndOfFile() returns non-zero when successful, or zero when it fails. */
3248332778
if( seekWinFile(pFile, nByte) ){
@@ -32860,14 +33155,23 @@
3286033155
case SQLITE_FCNTL_CHUNK_SIZE: {
3286133156
pFile->szChunk = *(int *)pArg;
3286233157
return SQLITE_OK;
3286333158
}
3286433159
case SQLITE_FCNTL_SIZE_HINT: {
32865
- sqlite3_int64 sz = *(sqlite3_int64*)pArg;
32866
- SimulateIOErrorBenign(1);
32867
- winTruncate(id, sz);
32868
- SimulateIOErrorBenign(0);
33160
+ if( pFile->szChunk>0 ){
33161
+ sqlite3_int64 oldSz;
33162
+ int rc = winFileSize(id, &oldSz);
33163
+ if( rc==SQLITE_OK ){
33164
+ sqlite3_int64 newSz = *(sqlite3_int64*)pArg;
33165
+ if( newSz>oldSz ){
33166
+ SimulateIOErrorBenign(1);
33167
+ rc = winTruncate(id, newSz);
33168
+ SimulateIOErrorBenign(0);
33169
+ }
33170
+ }
33171
+ return rc;
33172
+ }
3286933173
return SQLITE_OK;
3287033174
}
3287133175
case SQLITE_FCNTL_PERSIST_WAL: {
3287233176
int bPersist = *(int*)pArg;
3287333177
if( bPersist<0 ){
@@ -35473,10 +35777,13 @@
3547335777
typedef struct PCache1 PCache1;
3547435778
typedef struct PgHdr1 PgHdr1;
3547535779
typedef struct PgFreeslot PgFreeslot;
3547635780
typedef struct PGroup PGroup;
3547735781
35782
+typedef struct PGroupBlock PGroupBlock;
35783
+typedef struct PGroupBlockList PGroupBlockList;
35784
+
3547835785
/* Each page cache (or PCache) belongs to a PGroup. A PGroup is a set
3547935786
** of one or more PCaches that are able to recycle each others unpinned
3548035787
** pages when they are under memory pressure. A PGroup is an instance of
3548135788
** the following object.
3548235789
**
@@ -35502,12 +35809,70 @@
3550235809
int nMaxPage; /* Sum of nMax for purgeable caches */
3550335810
int nMinPage; /* Sum of nMin for purgeable caches */
3550435811
int mxPinned; /* nMaxpage + 10 - nMinPage */
3550535812
int nCurrentPage; /* Number of purgeable pages allocated */
3550635813
PgHdr1 *pLruHead, *pLruTail; /* LRU list of unpinned pages */
35814
+#ifdef SQLITE_PAGECACHE_BLOCKALLOC
35815
+ int isBusy; /* Do not run ReleaseMemory() if true */
35816
+ PGroupBlockList *pBlockList; /* List of block-lists for this group */
35817
+#endif
3550735818
};
3550835819
35820
+/*
35821
+** If SQLITE_PAGECACHE_BLOCKALLOC is defined when the library is built,
35822
+** each PGroup structure has a linked list of the the following starting
35823
+** at PGroup.pBlockList. There is one entry for each distinct page-size
35824
+** currently used by members of the PGroup (i.e. 1024 bytes, 4096 bytes
35825
+** etc.). Variable PGroupBlockList.nByte is set to the actual allocation
35826
+** size requested by each pcache, which is the database page-size plus
35827
+** the various header structures used by the pcache, pager and btree layers.
35828
+** Usually around (pgsz+200) bytes.
35829
+**
35830
+** This size (pgsz+200) bytes is not allocated efficiently by some
35831
+** implementations of malloc. In particular, some implementations are only
35832
+** able to allocate blocks of memory chunks of 2^N bytes, where N is some
35833
+** integer value. Since the page-size is a power of 2, this means we
35834
+** end up wasting (pgsz-200) bytes in each allocation.
35835
+**
35836
+** If SQLITE_PAGECACHE_BLOCKALLOC is defined, the (pgsz+200) byte blocks
35837
+** are not allocated directly. Instead, blocks of roughly M*(pgsz+200) bytes
35838
+** are requested from malloc allocator. After a block is returned,
35839
+** sqlite3MallocSize() is used to determine how many (pgsz+200) byte
35840
+** allocations can fit in the space returned by malloc(). This value may
35841
+** be more than M.
35842
+**
35843
+** The blocks are stored in a doubly-linked list. Variable PGroupBlock.nEntry
35844
+** contains the number of allocations that will fit in the aData[] space.
35845
+** nEntry is limited to the number of bits in bitmask mUsed. If a slot
35846
+** within aData is in use, the corresponding bit in mUsed is set. Thus
35847
+** when (mUsed+1==(1 << nEntry)) the block is completely full.
35848
+**
35849
+** Each time a slot within a block is freed, the block is moved to the start
35850
+** of the linked-list. And if a block becomes completely full, then it is
35851
+** moved to the end of the list. As a result, when searching for a free
35852
+** slot, only the first block in the list need be examined. If it is full,
35853
+** then it is guaranteed that all blocks are full.
35854
+*/
35855
+struct PGroupBlockList {
35856
+ int nByte; /* Size of each allocation in bytes */
35857
+ PGroupBlock *pFirst; /* First PGroupBlock in list */
35858
+ PGroupBlock *pLast; /* Last PGroupBlock in list */
35859
+ PGroupBlockList *pNext; /* Next block-list attached to group */
35860
+};
35861
+
35862
+struct PGroupBlock {
35863
+ Bitmask mUsed; /* Mask of used slots */
35864
+ int nEntry; /* Maximum number of allocations in aData[] */
35865
+ u8 *aData; /* Pointer to data block */
35866
+ PGroupBlock *pNext; /* Next PGroupBlock in list */
35867
+ PGroupBlock *pPrev; /* Previous PGroupBlock in list */
35868
+ PGroupBlockList *pList; /* Owner list */
35869
+};
35870
+
35871
+/* Minimum value for PGroupBlock.nEntry */
35872
+#define PAGECACHE_BLOCKALLOC_MINENTRY 15
35873
+
3550935874
/* Each page cache is an instance of the following object. Every
3551035875
** open database file (including each in-memory database and each
3551135876
** temporary or transient database) has a single page cache which
3551235877
** is an instance of this object.
3551335878
**
@@ -35606,10 +35971,21 @@
3560635971
**
3560735972
** assert( PGHDR1_TO_PAGE(PAGE_TO_PGHDR1(pCache, X))==X );
3560835973
*/
3560935974
#define PGHDR1_TO_PAGE(p) (void*)(((char*)p) - p->pCache->szPage)
3561035975
#define PAGE_TO_PGHDR1(c, p) (PgHdr1*)(((char*)p) + c->szPage)
35976
+
35977
+/*
35978
+** Blocks used by the SQLITE_PAGECACHE_BLOCKALLOC blocks to store/retrieve
35979
+** a PGroupBlock pointer based on a pointer to a page buffer.
35980
+*/
35981
+#define PAGE_SET_BLOCKPTR(pCache, pPg, pBlock) \
35982
+ ( *(PGroupBlock **)&(((u8*)pPg)[sizeof(PgHdr1) + pCache->szPage]) = pBlock )
35983
+
35984
+#define PAGE_GET_BLOCKPTR(pCache, pPg) \
35985
+ ( *(PGroupBlock **)&(((u8*)pPg)[sizeof(PgHdr1) + pCache->szPage]) )
35986
+
3561135987
3561235988
/*
3561335989
** Macros to enter and leave the PCache LRU mutex.
3561435990
*/
3561535991
#define pcache1EnterMutex(X) sqlite3_mutex_enter((X)->mutex)
@@ -35732,25 +36108,159 @@
3573236108
return iSize;
3573336109
}
3573436110
}
3573536111
#endif /* SQLITE_ENABLE_MEMORY_MANAGEMENT */
3573636112
36113
+#ifdef SQLITE_PAGECACHE_BLOCKALLOC
36114
+/*
36115
+** The block pBlock belongs to list pList but is not currently linked in.
36116
+** Insert it into the start of the list.
36117
+*/
36118
+static void addBlockToList(PGroupBlockList *pList, PGroupBlock *pBlock){
36119
+ pBlock->pPrev = 0;
36120
+ pBlock->pNext = pList->pFirst;
36121
+ pList->pFirst = pBlock;
36122
+ if( pBlock->pNext ){
36123
+ pBlock->pNext->pPrev = pBlock;
36124
+ }else{
36125
+ assert( pList->pLast==0 );
36126
+ pList->pLast = pBlock;
36127
+ }
36128
+}
36129
+
36130
+/*
36131
+** If there are no blocks in the list headed by pList, remove pList
36132
+** from the pGroup->pBlockList list and free it with sqlite3_free().
36133
+*/
36134
+static void freeListIfEmpty(PGroup *pGroup, PGroupBlockList *pList){
36135
+ assert( sqlite3_mutex_held(pGroup->mutex) );
36136
+ if( pList->pFirst==0 ){
36137
+ PGroupBlockList **pp;
36138
+ for(pp=&pGroup->pBlockList; *pp!=pList; pp=&(*pp)->pNext);
36139
+ *pp = (*pp)->pNext;
36140
+ sqlite3_free(pList);
36141
+ }
36142
+}
36143
+#endif /* SQLITE_PAGECACHE_BLOCKALLOC */
36144
+
3573736145
/*
3573836146
** Allocate a new page object initially associated with cache pCache.
3573936147
*/
3574036148
static PgHdr1 *pcache1AllocPage(PCache1 *pCache){
3574136149
int nByte = sizeof(PgHdr1) + pCache->szPage;
35742
- void *pPg = pcache1Alloc(nByte);
36150
+ void *pPg = 0;
3574336151
PgHdr1 *p;
36152
+
36153
+#ifdef SQLITE_PAGECACHE_BLOCKALLOC
36154
+ PGroup *pGroup = pCache->pGroup;
36155
+ PGroupBlockList *pList;
36156
+ PGroupBlock *pBlock;
36157
+ int i;
36158
+
36159
+ nByte += sizeof(PGroupBlockList *);
36160
+ nByte = ROUND8(nByte);
36161
+
36162
+ for(pList=pGroup->pBlockList; pList; pList=pList->pNext){
36163
+ if( pList->nByte==nByte ) break;
36164
+ }
36165
+ if( pList==0 ){
36166
+ PGroupBlockList *pNew;
36167
+ assert( pGroup->isBusy==0 );
36168
+ assert( sqlite3_mutex_held(pGroup->mutex) );
36169
+ pGroup->isBusy = 1; /* Disable sqlite3PcacheReleaseMemory() */
36170
+ pNew = (PGroupBlockList *)sqlite3MallocZero(sizeof(PGroupBlockList));
36171
+ pGroup->isBusy = 0; /* Reenable sqlite3PcacheReleaseMemory() */
36172
+ if( pNew==0 ){
36173
+ /* malloc() failure. Return early. */
36174
+ return 0;
36175
+ }
36176
+#ifdef SQLITE_DEBUG
36177
+ for(pList=pGroup->pBlockList; pList; pList=pList->pNext){
36178
+ assert( pList->nByte!=nByte );
36179
+ }
36180
+#endif
36181
+ pNew->nByte = nByte;
36182
+ pNew->pNext = pGroup->pBlockList;
36183
+ pGroup->pBlockList = pNew;
36184
+ pList = pNew;
36185
+ }
36186
+
36187
+ pBlock = pList->pFirst;
36188
+ if( pBlock==0 || pBlock->mUsed==(((Bitmask)1<<pBlock->nEntry)-1) ){
36189
+ int sz;
36190
+
36191
+ /* Allocate a new block. Try to allocate enough space for the PGroupBlock
36192
+ ** structure and MINENTRY allocations of nByte bytes each. If the
36193
+ ** allocator returns more memory than requested, then more than MINENTRY
36194
+ ** allocations may fit in it. */
36195
+ assert( sqlite3_mutex_held(pGroup->mutex) );
36196
+ pcache1LeaveMutex(pCache->pGroup);
36197
+ sz = sizeof(PGroupBlock) + PAGECACHE_BLOCKALLOC_MINENTRY * nByte;
36198
+ pBlock = (PGroupBlock *)sqlite3Malloc(sz);
36199
+ pcache1EnterMutex(pCache->pGroup);
36200
+
36201
+ if( !pBlock ){
36202
+ freeListIfEmpty(pGroup, pList);
36203
+ return 0;
36204
+ }
36205
+ pBlock->nEntry = (sqlite3MallocSize(pBlock) - sizeof(PGroupBlock)) / nByte;
36206
+ if( pBlock->nEntry>=BMS ){
36207
+ pBlock->nEntry = BMS-1;
36208
+ }
36209
+ pBlock->pList = pList;
36210
+ pBlock->mUsed = 0;
36211
+ pBlock->aData = (u8 *)&pBlock[1];
36212
+ addBlockToList(pList, pBlock);
36213
+
36214
+ sz = sqlite3MallocSize(pBlock);
36215
+ sqlite3_mutex_enter(pcache1.mutex);
36216
+ sqlite3StatusAdd(SQLITE_STATUS_PAGECACHE_OVERFLOW, sz);
36217
+ sqlite3_mutex_leave(pcache1.mutex);
36218
+ }
36219
+
36220
+ for(i=0; pPg==0 && ALWAYS(i<pBlock->nEntry); i++){
36221
+ if( 0==(pBlock->mUsed & ((Bitmask)1<<i)) ){
36222
+ pBlock->mUsed |= ((Bitmask)1<<i);
36223
+ pPg = (void *)&pBlock->aData[pList->nByte * i];
36224
+ }
36225
+ }
36226
+ assert( pPg );
36227
+ PAGE_SET_BLOCKPTR(pCache, pPg, pBlock);
36228
+
36229
+ /* If the block is now full, shift it to the end of the list */
36230
+ if( pBlock->mUsed==(((Bitmask)1<<pBlock->nEntry)-1) && pList->pLast!=pBlock ){
36231
+ assert( pList->pFirst==pBlock );
36232
+ assert( pBlock->pPrev==0 );
36233
+ assert( pList->pLast->pNext==0 );
36234
+ pList->pFirst = pBlock->pNext;
36235
+ pList->pFirst->pPrev = 0;
36236
+ pBlock->pPrev = pList->pLast;
36237
+ pBlock->pNext = 0;
36238
+ pList->pLast->pNext = pBlock;
36239
+ pList->pLast = pBlock;
36240
+ }
36241
+ p = PAGE_TO_PGHDR1(pCache, pPg);
36242
+ if( pCache->bPurgeable ){
36243
+ pCache->pGroup->nCurrentPage++;
36244
+ }
36245
+#else
36246
+ /* The group mutex must be released before pcache1Alloc() is called. This
36247
+ ** is because it may call sqlite3_release_memory(), which assumes that
36248
+ ** this mutex is not held. */
36249
+ assert( sqlite3_mutex_held(pCache->pGroup->mutex) );
36250
+ pcache1LeaveMutex(pCache->pGroup);
36251
+ pPg = pcache1Alloc(nByte);
36252
+ pcache1EnterMutex(pCache->pGroup);
3574436253
if( pPg ){
3574536254
p = PAGE_TO_PGHDR1(pCache, pPg);
3574636255
if( pCache->bPurgeable ){
3574736256
pCache->pGroup->nCurrentPage++;
3574836257
}
3574936258
}else{
3575036259
p = 0;
3575136260
}
36261
+#endif
3575236262
return p;
3575336263
}
3575436264
3575536265
/*
3575636266
** Free a page object allocated by pcache1AllocPage().
@@ -35760,14 +36270,56 @@
3576036270
** with a NULL pointer, so we mark the NULL test with ALWAYS().
3576136271
*/
3576236272
static void pcache1FreePage(PgHdr1 *p){
3576336273
if( ALWAYS(p) ){
3576436274
PCache1 *pCache = p->pCache;
36275
+ void *pPg = PGHDR1_TO_PAGE(p);
36276
+
36277
+#ifdef SQLITE_PAGECACHE_BLOCKALLOC
36278
+ PGroupBlock *pBlock = PAGE_GET_BLOCKPTR(pCache, pPg);
36279
+ PGroupBlockList *pList = pBlock->pList;
36280
+ int i = ((u8 *)pPg - pBlock->aData) / pList->nByte;
36281
+
36282
+ assert( pPg==(void *)&pBlock->aData[i*pList->nByte] );
36283
+ assert( pBlock->mUsed & ((Bitmask)1<<i) );
36284
+ pBlock->mUsed &= ~((Bitmask)1<<i);
36285
+
36286
+ /* Remove the block from the list. If it is completely empty, free it.
36287
+ ** Or if it is not completely empty, re-insert it at the start of the
36288
+ ** list. */
36289
+ if( pList->pFirst==pBlock ){
36290
+ pList->pFirst = pBlock->pNext;
36291
+ if( pList->pFirst ) pList->pFirst->pPrev = 0;
36292
+ }else{
36293
+ pBlock->pPrev->pNext = pBlock->pNext;
36294
+ }
36295
+ if( pList->pLast==pBlock ){
36296
+ pList->pLast = pBlock->pPrev;
36297
+ if( pList->pLast ) pList->pLast->pNext = 0;
36298
+ }else{
36299
+ pBlock->pNext->pPrev = pBlock->pPrev;
36300
+ }
36301
+
36302
+ if( pBlock->mUsed==0 ){
36303
+ PGroup *pGroup = p->pCache->pGroup;
36304
+
36305
+ int sz = sqlite3MallocSize(pBlock);
36306
+ sqlite3_mutex_enter(pcache1.mutex);
36307
+ sqlite3StatusAdd(SQLITE_STATUS_PAGECACHE_OVERFLOW, -sz);
36308
+ sqlite3_mutex_leave(pcache1.mutex);
36309
+ freeListIfEmpty(pGroup, pList);
36310
+ sqlite3_free(pBlock);
36311
+ }else{
36312
+ addBlockToList(pList, pBlock);
36313
+ }
36314
+#else
36315
+ assert( sqlite3_mutex_held(p->pCache->pGroup->mutex) );
36316
+ pcache1Free(pPg);
36317
+#endif
3576536318
if( pCache->bPurgeable ){
3576636319
pCache->pGroup->nCurrentPage--;
3576736320
}
35768
- pcache1Free(PGHDR1_TO_PAGE(p));
3576936321
}
3577036322
}
3577136323
3577236324
/*
3577336325
** Malloc function used by SQLite to obtain space from the buffer configured
@@ -36201,13 +36753,11 @@
3620136753
/* Step 5. If a usable page buffer has still not been found,
3620236754
** attempt to allocate a new one.
3620336755
*/
3620436756
if( !pPage ){
3620536757
if( createFlag==1 ) sqlite3BeginBenignMalloc();
36206
- pcache1LeaveMutex(pGroup);
3620736758
pPage = pcache1AllocPage(pCache);
36208
- pcache1EnterMutex(pGroup);
3620936759
if( createFlag==1 ) sqlite3EndBenignMalloc();
3621036760
}
3621136761
3621236762
if( pPage ){
3621336763
unsigned int h = iKey % pCache->nHash;
@@ -36373,10 +36923,13 @@
3637336923
** been released, the function returns. The return value is the total number
3637436924
** of bytes of memory released.
3637536925
*/
3637636926
SQLITE_PRIVATE int sqlite3PcacheReleaseMemory(int nReq){
3637736927
int nFree = 0;
36928
+#ifdef SQLITE_PAGECACHE_BLOCKALLOC
36929
+ if( pcache1.grp.isBusy ) return 0;
36930
+#endif
3637836931
assert( sqlite3_mutex_notheld(pcache1.grp.mutex) );
3637936932
assert( sqlite3_mutex_notheld(pcache1.mutex) );
3638036933
if( pcache1.pStart==0 ){
3638136934
PgHdr1 *p;
3638236935
pcache1EnterMutex(&pcache1.grp);
@@ -37585,10 +38138,11 @@
3758538138
u8 ckptSyncFlags; /* SYNC_NORMAL or SYNC_FULL for checkpoint */
3758638139
u8 syncFlags; /* SYNC_NORMAL or SYNC_FULL otherwise */
3758738140
u8 tempFile; /* zFilename is a temporary file */
3758838141
u8 readOnly; /* True for a read-only database */
3758938142
u8 memDb; /* True to inhibit all file I/O */
38143
+ u8 hasSeenStress; /* pagerStress() called one or more times */
3759038144
3759138145
/**************************************************************************
3759238146
** The following block contains those class members that change during
3759338147
** routine opertion. Class members not in this block are either fixed
3759438148
** when the pager is first created or else only change when there is a
@@ -40704,10 +41258,11 @@
4070441258
** to the caller.
4070541259
*/
4070641260
SQLITE_PRIVATE int sqlite3PagerClose(Pager *pPager){
4070741261
u8 *pTmp = (u8 *)pPager->pTmpSpace;
4070841262
41263
+ assert( assert_pager_state(pPager) );
4070941264
disable_simulated_io_errors();
4071041265
sqlite3BeginBenignMalloc();
4071141266
/* pPager->errCode = 0; */
4071241267
pPager->exclusiveMode = 0;
4071341268
#ifndef SQLITE_OMIT_WAL
@@ -41138,10 +41693,11 @@
4113841693
** is impossible for sqlite3PCacheFetch() to be called with createFlag==1
4113941694
** while in the error state, hence it is impossible for this routine to
4114041695
** be called in the error state. Nevertheless, we include a NEVER()
4114141696
** test for the error state as a safeguard against future changes.
4114241697
*/
41698
+ pPager->hasSeenStress = 1;
4114341699
if( NEVER(pPager->errCode) ) return SQLITE_OK;
4114441700
if( pPager->doNotSpill ) return SQLITE_OK;
4114541701
if( pPager->doNotSyncSpill && (pPg->flags & PGHDR_NEED_SYNC)!=0 ){
4114641702
return SQLITE_OK;
4114741703
}
@@ -50430,15 +50986,16 @@
5043050986
for(i=0; i<nCell; i++){
5043150987
u8 *pCell = findCell(pPage, i);
5043250988
if( eType==PTRMAP_OVERFLOW1 ){
5043350989
CellInfo info;
5043450990
btreeParseCellPtr(pPage, pCell, &info);
50435
- if( info.iOverflow ){
50436
- if( iFrom==get4byte(&pCell[info.iOverflow]) ){
50437
- put4byte(&pCell[info.iOverflow], iTo);
50438
- break;
50439
- }
50991
+ if( info.iOverflow
50992
+ && pCell+info.iOverflow+3<=pPage->aData+pPage->maskPage
50993
+ && iFrom==get4byte(&pCell[info.iOverflow])
50994
+ ){
50995
+ put4byte(&pCell[info.iOverflow], iTo);
50996
+ break;
5044050997
}
5044150998
}else{
5044250999
if( get4byte(pCell)==iFrom ){
5044351000
put4byte(pCell, iTo);
5044451001
break;
@@ -51155,11 +51712,12 @@
5115551712
5115651713
if( NEVER(wrFlag && pBt->readOnly) ){
5115751714
return SQLITE_READONLY;
5115851715
}
5115951716
if( iTable==1 && btreePagecount(pBt)==0 ){
51160
- return SQLITE_EMPTY;
51717
+ assert( wrFlag==0 );
51718
+ iTable = 0;
5116151719
}
5116251720
5116351721
/* Now that no other errors can occur, finish filling in the BtCursor
5116451722
** variables and link the cursor into the BtShared list. */
5116551723
pCur->pgnoRoot = (Pgno)iTable;
@@ -51909,10 +52467,13 @@
5190952467
int i;
5191052468
for(i=1; i<=pCur->iPage; i++){
5191152469
releasePage(pCur->apPage[i]);
5191252470
}
5191352471
pCur->iPage = 0;
52472
+ }else if( pCur->pgnoRoot==0 ){
52473
+ pCur->eState = CURSOR_INVALID;
52474
+ return SQLITE_OK;
5191452475
}else{
5191552476
rc = getAndInitPage(pBt, pCur->pgnoRoot, &pCur->apPage[0]);
5191652477
if( rc!=SQLITE_OK ){
5191752478
pCur->eState = CURSOR_INVALID;
5191852479
return rc;
@@ -52018,11 +52579,11 @@
5201852579
assert( cursorHoldsMutex(pCur) );
5201952580
assert( sqlite3_mutex_held(pCur->pBtree->db->mutex) );
5202052581
rc = moveToRoot(pCur);
5202152582
if( rc==SQLITE_OK ){
5202252583
if( pCur->eState==CURSOR_INVALID ){
52023
- assert( pCur->apPage[pCur->iPage]->nCell==0 );
52584
+ assert( pCur->pgnoRoot==0 || pCur->apPage[pCur->iPage]->nCell==0 );
5202452585
*pRes = 1;
5202552586
}else{
5202652587
assert( pCur->apPage[pCur->iPage]->nCell>0 );
5202752588
*pRes = 0;
5202852589
rc = moveToLeftmost(pCur);
@@ -52057,11 +52618,11 @@
5205752618
}
5205852619
5205952620
rc = moveToRoot(pCur);
5206052621
if( rc==SQLITE_OK ){
5206152622
if( CURSOR_INVALID==pCur->eState ){
52062
- assert( pCur->apPage[pCur->iPage]->nCell==0 );
52623
+ assert( pCur->pgnoRoot==0 || pCur->apPage[pCur->iPage]->nCell==0 );
5206352624
*pRes = 1;
5206452625
}else{
5206552626
assert( pCur->eState==CURSOR_VALID );
5206652627
*pRes = 0;
5206752628
rc = moveToRightmost(pCur);
@@ -52130,16 +52691,16 @@
5213052691
5213152692
rc = moveToRoot(pCur);
5213252693
if( rc ){
5213352694
return rc;
5213452695
}
52135
- assert( pCur->apPage[pCur->iPage] );
52136
- assert( pCur->apPage[pCur->iPage]->isInit );
52137
- assert( pCur->apPage[pCur->iPage]->nCell>0 || pCur->eState==CURSOR_INVALID );
52696
+ assert( pCur->pgnoRoot==0 || pCur->apPage[pCur->iPage] );
52697
+ assert( pCur->pgnoRoot==0 || pCur->apPage[pCur->iPage]->isInit );
52698
+ assert( pCur->eState==CURSOR_INVALID || pCur->apPage[pCur->iPage]->nCell>0 );
5213852699
if( pCur->eState==CURSOR_INVALID ){
5213952700
*pRes = -1;
52140
- assert( pCur->apPage[pCur->iPage]->nCell==0 );
52701
+ assert( pCur->pgnoRoot==0 || pCur->apPage[pCur->iPage]->nCell==0 );
5214152702
return SQLITE_OK;
5214252703
}
5214352704
assert( pCur->apPage[0]->intKey || pIdxKey );
5214452705
for(;;){
5214552706
int lwr, upr, idx;
@@ -52862,10 +53423,13 @@
5286253423
assert( sqlite3_mutex_held(pPage->pBt->mutex) );
5286353424
btreeParseCellPtr(pPage, pCell, &info);
5286453425
if( info.iOverflow==0 ){
5286553426
return SQLITE_OK; /* No overflow pages. Return without doing anything */
5286653427
}
53428
+ if( pCell+info.iOverflow+3 > pPage->aData+pPage->maskPage ){
53429
+ return SQLITE_CORRUPT; /* Cell extends past end of page */
53430
+ }
5286753431
ovflPgno = get4byte(&pCell[info.iOverflow]);
5286853432
assert( pBt->usableSize > 4 );
5286953433
ovflPageSize = pBt->usableSize - 4;
5287053434
nOvfl = (info.nPayload - info.nLocal + ovflPageSize - 1)/ovflPageSize;
5287153435
assert( ovflPgno==0 || nOvfl>0 );
@@ -55045,10 +55609,15 @@
5504555609
** corruption) an SQLite error code is returned.
5504655610
*/
5504755611
SQLITE_PRIVATE int sqlite3BtreeCount(BtCursor *pCur, i64 *pnEntry){
5504855612
i64 nEntry = 0; /* Value to return in *pnEntry */
5504955613
int rc; /* Return code */
55614
+
55615
+ if( pCur->pgnoRoot==0 ){
55616
+ *pnEntry = 0;
55617
+ return SQLITE_OK;
55618
+ }
5505055619
rc = moveToRoot(pCur);
5505155620
5505255621
/* Unless an error occurs, the following loop runs one iteration for each
5505355622
** page in the B-Tree structure (not including overflow pages).
5505455623
*/
@@ -55829,11 +56398,10 @@
5582956398
*/
5583056399
SQLITE_PRIVATE int sqlite3BtreeSetVersion(Btree *pBtree, int iVersion){
5583156400
BtShared *pBt = pBtree->pBt;
5583256401
int rc; /* Return code */
5583356402
55834
- assert( pBtree->inTrans==TRANS_NONE );
5583556403
assert( iVersion==1 || iVersion==2 );
5583656404
5583756405
/* If setting the version fields to 1, do not automatically open the
5583856406
** WAL connection, even if the version fields are currently set to 2.
5583956407
*/
@@ -56268,106 +56836,110 @@
5626856836
/* Update the schema version field in the destination database. This
5626956837
** is to make sure that the schema-version really does change in
5627056838
** the case where the source and destination databases have the
5627156839
** same schema version.
5627256840
*/
56273
- if( rc==SQLITE_DONE
56274
- && (rc = sqlite3BtreeUpdateMeta(p->pDest,1,p->iDestSchema+1))==SQLITE_OK
56275
- ){
56276
- int nDestTruncate;
56277
-
56278
- if( p->pDestDb ){
56279
- sqlite3ResetInternalSchema(p->pDestDb, -1);
56280
- }
56281
-
56282
- /* Set nDestTruncate to the final number of pages in the destination
56283
- ** database. The complication here is that the destination page
56284
- ** size may be different to the source page size.
56285
- **
56286
- ** If the source page size is smaller than the destination page size,
56287
- ** round up. In this case the call to sqlite3OsTruncate() below will
56288
- ** fix the size of the file. However it is important to call
56289
- ** sqlite3PagerTruncateImage() here so that any pages in the
56290
- ** destination file that lie beyond the nDestTruncate page mark are
56291
- ** journalled by PagerCommitPhaseOne() before they are destroyed
56292
- ** by the file truncation.
56293
- */
56294
- assert( pgszSrc==sqlite3BtreeGetPageSize(p->pSrc) );
56295
- assert( pgszDest==sqlite3BtreeGetPageSize(p->pDest) );
56296
- if( pgszSrc<pgszDest ){
56297
- int ratio = pgszDest/pgszSrc;
56298
- nDestTruncate = (nSrcPage+ratio-1)/ratio;
56299
- if( nDestTruncate==(int)PENDING_BYTE_PAGE(p->pDest->pBt) ){
56300
- nDestTruncate--;
56301
- }
56302
- }else{
56303
- nDestTruncate = nSrcPage * (pgszSrc/pgszDest);
56304
- }
56305
- sqlite3PagerTruncateImage(pDestPager, nDestTruncate);
56306
-
56307
- if( pgszSrc<pgszDest ){
56308
- /* If the source page-size is smaller than the destination page-size,
56309
- ** two extra things may need to happen:
56310
- **
56311
- ** * The destination may need to be truncated, and
56312
- **
56313
- ** * Data stored on the pages immediately following the
56314
- ** pending-byte page in the source database may need to be
56315
- ** copied into the destination database.
56316
- */
56317
- const i64 iSize = (i64)pgszSrc * (i64)nSrcPage;
56318
- sqlite3_file * const pFile = sqlite3PagerFile(pDestPager);
56319
- i64 iOff;
56320
- i64 iEnd;
56321
-
56322
- assert( pFile );
56323
- assert( (i64)nDestTruncate*(i64)pgszDest >= iSize || (
56324
- nDestTruncate==(int)(PENDING_BYTE_PAGE(p->pDest->pBt)-1)
56325
- && iSize>=PENDING_BYTE && iSize<=PENDING_BYTE+pgszDest
56326
- ));
56327
-
56328
- /* This call ensures that all data required to recreate the original
56329
- ** database has been stored in the journal for pDestPager and the
56330
- ** journal synced to disk. So at this point we may safely modify
56331
- ** the database file in any way, knowing that if a power failure
56332
- ** occurs, the original database will be reconstructed from the
56333
- ** journal file. */
56334
- rc = sqlite3PagerCommitPhaseOne(pDestPager, 0, 1);
56335
-
56336
- /* Write the extra pages and truncate the database file as required. */
56337
- iEnd = MIN(PENDING_BYTE + pgszDest, iSize);
56338
- for(
56339
- iOff=PENDING_BYTE+pgszSrc;
56340
- rc==SQLITE_OK && iOff<iEnd;
56341
- iOff+=pgszSrc
56342
- ){
56343
- PgHdr *pSrcPg = 0;
56344
- const Pgno iSrcPg = (Pgno)((iOff/pgszSrc)+1);
56345
- rc = sqlite3PagerGet(pSrcPager, iSrcPg, &pSrcPg);
56346
- if( rc==SQLITE_OK ){
56347
- u8 *zData = sqlite3PagerGetData(pSrcPg);
56348
- rc = sqlite3OsWrite(pFile, zData, pgszSrc, iOff);
56349
- }
56350
- sqlite3PagerUnref(pSrcPg);
56351
- }
56352
- if( rc==SQLITE_OK ){
56353
- rc = backupTruncateFile(pFile, iSize);
56354
- }
56355
-
56356
- /* Sync the database file to disk. */
56357
- if( rc==SQLITE_OK ){
56358
- rc = sqlite3PagerSync(pDestPager);
56359
- }
56360
- }else{
56361
- rc = sqlite3PagerCommitPhaseOne(pDestPager, 0, 0);
56362
- }
56363
-
56364
- /* Finish committing the transaction to the destination database. */
56365
- if( SQLITE_OK==rc
56366
- && SQLITE_OK==(rc = sqlite3BtreeCommitPhaseTwo(p->pDest, 0))
56367
- ){
56368
- rc = SQLITE_DONE;
56841
+ if( rc==SQLITE_DONE ){
56842
+ rc = sqlite3BtreeUpdateMeta(p->pDest,1,p->iDestSchema+1);
56843
+ if( rc==SQLITE_OK ){
56844
+ if( p->pDestDb ){
56845
+ sqlite3ResetInternalSchema(p->pDestDb, -1);
56846
+ }
56847
+ if( destMode==PAGER_JOURNALMODE_WAL ){
56848
+ rc = sqlite3BtreeSetVersion(p->pDest, 2);
56849
+ }
56850
+ }
56851
+ if( rc==SQLITE_OK ){
56852
+ int nDestTruncate;
56853
+ /* Set nDestTruncate to the final number of pages in the destination
56854
+ ** database. The complication here is that the destination page
56855
+ ** size may be different to the source page size.
56856
+ **
56857
+ ** If the source page size is smaller than the destination page size,
56858
+ ** round up. In this case the call to sqlite3OsTruncate() below will
56859
+ ** fix the size of the file. However it is important to call
56860
+ ** sqlite3PagerTruncateImage() here so that any pages in the
56861
+ ** destination file that lie beyond the nDestTruncate page mark are
56862
+ ** journalled by PagerCommitPhaseOne() before they are destroyed
56863
+ ** by the file truncation.
56864
+ */
56865
+ assert( pgszSrc==sqlite3BtreeGetPageSize(p->pSrc) );
56866
+ assert( pgszDest==sqlite3BtreeGetPageSize(p->pDest) );
56867
+ if( pgszSrc<pgszDest ){
56868
+ int ratio = pgszDest/pgszSrc;
56869
+ nDestTruncate = (nSrcPage+ratio-1)/ratio;
56870
+ if( nDestTruncate==(int)PENDING_BYTE_PAGE(p->pDest->pBt) ){
56871
+ nDestTruncate--;
56872
+ }
56873
+ }else{
56874
+ nDestTruncate = nSrcPage * (pgszSrc/pgszDest);
56875
+ }
56876
+ sqlite3PagerTruncateImage(pDestPager, nDestTruncate);
56877
+
56878
+ if( pgszSrc<pgszDest ){
56879
+ /* If the source page-size is smaller than the destination page-size,
56880
+ ** two extra things may need to happen:
56881
+ **
56882
+ ** * The destination may need to be truncated, and
56883
+ **
56884
+ ** * Data stored on the pages immediately following the
56885
+ ** pending-byte page in the source database may need to be
56886
+ ** copied into the destination database.
56887
+ */
56888
+ const i64 iSize = (i64)pgszSrc * (i64)nSrcPage;
56889
+ sqlite3_file * const pFile = sqlite3PagerFile(pDestPager);
56890
+ i64 iOff;
56891
+ i64 iEnd;
56892
+
56893
+ assert( pFile );
56894
+ assert( (i64)nDestTruncate*(i64)pgszDest >= iSize || (
56895
+ nDestTruncate==(int)(PENDING_BYTE_PAGE(p->pDest->pBt)-1)
56896
+ && iSize>=PENDING_BYTE && iSize<=PENDING_BYTE+pgszDest
56897
+ ));
56898
+
56899
+ /* This call ensures that all data required to recreate the original
56900
+ ** database has been stored in the journal for pDestPager and the
56901
+ ** journal synced to disk. So at this point we may safely modify
56902
+ ** the database file in any way, knowing that if a power failure
56903
+ ** occurs, the original database will be reconstructed from the
56904
+ ** journal file. */
56905
+ rc = sqlite3PagerCommitPhaseOne(pDestPager, 0, 1);
56906
+
56907
+ /* Write the extra pages and truncate the database file as required */
56908
+ iEnd = MIN(PENDING_BYTE + pgszDest, iSize);
56909
+ for(
56910
+ iOff=PENDING_BYTE+pgszSrc;
56911
+ rc==SQLITE_OK && iOff<iEnd;
56912
+ iOff+=pgszSrc
56913
+ ){
56914
+ PgHdr *pSrcPg = 0;
56915
+ const Pgno iSrcPg = (Pgno)((iOff/pgszSrc)+1);
56916
+ rc = sqlite3PagerGet(pSrcPager, iSrcPg, &pSrcPg);
56917
+ if( rc==SQLITE_OK ){
56918
+ u8 *zData = sqlite3PagerGetData(pSrcPg);
56919
+ rc = sqlite3OsWrite(pFile, zData, pgszSrc, iOff);
56920
+ }
56921
+ sqlite3PagerUnref(pSrcPg);
56922
+ }
56923
+ if( rc==SQLITE_OK ){
56924
+ rc = backupTruncateFile(pFile, iSize);
56925
+ }
56926
+
56927
+ /* Sync the database file to disk. */
56928
+ if( rc==SQLITE_OK ){
56929
+ rc = sqlite3PagerSync(pDestPager);
56930
+ }
56931
+ }else{
56932
+ rc = sqlite3PagerCommitPhaseOne(pDestPager, 0, 0);
56933
+ }
56934
+
56935
+ /* Finish committing the transaction to the destination database. */
56936
+ if( SQLITE_OK==rc
56937
+ && SQLITE_OK==(rc = sqlite3BtreeCommitPhaseTwo(p->pDest, 0))
56938
+ ){
56939
+ rc = SQLITE_DONE;
56940
+ }
5636956941
}
5637056942
}
5637156943
5637256944
/* If bCloseTrans is true, then this function opened a read transaction
5637356945
** on the source database. Close the read transaction here. There is
@@ -56831,38 +57403,32 @@
5683157403
** invoking an external callback, free it now. Calling this function
5683257404
** does not free any Mem.zMalloc buffer.
5683357405
*/
5683457406
SQLITE_PRIVATE void sqlite3VdbeMemReleaseExternal(Mem *p){
5683557407
assert( p->db==0 || sqlite3_mutex_held(p->db->mutex) );
56836
- testcase( p->flags & MEM_Agg );
56837
- testcase( p->flags & MEM_Dyn );
56838
- testcase( p->flags & MEM_RowSet );
56839
- testcase( p->flags & MEM_Frame );
56840
- if( p->flags&(MEM_Agg|MEM_Dyn|MEM_RowSet|MEM_Frame) ){
56841
- if( p->flags&MEM_Agg ){
56842
- sqlite3VdbeMemFinalize(p, p->u.pDef);
56843
- assert( (p->flags & MEM_Agg)==0 );
56844
- sqlite3VdbeMemRelease(p);
56845
- }else if( p->flags&MEM_Dyn && p->xDel ){
56846
- assert( (p->flags&MEM_RowSet)==0 );
56847
- p->xDel((void *)p->z);
56848
- p->xDel = 0;
56849
- }else if( p->flags&MEM_RowSet ){
56850
- sqlite3RowSetClear(p->u.pRowSet);
56851
- }else if( p->flags&MEM_Frame ){
56852
- sqlite3VdbeMemSetNull(p);
56853
- }
57408
+ if( p->flags&MEM_Agg ){
57409
+ sqlite3VdbeMemFinalize(p, p->u.pDef);
57410
+ assert( (p->flags & MEM_Agg)==0 );
57411
+ sqlite3VdbeMemRelease(p);
57412
+ }else if( p->flags&MEM_Dyn && p->xDel ){
57413
+ assert( (p->flags&MEM_RowSet)==0 );
57414
+ p->xDel((void *)p->z);
57415
+ p->xDel = 0;
57416
+ }else if( p->flags&MEM_RowSet ){
57417
+ sqlite3RowSetClear(p->u.pRowSet);
57418
+ }else if( p->flags&MEM_Frame ){
57419
+ sqlite3VdbeMemSetNull(p);
5685457420
}
5685557421
}
5685657422
5685757423
/*
5685857424
** Release any memory held by the Mem. This may leave the Mem in an
5685957425
** inconsistent state, for example with (Mem.z==0) and
5686057426
** (Mem.type==SQLITE_TEXT).
5686157427
*/
5686257428
SQLITE_PRIVATE void sqlite3VdbeMemRelease(Mem *p){
56863
- sqlite3VdbeMemReleaseExternal(p);
57429
+ MemReleaseExt(p);
5686457430
sqlite3DbFree(p->db, p->zMalloc);
5686557431
p->z = 0;
5686657432
p->zMalloc = 0;
5686757433
p->xDel = 0;
5686857434
}
@@ -57180,11 +57746,11 @@
5718057746
** pFrom->z is used, then pTo->z points to the same thing as pFrom->z
5718157747
** and flags gets srcType (either MEM_Ephem or MEM_Static).
5718257748
*/
5718357749
SQLITE_PRIVATE void sqlite3VdbeMemShallowCopy(Mem *pTo, const Mem *pFrom, int srcType){
5718457750
assert( (pFrom->flags & MEM_RowSet)==0 );
57185
- sqlite3VdbeMemReleaseExternal(pTo);
57751
+ MemReleaseExt(pTo);
5718657752
memcpy(pTo, pFrom, MEMCELLSIZE);
5718757753
pTo->xDel = 0;
5718857754
if( (pFrom->flags&MEM_Static)==0 ){
5718957755
pTo->flags &= ~(MEM_Dyn|MEM_Static|MEM_Ephem);
5719057756
assert( srcType==MEM_Ephem || srcType==MEM_Static );
@@ -57198,11 +57764,11 @@
5719857764
*/
5719957765
SQLITE_PRIVATE int sqlite3VdbeMemCopy(Mem *pTo, const Mem *pFrom){
5720057766
int rc = SQLITE_OK;
5720157767
5720257768
assert( (pFrom->flags & MEM_RowSet)==0 );
57203
- sqlite3VdbeMemReleaseExternal(pTo);
57769
+ MemReleaseExt(pTo);
5720457770
memcpy(pTo, pFrom, MEMCELLSIZE);
5720557771
pTo->flags &= ~MEM_Dyn;
5720657772
5720757773
if( pTo->flags&(MEM_Str|MEM_Blob) ){
5720857774
if( 0==(pFrom->flags&MEM_Static) ){
@@ -57592,15 +58158,15 @@
5759258158
*ppVal = 0;
5759358159
return SQLITE_OK;
5759458160
}
5759558161
op = pExpr->op;
5759658162
57597
- /* op can only be TK_REGISTER if we have compiled with SQLITE_ENABLE_STAT3.
58163
+ /* op can only be TK_REGISTER if we have compiled with SQLITE_ENABLE_STAT2.
5759858164
** The ifdef here is to enable us to achieve 100% branch test coverage even
57599
- ** when SQLITE_ENABLE_STAT3 is omitted.
58165
+ ** when SQLITE_ENABLE_STAT2 is omitted.
5760058166
*/
57601
-#ifdef SQLITE_ENABLE_STAT3
58167
+#ifdef SQLITE_ENABLE_STAT2
5760258168
if( op==TK_REGISTER ) op = pExpr->op2;
5760358169
#else
5760458170
if( NEVER(op==TK_REGISTER) ) op = pExpr->op2;
5760558171
#endif
5760658172
@@ -58153,10 +58719,16 @@
5815358719
assert( p->nOp - i >= 3 );
5815458720
assert( pOp[-1].opcode==OP_Integer );
5815558721
n = pOp[-1].p1;
5815658722
if( n>nMaxArgs ) nMaxArgs = n;
5815758723
#endif
58724
+ }else if( opcode==OP_Next || opcode==OP_SorterNext ){
58725
+ pOp->p4.xAdvance = sqlite3BtreeNext;
58726
+ pOp->p4type = P4_ADVANCE;
58727
+ }else if( opcode==OP_Prev ){
58728
+ pOp->p4.xAdvance = sqlite3BtreePrevious;
58729
+ pOp->p4type = P4_ADVANCE;
5815858730
}
5815958731
5816058732
if( (pOp->opflags & OPFLG_JUMP)!=0 && pOp->p2<0 ){
5816158733
assert( -1-pOp->p2<p->nLabel );
5816258734
pOp->p2 = aLabel[-1-pOp->p2];
@@ -58244,37 +58816,34 @@
5824458816
** Change the value of the P1 operand for a specific instruction.
5824558817
** This routine is useful when a large program is loaded from a
5824658818
** static array using sqlite3VdbeAddOpList but we want to make a
5824758819
** few minor changes to the program.
5824858820
*/
58249
-SQLITE_PRIVATE void sqlite3VdbeChangeP1(Vdbe *p, int addr, int val){
58821
+SQLITE_PRIVATE void sqlite3VdbeChangeP1(Vdbe *p, u32 addr, int val){
5825058822
assert( p!=0 );
58251
- assert( addr>=0 );
58252
- if( p->nOp>addr ){
58823
+ if( ((u32)p->nOp)>addr ){
5825358824
p->aOp[addr].p1 = val;
5825458825
}
5825558826
}
5825658827
5825758828
/*
5825858829
** Change the value of the P2 operand for a specific instruction.
5825958830
** This routine is useful for setting a jump destination.
5826058831
*/
58261
-SQLITE_PRIVATE void sqlite3VdbeChangeP2(Vdbe *p, int addr, int val){
58832
+SQLITE_PRIVATE void sqlite3VdbeChangeP2(Vdbe *p, u32 addr, int val){
5826258833
assert( p!=0 );
58263
- assert( addr>=0 );
58264
- if( p->nOp>addr ){
58834
+ if( ((u32)p->nOp)>addr ){
5826558835
p->aOp[addr].p2 = val;
5826658836
}
5826758837
}
5826858838
5826958839
/*
5827058840
** Change the value of the P3 operand for a specific instruction.
5827158841
*/
58272
-SQLITE_PRIVATE void sqlite3VdbeChangeP3(Vdbe *p, int addr, int val){
58842
+SQLITE_PRIVATE void sqlite3VdbeChangeP3(Vdbe *p, u32 addr, int val){
5827358843
assert( p!=0 );
58274
- assert( addr>=0 );
58275
- if( p->nOp>addr ){
58844
+ if( ((u32)p->nOp)>addr ){
5827658845
p->aOp[addr].p3 = val;
5827758846
}
5827858847
}
5827958848
5828058849
/*
@@ -58292,12 +58861,12 @@
5829258861
/*
5829358862
** Change the P2 operand of instruction addr so that it points to
5829458863
** the address of the next instruction to be coded.
5829558864
*/
5829658865
SQLITE_PRIVATE void sqlite3VdbeJumpHere(Vdbe *p, int addr){
58297
- assert( addr>=0 || p->db->mallocFailed );
58298
- if( addr>=0 ) sqlite3VdbeChangeP2(p, addr, p->nOp);
58866
+ assert( addr>=0 );
58867
+ sqlite3VdbeChangeP2(p, addr, p->nOp);
5829958868
}
5830058869
5830158870
5830258871
/*
5830358872
** If the input FuncDef structure is ephemeral, then free it. If
@@ -58661,10 +59230,14 @@
5866159230
break;
5866259231
}
5866359232
case P4_SUBPROGRAM: {
5866459233
sqlite3_snprintf(nTemp, zTemp, "program");
5866559234
break;
59235
+ }
59236
+ case P4_ADVANCE: {
59237
+ zTemp[0] = 0;
59238
+ break;
5866659239
}
5866759240
default: {
5866859241
zP4 = pOp->p4.z;
5866959242
if( zP4==0 ){
5867059243
zP4 = zTemp;
@@ -59285,10 +59858,11 @@
5928559858
*/
5928659859
SQLITE_PRIVATE void sqlite3VdbeFreeCursor(Vdbe *p, VdbeCursor *pCx){
5928759860
if( pCx==0 ){
5928859861
return;
5928959862
}
59863
+ sqlite3VdbeSorterClose(p->db, pCx);
5929059864
if( pCx->pBt ){
5929159865
sqlite3BtreeClose(pCx->pBt);
5929259866
/* The pCx->pCursor will be close automatically, if it exists, by
5929359867
** the call above. */
5929459868
}else if( pCx->pCursor ){
@@ -62585,10 +63159,17 @@
6258563159
** Call sqlite3VdbeMemExpandBlob() on the supplied value (type Mem*)
6258663160
** P if required.
6258763161
*/
6258863162
#define ExpandBlob(P) (((P)->flags&MEM_Zero)?sqlite3VdbeMemExpandBlob(P):0)
6258963163
63164
+/* Return true if the cursor was opened using the OP_OpenSorter opcode. */
63165
+#ifdef SQLITE_OMIT_MERGE_SORT
63166
+# define isSorter(x) 0
63167
+#else
63168
+# define isSorter(x) ((x)->pSorter!=0)
63169
+#endif
63170
+
6259063171
/*
6259163172
** Argument pMem points at a register that will be passed to a
6259263173
** user-defined function or returned to the user as the result of a query.
6259363174
** This routine sets the pMem->type variable used by the sqlite3_value_*()
6259463175
** routines.
@@ -63179,10 +63760,11 @@
6317963760
u8 *zEndHdr; /* Pointer to first byte after the header */
6318063761
u32 offset; /* Offset into the data */
6318163762
u32 szField; /* Number of bytes in the content of a field */
6318263763
int szHdr; /* Size of the header size field at start of record */
6318363764
int avail; /* Number of bytes of available data */
63765
+ u32 t; /* A type code from the record header */
6318463766
Mem *pReg; /* PseudoTable input register */
6318563767
} am;
6318663768
struct OP_Affinity_stack_vars {
6318763769
const char *zAffinity; /* The affinity to be applied */
6318863770
char cAff; /* A single character of affinity */
@@ -63250,55 +63832,58 @@
6325063832
Db *pDb;
6325163833
} aw;
6325263834
struct OP_OpenEphemeral_stack_vars {
6325363835
VdbeCursor *pCx;
6325463836
} ax;
63255
- struct OP_OpenPseudo_stack_vars {
63837
+ struct OP_SorterOpen_stack_vars {
6325663838
VdbeCursor *pCx;
6325763839
} ay;
63840
+ struct OP_OpenPseudo_stack_vars {
63841
+ VdbeCursor *pCx;
63842
+ } az;
6325863843
struct OP_SeekGt_stack_vars {
6325963844
int res;
6326063845
int oc;
6326163846
VdbeCursor *pC;
6326263847
UnpackedRecord r;
6326363848
int nField;
6326463849
i64 iKey; /* The rowid we are to seek to */
63265
- } az;
63850
+ } ba;
6326663851
struct OP_Seek_stack_vars {
6326763852
VdbeCursor *pC;
63268
- } ba;
63853
+ } bb;
6326963854
struct OP_Found_stack_vars {
6327063855
int alreadyExists;
6327163856
VdbeCursor *pC;
6327263857
int res;
6327363858
UnpackedRecord *pIdxKey;
6327463859
UnpackedRecord r;
6327563860
char aTempRec[ROUND8(sizeof(UnpackedRecord)) + sizeof(Mem)*3 + 7];
63276
- } bb;
63861
+ } bc;
6327763862
struct OP_IsUnique_stack_vars {
6327863863
u16 ii;
6327963864
VdbeCursor *pCx;
6328063865
BtCursor *pCrsr;
6328163866
u16 nField;
6328263867
Mem *aMx;
6328363868
UnpackedRecord r; /* B-Tree index search key */
6328463869
i64 R; /* Rowid stored in register P3 */
63285
- } bc;
63870
+ } bd;
6328663871
struct OP_NotExists_stack_vars {
6328763872
VdbeCursor *pC;
6328863873
BtCursor *pCrsr;
6328963874
int res;
6329063875
u64 iKey;
63291
- } bd;
63876
+ } be;
6329263877
struct OP_NewRowid_stack_vars {
6329363878
i64 v; /* The new rowid */
6329463879
VdbeCursor *pC; /* Cursor of table to get the new rowid */
6329563880
int res; /* Result of an sqlite3BtreeLast() */
6329663881
int cnt; /* Counter to limit the number of searches */
6329763882
Mem *pMem; /* Register holding largest rowid for AUTOINCREMENT */
6329863883
VdbeFrame *pFrame; /* Root frame of VDBE */
63299
- } be;
63884
+ } bf;
6330063885
struct OP_InsertInt_stack_vars {
6330163886
Mem *pData; /* MEM cell holding data for the record to be inserted */
6330263887
Mem *pKey; /* MEM cell holding key for the record */
6330363888
i64 iKey; /* The integer ROWID or key for the record to be inserted */
6330463889
VdbeCursor *pC; /* Cursor to table into which insert is written */
@@ -63305,155 +63890,161 @@
6330563890
int nZero; /* Number of zero-bytes to append */
6330663891
int seekResult; /* Result of prior seek or 0 if no USESEEKRESULT flag */
6330763892
const char *zDb; /* database name - used by the update hook */
6330863893
const char *zTbl; /* Table name - used by the opdate hook */
6330963894
int op; /* Opcode for update hook: SQLITE_UPDATE or SQLITE_INSERT */
63310
- } bf;
63895
+ } bg;
6331163896
struct OP_Delete_stack_vars {
6331263897
i64 iKey;
6331363898
VdbeCursor *pC;
63314
- } bg;
63899
+ } bh;
63900
+ struct OP_SorterCompare_stack_vars {
63901
+ VdbeCursor *pC;
63902
+ int res;
63903
+ } bi;
63904
+ struct OP_SorterData_stack_vars {
63905
+ VdbeCursor *pC;
63906
+ } bj;
6331563907
struct OP_RowData_stack_vars {
6331663908
VdbeCursor *pC;
6331763909
BtCursor *pCrsr;
6331863910
u32 n;
6331963911
i64 n64;
63320
- } bh;
63912
+ } bk;
6332163913
struct OP_Rowid_stack_vars {
6332263914
VdbeCursor *pC;
6332363915
i64 v;
6332463916
sqlite3_vtab *pVtab;
6332563917
const sqlite3_module *pModule;
63326
- } bi;
63918
+ } bl;
6332763919
struct OP_NullRow_stack_vars {
6332863920
VdbeCursor *pC;
63329
- } bj;
63921
+ } bm;
6333063922
struct OP_Last_stack_vars {
6333163923
VdbeCursor *pC;
6333263924
BtCursor *pCrsr;
6333363925
int res;
63334
- } bk;
63926
+ } bn;
6333563927
struct OP_Rewind_stack_vars {
6333663928
VdbeCursor *pC;
6333763929
BtCursor *pCrsr;
6333863930
int res;
63339
- } bl;
63931
+ } bo;
6334063932
struct OP_Next_stack_vars {
6334163933
VdbeCursor *pC;
63342
- BtCursor *pCrsr;
6334363934
int res;
63344
- } bm;
63935
+ } bp;
6334563936
struct OP_IdxInsert_stack_vars {
6334663937
VdbeCursor *pC;
6334763938
BtCursor *pCrsr;
6334863939
int nKey;
6334963940
const char *zKey;
63350
- } bn;
63941
+ } bq;
6335163942
struct OP_IdxDelete_stack_vars {
6335263943
VdbeCursor *pC;
6335363944
BtCursor *pCrsr;
6335463945
int res;
6335563946
UnpackedRecord r;
63356
- } bo;
63947
+ } br;
6335763948
struct OP_IdxRowid_stack_vars {
6335863949
BtCursor *pCrsr;
6335963950
VdbeCursor *pC;
6336063951
i64 rowid;
63361
- } bp;
63952
+ } bs;
6336263953
struct OP_IdxGE_stack_vars {
6336363954
VdbeCursor *pC;
6336463955
int res;
6336563956
UnpackedRecord r;
63366
- } bq;
63957
+ } bt;
6336763958
struct OP_Destroy_stack_vars {
6336863959
int iMoved;
6336963960
int iCnt;
6337063961
Vdbe *pVdbe;
6337163962
int iDb;
63372
- } br;
63963
+ } bu;
6337363964
struct OP_Clear_stack_vars {
6337463965
int nChange;
63375
- } bs;
63966
+ } bv;
6337663967
struct OP_CreateTable_stack_vars {
6337763968
int pgno;
6337863969
int flags;
6337963970
Db *pDb;
63380
- } bt;
63971
+ } bw;
6338163972
struct OP_ParseSchema_stack_vars {
6338263973
int iDb;
6338363974
const char *zMaster;
6338463975
char *zSql;
6338563976
InitData initData;
63386
- } bu;
63977
+ } bx;
6338763978
struct OP_IntegrityCk_stack_vars {
6338863979
int nRoot; /* Number of tables to check. (Number of root pages.) */
6338963980
int *aRoot; /* Array of rootpage numbers for tables to be checked */
6339063981
int j; /* Loop counter */
6339163982
int nErr; /* Number of errors reported */
6339263983
char *z; /* Text of the error report */
6339363984
Mem *pnErr; /* Register keeping track of errors remaining */
63394
- } bv;
63985
+ } by;
6339563986
struct OP_RowSetRead_stack_vars {
6339663987
i64 val;
63397
- } bw;
63988
+ } bz;
6339863989
struct OP_RowSetTest_stack_vars {
6339963990
int iSet;
6340063991
int exists;
63401
- } bx;
63992
+ } ca;
6340263993
struct OP_Program_stack_vars {
6340363994
int nMem; /* Number of memory registers for sub-program */
6340463995
int nByte; /* Bytes of runtime space required for sub-program */
6340563996
Mem *pRt; /* Register to allocate runtime space */
6340663997
Mem *pMem; /* Used to iterate through memory cells */
6340763998
Mem *pEnd; /* Last memory cell in new array */
6340863999
VdbeFrame *pFrame; /* New vdbe frame to execute in */
6340964000
SubProgram *pProgram; /* Sub-program to execute */
6341064001
void *t; /* Token identifying trigger */
63411
- } by;
64002
+ } cb;
6341264003
struct OP_Param_stack_vars {
6341364004
VdbeFrame *pFrame;
6341464005
Mem *pIn;
63415
- } bz;
64006
+ } cc;
6341664007
struct OP_MemMax_stack_vars {
6341764008
Mem *pIn1;
6341864009
VdbeFrame *pFrame;
63419
- } ca;
64010
+ } cd;
6342064011
struct OP_AggStep_stack_vars {
6342164012
int n;
6342264013
int i;
6342364014
Mem *pMem;
6342464015
Mem *pRec;
6342564016
sqlite3_context ctx;
6342664017
sqlite3_value **apVal;
63427
- } cb;
64018
+ } ce;
6342864019
struct OP_AggFinal_stack_vars {
6342964020
Mem *pMem;
63430
- } cc;
64021
+ } cf;
6343164022
struct OP_Checkpoint_stack_vars {
6343264023
int i; /* Loop counter */
6343364024
int aRes[3]; /* Results */
6343464025
Mem *pMem; /* Write results here */
63435
- } cd;
64026
+ } cg;
6343664027
struct OP_JournalMode_stack_vars {
6343764028
Btree *pBt; /* Btree to change journal mode of */
6343864029
Pager *pPager; /* Pager associated with pBt */
6343964030
int eNew; /* New journal mode */
6344064031
int eOld; /* The old journal mode */
6344164032
const char *zFilename; /* Name of database file for pPager */
63442
- } ce;
64033
+ } ch;
6344364034
struct OP_IncrVacuum_stack_vars {
6344464035
Btree *pBt;
63445
- } cf;
64036
+ } ci;
6344664037
struct OP_VBegin_stack_vars {
6344764038
VTable *pVTab;
63448
- } cg;
64039
+ } cj;
6344964040
struct OP_VOpen_stack_vars {
6345064041
VdbeCursor *pCur;
6345164042
sqlite3_vtab_cursor *pVtabCursor;
6345264043
sqlite3_vtab *pVtab;
6345364044
sqlite3_module *pModule;
63454
- } ch;
64045
+ } ck;
6345564046
struct OP_VFilter_stack_vars {
6345664047
int nArg;
6345764048
int iQuery;
6345864049
const sqlite3_module *pModule;
6345964050
Mem *pQuery;
@@ -63462,40 +64053,40 @@
6346264053
sqlite3_vtab *pVtab;
6346364054
VdbeCursor *pCur;
6346464055
int res;
6346564056
int i;
6346664057
Mem **apArg;
63467
- } ci;
64058
+ } cl;
6346864059
struct OP_VColumn_stack_vars {
6346964060
sqlite3_vtab *pVtab;
6347064061
const sqlite3_module *pModule;
6347164062
Mem *pDest;
6347264063
sqlite3_context sContext;
63473
- } cj;
64064
+ } cm;
6347464065
struct OP_VNext_stack_vars {
6347564066
sqlite3_vtab *pVtab;
6347664067
const sqlite3_module *pModule;
6347764068
int res;
6347864069
VdbeCursor *pCur;
63479
- } ck;
64070
+ } cn;
6348064071
struct OP_VRename_stack_vars {
6348164072
sqlite3_vtab *pVtab;
6348264073
Mem *pName;
63483
- } cl;
64074
+ } co;
6348464075
struct OP_VUpdate_stack_vars {
6348564076
sqlite3_vtab *pVtab;
6348664077
sqlite3_module *pModule;
6348764078
int nArg;
6348864079
int i;
6348964080
sqlite_int64 rowid;
6349064081
Mem **apArg;
6349164082
Mem *pX;
63492
- } cm;
64083
+ } cp;
6349364084
struct OP_Trace_stack_vars {
6349464085
char *zTrace;
6349564086
char *z;
63496
- } cn;
64087
+ } cq;
6349764088
} u;
6349864089
/* End automatically generated code
6349964090
********************************************************************/
6350064091
6350164092
assert( p->magic==VDBE_MAGIC_RUN ); /* sqlite3_step() verifies this */
@@ -63591,11 +64182,11 @@
6359164182
if( pOp->opflags & OPFLG_OUT2_PRERELEASE ){
6359264183
assert( pOp->p2>0 );
6359364184
assert( pOp->p2<=p->nMem );
6359464185
pOut = &aMem[pOp->p2];
6359564186
memAboutToChange(p, pOut);
63596
- sqlite3VdbeMemReleaseExternal(pOut);
64187
+ MemReleaseExt(pOut);
6359764188
pOut->flags = MEM_Int;
6359864189
}
6359964190
6360064191
/* Sanity checking on other operands */
6360164192
#ifdef SQLITE_DEBUG
@@ -65061,10 +65652,11 @@
6506165652
u8 *zEndHdr; /* Pointer to first byte after the header */
6506265653
u32 offset; /* Offset into the data */
6506365654
u32 szField; /* Number of bytes in the content of a field */
6506465655
int szHdr; /* Size of the header size field at start of record */
6506565656
int avail; /* Number of bytes of available data */
65657
+ u32 t; /* A type code from the record header */
6506665658
Mem *pReg; /* PseudoTable input register */
6506765659
#endif /* local variables moved into u.am */
6506865660
6506965661
6507065662
u.am.p1 = pOp->p1;
@@ -65073,11 +65665,10 @@
6507365665
memset(&u.am.sMem, 0, sizeof(u.am.sMem));
6507465666
assert( u.am.p1<p->nCursor );
6507565667
assert( pOp->p3>0 && pOp->p3<=p->nMem );
6507665668
u.am.pDest = &aMem[pOp->p3];
6507765669
memAboutToChange(p, u.am.pDest);
65078
- MemSetTypeFlag(u.am.pDest, MEM_Null);
6507965670
u.am.zRec = 0;
6508065671
6508165672
/* This block sets the variable u.am.payloadSize to be the total number of
6508265673
** bytes in the record.
6508365674
**
@@ -65117,11 +65708,11 @@
6511765708
}else{
6511865709
assert( sqlite3BtreeCursorIsValid(u.am.pCrsr) );
6511965710
rc = sqlite3BtreeDataSize(u.am.pCrsr, &u.am.payloadSize);
6512065711
assert( rc==SQLITE_OK ); /* DataSize() cannot fail */
6512165712
}
65122
- }else if( u.am.pC->pseudoTableReg>0 ){
65713
+ }else if( ALWAYS(u.am.pC->pseudoTableReg>0) ){
6512365714
u.am.pReg = &aMem[u.am.pC->pseudoTableReg];
6512465715
assert( u.am.pReg->flags & MEM_Blob );
6512565716
assert( memIsValid(u.am.pReg) );
6512665717
u.am.payloadSize = u.am.pReg->n;
6512765718
u.am.zRec = u.am.pReg->z;
@@ -65130,13 +65721,14 @@
6513065721
}else{
6513165722
/* Consider the row to be NULL */
6513265723
u.am.payloadSize = 0;
6513365724
}
6513465725
65135
- /* If u.am.payloadSize is 0, then just store a NULL */
65726
+ /* If u.am.payloadSize is 0, then just store a NULL. This can happen because of
65727
+ ** nullRow or because of a corrupt database. */
6513665728
if( u.am.payloadSize==0 ){
65137
- assert( u.am.pDest->flags&MEM_Null );
65729
+ MemSetTypeFlag(u.am.pDest, MEM_Null);
6513865730
goto op_column_out;
6513965731
}
6514065732
assert( db->aLimit[SQLITE_LIMIT_LENGTH]>=0 );
6514165733
if( u.am.payloadSize > (u32)db->aLimit[SQLITE_LIMIT_LENGTH] ){
6514265734
goto too_big;
@@ -65239,12 +65831,18 @@
6523965831
** of the record to the start of the data for the u.am.i-th column
6524065832
*/
6524165833
for(u.am.i=0; u.am.i<u.am.nField; u.am.i++){
6524265834
if( u.am.zIdx<u.am.zEndHdr ){
6524365835
u.am.aOffset[u.am.i] = u.am.offset;
65244
- u.am.zIdx += getVarint32(u.am.zIdx, u.am.aType[u.am.i]);
65245
- u.am.szField = sqlite3VdbeSerialTypeLen(u.am.aType[u.am.i]);
65836
+ if( u.am.zIdx[0]<0x80 ){
65837
+ u.am.t = u.am.zIdx[0];
65838
+ u.am.zIdx++;
65839
+ }else{
65840
+ u.am.zIdx += sqlite3GetVarint32(u.am.zIdx, &u.am.t);
65841
+ }
65842
+ u.am.aType[u.am.i] = u.am.t;
65843
+ u.am.szField = sqlite3VdbeSerialTypeLen(u.am.t);
6524665844
u.am.offset += u.am.szField;
6524765845
if( u.am.offset<u.am.szField ){ /* True if u.am.offset overflows */
6524865846
u.am.zIdx = &u.am.zEndHdr[1]; /* Forces SQLITE_CORRUPT return below */
6524965847
break;
6525065848
}
@@ -65281,11 +65879,11 @@
6528165879
** a pointer to a Mem object.
6528265880
*/
6528365881
if( u.am.aOffset[u.am.p2] ){
6528465882
assert( rc==SQLITE_OK );
6528565883
if( u.am.zRec ){
65286
- sqlite3VdbeMemReleaseExternal(u.am.pDest);
65884
+ MemReleaseExt(u.am.pDest);
6528765885
sqlite3VdbeSerialGet((u8 *)&u.am.zRec[u.am.aOffset[u.am.p2]], u.am.aType[u.am.p2], u.am.pDest);
6528865886
}else{
6528965887
u.am.len = sqlite3VdbeSerialTypeLen(u.am.aType[u.am.p2]);
6529065888
sqlite3VdbeMemMove(&u.am.sMem, u.am.pDest);
6529165889
rc = sqlite3VdbeMemFromBtree(u.am.pCrsr, u.am.aOffset[u.am.p2], u.am.len, u.am.pC->isIndex, &u.am.sMem);
@@ -65298,11 +65896,11 @@
6529865896
u.am.pDest->enc = encoding;
6529965897
}else{
6530065898
if( pOp->p4type==P4_MEM ){
6530165899
sqlite3VdbeMemShallowCopy(u.am.pDest, pOp->p4.pMem, MEM_Static);
6530265900
}else{
65303
- assert( u.am.pDest->flags&MEM_Null );
65901
+ MemSetTypeFlag(u.am.pDest, MEM_Null);
6530465902
}
6530565903
}
6530665904
6530765905
/* If we dynamically allocated space to hold the data (in the
6530865906
** sqlite3VdbeMemFromBtree() call above) then transfer control of that
@@ -65500,11 +66098,11 @@
6550066098
i64 nEntry;
6550166099
BtCursor *pCrsr;
6550266100
#endif /* local variables moved into u.ap */
6550366101
6550466102
u.ap.pCrsr = p->apCsr[pOp->p1]->pCursor;
65505
- if( u.ap.pCrsr ){
66103
+ if( ALWAYS(u.ap.pCrsr) ){
6550666104
rc = sqlite3BtreeCount(u.ap.pCrsr, &u.ap.nEntry);
6550766105
}else{
6550866106
u.ap.nEntry = 0;
6550966107
}
6551066108
pOut->u.i = u.ap.nEntry;
@@ -66076,19 +66674,13 @@
6607666674
u.aw.pCur->nullRow = 1;
6607766675
u.aw.pCur->isOrdered = 1;
6607866676
rc = sqlite3BtreeCursor(u.aw.pX, u.aw.p2, u.aw.wrFlag, u.aw.pKeyInfo, u.aw.pCur->pCursor);
6607966677
u.aw.pCur->pKeyInfo = u.aw.pKeyInfo;
6608066678
66081
- /* Since it performs no memory allocation or IO, the only values that
66082
- ** sqlite3BtreeCursor() may return are SQLITE_EMPTY and SQLITE_OK.
66083
- ** SQLITE_EMPTY is only returned when attempting to open the table
66084
- ** rooted at page 1 of a zero-byte database. */
66085
- assert( rc==SQLITE_EMPTY || rc==SQLITE_OK );
66086
- if( rc==SQLITE_EMPTY ){
66087
- u.aw.pCur->pCursor = 0;
66088
- rc = SQLITE_OK;
66089
- }
66679
+ /* Since it performs no memory allocation or IO, the only value that
66680
+ ** sqlite3BtreeCursor() may return is SQLITE_OK. */
66681
+ assert( rc==SQLITE_OK );
6609066682
6609166683
/* Set the VdbeCursor.isTable and isIndex variables. Previous versions of
6609266684
** SQLite used to check if the root-page flags were sane at this point
6609366685
** and report database corruption if they were not, but this check has
6609466686
** since moved into the btree layer. */
@@ -66095,11 +66687,11 @@
6609566687
u.aw.pCur->isTable = pOp->p4type!=P4_KEYINFO;
6609666688
u.aw.pCur->isIndex = !u.aw.pCur->isTable;
6609766689
break;
6609866690
}
6609966691
66100
-/* Opcode: OpenEphemeral P1 P2 * P4 *
66692
+/* Opcode: OpenEphemeral P1 P2 * P4 P5
6610166693
**
6610266694
** Open a new cursor P1 to a transient table.
6610366695
** The cursor is always opened read/write even if
6610466696
** the main database is read-only. The ephemeral
6610566697
** table is deleted automatically when the cursor is closed.
@@ -66112,10 +66704,15 @@
6611266704
** This opcode was once called OpenTemp. But that created
6611366705
** confusion because the term "temp table", might refer either
6611466706
** to a TEMP table at the SQL level, or to a table opened by
6611566707
** this opcode. Then this opcode was call OpenVirtual. But
6611666708
** that created confusion with the whole virtual-table idea.
66709
+**
66710
+** The P5 parameter can be a mask of the BTREE_* flags defined
66711
+** in btree.h. These flags control aspects of the operation of
66712
+** the btree. The BTREE_OMIT_JOURNAL and BTREE_SINGLE flags are
66713
+** added automatically.
6611766714
*/
6611866715
/* Opcode: OpenAutoindex P1 P2 * P4 *
6611966716
**
6612066717
** This opcode works the same as OP_OpenEphemeral. It has a
6612166718