Fossil SCM

Merge in trunk; resolve conflicts

ashepilko 2020-08-09 21:45 UTC cmake-ide merge
Commit 7cfbf66a027855eb4e1d57069f6c44cd16a742cb5dbb32a6b5dbf550fecbbc75
307 files changed +16 -14 +16 -14 +2 -3 +7 -1 +1 -1 +10 -10 +17 -10 +11 -16 +1 -1 +1 -1 +1 -1 +1 -1 +4 -3 +52 +27 +176 -59 +19 +463 -200 +23 -39 +33 -28 +6 +184 -23 +169 -77 +76 -6 +21 -13 +150 -80 +251 -11 +13 -27 +26 -10 +95 +138 -60 +217 -114 +4 -4 +29 -23 +37 -18 +17 -31 +2 -1 +18 -15 +40 -7 +4 -1 +427 -112 +6 -29 +6 -29 +65 -20 +81 -51 +1 -1 +731 -57 +201 -24 +24 -5 +61 -9 +2 -1 +41 -11 +174 -3 +266 +28 -21 +402 -69 +1 -1 +167 +5 +4 +74 +4 +8 +64 +8 +4 +9 -2 +1 -1 +18 +99 -6 +17 -3 +1 +1 -1 +238 -123 +3 -3 +16 -12 +306 -256 +130 -51 +10 -1 +2 -5 +2 +1 -1 +10 -11 +1 -1 +2 -1 +11 +201 -142 +196 -68 +95 -22 +2 -1 +53 -83 +53 -83 +66 -17 +105 -43 +8 -2 +13 -14 +17 -2 +17 -9 +1 -168 +4 +99 -3 +3 -2 +314 -64 +24 -11 +4 -1 +42 -10 +2 -2 +20 -31 +91 -23 +4 -1 +4 -3 +20 -25 +15 -4 +25 -7 +1 -1 +118 -32 +122 -74 +184 -61 +55 -18 +2 +2 +1979 -318 +2 -2 +4 +15 -3 +5 -2 +15 +48 -11 +2 -2 +13493 -11204 +1028 -811 +50 -63 +22 -20 +6 +490 -168 +99 +8 +207 -60 +12 -10 +2 -2 +9 +2 -2 +25 -9 +238 -77 +97 -42 +1 -1 +11 -8 +52 -49 +78 -21 +86 -27 +47 -19 +6 -6 +53 +156 -1 +870 -283 +338 -35 -325 +201 -66 +1 -1 +2 -2 +79 -82 +23 -5 +7 -1 +18 +4 -4 +2 -2 +1 -1 +72 +51 -22 +79 +6 -6 +1 -1 +5 -5 +32 -2 +10 +164 +9 -6 +2 +64 -33 +3 -2 +11 -10 +8 -5 +288 -288 +6 +5 -1 +72 +3 -6 +38 -21 +97 -36 +81 -24 +141 -50 +141 -50 +66 -22 -4 +11 -2 +2 -2 +1 -1 +38 -2 +121 -87 +54 -1 +3 -3 +5 -5 +11 -3 +2 -2 +153 -7 +67 -28 +2 -1 +2 -2 +3 +214 -83 +157 -60 +99 -54 +32 -44 +3 -1 +30 +2 -2 +46 -32 +143 +199 -134 +5 -6 +3 -3 +3 -3 +109 +48 -30 +72 +122 +461 -383 +52 -40 +339 -293 +22 -73 +22 +160 +8 +86 +45 +36 +44 +53 +53 +92 +22 +59 +7 +136 +214 +142 +32 +301 +332 +10 +38 +208 +102 +2 -2 +7 -7 +38 -16 +10 -3 +24 -3 +15 -2 +4 -4 +12 -10 +91 -67 +15 -15 +11 +3 +6 +5 -9 +38 -6 +26 -4 +5 +247 +5 +1 -1 +6 -4 +36 -13 +7 +60 -17 +3 -3 +1 +26 -35 +4 -4 +6 -3 +3 -2
~ CMakeLists.txt + CMakeLists.txt ~ Makefile.classic ~ Makefile.in ~ Makefile.osx-jaguar ~ VERSION ~ auto.def ~ skins/README.md ~ skins/ardoise/css.txt ~ skins/blitz/ticket.txt ~ skins/blitz_no_logo/ticket.txt ~ skins/bootstrap/header.txt ~ skins/default/css.txt ~ skins/default/header.txt ~ skins/eagle/css.txt ~ src/accordion.js ~ src/add.c ~ src/ajax.c ~ src/alerts.c ~ src/allrepo.c ~ src/attach.c ~ src/backlink.c ~ src/backoffice.c ~ src/bisect.c ~ src/blob.c ~ src/branch.c ~ src/browse.c ~ src/builtin.c ~ src/bundle.c ~ src/capabilities.c ~ src/captcha.c ~ src/cgi.c ~ src/checkin.c ~ src/checkout.c ~ src/clone.c ~ src/codecheck1.c ~ src/comformat.c ~ src/config.h ~ src/configure.c ~ src/content.c ~ src/cookies.c ~ src/db.c ~ src/default.css + src/default.css - src/default_css.txt ~ src/descendants.c ~ src/diff.c ~ src/diffcmd.c ~ src/dispatch.c ~ src/doc.c ~ src/encode.c ~ src/etag.c ~ src/event.c ~ src/export.c ~ src/file.c ~ src/fileedit.c ~ src/finfo.c ~ src/forum.c ~ src/forum.js ~ src/fossil.bootstrap.js ~ src/fossil.confirmer.js ~ src/fossil.dom.js ~ src/fossil.fetch.js ~ src/fossil.page.fileedit.js ~ src/fossil.page.forumpost.js ~ src/fossil.page.wikiedit.js ~ src/fossil.storage.js ~ src/fossil.tabs.js ~ src/fshell.c ~ src/fusefs.c ~ src/glob.c ~ src/graph.c ~ src/graph.js ~ src/hook.c ~ src/http.c ~ src/http_ssl.c ~ src/http_transport.c ~ src/import.c ~ src/info.c ~ src/json.c ~ src/json_artifact.c ~ src/json_branch.c ~ src/json_config.c ~ src/json_finfo.c ~ src/json_login.c ~ src/json_tag.c ~ src/json_timeline.c ~ src/leaf.c ~ src/login.c ~ src/main.c ~ src/main.mk ~ src/makeheaders.c ~ src/makemake.tcl ~ src/makemake.tcl ~ src/manifest.c ~ src/markdown.c ~ src/markdown.md ~ src/markdown_html.c ~ src/merge.c ~ src/merge3.c ~ src/mkbuiltin.c - src/mkcss.c ~ src/mkindex.c ~ src/mkversion.c ~ src/moderate.c ~ src/name.c ~ src/path.c ~ src/piechart.c ~ src/printf.c ~ src/publish.c ~ src/purge.c ~ src/rebuild.c ~ src/repolist.c ~ src/report.c ~ src/rss.c ~ src/sbsdiff.js ~ src/schema.c ~ src/scroll.js ~ src/search.c ~ src/security_audit.c ~ src/setup.c ~ src/setupuser.c ~ src/sha1.c ~ src/sha3.c ~ src/shell.c ~ src/shun.c ~ src/sitemap.c ~ src/skins.c ~ src/smtp.c ~ src/sounds/0.wav ~ src/sounds/1.wav ~ src/sounds/2.wav ~ src/sounds/3.wav ~ src/sounds/4.wav ~ src/sounds/5.wav ~ src/sounds/6.wav ~ src/sounds/7.wav ~ src/sounds/8.wav ~ src/sounds/9.wav ~ src/sounds/README.md ~ src/sounds/a.wav ~ src/sounds/b.wav ~ src/sounds/c.wav ~ src/sounds/d.wav ~ src/sounds/e.wav ~ src/sounds/f.wav ~ src/sqlcmd.c ~ src/sqlcompattest.c ~ src/sqlite3.c ~ src/sqlite3.h ~ src/stash.c ~ src/stat.c ~ src/style.admin_log.css ~ src/style.c ~ src/style.fileedit.css ~ src/style.wikiedit.css ~ src/sync.c ~ src/tag.c ~ src/tar.c ~ src/terminal.c ~ src/th.c ~ src/th_main.c ~ src/timeline.c ~ src/tkt.c ~ src/tktsetup.c ~ src/undo.c ~ src/unicode.c ~ src/unversioned.c ~ src/update.c ~ src/url.c ~ src/user.c ~ src/utf8.c ~ src/util.c ~ src/wiki.c ~ src/wikiformat.c - src/wysiwyg.c ~ src/xfer.c ~ src/xfersetup.c ~ src/zip.c ~ test/amend.test ~ test/cmdline.test ~ test/commit-warning.test ~ test/csp1.html ~ test/diff.test ~ test/fake-editor.tcl ~ test/fileStat.th1 ~ test/graph-test-2.md ~ test/json.test ~ test/markdown-test2.md ~ test/merge1.test ~ test/merge3.test ~ test/merge4.test ~ test/mv-rm.test ~ test/release-checklist.wiki ~ test/revert.test ~ test/set-manifest.test ~ test/subdir with spaces/filename with spaces.txt ~ test/tester.tcl ~ test/th1-hooks.test ~ test/th1.test ~ test/unversioned.test ~ test/utf.test ~ test/wiki.test ~ tools/email-monitor.tcl ~ tools/email-sender.tcl ~ tools/encode_math.sh ~ tools/fossil-autocomplete.bash ~ tools/fossil-diff-log ~ tools/fossil-stress.tcl ~ tools/fossil_chat.tcl ~ win/Makefile.PellesCGMake ~ win/Makefile.dmc ~ win/Makefile.mingw ~ win/Makefile.mingw.mistachkin ~ win/Makefile.msc ~ win/Makefile.msc ~ win/buildmsvc.bat ~ win/fossil.rc ~ www/adding_code.wiki ~ www/alerts.md ~ www/antibot.wiki ~ www/backoffice.md ~ www/branching.wiki ~ www/build.wiki ~ www/caps/admin-v-setup.md ~ www/caps/index.md ~ www/caps/ref.html ~ www/cgi.wiki ~ www/changes.wiki ~ www/checkin_names.wiki ~ www/chroot.md ~ www/concepts.wiki ~ www/css-tricks.md ~ www/customskin.md ~ www/defcsp.md ~ www/embeddeddoc.wiki ~ www/env-opts.md ~ www/faq.wiki ~ www/fileedit-page.md ~ www/fiveminutes.wiki ~ www/fossil-v-git.wiki ~ www/gitusers.md ~ www/globs.md ~ www/grep.md ~ www/hacker-howto.wiki ~ www/hacker-howto.wiki ~ www/hashes.md ~ www/hashpolicy.wiki ~ www/history.md ~ www/hooks.md ~ www/image-format-vs-repo-size.ipynb ~ www/image-format-vs-repo-size.md ~ www/image-format-vs-repo-size.svg ~ www/index.wiki ~ www/json-api/_template.md ~ www/json-api/api-artifact.md ~ www/json-api/api-auth.md ~ www/json-api/api-branch.md ~ www/json-api/api-checkout.md ~ www/json-api/api-config.md ~ www/json-api/api-diff.md ~ www/json-api/api-dir.md ~ www/json-api/api-finfo.md ~ www/json-api/api-misc.md ~ www/json-api/api-query.md ~ www/json-api/api-stat.md ~ www/json-api/api-tag.md ~ www/json-api/api-ticket.md ~ www/json-api/api-timeline.md ~ www/json-api/api-user.md ~ www/json-api/api-version.md ~ www/json-api/api-wiki.md ~ www/json-api/conventions.md ~ www/json-api/hacking.md ~ www/json-api/index.md ~ www/json-api/intro.md ~ www/json-api/tips.md ~ www/loadmgmt.md ~ www/mdtest/test1.md ~ www/mirrorlimitations.md ~ www/mkindex.tcl ~ www/permutedindex.html ~ www/private.wiki ~ www/qandc.wiki ~ www/quickstart.wiki ~ www/rebaseharm.md ~ www/selfcheck.wiki ~ www/server/any/index.md ~ www/server/any/scgi.md ~ www/server/debian/index.md ~ www/server/debian/nginx.md ~ www/server/debian/service.md ~ www/server/index.html ~ www/server/macos/index.md ~ www/server/openbsd/fastcgi.md ~ www/server/openbsd/index.md ~ www/server/whyuseaserver.wiki ~ www/serverext.wiki ~ www/ssl.wiki ~ www/sync.wiki ~ www/tech_overview.wiki ~ www/th1.md ~ www/userlinks.wiki ~ www/webpage-ex.md ~ www/webui.wiki ~ www/whyusefossil.wiki ~ www/wikitheory.wiki
+16 -14
--- CMakeLists.txt
+++ CMakeLists.txt
@@ -82,10 +82,11 @@
8282
)
8383
8484
file(GLOB project_sources_FILES
8585
"auto.def"
8686
"configure"
87
+ "Makefile.in"
8788
8889
"fossil.1"
8990
"manifest.uuid"
9091
"VERSION"
9192
@@ -151,19 +152,31 @@
151152
152153
separate_arguments(fossil_configure_FLAGS)
153154
separate_arguments(fossil_build_FLAGS)
154155
155156
if(MSVC)
156
- file(RELATIVE_PATH fossil_DESTDIR "${fossil_BINARY_DIR}" "${fossil_EXE_DIR}")
157
+ file(RELATIVE_PATH fossil_DESTDIR "${fossil_BUILD_DIR}" "${fossil_EXE_DIR}")
157158
file(TO_NATIVE_PATH "${fossil_DESTDIR}" fossil_DESTDIR)
158159
160
+ ## Work around the suprisingly obstinate "simplification" of buildmsvc.bat
161
+ ## which mandates the use of BUILDDIR env variable to be able to build
162
+ ## out-of-source, instead of inferring the path automatically from the
163
+ ## current work directory, as it's commonly done.
164
+ ##
165
+ ## Create a wrapper which defines BUILDDIR then starts the build.
166
+
167
+ file(TO_NATIVE_PATH "${fossil_BUILD_DIR}" fossil_BUILD_DIR_WIN)
168
+ file(TO_NATIVE_PATH "${fossil_SOURCE_DIR}/win/buildmsvc.bat" fossil_BUILDMSVC)
169
+ file(WRITE "${fossil_BINARY_DIR}/build.cmd"
170
+ "set \"BUILDDIR=${fossil_BUILD_DIR_WIN}\"\n\"${fossil_BUILDMSVC}\" %*\n")
171
+
159172
ExternalProject_Add(fossil
160173
PREFIX fossil
161174
SOURCE_DIR "${fossil_SOURCE_DIR}"
162175
CONFIGURE_COMMAND ""
163176
BINARY_DIR "${fossil_BINARY_DIR}"
164
- BUILD_COMMAND "${fossil_SOURCE_DIR}/win/buildmsvc.bat"
177
+ BUILD_COMMAND "${fossil_BINARY_DIR}/build.cmd"
165178
${fossil_configure_FLAGS}
166179
${fossil_build_FLAGS}
167180
all
168181
install DESTDIR=${fossil_DESTDIR}
169182
VERBATIM
@@ -280,16 +293,12 @@
280293
WORKING_DIRECTORY "${fossil_BINARY_DIR}"
281294
COMMENT "Copying data for test-fossil"
282295
VERBATIM
283296
)
284297
add_custom_command(TARGET test-fossil-setup POST_BUILD
285
- COMMAND "${fossil_EXE}" new "${fossil_BINARY_DIR}/test-fossil.fsl"
286
- --admin-user testuser
287
- COMMAND "${fossil_EXE}" open "${fossil_BINARY_DIR}/test-fossil.fsl"
288
- COMMAND "${fossil_EXE}" user default testuser --user testuser
289298
WORKING_DIRECTORY "${fossil_TEST_DIR}"
290
- COMMENT "Setting up repository for test-fossil"
299
+ COMMENT "Setting up test-fossil"
291300
VERBATIM
292301
)
293302
294303
295304
# Run the test suite.
@@ -321,16 +330,10 @@
321330
322331
add_custom_target(test-fossil-clean
323332
COMMENT "Tearing down test-fossil"
324333
DEPENDS fossil-install
325334
)
326
-add_custom_command(TARGET test-fossil-clean PRE_BUILD
327
- COMMAND "${CMAKE_COMMAND}" -E remove "${fossil_BINARY_DIR}/test-fossil.fsl"
328
- WORKING_DIRECTORY "${fossil_TEST_DIR}"
329
- COMMENT "Removing repository for test-fossil"
330
- VERBATIM
331
-)
332335
add_custom_command(TARGET test-fossil-clean POST_BUILD
333336
COMMAND "${CMAKE_COMMAND}" -E remove_directory "${fossil_TEST_DIR}"
334337
WORKING_DIRECTORY "${fossil_BINARY_DIR}"
335338
COMMENT "Removing data for test-fossil"
336339
VERBATIM
@@ -362,14 +365,13 @@
362365
set_property(TEST 03-clean APPEND PROPERTY
363366
DEPENDS 01-setup)
364367
365368
add_custom_target(check
366369
COMMAND "${CMAKE_CTEST_COMMAND}" -V
367
- DEPENDS test-fossil
368370
)
369371
370372
## INSTALL ---------------------------------------------------------------
371373
##
372374
install(DIRECTORY ${fossil_EXE_DIR}/
373375
DESTINATION ${CMAKE_INSTALL_PREFIX}/bin/
374376
USE_SOURCE_PERMISSIONS
375377
)
376378
--- CMakeLists.txt
+++ CMakeLists.txt
@@ -82,10 +82,11 @@
82 )
83
84 file(GLOB project_sources_FILES
85 "auto.def"
86 "configure"
 
87
88 "fossil.1"
89 "manifest.uuid"
90 "VERSION"
91
@@ -151,19 +152,31 @@
151
152 separate_arguments(fossil_configure_FLAGS)
153 separate_arguments(fossil_build_FLAGS)
154
155 if(MSVC)
156 file(RELATIVE_PATH fossil_DESTDIR "${fossil_BINARY_DIR}" "${fossil_EXE_DIR}")
157 file(TO_NATIVE_PATH "${fossil_DESTDIR}" fossil_DESTDIR)
158
 
 
 
 
 
 
 
 
 
 
 
 
159 ExternalProject_Add(fossil
160 PREFIX fossil
161 SOURCE_DIR "${fossil_SOURCE_DIR}"
162 CONFIGURE_COMMAND ""
163 BINARY_DIR "${fossil_BINARY_DIR}"
164 BUILD_COMMAND "${fossil_SOURCE_DIR}/win/buildmsvc.bat"
165 ${fossil_configure_FLAGS}
166 ${fossil_build_FLAGS}
167 all
168 install DESTDIR=${fossil_DESTDIR}
169 VERBATIM
@@ -280,16 +293,12 @@
280 WORKING_DIRECTORY "${fossil_BINARY_DIR}"
281 COMMENT "Copying data for test-fossil"
282 VERBATIM
283 )
284 add_custom_command(TARGET test-fossil-setup POST_BUILD
285 COMMAND "${fossil_EXE}" new "${fossil_BINARY_DIR}/test-fossil.fsl"
286 --admin-user testuser
287 COMMAND "${fossil_EXE}" open "${fossil_BINARY_DIR}/test-fossil.fsl"
288 COMMAND "${fossil_EXE}" user default testuser --user testuser
289 WORKING_DIRECTORY "${fossil_TEST_DIR}"
290 COMMENT "Setting up repository for test-fossil"
291 VERBATIM
292 )
293
294
295 # Run the test suite.
@@ -321,16 +330,10 @@
321
322 add_custom_target(test-fossil-clean
323 COMMENT "Tearing down test-fossil"
324 DEPENDS fossil-install
325 )
326 add_custom_command(TARGET test-fossil-clean PRE_BUILD
327 COMMAND "${CMAKE_COMMAND}" -E remove "${fossil_BINARY_DIR}/test-fossil.fsl"
328 WORKING_DIRECTORY "${fossil_TEST_DIR}"
329 COMMENT "Removing repository for test-fossil"
330 VERBATIM
331 )
332 add_custom_command(TARGET test-fossil-clean POST_BUILD
333 COMMAND "${CMAKE_COMMAND}" -E remove_directory "${fossil_TEST_DIR}"
334 WORKING_DIRECTORY "${fossil_BINARY_DIR}"
335 COMMENT "Removing data for test-fossil"
336 VERBATIM
@@ -362,14 +365,13 @@
362 set_property(TEST 03-clean APPEND PROPERTY
363 DEPENDS 01-setup)
364
365 add_custom_target(check
366 COMMAND "${CMAKE_CTEST_COMMAND}" -V
367 DEPENDS test-fossil
368 )
369
370 ## INSTALL ---------------------------------------------------------------
371 ##
372 install(DIRECTORY ${fossil_EXE_DIR}/
373 DESTINATION ${CMAKE_INSTALL_PREFIX}/bin/
374 USE_SOURCE_PERMISSIONS
375 )
376
--- CMakeLists.txt
+++ CMakeLists.txt
@@ -82,10 +82,11 @@
82 )
83
84 file(GLOB project_sources_FILES
85 "auto.def"
86 "configure"
87 "Makefile.in"
88
89 "fossil.1"
90 "manifest.uuid"
91 "VERSION"
92
@@ -151,19 +152,31 @@
152
153 separate_arguments(fossil_configure_FLAGS)
154 separate_arguments(fossil_build_FLAGS)
155
156 if(MSVC)
157 file(RELATIVE_PATH fossil_DESTDIR "${fossil_BUILD_DIR}" "${fossil_EXE_DIR}")
158 file(TO_NATIVE_PATH "${fossil_DESTDIR}" fossil_DESTDIR)
159
160 ## Work around the suprisingly obstinate "simplification" of buildmsvc.bat
161 ## which mandates the use of BUILDDIR env variable to be able to build
162 ## out-of-source, instead of inferring the path automatically from the
163 ## current work directory, as it's commonly done.
164 ##
165 ## Create a wrapper which defines BUILDDIR then starts the build.
166
167 file(TO_NATIVE_PATH "${fossil_BUILD_DIR}" fossil_BUILD_DIR_WIN)
168 file(TO_NATIVE_PATH "${fossil_SOURCE_DIR}/win/buildmsvc.bat" fossil_BUILDMSVC)
169 file(WRITE "${fossil_BINARY_DIR}/build.cmd"
170 "set \"BUILDDIR=${fossil_BUILD_DIR_WIN}\"\n\"${fossil_BUILDMSVC}\" %*\n")
171
172 ExternalProject_Add(fossil
173 PREFIX fossil
174 SOURCE_DIR "${fossil_SOURCE_DIR}"
175 CONFIGURE_COMMAND ""
176 BINARY_DIR "${fossil_BINARY_DIR}"
177 BUILD_COMMAND "${fossil_BINARY_DIR}/build.cmd"
178 ${fossil_configure_FLAGS}
179 ${fossil_build_FLAGS}
180 all
181 install DESTDIR=${fossil_DESTDIR}
182 VERBATIM
@@ -280,16 +293,12 @@
293 WORKING_DIRECTORY "${fossil_BINARY_DIR}"
294 COMMENT "Copying data for test-fossil"
295 VERBATIM
296 )
297 add_custom_command(TARGET test-fossil-setup POST_BUILD
 
 
 
 
298 WORKING_DIRECTORY "${fossil_TEST_DIR}"
299 COMMENT "Setting up test-fossil"
300 VERBATIM
301 )
302
303
304 # Run the test suite.
@@ -321,16 +330,10 @@
330
331 add_custom_target(test-fossil-clean
332 COMMENT "Tearing down test-fossil"
333 DEPENDS fossil-install
334 )
 
 
 
 
 
 
335 add_custom_command(TARGET test-fossil-clean POST_BUILD
336 COMMAND "${CMAKE_COMMAND}" -E remove_directory "${fossil_TEST_DIR}"
337 WORKING_DIRECTORY "${fossil_BINARY_DIR}"
338 COMMENT "Removing data for test-fossil"
339 VERBATIM
@@ -362,14 +365,13 @@
365 set_property(TEST 03-clean APPEND PROPERTY
366 DEPENDS 01-setup)
367
368 add_custom_target(check
369 COMMAND "${CMAKE_CTEST_COMMAND}" -V
 
370 )
371
372 ## INSTALL ---------------------------------------------------------------
373 ##
374 install(DIRECTORY ${fossil_EXE_DIR}/
375 DESTINATION ${CMAKE_INSTALL_PREFIX}/bin/
376 USE_SOURCE_PERMISSIONS
377 )
378
+16 -14
--- CMakeLists.txt
+++ CMakeLists.txt
@@ -82,10 +82,11 @@
8282
)
8383
8484
file(GLOB project_sources_FILES
8585
"auto.def"
8686
"configure"
87
+ "Makefile.in"
8788
8889
"fossil.1"
8990
"manifest.uuid"
9091
"VERSION"
9192
@@ -151,19 +152,31 @@
151152
152153
separate_arguments(fossil_configure_FLAGS)
153154
separate_arguments(fossil_build_FLAGS)
154155
155156
if(MSVC)
156
- file(RELATIVE_PATH fossil_DESTDIR "${fossil_BINARY_DIR}" "${fossil_EXE_DIR}")
157
+ file(RELATIVE_PATH fossil_DESTDIR "${fossil_BUILD_DIR}" "${fossil_EXE_DIR}")
157158
file(TO_NATIVE_PATH "${fossil_DESTDIR}" fossil_DESTDIR)
158159
160
+ ## Work around the suprisingly obstinate "simplification" of buildmsvc.bat
161
+ ## which mandates the use of BUILDDIR env variable to be able to build
162
+ ## out-of-source, instead of inferring the path automatically from the
163
+ ## current work directory, as it's commonly done.
164
+ ##
165
+ ## Create a wrapper which defines BUILDDIR then starts the build.
166
+
167
+ file(TO_NATIVE_PATH "${fossil_BUILD_DIR}" fossil_BUILD_DIR_WIN)
168
+ file(TO_NATIVE_PATH "${fossil_SOURCE_DIR}/win/buildmsvc.bat" fossil_BUILDMSVC)
169
+ file(WRITE "${fossil_BINARY_DIR}/build.cmd"
170
+ "set \"BUILDDIR=${fossil_BUILD_DIR_WIN}\"\n\"${fossil_BUILDMSVC}\" %*\n")
171
+
159172
ExternalProject_Add(fossil
160173
PREFIX fossil
161174
SOURCE_DIR "${fossil_SOURCE_DIR}"
162175
CONFIGURE_COMMAND ""
163176
BINARY_DIR "${fossil_BINARY_DIR}"
164
- BUILD_COMMAND "${fossil_SOURCE_DIR}/win/buildmsvc.bat"
177
+ BUILD_COMMAND "${fossil_BINARY_DIR}/build.cmd"
165178
${fossil_configure_FLAGS}
166179
${fossil_build_FLAGS}
167180
all
168181
install DESTDIR=${fossil_DESTDIR}
169182
VERBATIM
@@ -280,16 +293,12 @@
280293
WORKING_DIRECTORY "${fossil_BINARY_DIR}"
281294
COMMENT "Copying data for test-fossil"
282295
VERBATIM
283296
)
284297
add_custom_command(TARGET test-fossil-setup POST_BUILD
285
- COMMAND "${fossil_EXE}" new "${fossil_BINARY_DIR}/test-fossil.fsl"
286
- --admin-user testuser
287
- COMMAND "${fossil_EXE}" open "${fossil_BINARY_DIR}/test-fossil.fsl"
288
- COMMAND "${fossil_EXE}" user default testuser --user testuser
289298
WORKING_DIRECTORY "${fossil_TEST_DIR}"
290
- COMMENT "Setting up repository for test-fossil"
299
+ COMMENT "Setting up test-fossil"
291300
VERBATIM
292301
)
293302
294303
295304
# Run the test suite.
@@ -321,16 +330,10 @@
321330
322331
add_custom_target(test-fossil-clean
323332
COMMENT "Tearing down test-fossil"
324333
DEPENDS fossil-install
325334
)
326
-add_custom_command(TARGET test-fossil-clean PRE_BUILD
327
- COMMAND "${CMAKE_COMMAND}" -E remove "${fossil_BINARY_DIR}/test-fossil.fsl"
328
- WORKING_DIRECTORY "${fossil_TEST_DIR}"
329
- COMMENT "Removing repository for test-fossil"
330
- VERBATIM
331
-)
332335
add_custom_command(TARGET test-fossil-clean POST_BUILD
333336
COMMAND "${CMAKE_COMMAND}" -E remove_directory "${fossil_TEST_DIR}"
334337
WORKING_DIRECTORY "${fossil_BINARY_DIR}"
335338
COMMENT "Removing data for test-fossil"
336339
VERBATIM
@@ -362,14 +365,13 @@
362365
set_property(TEST 03-clean APPEND PROPERTY
363366
DEPENDS 01-setup)
364367
365368
add_custom_target(check
366369
COMMAND "${CMAKE_CTEST_COMMAND}" -V
367
- DEPENDS test-fossil
368370
)
369371
370372
## INSTALL ---------------------------------------------------------------
371373
##
372374
install(DIRECTORY ${fossil_EXE_DIR}/
373375
DESTINATION ${CMAKE_INSTALL_PREFIX}/bin/
374376
USE_SOURCE_PERMISSIONS
375377
)
376378
--- CMakeLists.txt
+++ CMakeLists.txt
@@ -82,10 +82,11 @@
82 )
83
84 file(GLOB project_sources_FILES
85 "auto.def"
86 "configure"
 
87
88 "fossil.1"
89 "manifest.uuid"
90 "VERSION"
91
@@ -151,19 +152,31 @@
151
152 separate_arguments(fossil_configure_FLAGS)
153 separate_arguments(fossil_build_FLAGS)
154
155 if(MSVC)
156 file(RELATIVE_PATH fossil_DESTDIR "${fossil_BINARY_DIR}" "${fossil_EXE_DIR}")
157 file(TO_NATIVE_PATH "${fossil_DESTDIR}" fossil_DESTDIR)
158
 
 
 
 
 
 
 
 
 
 
 
 
159 ExternalProject_Add(fossil
160 PREFIX fossil
161 SOURCE_DIR "${fossil_SOURCE_DIR}"
162 CONFIGURE_COMMAND ""
163 BINARY_DIR "${fossil_BINARY_DIR}"
164 BUILD_COMMAND "${fossil_SOURCE_DIR}/win/buildmsvc.bat"
165 ${fossil_configure_FLAGS}
166 ${fossil_build_FLAGS}
167 all
168 install DESTDIR=${fossil_DESTDIR}
169 VERBATIM
@@ -280,16 +293,12 @@
280 WORKING_DIRECTORY "${fossil_BINARY_DIR}"
281 COMMENT "Copying data for test-fossil"
282 VERBATIM
283 )
284 add_custom_command(TARGET test-fossil-setup POST_BUILD
285 COMMAND "${fossil_EXE}" new "${fossil_BINARY_DIR}/test-fossil.fsl"
286 --admin-user testuser
287 COMMAND "${fossil_EXE}" open "${fossil_BINARY_DIR}/test-fossil.fsl"
288 COMMAND "${fossil_EXE}" user default testuser --user testuser
289 WORKING_DIRECTORY "${fossil_TEST_DIR}"
290 COMMENT "Setting up repository for test-fossil"
291 VERBATIM
292 )
293
294
295 # Run the test suite.
@@ -321,16 +330,10 @@
321
322 add_custom_target(test-fossil-clean
323 COMMENT "Tearing down test-fossil"
324 DEPENDS fossil-install
325 )
326 add_custom_command(TARGET test-fossil-clean PRE_BUILD
327 COMMAND "${CMAKE_COMMAND}" -E remove "${fossil_BINARY_DIR}/test-fossil.fsl"
328 WORKING_DIRECTORY "${fossil_TEST_DIR}"
329 COMMENT "Removing repository for test-fossil"
330 VERBATIM
331 )
332 add_custom_command(TARGET test-fossil-clean POST_BUILD
333 COMMAND "${CMAKE_COMMAND}" -E remove_directory "${fossil_TEST_DIR}"
334 WORKING_DIRECTORY "${fossil_BINARY_DIR}"
335 COMMENT "Removing data for test-fossil"
336 VERBATIM
@@ -362,14 +365,13 @@
362 set_property(TEST 03-clean APPEND PROPERTY
363 DEPENDS 01-setup)
364
365 add_custom_target(check
366 COMMAND "${CMAKE_CTEST_COMMAND}" -V
367 DEPENDS test-fossil
368 )
369
370 ## INSTALL ---------------------------------------------------------------
371 ##
372 install(DIRECTORY ${fossil_EXE_DIR}/
373 DESTINATION ${CMAKE_INSTALL_PREFIX}/bin/
374 USE_SOURCE_PERMISSIONS
375 )
376
--- CMakeLists.txt
+++ CMakeLists.txt
@@ -82,10 +82,11 @@
82 )
83
84 file(GLOB project_sources_FILES
85 "auto.def"
86 "configure"
87 "Makefile.in"
88
89 "fossil.1"
90 "manifest.uuid"
91 "VERSION"
92
@@ -151,19 +152,31 @@
152
153 separate_arguments(fossil_configure_FLAGS)
154 separate_arguments(fossil_build_FLAGS)
155
156 if(MSVC)
157 file(RELATIVE_PATH fossil_DESTDIR "${fossil_BUILD_DIR}" "${fossil_EXE_DIR}")
158 file(TO_NATIVE_PATH "${fossil_DESTDIR}" fossil_DESTDIR)
159
160 ## Work around the suprisingly obstinate "simplification" of buildmsvc.bat
161 ## which mandates the use of BUILDDIR env variable to be able to build
162 ## out-of-source, instead of inferring the path automatically from the
163 ## current work directory, as it's commonly done.
164 ##
165 ## Create a wrapper which defines BUILDDIR then starts the build.
166
167 file(TO_NATIVE_PATH "${fossil_BUILD_DIR}" fossil_BUILD_DIR_WIN)
168 file(TO_NATIVE_PATH "${fossil_SOURCE_DIR}/win/buildmsvc.bat" fossil_BUILDMSVC)
169 file(WRITE "${fossil_BINARY_DIR}/build.cmd"
170 "set \"BUILDDIR=${fossil_BUILD_DIR_WIN}\"\n\"${fossil_BUILDMSVC}\" %*\n")
171
172 ExternalProject_Add(fossil
173 PREFIX fossil
174 SOURCE_DIR "${fossil_SOURCE_DIR}"
175 CONFIGURE_COMMAND ""
176 BINARY_DIR "${fossil_BINARY_DIR}"
177 BUILD_COMMAND "${fossil_BINARY_DIR}/build.cmd"
178 ${fossil_configure_FLAGS}
179 ${fossil_build_FLAGS}
180 all
181 install DESTDIR=${fossil_DESTDIR}
182 VERBATIM
@@ -280,16 +293,12 @@
293 WORKING_DIRECTORY "${fossil_BINARY_DIR}"
294 COMMENT "Copying data for test-fossil"
295 VERBATIM
296 )
297 add_custom_command(TARGET test-fossil-setup POST_BUILD
 
 
 
 
298 WORKING_DIRECTORY "${fossil_TEST_DIR}"
299 COMMENT "Setting up test-fossil"
300 VERBATIM
301 )
302
303
304 # Run the test suite.
@@ -321,16 +330,10 @@
330
331 add_custom_target(test-fossil-clean
332 COMMENT "Tearing down test-fossil"
333 DEPENDS fossil-install
334 )
 
 
 
 
 
 
335 add_custom_command(TARGET test-fossil-clean POST_BUILD
336 COMMAND "${CMAKE_COMMAND}" -E remove_directory "${fossil_TEST_DIR}"
337 WORKING_DIRECTORY "${fossil_BINARY_DIR}"
338 COMMENT "Removing data for test-fossil"
339 VERBATIM
@@ -362,14 +365,13 @@
365 set_property(TEST 03-clean APPEND PROPERTY
366 DEPENDS 01-setup)
367
368 add_custom_target(check
369 COMMAND "${CMAKE_CTEST_COMMAND}" -V
 
370 )
371
372 ## INSTALL ---------------------------------------------------------------
373 ##
374 install(DIRECTORY ${fossil_EXE_DIR}/
375 DESTINATION ${CMAKE_INSTALL_PREFIX}/bin/
376 USE_SOURCE_PERMISSIONS
377 )
378
--- Makefile.classic
+++ Makefile.classic
@@ -43,13 +43,10 @@
4343
# TCC += -DFOSSIL_ENABLE_MINIZ
4444
4545
# To add support for HTTPS
4646
TCC += -DFOSSIL_ENABLE_SSL
4747
48
-# To enable legacy mv/rm support
49
-TCC += -DFOSSIL_ENABLE_LEGACY_MV_RM=1
50
-
5148
#### We sometimes add the -static option here so that we can build a
5249
# static executable that will run in a chroot jail.
5350
#LIB = -static
5451
TCC += -DFOSSIL_DYNAMIC_BUILD=1
5552
@@ -99,7 +96,9 @@
9996
TCC.DragonFly += -DUSE_PREAD
10097
TCC.FreeBSD += -DUSE_PREAD
10198
TCC.NetBSD += -DUSE_PREAD
10299
TCC.OpenBSD += -DUSE_PREAD
103100
TCC += $(TCC.$(HOST_OS))
101
+
102
+APPNAME = fossil$(E)
104103
105104
include $(SRCDIR)/main.mk
106105
--- Makefile.classic
+++ Makefile.classic
@@ -43,13 +43,10 @@
43 # TCC += -DFOSSIL_ENABLE_MINIZ
44
45 # To add support for HTTPS
46 TCC += -DFOSSIL_ENABLE_SSL
47
48 # To enable legacy mv/rm support
49 TCC += -DFOSSIL_ENABLE_LEGACY_MV_RM=1
50
51 #### We sometimes add the -static option here so that we can build a
52 # static executable that will run in a chroot jail.
53 #LIB = -static
54 TCC += -DFOSSIL_DYNAMIC_BUILD=1
55
@@ -99,7 +96,9 @@
99 TCC.DragonFly += -DUSE_PREAD
100 TCC.FreeBSD += -DUSE_PREAD
101 TCC.NetBSD += -DUSE_PREAD
102 TCC.OpenBSD += -DUSE_PREAD
103 TCC += $(TCC.$(HOST_OS))
 
 
104
105 include $(SRCDIR)/main.mk
106
--- Makefile.classic
+++ Makefile.classic
@@ -43,13 +43,10 @@
43 # TCC += -DFOSSIL_ENABLE_MINIZ
44
45 # To add support for HTTPS
46 TCC += -DFOSSIL_ENABLE_SSL
47
 
 
 
48 #### We sometimes add the -static option here so that we can build a
49 # static executable that will run in a chroot jail.
50 #LIB = -static
51 TCC += -DFOSSIL_DYNAMIC_BUILD=1
52
@@ -99,7 +96,9 @@
96 TCC.DragonFly += -DUSE_PREAD
97 TCC.FreeBSD += -DUSE_PREAD
98 TCC.NetBSD += -DUSE_PREAD
99 TCC.OpenBSD += -DUSE_PREAD
100 TCC += $(TCC.$(HOST_OS))
101
102 APPNAME = fossil$(E)
103
104 include $(SRCDIR)/main.mk
105
--- Makefile.in
+++ Makefile.in
@@ -47,19 +47,26 @@
4747
USE_LINENOISE = @USE_LINENOISE@
4848
USE_MMAN_H = @USE_MMAN_H@
4949
USE_SEE = @USE_SEE@
5050
FOSSIL_ENABLE_MINIZ = @FOSSIL_ENABLE_MINIZ@
5151
APPNAME = fossil
52
+
53
+.PHONY: all tags
5254
5355
include $(SRCDIR)/main.mk
5456
5557
distclean: clean
5658
-rm -f autoconfig.h config.log Makefile
59
+ -rm -f cscope.out tags
5760
5861
reconfig:
5962
@AUTOREMAKE@
6063
64
+tags:
65
+ ctags -R @srcdir@/src
66
+ @COLLECT_CSCOPE_DATA@
67
+
6168
# Automatically reconfigure whenever an autosetup file or one of the
6269
# make source files change.
6370
#
6471
# The "touch" is necessary to avoid a make loop due to a new upstream
6572
# feature in autosetup (GH 0a71e3c3b7) which rewrites *.in outputs only
6673
--- Makefile.in
+++ Makefile.in
@@ -47,19 +47,26 @@
47 USE_LINENOISE = @USE_LINENOISE@
48 USE_MMAN_H = @USE_MMAN_H@
49 USE_SEE = @USE_SEE@
50 FOSSIL_ENABLE_MINIZ = @FOSSIL_ENABLE_MINIZ@
51 APPNAME = fossil
 
 
52
53 include $(SRCDIR)/main.mk
54
55 distclean: clean
56 -rm -f autoconfig.h config.log Makefile
 
57
58 reconfig:
59 @AUTOREMAKE@
60
 
 
 
 
61 # Automatically reconfigure whenever an autosetup file or one of the
62 # make source files change.
63 #
64 # The "touch" is necessary to avoid a make loop due to a new upstream
65 # feature in autosetup (GH 0a71e3c3b7) which rewrites *.in outputs only
66
--- Makefile.in
+++ Makefile.in
@@ -47,19 +47,26 @@
47 USE_LINENOISE = @USE_LINENOISE@
48 USE_MMAN_H = @USE_MMAN_H@
49 USE_SEE = @USE_SEE@
50 FOSSIL_ENABLE_MINIZ = @FOSSIL_ENABLE_MINIZ@
51 APPNAME = fossil
52
53 .PHONY: all tags
54
55 include $(SRCDIR)/main.mk
56
57 distclean: clean
58 -rm -f autoconfig.h config.log Makefile
59 -rm -f cscope.out tags
60
61 reconfig:
62 @AUTOREMAKE@
63
64 tags:
65 ctags -R @srcdir@/src
66 @COLLECT_CSCOPE_DATA@
67
68 # Automatically reconfigure whenever an autosetup file or one of the
69 # make source files change.
70 #
71 # The "touch" is necessary to avoid a make loop due to a new upstream
72 # feature in autosetup (GH 0a71e3c3b7) which rewrites *.in outputs only
73
--- Makefile.osx-jaguar
+++ Makefile.osx-jaguar
@@ -57,11 +57,10 @@
5757
TCC += -DSQLITE_WITHOUT_ZONEMALLOC
5858
TCC += -D_BSD_SOURCE=1
5959
TCC += -DWITHOUT_ICONV
6060
TCC += -Dsocklen_t=int
6161
TCC += -DSQLITE_MAX_MMAP_SIZE=0
62
-TCC += -DFOSSIL_ENABLE_LEGACY_MV_RM=1
6362
INSTALLDIR = $(DESTDIR)/usr/local/bin
6463
USE_SYSTEM_SQLITE =
6564
USE_LINENOISE = 1
6665
# FOSSIL_ENABLE_TCL = @FOSSIL_ENABLE_TCL@
6766
FOSSIL_ENABLE_TCL = 0
6867
--- Makefile.osx-jaguar
+++ Makefile.osx-jaguar
@@ -57,11 +57,10 @@
57 TCC += -DSQLITE_WITHOUT_ZONEMALLOC
58 TCC += -D_BSD_SOURCE=1
59 TCC += -DWITHOUT_ICONV
60 TCC += -Dsocklen_t=int
61 TCC += -DSQLITE_MAX_MMAP_SIZE=0
62 TCC += -DFOSSIL_ENABLE_LEGACY_MV_RM=1
63 INSTALLDIR = $(DESTDIR)/usr/local/bin
64 USE_SYSTEM_SQLITE =
65 USE_LINENOISE = 1
66 # FOSSIL_ENABLE_TCL = @FOSSIL_ENABLE_TCL@
67 FOSSIL_ENABLE_TCL = 0
68
--- Makefile.osx-jaguar
+++ Makefile.osx-jaguar
@@ -57,11 +57,10 @@
57 TCC += -DSQLITE_WITHOUT_ZONEMALLOC
58 TCC += -D_BSD_SOURCE=1
59 TCC += -DWITHOUT_ICONV
60 TCC += -Dsocklen_t=int
61 TCC += -DSQLITE_MAX_MMAP_SIZE=0
 
62 INSTALLDIR = $(DESTDIR)/usr/local/bin
63 USE_SYSTEM_SQLITE =
64 USE_LINENOISE = 1
65 # FOSSIL_ENABLE_TCL = @FOSSIL_ENABLE_TCL@
66 FOSSIL_ENABLE_TCL = 0
67
+1 -1
--- VERSION
+++ VERSION
@@ -1,1 +1,1 @@
1
-2.11
1
+2.12
22
--- VERSION
+++ VERSION
@@ -1,1 +1,1 @@
1 2.11
2
--- VERSION
+++ VERSION
@@ -1,1 +1,1 @@
1 2.12
2
+10 -10
--- auto.def
+++ auto.def
@@ -8,11 +8,10 @@
88
with-miniz=0 => {Use miniz from the source tree}
99
with-zlib:path|auto|tree
1010
=> {Look for zlib in the given path, automatically, or in the source tree}
1111
with-exec-rel-paths=0
1212
=> {Enable relative paths for external diff/gdiff}
13
- with-legacy-mv-rm=1 => {Enable legacy behavior for mv/rm (skip checkout files)}
1413
with-sanitizer: => {Build with C compiler's -fsanitize=LIST; e.g. address,enum,null,undefined}
1514
with-th1-docs=0 => {Enable TH1 for embedded documentation pages}
1615
with-th1-hooks=0 => {Enable TH1 hooks for commands and web pages}
1716
with-tcl:path => {Enable Tcl integration, with Tcl in the specified path}
1817
with-tcl-stubs=0 => {Enable Tcl integration via stubs library mechanism}
@@ -33,10 +32,17 @@
3332
cc-check-types uint32_t uint16_t int16_t uint8_t
3433
}
3534
3635
# Use pread/pwrite system calls in place of seek + read/write if possible
3736
define USE_PREAD [cc-check-functions pread]
37
+
38
+# If we have cscope here, we'll use it in the "tags" target
39
+if {[cc-check-progs cscope]} {
40
+ define COLLECT_CSCOPE_DATA "cscope -bR -s$::autosetup(srcdir)/src"
41
+} else {
42
+ define COLLECT_CSCOPE_DATA ""
43
+}
3844
3945
# Find tclsh for the test suite.
4046
#
4147
# We can't use jimsh for this: the test suite uses features of Tcl that
4248
# Jim doesn't support, either statically or due to the way it's built by
@@ -176,11 +182,11 @@
176182
user-error $result
177183
}
178184
file delete ./conftest__
179185
}
180186
test_system_sqlite
181
-
187
+
182188
}
183189
184190
proc is_mingw {} {
185191
return [string match *mingw* [get-define host]]
186192
}
@@ -231,16 +237,10 @@
231237
define-append EXTRA_CFLAGS -DFOSSIL_ENABLE_JSON
232238
define FOSSIL_ENABLE_JSON
233239
msg-result "JSON support enabled"
234240
}
235241
236
-if {[opt-bool with-legacy-mv-rm]} {
237
- define-append EXTRA_CFLAGS -DFOSSIL_ENABLE_LEGACY_MV_RM=1
238
- define FOSSIL_ENABLE_LEGACY_MV_RM
239
- msg-result "Legacy mv/rm support enabled"
240
-}
241
-
242242
if {[opt-bool with-exec-rel-paths]} {
243243
define-append EXTRA_CFLAGS -DFOSSIL_ENABLE_EXEC_REL_PATHS
244244
define FOSSIL_ENABLE_EXEC_REL_PATHS
245245
msg-result "Relative paths in external diff/gdiff enabled"
246246
}
@@ -273,11 +273,11 @@
273273
274274
# Check for libraries that need to be sorted out early
275275
cc-check-function-in-lib iconv iconv
276276
277277
# Helper for OpenSSL checking
278
-proc check-for-openssl {msg {cflags {}} {libs {-lssl -lcrypto}}} {
278
+proc check-for-openssl {msg {cflags {}} {libs {-lssl -lcrypto -lpthread}}} {
279279
msg-checking "Checking for $msg..."
280280
set rc 0
281281
if {[is_mingw]} {
282282
lappend libs -lgdi32 -lwsock32 -lcrypt32
283283
}
@@ -351,11 +351,11 @@
351351
user-error "The OpenSSL in source tree directory does not exist"
352352
}
353353
set msg "ssl in $ssldir"
354354
set cflags "-I$ssldir/include"
355355
set ldflags "-L$ssldir"
356
- set ssllibs "$ssldir/libssl.a $ssldir/libcrypto.a"
356
+ set ssllibs "$ssldir/libssl.a $ssldir/libcrypto.a -lpthread"
357357
set found [check-for-openssl "ssl in source tree" "$cflags $ldflags" $ssllibs]
358358
} else {
359359
if {$ssldirs in {auto ""}} {
360360
catch {
361361
set cflags [exec pkg-config openssl --cflags-only-I]
362362
--- auto.def
+++ auto.def
@@ -8,11 +8,10 @@
8 with-miniz=0 => {Use miniz from the source tree}
9 with-zlib:path|auto|tree
10 => {Look for zlib in the given path, automatically, or in the source tree}
11 with-exec-rel-paths=0
12 => {Enable relative paths for external diff/gdiff}
13 with-legacy-mv-rm=1 => {Enable legacy behavior for mv/rm (skip checkout files)}
14 with-sanitizer: => {Build with C compiler's -fsanitize=LIST; e.g. address,enum,null,undefined}
15 with-th1-docs=0 => {Enable TH1 for embedded documentation pages}
16 with-th1-hooks=0 => {Enable TH1 hooks for commands and web pages}
17 with-tcl:path => {Enable Tcl integration, with Tcl in the specified path}
18 with-tcl-stubs=0 => {Enable Tcl integration via stubs library mechanism}
@@ -33,10 +32,17 @@
33 cc-check-types uint32_t uint16_t int16_t uint8_t
34 }
35
36 # Use pread/pwrite system calls in place of seek + read/write if possible
37 define USE_PREAD [cc-check-functions pread]
 
 
 
 
 
 
 
38
39 # Find tclsh for the test suite.
40 #
41 # We can't use jimsh for this: the test suite uses features of Tcl that
42 # Jim doesn't support, either statically or due to the way it's built by
@@ -176,11 +182,11 @@
176 user-error $result
177 }
178 file delete ./conftest__
179 }
180 test_system_sqlite
181
182 }
183
184 proc is_mingw {} {
185 return [string match *mingw* [get-define host]]
186 }
@@ -231,16 +237,10 @@
231 define-append EXTRA_CFLAGS -DFOSSIL_ENABLE_JSON
232 define FOSSIL_ENABLE_JSON
233 msg-result "JSON support enabled"
234 }
235
236 if {[opt-bool with-legacy-mv-rm]} {
237 define-append EXTRA_CFLAGS -DFOSSIL_ENABLE_LEGACY_MV_RM=1
238 define FOSSIL_ENABLE_LEGACY_MV_RM
239 msg-result "Legacy mv/rm support enabled"
240 }
241
242 if {[opt-bool with-exec-rel-paths]} {
243 define-append EXTRA_CFLAGS -DFOSSIL_ENABLE_EXEC_REL_PATHS
244 define FOSSIL_ENABLE_EXEC_REL_PATHS
245 msg-result "Relative paths in external diff/gdiff enabled"
246 }
@@ -273,11 +273,11 @@
273
274 # Check for libraries that need to be sorted out early
275 cc-check-function-in-lib iconv iconv
276
277 # Helper for OpenSSL checking
278 proc check-for-openssl {msg {cflags {}} {libs {-lssl -lcrypto}}} {
279 msg-checking "Checking for $msg..."
280 set rc 0
281 if {[is_mingw]} {
282 lappend libs -lgdi32 -lwsock32 -lcrypt32
283 }
@@ -351,11 +351,11 @@
351 user-error "The OpenSSL in source tree directory does not exist"
352 }
353 set msg "ssl in $ssldir"
354 set cflags "-I$ssldir/include"
355 set ldflags "-L$ssldir"
356 set ssllibs "$ssldir/libssl.a $ssldir/libcrypto.a"
357 set found [check-for-openssl "ssl in source tree" "$cflags $ldflags" $ssllibs]
358 } else {
359 if {$ssldirs in {auto ""}} {
360 catch {
361 set cflags [exec pkg-config openssl --cflags-only-I]
362
--- auto.def
+++ auto.def
@@ -8,11 +8,10 @@
8 with-miniz=0 => {Use miniz from the source tree}
9 with-zlib:path|auto|tree
10 => {Look for zlib in the given path, automatically, or in the source tree}
11 with-exec-rel-paths=0
12 => {Enable relative paths for external diff/gdiff}
 
13 with-sanitizer: => {Build with C compiler's -fsanitize=LIST; e.g. address,enum,null,undefined}
14 with-th1-docs=0 => {Enable TH1 for embedded documentation pages}
15 with-th1-hooks=0 => {Enable TH1 hooks for commands and web pages}
16 with-tcl:path => {Enable Tcl integration, with Tcl in the specified path}
17 with-tcl-stubs=0 => {Enable Tcl integration via stubs library mechanism}
@@ -33,10 +32,17 @@
32 cc-check-types uint32_t uint16_t int16_t uint8_t
33 }
34
35 # Use pread/pwrite system calls in place of seek + read/write if possible
36 define USE_PREAD [cc-check-functions pread]
37
38 # If we have cscope here, we'll use it in the "tags" target
39 if {[cc-check-progs cscope]} {
40 define COLLECT_CSCOPE_DATA "cscope -bR -s$::autosetup(srcdir)/src"
41 } else {
42 define COLLECT_CSCOPE_DATA ""
43 }
44
45 # Find tclsh for the test suite.
46 #
47 # We can't use jimsh for this: the test suite uses features of Tcl that
48 # Jim doesn't support, either statically or due to the way it's built by
@@ -176,11 +182,11 @@
182 user-error $result
183 }
184 file delete ./conftest__
185 }
186 test_system_sqlite
187
188 }
189
190 proc is_mingw {} {
191 return [string match *mingw* [get-define host]]
192 }
@@ -231,16 +237,10 @@
237 define-append EXTRA_CFLAGS -DFOSSIL_ENABLE_JSON
238 define FOSSIL_ENABLE_JSON
239 msg-result "JSON support enabled"
240 }
241
 
 
 
 
 
 
242 if {[opt-bool with-exec-rel-paths]} {
243 define-append EXTRA_CFLAGS -DFOSSIL_ENABLE_EXEC_REL_PATHS
244 define FOSSIL_ENABLE_EXEC_REL_PATHS
245 msg-result "Relative paths in external diff/gdiff enabled"
246 }
@@ -273,11 +273,11 @@
273
274 # Check for libraries that need to be sorted out early
275 cc-check-function-in-lib iconv iconv
276
277 # Helper for OpenSSL checking
278 proc check-for-openssl {msg {cflags {}} {libs {-lssl -lcrypto -lpthread}}} {
279 msg-checking "Checking for $msg..."
280 set rc 0
281 if {[is_mingw]} {
282 lappend libs -lgdi32 -lwsock32 -lcrypt32
283 }
@@ -351,11 +351,11 @@
351 user-error "The OpenSSL in source tree directory does not exist"
352 }
353 set msg "ssl in $ssldir"
354 set cflags "-I$ssldir/include"
355 set ldflags "-L$ssldir"
356 set ssllibs "$ssldir/libssl.a $ssldir/libcrypto.a -lpthread"
357 set found [check-for-openssl "ssl in source tree" "$cflags $ldflags" $ssllibs]
358 } else {
359 if {$ssldirs in {auto ""}} {
360 catch {
361 set cflags [exec pkg-config openssl --cflags-only-I]
362
+17 -10
--- skins/README.md
+++ skins/README.md
@@ -1,11 +1,16 @@
11
Built-in Skins
22
==============
33
44
Each subdirectory under this folder describes a built-in "skin".
5
-There are four files in each subdirectory for the CSS, the "details"
6
-file, the footer, and the header for that skin.
5
+There are five key files in each subdirectory:
6
+
7
+ * `css.txt` → The CSS for the skin
8
+ * `details.txt` → Skin-specific settings
9
+ * `footer.txt` → Text of the Content Footer for each page
10
+ * `header.txt` → Text of the Content Header for each page
11
+ * `js.txt` → Javascript included in the Content Footer
712
813
To improve an existing built-in skin, simply edit the appropriate
914
files and recompile.
1015
1116
To add a new skin:
@@ -13,12 +18,12 @@
1318
1. Create a new subdirectory under skins/. (The new directory is
1419
called "skins/newskin" below but you should use a new original
1520
name, of course.)
1621
1722
2. Add files skins/newskin/css.txt, skins/newskin/details.txt,
18
- skins/newskin/footer.txt and skins/newskin/header.txt.
19
- Be sure to "fossil add" these files.
23
+ skins/newskin/footer.txt, skins/newskin/header.txt, and
24
+ skins/newskin/js.txt. Be sure to "fossil add" these files.
2025
2126
3. Go to the src/ directory and rerun "tclsh makemake.tcl". This
2227
step rebuilds the various makefiles so that they have dependencies
2328
on the skin files you just installed.
2429
@@ -25,21 +30,23 @@
2530
4. Edit the BuiltinSkin[] array near the top of the src/skins.c source
2631
file so that it describes and references the "newskin" skin.
2732
2833
5. Type "make" to rebuild.
2934
35
+See the [custom skin documentation](../www/customskin.md) for more information.
36
+
3037
Development Hints
3138
-----------------
3239
3340
One way to develop a new skin is to copy the baseline files (css.txt,
34
-details.txt, footer.txt, and header.txt) into a working directory $WORKDIR
35
-then launch Fossil with a command-line option "--skin $WORKDIR". Example:
41
+details.txt, footer.txt, header.txt, and js.txt) into a working
42
+directory $WORKDIR then launch Fossil with a command-line option
43
+"--skin $WORKDIR". Example:
3644
3745
cp -r skins/default newskin
3846
fossil ui --skin ./newskin
3947
4048
When the argument to --skin contains one or more '/' characters, the
4149
appropriate skin files are read from disk from the directory specified.
42
-So after launching fossil as shown above, you can edit the newskin/css.txt,
43
-newskin/details.txt, newskin/footer.txt, and newskin/header.txt files using
44
-your favorite text editor, then press Reload on your browser to see
45
-immediate results.
50
+So after launching fossil as shown above, you can edit the newskin/*.txt
51
+files using your favorite text editor, then press Reload on your browser
52
+to see immediate results.
4653
--- skins/README.md
+++ skins/README.md
@@ -1,11 +1,16 @@
1 Built-in Skins
2 ==============
3
4 Each subdirectory under this folder describes a built-in "skin".
5 There are four files in each subdirectory for the CSS, the "details"
6 file, the footer, and the header for that skin.
 
 
 
 
 
7
8 To improve an existing built-in skin, simply edit the appropriate
9 files and recompile.
10
11 To add a new skin:
@@ -13,12 +18,12 @@
13 1. Create a new subdirectory under skins/. (The new directory is
14 called "skins/newskin" below but you should use a new original
15 name, of course.)
16
17 2. Add files skins/newskin/css.txt, skins/newskin/details.txt,
18 skins/newskin/footer.txt and skins/newskin/header.txt.
19 Be sure to "fossil add" these files.
20
21 3. Go to the src/ directory and rerun "tclsh makemake.tcl". This
22 step rebuilds the various makefiles so that they have dependencies
23 on the skin files you just installed.
24
@@ -25,21 +30,23 @@
25 4. Edit the BuiltinSkin[] array near the top of the src/skins.c source
26 file so that it describes and references the "newskin" skin.
27
28 5. Type "make" to rebuild.
29
 
 
30 Development Hints
31 -----------------
32
33 One way to develop a new skin is to copy the baseline files (css.txt,
34 details.txt, footer.txt, and header.txt) into a working directory $WORKDIR
35 then launch Fossil with a command-line option "--skin $WORKDIR". Example:
 
36
37 cp -r skins/default newskin
38 fossil ui --skin ./newskin
39
40 When the argument to --skin contains one or more '/' characters, the
41 appropriate skin files are read from disk from the directory specified.
42 So after launching fossil as shown above, you can edit the newskin/css.txt,
43 newskin/details.txt, newskin/footer.txt, and newskin/header.txt files using
44 your favorite text editor, then press Reload on your browser to see
45 immediate results.
46
--- skins/README.md
+++ skins/README.md
@@ -1,11 +1,16 @@
1 Built-in Skins
2 ==============
3
4 Each subdirectory under this folder describes a built-in "skin".
5 There are five key files in each subdirectory:
6
7 * `css.txt` → The CSS for the skin
8 * `details.txt` → Skin-specific settings
9 * `footer.txt` → Text of the Content Footer for each page
10 * `header.txt` → Text of the Content Header for each page
11 * `js.txt` → Javascript included in the Content Footer
12
13 To improve an existing built-in skin, simply edit the appropriate
14 files and recompile.
15
16 To add a new skin:
@@ -13,12 +18,12 @@
18 1. Create a new subdirectory under skins/. (The new directory is
19 called "skins/newskin" below but you should use a new original
20 name, of course.)
21
22 2. Add files skins/newskin/css.txt, skins/newskin/details.txt,
23 skins/newskin/footer.txt, skins/newskin/header.txt, and
24 skins/newskin/js.txt. Be sure to "fossil add" these files.
25
26 3. Go to the src/ directory and rerun "tclsh makemake.tcl". This
27 step rebuilds the various makefiles so that they have dependencies
28 on the skin files you just installed.
29
@@ -25,21 +30,23 @@
30 4. Edit the BuiltinSkin[] array near the top of the src/skins.c source
31 file so that it describes and references the "newskin" skin.
32
33 5. Type "make" to rebuild.
34
35 See the [custom skin documentation](../www/customskin.md) for more information.
36
37 Development Hints
38 -----------------
39
40 One way to develop a new skin is to copy the baseline files (css.txt,
41 details.txt, footer.txt, header.txt, and js.txt) into a working
42 directory $WORKDIR then launch Fossil with a command-line option
43 "--skin $WORKDIR". Example:
44
45 cp -r skins/default newskin
46 fossil ui --skin ./newskin
47
48 When the argument to --skin contains one or more '/' characters, the
49 appropriate skin files are read from disk from the directory specified.
50 So after launching fossil as shown above, you can edit the newskin/*.txt
51 files using your favorite text editor, then press Reload on your browser
52 to see immediate results.
 
53
--- skins/ardoise/css.txt
+++ skins/ardoise/css.txt
@@ -57,12 +57,10 @@
5757
span.modpending {
5858
font-style: italic
5959
}
6060
html {
6161
font-family: sans-serif;
62
- -ms-text-size-adjust: 100%;
63
- -webkit-text-size-adjust: 100%
6462
}
6563
audio,
6664
canvas,
6765
progress,
6866
video {
@@ -162,11 +160,10 @@
162160
}
163161
button,
164162
html input[type=button],
165163
input[type=reset],
166164
input[type=submit] {
167
- -webkit-appearance: button;
168165
cursor: pointer
169166
}
170167
button[disabled],
171168
html input[disabled] {
172169
cursor: default
@@ -187,17 +184,11 @@
187184
}
188185
input[type=number]::-webkit-inner-spin-button,
189186
input[type=number]::-webkit-outer-spin-button {
190187
height: auto
191188
}
192
-input[type=search] {
193
- -webkit-appearance: textfield
194
-}
195189
input[type=search]::-webkit-search-cancel-button,
196
-input[type=search]::-webkit-search-decoration {
197
- -webkit-appearance: none
198
-}
199190
fieldset {
200191
border: 1px solid silver;
201192
margin: 0 2px
202193
}
203194
legend {
@@ -291,11 +282,11 @@
291282
box-sizing: border-box
292283
}
293284
.column,
294285
.columns {
295286
width: 100%;
296
- float: left;
287
+ /*float: left; can break README.md in /dir view*/
297288
box-sizing: border-box
298289
}
299290
@media (min-width:400px) {
300291
.container {
301292
width: 95%;
@@ -487,13 +478,10 @@
487478
input[type=tel],
488479
input[type=text],
489480
input[type=url] {
490481
box-shadow: none;
491482
box-sizing: border-box;
492
- -webkit-appearance: none;
493
- -moz-appearance: none;
494
- appearance: none
495483
}
496484
input[type=email],
497485
input[type=number],
498486
input[type=password],
499487
input[type=search],
@@ -508,10 +496,13 @@
508496
background-color: #303536;
509497
border: 0;
510498
border-radius: 5px;
511499
box-shadow: none;
512500
box-sizing: border-box
501
+}
502
+textarea, select {
503
+ height: initial;
513504
}
514505
input[type=email]:hover,
515506
input[type=number]:hover,
516507
input[type=password]:hover,
517508
input[type=search]:hover,
@@ -523,13 +514,10 @@
523514
color: #eef8ff;
524515
background-color: #555
525516
}
526517
textarea {
527518
overflow: auto;
528
- -webkit-appearance: none;
529
- -moz-appearance: none;
530
- appearance: none;
531519
min-height: 65px;
532520
padding-top: 6px;
533521
padding-bottom: 6px
534522
}
535523
input[type=email]:focus,
@@ -1392,5 +1380,12 @@
13921380
.u-cf {
13931381
content: "";
13941382
display: table;
13951383
clear: both
13961384
}
1385
+div.forumSel {
1386
+ background-color: #3a3a3a;
1387
+}
1388
+.debug {
1389
+ background-color: #330;
1390
+ border: 2px solid #aa0;
1391
+}
13971392
--- skins/ardoise/css.txt
+++ skins/ardoise/css.txt
@@ -57,12 +57,10 @@
57 span.modpending {
58 font-style: italic
59 }
60 html {
61 font-family: sans-serif;
62 -ms-text-size-adjust: 100%;
63 -webkit-text-size-adjust: 100%
64 }
65 audio,
66 canvas,
67 progress,
68 video {
@@ -162,11 +160,10 @@
162 }
163 button,
164 html input[type=button],
165 input[type=reset],
166 input[type=submit] {
167 -webkit-appearance: button;
168 cursor: pointer
169 }
170 button[disabled],
171 html input[disabled] {
172 cursor: default
@@ -187,17 +184,11 @@
187 }
188 input[type=number]::-webkit-inner-spin-button,
189 input[type=number]::-webkit-outer-spin-button {
190 height: auto
191 }
192 input[type=search] {
193 -webkit-appearance: textfield
194 }
195 input[type=search]::-webkit-search-cancel-button,
196 input[type=search]::-webkit-search-decoration {
197 -webkit-appearance: none
198 }
199 fieldset {
200 border: 1px solid silver;
201 margin: 0 2px
202 }
203 legend {
@@ -291,11 +282,11 @@
291 box-sizing: border-box
292 }
293 .column,
294 .columns {
295 width: 100%;
296 float: left;
297 box-sizing: border-box
298 }
299 @media (min-width:400px) {
300 .container {
301 width: 95%;
@@ -487,13 +478,10 @@
487 input[type=tel],
488 input[type=text],
489 input[type=url] {
490 box-shadow: none;
491 box-sizing: border-box;
492 -webkit-appearance: none;
493 -moz-appearance: none;
494 appearance: none
495 }
496 input[type=email],
497 input[type=number],
498 input[type=password],
499 input[type=search],
@@ -508,10 +496,13 @@
508 background-color: #303536;
509 border: 0;
510 border-radius: 5px;
511 box-shadow: none;
512 box-sizing: border-box
 
 
 
513 }
514 input[type=email]:hover,
515 input[type=number]:hover,
516 input[type=password]:hover,
517 input[type=search]:hover,
@@ -523,13 +514,10 @@
523 color: #eef8ff;
524 background-color: #555
525 }
526 textarea {
527 overflow: auto;
528 -webkit-appearance: none;
529 -moz-appearance: none;
530 appearance: none;
531 min-height: 65px;
532 padding-top: 6px;
533 padding-bottom: 6px
534 }
535 input[type=email]:focus,
@@ -1392,5 +1380,12 @@
1392 .u-cf {
1393 content: "";
1394 display: table;
1395 clear: both
1396 }
 
 
 
 
 
 
 
1397
--- skins/ardoise/css.txt
+++ skins/ardoise/css.txt
@@ -57,12 +57,10 @@
57 span.modpending {
58 font-style: italic
59 }
60 html {
61 font-family: sans-serif;
 
 
62 }
63 audio,
64 canvas,
65 progress,
66 video {
@@ -162,11 +160,10 @@
160 }
161 button,
162 html input[type=button],
163 input[type=reset],
164 input[type=submit] {
 
165 cursor: pointer
166 }
167 button[disabled],
168 html input[disabled] {
169 cursor: default
@@ -187,17 +184,11 @@
184 }
185 input[type=number]::-webkit-inner-spin-button,
186 input[type=number]::-webkit-outer-spin-button {
187 height: auto
188 }
 
 
 
189 input[type=search]::-webkit-search-cancel-button,
 
 
 
190 fieldset {
191 border: 1px solid silver;
192 margin: 0 2px
193 }
194 legend {
@@ -291,11 +282,11 @@
282 box-sizing: border-box
283 }
284 .column,
285 .columns {
286 width: 100%;
287 /*float: left; can break README.md in /dir view*/
288 box-sizing: border-box
289 }
290 @media (min-width:400px) {
291 .container {
292 width: 95%;
@@ -487,13 +478,10 @@
478 input[type=tel],
479 input[type=text],
480 input[type=url] {
481 box-shadow: none;
482 box-sizing: border-box;
 
 
 
483 }
484 input[type=email],
485 input[type=number],
486 input[type=password],
487 input[type=search],
@@ -508,10 +496,13 @@
496 background-color: #303536;
497 border: 0;
498 border-radius: 5px;
499 box-shadow: none;
500 box-sizing: border-box
501 }
502 textarea, select {
503 height: initial;
504 }
505 input[type=email]:hover,
506 input[type=number]:hover,
507 input[type=password]:hover,
508 input[type=search]:hover,
@@ -523,13 +514,10 @@
514 color: #eef8ff;
515 background-color: #555
516 }
517 textarea {
518 overflow: auto;
 
 
 
519 min-height: 65px;
520 padding-top: 6px;
521 padding-bottom: 6px
522 }
523 input[type=email]:focus,
@@ -1392,5 +1380,12 @@
1380 .u-cf {
1381 content: "";
1382 display: table;
1383 clear: both
1384 }
1385 div.forumSel {
1386 background-color: #3a3a3a;
1387 }
1388 .debug {
1389 background-color: #330;
1390 border: 2px solid #aa0;
1391 }
1392
--- skins/blitz/ticket.txt
+++ skins/blitz/ticket.txt
@@ -1,8 +1,8 @@
11
<h4>$<title></h4>
22
<table class="tktDsp">
3
-<tr><td class="tktDspLabel">Ticket&nbsp;UUID</td>
3
+<tr><td class="tktDspLabel">Ticket&nbsp;Hash</td>
44
<th1>
55
if {[info exists tkt_uuid]} {
66
if {[hascap s]} {
77
html "<td class='tktDspValue' colspan='3'>$tkt_uuid "
88
html "($tkt_id)</td></tr>\n"
99
--- skins/blitz/ticket.txt
+++ skins/blitz/ticket.txt
@@ -1,8 +1,8 @@
1 <h4>$<title></h4>
2 <table class="tktDsp">
3 <tr><td class="tktDspLabel">Ticket&nbsp;UUID</td>
4 <th1>
5 if {[info exists tkt_uuid]} {
6 if {[hascap s]} {
7 html "<td class='tktDspValue' colspan='3'>$tkt_uuid "
8 html "($tkt_id)</td></tr>\n"
9
--- skins/blitz/ticket.txt
+++ skins/blitz/ticket.txt
@@ -1,8 +1,8 @@
1 <h4>$<title></h4>
2 <table class="tktDsp">
3 <tr><td class="tktDspLabel">Ticket&nbsp;Hash</td>
4 <th1>
5 if {[info exists tkt_uuid]} {
6 if {[hascap s]} {
7 html "<td class='tktDspValue' colspan='3'>$tkt_uuid "
8 html "($tkt_id)</td></tr>\n"
9
--- skins/blitz_no_logo/ticket.txt
+++ skins/blitz_no_logo/ticket.txt
@@ -1,8 +1,8 @@
11
<h4>$<title></h4>
22
<table class="tktDsp">
3
-<tr><td class="tktDspLabel">Ticket&nbsp;UUID</td>
3
+<tr><td class="tktDspLabel">Ticket&nbsp;Hash</td>
44
<th1>
55
if {[info exists tkt_uuid]} {
66
if {[hascap s]} {
77
html "<td class='tktDspValue' colspan='3'>$tkt_uuid "
88
html "($tkt_id)</td></tr>\n"
99
--- skins/blitz_no_logo/ticket.txt
+++ skins/blitz_no_logo/ticket.txt
@@ -1,8 +1,8 @@
1 <h4>$<title></h4>
2 <table class="tktDsp">
3 <tr><td class="tktDspLabel">Ticket&nbsp;UUID</td>
4 <th1>
5 if {[info exists tkt_uuid]} {
6 if {[hascap s]} {
7 html "<td class='tktDspValue' colspan='3'>$tkt_uuid "
8 html "($tkt_id)</td></tr>\n"
9
--- skins/blitz_no_logo/ticket.txt
+++ skins/blitz_no_logo/ticket.txt
@@ -1,8 +1,8 @@
1 <h4>$<title></h4>
2 <table class="tktDsp">
3 <tr><td class="tktDspLabel">Ticket&nbsp;Hash</td>
4 <th1>
5 if {[info exists tkt_uuid]} {
6 if {[hascap s]} {
7 html "<td class='tktDspValue' colspan='3'>$tkt_uuid "
8 html "($tkt_id)</td></tr>\n"
9
--- skins/bootstrap/header.txt
+++ skins/bootstrap/header.txt
@@ -4,11 +4,11 @@
44
<base href="$baseurl/$current_page" />
55
<title>$<project_name>: $<title></title>
66
<meta name="viewport" content="width=device-width, initial-scale=1.0">
77
<meta http-equiv="Content-Security-Policy" content="$default_csp"/>
88
<link rel="alternate" type="application/rss+xml" title="RSS Feed" href="$home/timeline.rss" />
9
- <link rel="stylesheet" href="$home/style.css?default" type="text/css" media="screen" />
9
+ <link rel="stylesheet" href="$stylesheet_url" type="text/css" media="screen" />
1010
<script nonce="$<nonce>">
1111
function gebi(x){
1212
if(/^#/.test(x)) x = x.substr(1);
1313
var e = document.getElementById(x);
1414
if(!e) throw new Error("Expecting element with ID "+x);
1515
--- skins/bootstrap/header.txt
+++ skins/bootstrap/header.txt
@@ -4,11 +4,11 @@
4 <base href="$baseurl/$current_page" />
5 <title>$<project_name>: $<title></title>
6 <meta name="viewport" content="width=device-width, initial-scale=1.0">
7 <meta http-equiv="Content-Security-Policy" content="$default_csp"/>
8 <link rel="alternate" type="application/rss+xml" title="RSS Feed" href="$home/timeline.rss" />
9 <link rel="stylesheet" href="$home/style.css?default" type="text/css" media="screen" />
10 <script nonce="$<nonce>">
11 function gebi(x){
12 if(/^#/.test(x)) x = x.substr(1);
13 var e = document.getElementById(x);
14 if(!e) throw new Error("Expecting element with ID "+x);
15
--- skins/bootstrap/header.txt
+++ skins/bootstrap/header.txt
@@ -4,11 +4,11 @@
4 <base href="$baseurl/$current_page" />
5 <title>$<project_name>: $<title></title>
6 <meta name="viewport" content="width=device-width, initial-scale=1.0">
7 <meta http-equiv="Content-Security-Policy" content="$default_csp"/>
8 <link rel="alternate" type="application/rss+xml" title="RSS Feed" href="$home/timeline.rss" />
9 <link rel="stylesheet" href="$stylesheet_url" type="text/css" media="screen" />
10 <script nonce="$<nonce>">
11 function gebi(x){
12 if(/^#/.test(x)) x = x.substr(1);
13 var e = document.getElementById(x);
14 if(!e) throw new Error("Expecting element with ID "+x);
15
--- skins/default/css.txt
+++ skins/default/css.txt
@@ -145,11 +145,11 @@
145145
border-radius: 5px;
146146
}
147147
.content blockquote {
148148
padding: 0 15px;
149149
}
150
-div.forumHierRoot blockquote, div.forumHier blockquote, div.forumEdit blockquote {
150
+div.forumHierRoot blockquote, div.forumHier blockquote, div.forumEdit blockquote, div.forumTime blockquote, div.forumTimeline blockquote {
151151
background-color: rgba(65, 131, 196, 0.1);
152152
border-left: 3px solid #254769;
153153
padding: .1em 1em;
154154
}
155155
156156
--- skins/default/css.txt
+++ skins/default/css.txt
@@ -145,11 +145,11 @@
145 border-radius: 5px;
146 }
147 .content blockquote {
148 padding: 0 15px;
149 }
150 div.forumHierRoot blockquote, div.forumHier blockquote, div.forumEdit blockquote {
151 background-color: rgba(65, 131, 196, 0.1);
152 border-left: 3px solid #254769;
153 padding: .1em 1em;
154 }
155
156
--- skins/default/css.txt
+++ skins/default/css.txt
@@ -145,11 +145,11 @@
145 border-radius: 5px;
146 }
147 .content blockquote {
148 padding: 0 15px;
149 }
150 div.forumHierRoot blockquote, div.forumHier blockquote, div.forumEdit blockquote, div.forumTime blockquote, div.forumTimeline blockquote {
151 background-color: rgba(65, 131, 196, 0.1);
152 border-left: 3px solid #254769;
153 padding: .1em 1em;
154 }
155
156
--- skins/default/header.txt
+++ skins/default/header.txt
@@ -1,10 +1,10 @@
11
<div class="header">
22
<div class="title"><h1>$<project_name></h1>$<title></div>
33
<div class="status"><th1>
44
if {[info exists login]} {
5
- html "$login — <a href='$home/login'>Logout</a>\n"
5
+ html "<a href='$home/login'>$login</a>\n"
66
} else {
77
html "<a href='$home/login'>Login</a>\n"
88
}
99
</th1></div>
1010
</div>
@@ -17,17 +17,18 @@
1717
html "<a href='$home$url' class='active $cls'>$name</a>\n"
1818
} else {
1919
html "<a href='$home$url' class='$cls'>$name</a>\n"
2020
}
2121
}
22
-html "<a id='hbbtn' href='/sitemap'>&#9776;</a>"
22
+html "<a id='hbbtn' href='$home/sitemap' aria-label='Site Map'>&#9776;</a>"
2323
menulink $index_page Home {}
2424
if {[anycap jor]} {
2525
menulink /timeline Timeline {}
2626
}
2727
if {[hascap oh]} {
28
- menulink /dir?ci=tip Files desktoponly
28
+ if {![info exists current_checkin]} {set current_checkin tip}
29
+ menulink /dir?ci=$current_checkin Files desktoponly
2930
}
3031
if {[hascap o]} {
3132
menulink /brlist Branches desktoponly
3233
menulink /taglist Tags wideonly
3334
}
3435
--- skins/default/header.txt
+++ skins/default/header.txt
@@ -1,10 +1,10 @@
1 <div class="header">
2 <div class="title"><h1>$<project_name></h1>$<title></div>
3 <div class="status"><th1>
4 if {[info exists login]} {
5 html "$login — <a href='$home/login'>Logout</a>\n"
6 } else {
7 html "<a href='$home/login'>Login</a>\n"
8 }
9 </th1></div>
10 </div>
@@ -17,17 +17,18 @@
17 html "<a href='$home$url' class='active $cls'>$name</a>\n"
18 } else {
19 html "<a href='$home$url' class='$cls'>$name</a>\n"
20 }
21 }
22 html "<a id='hbbtn' href='/sitemap'>&#9776;</a>"
23 menulink $index_page Home {}
24 if {[anycap jor]} {
25 menulink /timeline Timeline {}
26 }
27 if {[hascap oh]} {
28 menulink /dir?ci=tip Files desktoponly
 
29 }
30 if {[hascap o]} {
31 menulink /brlist Branches desktoponly
32 menulink /taglist Tags wideonly
33 }
34
--- skins/default/header.txt
+++ skins/default/header.txt
@@ -1,10 +1,10 @@
1 <div class="header">
2 <div class="title"><h1>$<project_name></h1>$<title></div>
3 <div class="status"><th1>
4 if {[info exists login]} {
5 html "<a href='$home/login'>$login</a>\n"
6 } else {
7 html "<a href='$home/login'>Login</a>\n"
8 }
9 </th1></div>
10 </div>
@@ -17,17 +17,18 @@
17 html "<a href='$home$url' class='active $cls'>$name</a>\n"
18 } else {
19 html "<a href='$home$url' class='$cls'>$name</a>\n"
20 }
21 }
22 html "<a id='hbbtn' href='$home/sitemap' aria-label='Site Map'>&#9776;</a>"
23 menulink $index_page Home {}
24 if {[anycap jor]} {
25 menulink /timeline Timeline {}
26 }
27 if {[hascap oh]} {
28 if {![info exists current_checkin]} {set current_checkin tip}
29 menulink /dir?ci=$current_checkin Files desktoponly
30 }
31 if {[hascap o]} {
32 menulink /brlist Branches desktoponly
33 menulink /taglist Tags wideonly
34 }
35
--- skins/eagle/css.txt
+++ skins/eagle/css.txt
@@ -16,10 +16,11 @@
1616
text-align: center;
1717
vertical-align: bottom;
1818
font-weight: bold;
1919
color: white;
2020
padding: 5 0 5 0em;
21
+ min-width: 200px;
2122
white-space: nowrap;
2223
}
2324
2425
/* The page title centered at the top of each page */
2526
div.title {
@@ -353,10 +354,46 @@
353354
}
354355
355356
.fileage tr:hover {
356357
background-color: #7EA2D9;
357358
}
359
+
360
+span.modpending {
361
+ color: #c0c0c0;
362
+ font-style: italic;
363
+}
364
+span.forum_author {
365
+ color: white;
366
+ font-size: 75%;
367
+}
368
+span.forum_age {
369
+ color: white;
370
+ font-size: 85%;
371
+}
372
+span.forum_npost {
373
+ color: white;
374
+ font-size: 75%;
375
+}
376
+.debug {
377
+ background-color: #808080;
378
+ border: 2px solid white;
379
+}
380
+div.forumEdit {
381
+ border: 1px solid white;
382
+}
383
+div.forumTimeline {
384
+ border: 1px solid white;
385
+}
386
+div.forumHier, div.forumTime {
387
+ border: 1px solid white;
388
+}
389
+div.forumSel {
390
+ background-color: #808080;
391
+}
392
+div.forumObs {
393
+ color: white;
394
+}
358395
359396
.fileage td {
360397
font-family: "courier new";
361398
}
362399
@@ -373,5 +410,20 @@
373410
}
374411
375412
.timelineModernCell[id], .timelineColumnarCell[id], .timelineDetailCell[id] {
376413
background-color: #455978;
377414
}
415
+
416
+div.difflncol {
417
+ padding-right: 1em;
418
+ text-align: right;
419
+ color: white;
420
+}
421
+.capsumOff {
422
+ background-color: #bbbbbb;
423
+}
424
+.capsumRead {
425
+ background-color: #006d00;
426
+}
427
+.capsumWrite {
428
+ background-color: #e5e500;
429
+}
378430
379431
ADDED src/accordion.js
--- skins/eagle/css.txt
+++ skins/eagle/css.txt
@@ -16,10 +16,11 @@
16 text-align: center;
17 vertical-align: bottom;
18 font-weight: bold;
19 color: white;
20 padding: 5 0 5 0em;
 
21 white-space: nowrap;
22 }
23
24 /* The page title centered at the top of each page */
25 div.title {
@@ -353,10 +354,46 @@
353 }
354
355 .fileage tr:hover {
356 background-color: #7EA2D9;
357 }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
358
359 .fileage td {
360 font-family: "courier new";
361 }
362
@@ -373,5 +410,20 @@
373 }
374
375 .timelineModernCell[id], .timelineColumnarCell[id], .timelineDetailCell[id] {
376 background-color: #455978;
377 }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
378
379 DDED src/accordion.js
--- skins/eagle/css.txt
+++ skins/eagle/css.txt
@@ -16,10 +16,11 @@
16 text-align: center;
17 vertical-align: bottom;
18 font-weight: bold;
19 color: white;
20 padding: 5 0 5 0em;
21 min-width: 200px;
22 white-space: nowrap;
23 }
24
25 /* The page title centered at the top of each page */
26 div.title {
@@ -353,10 +354,46 @@
354 }
355
356 .fileage tr:hover {
357 background-color: #7EA2D9;
358 }
359
360 span.modpending {
361 color: #c0c0c0;
362 font-style: italic;
363 }
364 span.forum_author {
365 color: white;
366 font-size: 75%;
367 }
368 span.forum_age {
369 color: white;
370 font-size: 85%;
371 }
372 span.forum_npost {
373 color: white;
374 font-size: 75%;
375 }
376 .debug {
377 background-color: #808080;
378 border: 2px solid white;
379 }
380 div.forumEdit {
381 border: 1px solid white;
382 }
383 div.forumTimeline {
384 border: 1px solid white;
385 }
386 div.forumHier, div.forumTime {
387 border: 1px solid white;
388 }
389 div.forumSel {
390 background-color: #808080;
391 }
392 div.forumObs {
393 color: white;
394 }
395
396 .fileage td {
397 font-family: "courier new";
398 }
399
@@ -373,5 +410,20 @@
410 }
411
412 .timelineModernCell[id], .timelineColumnarCell[id], .timelineDetailCell[id] {
413 background-color: #455978;
414 }
415
416 div.difflncol {
417 padding-right: 1em;
418 text-align: right;
419 color: white;
420 }
421 .capsumOff {
422 background-color: #bbbbbb;
423 }
424 .capsumRead {
425 background-color: #006d00;
426 }
427 .capsumWrite {
428 background-color: #e5e500;
429 }
430
431 DDED src/accordion.js
--- a/src/accordion.js
+++ b/src/accordion.js
@@ -0,0 +1,27 @@
1
+/* Attach appropriate javascript to each ".accordion" button so that
2
+** it expands and contracts when clicked.
3
+**ntracts when clicked.
4
+**
5
+** The uncompressed source code for the SV
6
+** wiki page "branch/accordion-experiments" window to a smaller
7
+** width, causing vertical growth.)
8
+**
9
+** Ano"+"/"+"ttach appropriate javascript to each ".accordion" button so that
10
+** it expands and contracts when clicked.
11
+**ntracts when clicked.
12
+**
13
+** The uncompressed source code for the SV
14
+** wiki page "branch/accordion-experiments" window to a smaller
15
+** width, causing vertical growth.)
16
+**
17
+** Another problem is that `scrollHeight' used to calculate the expanded height
18
+** while still in the contracted state may return values with small errors on
19
+** some browsers, especially for large elements, presumably due to omitting the
20
+** space required by the vertical scrollbar that may become necessary, causing
21
+** additional horizontal shrinking and consequently more vertical growth than
22
+** calculated. That's why se/* Attach appropriate javascript to each ".accordion" button so that
23
+** it expands and contracts when clicked.
24
+**ntracts when clicked.
25
+**
26
+** The uncompressed source code for the SV
27
+** wiki page "branch/accordion-experiments" window to a smvar p = a[i].nextElementSibli
--- a/src/accordion.js
+++ b/src/accordion.js
@@ -0,0 +1,27 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
--- a/src/accordion.js
+++ b/src/accordion.js
@@ -0,0 +1,27 @@
1 /* Attach appropriate javascript to each ".accordion" button so that
2 ** it expands and contracts when clicked.
3 **ntracts when clicked.
4 **
5 ** The uncompressed source code for the SV
6 ** wiki page "branch/accordion-experiments" window to a smaller
7 ** width, causing vertical growth.)
8 **
9 ** Ano"+"/"+"ttach appropriate javascript to each ".accordion" button so that
10 ** it expands and contracts when clicked.
11 **ntracts when clicked.
12 **
13 ** The uncompressed source code for the SV
14 ** wiki page "branch/accordion-experiments" window to a smaller
15 ** width, causing vertical growth.)
16 **
17 ** Another problem is that `scrollHeight' used to calculate the expanded height
18 ** while still in the contracted state may return values with small errors on
19 ** some browsers, especially for large elements, presumably due to omitting the
20 ** space required by the vertical scrollbar that may become necessary, causing
21 ** additional horizontal shrinking and consequently more vertical growth than
22 ** calculated. That's why se/* Attach appropriate javascript to each ".accordion" button so that
23 ** it expands and contracts when clicked.
24 **ntracts when clicked.
25 **
26 ** The uncompressed source code for the SV
27 ** wiki page "branch/accordion-experiments" window to a smvar p = a[i].nextElementSibli
+176 -59
--- src/add.c
+++ src/add.c
@@ -22,28 +22,10 @@
2222
#include "add.h"
2323
#include <assert.h>
2424
#include <dirent.h>
2525
#include "cygsup.h"
2626
27
-/*
28
-** WARNING: For Fossil version x.x this value was always zero. For Fossil-NG
29
-** it will probably always be one. When this value is zero,
30
-** files in the checkout will not be moved by the "mv" command and
31
-** files in the checkout will not be removed by the "rm" command.
32
-**
33
-** If the FOSSIL_ENABLE_LEGACY_MV_RM compile-time option is used,
34
-** the "mv-rm-files" setting will be consulted instead of using
35
-** this value.
36
-**
37
-** To retain the Fossil version 2.x behavior when using Fossil-NG
38
-** the FOSSIL_ENABLE_LEGACY_MV_RM compile-time option must be used
39
-** -AND- the "mv-rm-files" setting must be set to zero.
40
-*/
41
-#ifndef FOSSIL_MV_RM_FILE
42
-#define FOSSIL_MV_RM_FILE (0)
43
-#endif
44
-
4527
/*
4628
** This routine returns the names of files in a working checkout that
4729
** are created by Fossil itself, and hence should not be added, deleted,
4830
** or merge, and should be omitted from "clean" and "extras" lists.
4931
**
@@ -240,18 +222,109 @@
240222
}
241223
db_finalize(&loop);
242224
blob_reset(&repoName);
243225
return nAdd;
244226
}
227
+
228
+/*
229
+** Resets the ADDED/DELETED state of a checkout, such that all
230
+** newly-added (but not yet committed) files are no longer added and
231
+** newly-removed (but not yet committed) files are no longer
232
+** removed. If bIsAdd is true, it operates on the "add" state, else it
233
+** operates on the "rm" state.
234
+**
235
+** If bDryRun is true it outputs what it would have done, but does not
236
+** actually do it. In this case it rolls back the transaction it
237
+** starts (so don't start a transaction before calling this).
238
+**
239
+** If bVerbose is true it outputs the name of each reset entry.
240
+**
241
+** This is intended to be called only in the context of the
242
+** add/rm/addremove commands, after a call to verify_all_options().
243
+**
244
+** Un-added files are not modified but any un-rm'd files which are
245
+** missing from the checkout are restored from the repo. un-rm'd files
246
+** which exist in the checkout are left as-is, rather than restoring
247
+** them using vfile_to_disk(), to avoid overwriting any local changes
248
+** made to those files.
249
+*/
250
+static void addremove_reset(int bIsAdd, int bDryRun, int bVerbose){
251
+ int nReset = 0; /* # of entries which get reset */
252
+ Stmt stmt; /* vfile loop query */
253
+
254
+ db_begin_transaction();
255
+ db_prepare(&stmt, "SELECT id, pathname FROM vfile "
256
+ "WHERE %s ORDER BY pathname",
257
+ bIsAdd==0 ? "deleted<>0" : "rid=0"/*safe-for-%s*/);
258
+ while( db_step(&stmt)==SQLITE_ROW ){
259
+ /* This loop exists only so we can restore the contents of un-rm'd
260
+ ** files and support verbose mode. All manipulation of vfile's
261
+ ** contents happens after the loop. For the ADD case in non-verbose
262
+ ** mode we "could" skip this loop entirely.
263
+ */
264
+ int const id = db_column_int(&stmt, 0);
265
+ char const * zPathname = db_column_text(&stmt, 1);
266
+ Blob relName = empty_blob;
267
+ if(bIsAdd==0 || bVerbose!=0){
268
+ /* Make filename relative... */
269
+ char *zFullName = mprintf("%s%s", g.zLocalRoot, zPathname);
270
+ file_relative_name(zFullName, &relName, 0);
271
+ fossil_free(zFullName);
272
+ }
273
+ if(bIsAdd==0){
274
+ /* Restore contents of missing un-rm'd files. We don't do this
275
+ ** unconditionally because we might cause data loss if a file
276
+ ** is modified, rm'd, then un-rm'd.
277
+ */
278
+ ++nReset;
279
+ if(!file_isfile_or_link(blob_str(&relName))){
280
+ if(bDryRun==0){
281
+ vfile_to_disk(0, id, 0, 0);
282
+ if(bVerbose){
283
+ fossil_print("Restored missing file: %b\n", &relName);
284
+ }
285
+ }else{
286
+ fossil_print("Dry-run: not restoring missing file: %b\n", &relName);
287
+ }
288
+ }
289
+ if(bVerbose){
290
+ fossil_print("Un-removed: %b\n", &relName);
291
+ }
292
+ }else{
293
+ /* un-add... */
294
+ ++nReset;
295
+ if(bVerbose){
296
+ fossil_print("Un-added: %b\n", &relName);
297
+ }
298
+ }
299
+ blob_reset(&relName);
300
+ }
301
+ db_finalize(&stmt);
302
+ if(nReset>0){
303
+ if(bIsAdd==0){
304
+ if(bDryRun==0){
305
+ db_exec_sql("UPDATE vfile SET deleted=0 WHERE deleted<>0");
306
+ }
307
+ fossil_print("Un-removed %d file(s).\n", nReset);
308
+ }else{
309
+ if(bDryRun==0){
310
+ db_exec_sql("DELETE FROM vfile WHERE rid=0");
311
+ }
312
+ fossil_print("Un-added %d file(s).\n", nReset);
313
+ }
314
+ }
315
+ db_end_transaction(bDryRun ? 1 : 0);
316
+}
317
+
245318
246319
/*
247320
** COMMAND: add
248321
**
249322
** Usage: %fossil add ?OPTIONS? FILE1 ?FILE2 ...?
250323
**
251324
** Make arrangements to add one or more files or directories to the
252
-** current checkout at the next commit.
325
+** current checkout at the next [[commit]].
253326
**
254327
** When adding files or directories recursively, filenames that begin
255328
** with "." are excluded by default. To include such files, add
256329
** the "--dotfiles" option to the command-line.
257330
**
@@ -269,19 +342,28 @@
269342
** be treated case sensitive or not. If the option is not given, the default
270343
** depends on the global setting, or the operating system default, if not set.
271344
**
272345
** Options:
273346
**
274
-** --case-sensitive <BOOL> Override the case-sensitive setting.
347
+** --case-sensitive BOOL Override the case-sensitive setting.
275348
** --dotfiles include files beginning with a dot (".")
276349
** -f|--force Add files without prompting
277
-** --ignore <CSG> Ignore unmanaged files matching patterns from
278
-** the comma separated list of glob patterns.
279
-** --clean <CSG> Also ignore files matching patterns from
280
-** the comma separated list of glob patterns.
350
+** --ignore CSG Ignore unmanaged files matching patterns from
351
+** the Comma Separated Glob (CSG) pattern list
352
+** --clean CSG Also ignore files matching patterns from
353
+** the Comma Separated Glob (CSG) list
354
+** --reset Reset the ADDED state of a checkout, such
355
+** that all newly-added (but not yet committed)
356
+** files are no longer added. No flags other
357
+** than --verbose and --dry-run may be used
358
+** with --reset.
359
+**
360
+** The following options are only valid with --reset:
361
+** -v|--verbose Outputs information about each --reset file.
362
+** -n|--dry-run Display instead of run actions.
281363
**
282
-** See also: addremove, rm
364
+** See also: [[addremove]], [[rm]]
283365
*/
284366
void add_cmd(void){
285367
int i; /* Loop counter */
286368
int vid; /* Currently checked out version */
287369
int nRoot; /* Full path characters in g.zLocalRoot */
@@ -288,10 +370,19 @@
288370
const char *zCleanFlag; /* The --clean option or clean-glob setting */
289371
const char *zIgnoreFlag; /* The --ignore option or ignore-glob setting */
290372
Glob *pIgnore, *pClean; /* Ignore everything matching the glob patterns */
291373
unsigned scanFlags = 0; /* Flags passed to vfile_scan() */
292374
int forceFlag;
375
+
376
+ if(0!=find_option("reset",0,0)){
377
+ int const verboseFlag = find_option("verbose","v",0)!=0;
378
+ int const dryRunFlag = find_option("dry-run","n",0)!=0;
379
+ db_must_be_within_tree();
380
+ verify_all_options();
381
+ addremove_reset(1, dryRunFlag, verboseFlag);
382
+ return;
383
+ }
293384
294385
zCleanFlag = find_option("clean",0,1);
295386
zIgnoreFlag = find_option("ignore",0,1);
296387
forceFlag = find_option("force","f",0)!=0;
297388
if( find_option("dotfiles",0,0)!=0 ) scanFlags |= SCAN_ALL;
@@ -442,22 +533,36 @@
442533
** --soft Skip removing files from the checkout.
443534
** This supersedes the --hard option.
444535
** --hard Remove files from the checkout.
445536
** --case-sensitive <BOOL> Override the case-sensitive setting.
446537
** -n|--dry-run If given, display instead of run actions.
538
+** --reset Reset the DELETED state of a checkout, such
539
+** that all newly-rm'd (but not yet committed)
540
+** files are no longer removed. No flags other
541
+** than --verbose or --dry-run may be used with
542
+** --reset.
543
+** --verbose|-v Outputs information about each --reset file.
544
+** Only usable with --reset.
447545
**
448
-** See also: addremove, add
546
+** See also: [[addremove]], [[add]]
449547
*/
450548
void delete_cmd(void){
451549
int i;
452550
int removeFiles;
453
- int dryRunFlag;
551
+ int dryRunFlag = find_option("dry-run","n",0)!=0;
454552
int softFlag;
455553
int hardFlag;
456554
Stmt loop;
457555
458
- dryRunFlag = find_option("dry-run","n",0)!=0;
556
+ if(0!=find_option("reset",0,0)){
557
+ int const verboseFlag = find_option("verbose","v",0)!=0;
558
+ db_must_be_within_tree();
559
+ verify_all_options();
560
+ addremove_reset(0, dryRunFlag, verboseFlag);
561
+ return;
562
+ }
563
+
459564
softFlag = find_option("soft",0,0)!=0;
460565
hardFlag = find_option("hard",0,0)!=0;
461566
462567
/* We should be done with options.. */
463568
verify_all_options();
@@ -469,15 +574,11 @@
469574
}else if( softFlag ){
470575
removeFiles = 0;
471576
}else if( hardFlag ){
472577
removeFiles = 1;
473578
}else{
474
-#if FOSSIL_ENABLE_LEGACY_MV_RM
475579
removeFiles = db_get_boolean("mv-rm-files",0);
476
-#else
477
- removeFiles = FOSSIL_MV_RM_FILE;
478
-#endif
479580
}
480581
db_multi_exec("CREATE TEMP TABLE sfile(pathname TEXT PRIMARY KEY %s)",
481582
filename_collation());
482583
for(i=2; i<g.argc; i++){
483584
Blob treeName;
@@ -588,22 +689,22 @@
588689
/*
589690
** COMMAND: addremove
590691
**
591692
** Usage: %fossil addremove ?OPTIONS?
592693
**
593
-** Do all necessary "add" and "rm" commands to synchronize the repository
594
-** with the content of the working checkout:
694
+** Do all necessary "[[add]]" and "[[rm]]" commands to synchronize the
695
+** repository with the content of the working checkout:
595696
**
596697
** * All files in the checkout but not in the repository (that is,
597698
** all files displayed using the "extras" command) are added as
598
-** if by the "add" command.
699
+** if by the "[[add]]" command.
599700
**
600701
** * All files in the repository but missing from the checkout (that is,
601702
** all files that show as MISSING with the "status" command) are
602
-** removed as if by the "rm" command.
703
+** removed as if by the "[[rm]]" command.
603704
**
604
-** The command does not "commit". You must run the "commit" separately
705
+** The command does not "[[commit]]". You must run the "[[commit]]" separately
605706
** as a separate step.
606707
**
607708
** Files and directories whose names begin with "." are ignored unless
608709
** the --dotfiles option is used.
609710
**
@@ -616,25 +717,33 @@
616717
** anything.
617718
**
618719
** This command can be used to track third party software.
619720
**
620721
** Options:
621
-** --case-sensitive <BOOL> Override the case-sensitive setting.
722
+** --case-sensitive BOOL Override the case-sensitive setting.
622723
** --dotfiles Include files beginning with a dot (".")
623
-** --ignore <CSG> Ignore unmanaged files matching patterns from
624
-** the comma separated list of glob patterns.
625
-** --clean <CSG> Also ignore files matching patterns from
626
-** the comma separated list of glob patterns.
724
+** --ignore CSG Ignore unmanaged files matching patterns from
725
+** the Comma Separated Glob (CSG) list
726
+** --clean CSG Also ignore files matching patterns from
727
+** the Comma Separated Glob (CSG) list
627728
** -n|--dry-run If given, display instead of run actions.
729
+** --reset Reset the ADDED/DELETED state of a checkout,
730
+** such that all newly-added (but not yet committed)
731
+** files are no longer added and all newly-removed
732
+** (but not yet committed) files are no longer
733
+** removed. No flags other than --verbose and
734
+** --dry-run may be used with --reset.
735
+** --verbose|-v Outputs information about each --reset file.
736
+** Only usable with --reset.
628737
**
629
-** See also: add, rm
738
+** See also: [[add]], [[rm]]
630739
*/
631740
void addremove_cmd(void){
632741
Blob path;
633
- const char *zCleanFlag = find_option("clean",0,1);
634
- const char *zIgnoreFlag = find_option("ignore",0,1);
635
- unsigned scanFlags = find_option("dotfiles",0,0)!=0 ? SCAN_ALL : 0;
742
+ const char *zCleanFlag;
743
+ const char *zIgnoreFlag;
744
+ unsigned scanFlags;
636745
int dryRunFlag = find_option("dry-run","n",0)!=0;
637746
int n;
638747
Stmt q;
639748
int vid;
640749
int nAdd = 0;
@@ -643,10 +752,23 @@
643752
644753
if( !dryRunFlag ){
645754
dryRunFlag = find_option("test",0,0)!=0; /* deprecated */
646755
}
647756
757
+ if(0!=find_option("reset",0,0)){
758
+ int const verboseFlag = find_option("verbose","v",0)!=0;
759
+ db_must_be_within_tree();
760
+ verify_all_options();
761
+ addremove_reset(0, dryRunFlag, verboseFlag);
762
+ addremove_reset(1, dryRunFlag, verboseFlag);
763
+ return;
764
+ }
765
+
766
+ zCleanFlag = find_option("clean",0,1);
767
+ zIgnoreFlag = find_option("ignore",0,1);
768
+ scanFlags = find_option("dotfiles",0,0)!=0 ? SCAN_ALL : 0;
769
+
648770
/* We should be done with options.. */
649771
verify_all_options();
650772
651773
/* Fail if unprocessed arguments are present, in case user expect the
652774
** addremove command to accept a list of file or directory.
@@ -710,11 +832,10 @@
710832
/* show command summary */
711833
fossil_print("added %d files, deleted %d files\n", nAdd, nDelete);
712834
713835
db_end_transaction(dryRunFlag);
714836
}
715
-
716837
717838
/*
718839
** Rename a single file.
719840
**
720841
** The original name of the file is zOrig. The new filename is zNew.
@@ -832,11 +953,11 @@
832953
** Move or rename one or more files or directories within the repository tree.
833954
** You can either rename a file or directory or move it to another subdirectory.
834955
**
835956
** The 'mv' command does NOT normally rename or move the files on disk.
836957
** This command merely records the fact that file names have changed so
837
-** that appropriate notations can be made at the next commit/check-in.
958
+** that appropriate notations can be made at the next [[commit]].
838959
** However, the default behavior of this command may be overridden via
839960
** command line options listed below and/or the 'mv-rm-files' setting.
840961
**
841962
** The 'rename' command never renames or moves files on disk, even when the
842963
** command line options and/or the 'mv-rm-files' setting would otherwise
@@ -845,17 +966,17 @@
845966
** WARNING: If the "--hard" option is specified -OR- the "mv-rm-files"
846967
** setting is non-zero, files WILL BE renamed or moved on disk
847968
** as well. This does NOT apply to the 'rename' command.
848969
**
849970
** Options:
850
-** --soft Skip moving files within the checkout.
851
-** This supersedes the --hard option.
852
-** --hard Move files within the checkout.
853
-** --case-sensitive <BOOL> Override the case-sensitive setting.
854
-** -n|--dry-run If given, display instead of run actions.
971
+** --soft Skip moving files within the checkout.
972
+** This supersedes the --hard option.
973
+** --hard Move files within the checkout.
974
+** --case-sensitive <BOOL> Override the case-sensitive setting.
975
+** -n|--dry-run If given, display instead of run actions.
855976
**
856
-** See also: changes, status
977
+** See also: [[changes]], [[status]]
857978
*/
858979
void mv_cmd(void){
859980
int i;
860981
int vid;
861982
int moveFiles;
@@ -890,15 +1011,11 @@
8901011
}else if( softFlag ){
8911012
moveFiles = 0;
8921013
}else if( hardFlag ){
8931014
moveFiles = 1;
8941015
}else{
895
-#if FOSSIL_ENABLE_LEGACY_MV_RM
8961016
moveFiles = db_get_boolean("mv-rm-files",0);
897
-#else
898
- moveFiles = FOSSIL_MV_RM_FILE;
899
-#endif
9001017
}
9011018
file_tree_name(zDest, &dest, 0, 1);
9021019
db_multi_exec(
9031020
"UPDATE vfile SET origname=pathname WHERE origname IS NULL;"
9041021
);
@@ -947,11 +1064,11 @@
9471064
const char *zPath = db_column_text(&q, 0);
9481065
int nPath = db_column_bytes(&q, 0);
9491066
const char *zTail;
9501067
if( nPath==nOrig ){
9511068
zTail = file_tail(zPath);
952
- }else if( destType==1 ){
1069
+ }else if( origType!=0 && destType==1 ){
9531070
zTail = &zPath[nOrig-strlen(file_tail(zOrig))];
9541071
}else{
9551072
zTail = &zPath[nOrig+1];
9561073
}
9571074
db_multi_exec(
9581075
9591076
ADDED src/ajax.c
--- src/add.c
+++ src/add.c
@@ -22,28 +22,10 @@
22 #include "add.h"
23 #include <assert.h>
24 #include <dirent.h>
25 #include "cygsup.h"
26
27 /*
28 ** WARNING: For Fossil version x.x this value was always zero. For Fossil-NG
29 ** it will probably always be one. When this value is zero,
30 ** files in the checkout will not be moved by the "mv" command and
31 ** files in the checkout will not be removed by the "rm" command.
32 **
33 ** If the FOSSIL_ENABLE_LEGACY_MV_RM compile-time option is used,
34 ** the "mv-rm-files" setting will be consulted instead of using
35 ** this value.
36 **
37 ** To retain the Fossil version 2.x behavior when using Fossil-NG
38 ** the FOSSIL_ENABLE_LEGACY_MV_RM compile-time option must be used
39 ** -AND- the "mv-rm-files" setting must be set to zero.
40 */
41 #ifndef FOSSIL_MV_RM_FILE
42 #define FOSSIL_MV_RM_FILE (0)
43 #endif
44
45 /*
46 ** This routine returns the names of files in a working checkout that
47 ** are created by Fossil itself, and hence should not be added, deleted,
48 ** or merge, and should be omitted from "clean" and "extras" lists.
49 **
@@ -240,18 +222,109 @@
240 }
241 db_finalize(&loop);
242 blob_reset(&repoName);
243 return nAdd;
244 }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
245
246 /*
247 ** COMMAND: add
248 **
249 ** Usage: %fossil add ?OPTIONS? FILE1 ?FILE2 ...?
250 **
251 ** Make arrangements to add one or more files or directories to the
252 ** current checkout at the next commit.
253 **
254 ** When adding files or directories recursively, filenames that begin
255 ** with "." are excluded by default. To include such files, add
256 ** the "--dotfiles" option to the command-line.
257 **
@@ -269,19 +342,28 @@
269 ** be treated case sensitive or not. If the option is not given, the default
270 ** depends on the global setting, or the operating system default, if not set.
271 **
272 ** Options:
273 **
274 ** --case-sensitive <BOOL> Override the case-sensitive setting.
275 ** --dotfiles include files beginning with a dot (".")
276 ** -f|--force Add files without prompting
277 ** --ignore <CSG> Ignore unmanaged files matching patterns from
278 ** the comma separated list of glob patterns.
279 ** --clean <CSG> Also ignore files matching patterns from
280 ** the comma separated list of glob patterns.
 
 
 
 
 
 
 
 
 
281 **
282 ** See also: addremove, rm
283 */
284 void add_cmd(void){
285 int i; /* Loop counter */
286 int vid; /* Currently checked out version */
287 int nRoot; /* Full path characters in g.zLocalRoot */
@@ -288,10 +370,19 @@
288 const char *zCleanFlag; /* The --clean option or clean-glob setting */
289 const char *zIgnoreFlag; /* The --ignore option or ignore-glob setting */
290 Glob *pIgnore, *pClean; /* Ignore everything matching the glob patterns */
291 unsigned scanFlags = 0; /* Flags passed to vfile_scan() */
292 int forceFlag;
 
 
 
 
 
 
 
 
 
293
294 zCleanFlag = find_option("clean",0,1);
295 zIgnoreFlag = find_option("ignore",0,1);
296 forceFlag = find_option("force","f",0)!=0;
297 if( find_option("dotfiles",0,0)!=0 ) scanFlags |= SCAN_ALL;
@@ -442,22 +533,36 @@
442 ** --soft Skip removing files from the checkout.
443 ** This supersedes the --hard option.
444 ** --hard Remove files from the checkout.
445 ** --case-sensitive <BOOL> Override the case-sensitive setting.
446 ** -n|--dry-run If given, display instead of run actions.
 
 
 
 
 
 
 
447 **
448 ** See also: addremove, add
449 */
450 void delete_cmd(void){
451 int i;
452 int removeFiles;
453 int dryRunFlag;
454 int softFlag;
455 int hardFlag;
456 Stmt loop;
457
458 dryRunFlag = find_option("dry-run","n",0)!=0;
 
 
 
 
 
 
 
459 softFlag = find_option("soft",0,0)!=0;
460 hardFlag = find_option("hard",0,0)!=0;
461
462 /* We should be done with options.. */
463 verify_all_options();
@@ -469,15 +574,11 @@
469 }else if( softFlag ){
470 removeFiles = 0;
471 }else if( hardFlag ){
472 removeFiles = 1;
473 }else{
474 #if FOSSIL_ENABLE_LEGACY_MV_RM
475 removeFiles = db_get_boolean("mv-rm-files",0);
476 #else
477 removeFiles = FOSSIL_MV_RM_FILE;
478 #endif
479 }
480 db_multi_exec("CREATE TEMP TABLE sfile(pathname TEXT PRIMARY KEY %s)",
481 filename_collation());
482 for(i=2; i<g.argc; i++){
483 Blob treeName;
@@ -588,22 +689,22 @@
588 /*
589 ** COMMAND: addremove
590 **
591 ** Usage: %fossil addremove ?OPTIONS?
592 **
593 ** Do all necessary "add" and "rm" commands to synchronize the repository
594 ** with the content of the working checkout:
595 **
596 ** * All files in the checkout but not in the repository (that is,
597 ** all files displayed using the "extras" command) are added as
598 ** if by the "add" command.
599 **
600 ** * All files in the repository but missing from the checkout (that is,
601 ** all files that show as MISSING with the "status" command) are
602 ** removed as if by the "rm" command.
603 **
604 ** The command does not "commit". You must run the "commit" separately
605 ** as a separate step.
606 **
607 ** Files and directories whose names begin with "." are ignored unless
608 ** the --dotfiles option is used.
609 **
@@ -616,25 +717,33 @@
616 ** anything.
617 **
618 ** This command can be used to track third party software.
619 **
620 ** Options:
621 ** --case-sensitive <BOOL> Override the case-sensitive setting.
622 ** --dotfiles Include files beginning with a dot (".")
623 ** --ignore <CSG> Ignore unmanaged files matching patterns from
624 ** the comma separated list of glob patterns.
625 ** --clean <CSG> Also ignore files matching patterns from
626 ** the comma separated list of glob patterns.
627 ** -n|--dry-run If given, display instead of run actions.
 
 
 
 
 
 
 
 
628 **
629 ** See also: add, rm
630 */
631 void addremove_cmd(void){
632 Blob path;
633 const char *zCleanFlag = find_option("clean",0,1);
634 const char *zIgnoreFlag = find_option("ignore",0,1);
635 unsigned scanFlags = find_option("dotfiles",0,0)!=0 ? SCAN_ALL : 0;
636 int dryRunFlag = find_option("dry-run","n",0)!=0;
637 int n;
638 Stmt q;
639 int vid;
640 int nAdd = 0;
@@ -643,10 +752,23 @@
643
644 if( !dryRunFlag ){
645 dryRunFlag = find_option("test",0,0)!=0; /* deprecated */
646 }
647
 
 
 
 
 
 
 
 
 
 
 
 
 
648 /* We should be done with options.. */
649 verify_all_options();
650
651 /* Fail if unprocessed arguments are present, in case user expect the
652 ** addremove command to accept a list of file or directory.
@@ -710,11 +832,10 @@
710 /* show command summary */
711 fossil_print("added %d files, deleted %d files\n", nAdd, nDelete);
712
713 db_end_transaction(dryRunFlag);
714 }
715
716
717 /*
718 ** Rename a single file.
719 **
720 ** The original name of the file is zOrig. The new filename is zNew.
@@ -832,11 +953,11 @@
832 ** Move or rename one or more files or directories within the repository tree.
833 ** You can either rename a file or directory or move it to another subdirectory.
834 **
835 ** The 'mv' command does NOT normally rename or move the files on disk.
836 ** This command merely records the fact that file names have changed so
837 ** that appropriate notations can be made at the next commit/check-in.
838 ** However, the default behavior of this command may be overridden via
839 ** command line options listed below and/or the 'mv-rm-files' setting.
840 **
841 ** The 'rename' command never renames or moves files on disk, even when the
842 ** command line options and/or the 'mv-rm-files' setting would otherwise
@@ -845,17 +966,17 @@
845 ** WARNING: If the "--hard" option is specified -OR- the "mv-rm-files"
846 ** setting is non-zero, files WILL BE renamed or moved on disk
847 ** as well. This does NOT apply to the 'rename' command.
848 **
849 ** Options:
850 ** --soft Skip moving files within the checkout.
851 ** This supersedes the --hard option.
852 ** --hard Move files within the checkout.
853 ** --case-sensitive <BOOL> Override the case-sensitive setting.
854 ** -n|--dry-run If given, display instead of run actions.
855 **
856 ** See also: changes, status
857 */
858 void mv_cmd(void){
859 int i;
860 int vid;
861 int moveFiles;
@@ -890,15 +1011,11 @@
890 }else if( softFlag ){
891 moveFiles = 0;
892 }else if( hardFlag ){
893 moveFiles = 1;
894 }else{
895 #if FOSSIL_ENABLE_LEGACY_MV_RM
896 moveFiles = db_get_boolean("mv-rm-files",0);
897 #else
898 moveFiles = FOSSIL_MV_RM_FILE;
899 #endif
900 }
901 file_tree_name(zDest, &dest, 0, 1);
902 db_multi_exec(
903 "UPDATE vfile SET origname=pathname WHERE origname IS NULL;"
904 );
@@ -947,11 +1064,11 @@
947 const char *zPath = db_column_text(&q, 0);
948 int nPath = db_column_bytes(&q, 0);
949 const char *zTail;
950 if( nPath==nOrig ){
951 zTail = file_tail(zPath);
952 }else if( destType==1 ){
953 zTail = &zPath[nOrig-strlen(file_tail(zOrig))];
954 }else{
955 zTail = &zPath[nOrig+1];
956 }
957 db_multi_exec(
958
959 DDED src/ajax.c
--- src/add.c
+++ src/add.c
@@ -22,28 +22,10 @@
22 #include "add.h"
23 #include <assert.h>
24 #include <dirent.h>
25 #include "cygsup.h"
26
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
27 /*
28 ** This routine returns the names of files in a working checkout that
29 ** are created by Fossil itself, and hence should not be added, deleted,
30 ** or merge, and should be omitted from "clean" and "extras" lists.
31 **
@@ -240,18 +222,109 @@
222 }
223 db_finalize(&loop);
224 blob_reset(&repoName);
225 return nAdd;
226 }
227
228 /*
229 ** Resets the ADDED/DELETED state of a checkout, such that all
230 ** newly-added (but not yet committed) files are no longer added and
231 ** newly-removed (but not yet committed) files are no longer
232 ** removed. If bIsAdd is true, it operates on the "add" state, else it
233 ** operates on the "rm" state.
234 **
235 ** If bDryRun is true it outputs what it would have done, but does not
236 ** actually do it. In this case it rolls back the transaction it
237 ** starts (so don't start a transaction before calling this).
238 **
239 ** If bVerbose is true it outputs the name of each reset entry.
240 **
241 ** This is intended to be called only in the context of the
242 ** add/rm/addremove commands, after a call to verify_all_options().
243 **
244 ** Un-added files are not modified but any un-rm'd files which are
245 ** missing from the checkout are restored from the repo. un-rm'd files
246 ** which exist in the checkout are left as-is, rather than restoring
247 ** them using vfile_to_disk(), to avoid overwriting any local changes
248 ** made to those files.
249 */
250 static void addremove_reset(int bIsAdd, int bDryRun, int bVerbose){
251 int nReset = 0; /* # of entries which get reset */
252 Stmt stmt; /* vfile loop query */
253
254 db_begin_transaction();
255 db_prepare(&stmt, "SELECT id, pathname FROM vfile "
256 "WHERE %s ORDER BY pathname",
257 bIsAdd==0 ? "deleted<>0" : "rid=0"/*safe-for-%s*/);
258 while( db_step(&stmt)==SQLITE_ROW ){
259 /* This loop exists only so we can restore the contents of un-rm'd
260 ** files and support verbose mode. All manipulation of vfile's
261 ** contents happens after the loop. For the ADD case in non-verbose
262 ** mode we "could" skip this loop entirely.
263 */
264 int const id = db_column_int(&stmt, 0);
265 char const * zPathname = db_column_text(&stmt, 1);
266 Blob relName = empty_blob;
267 if(bIsAdd==0 || bVerbose!=0){
268 /* Make filename relative... */
269 char *zFullName = mprintf("%s%s", g.zLocalRoot, zPathname);
270 file_relative_name(zFullName, &relName, 0);
271 fossil_free(zFullName);
272 }
273 if(bIsAdd==0){
274 /* Restore contents of missing un-rm'd files. We don't do this
275 ** unconditionally because we might cause data loss if a file
276 ** is modified, rm'd, then un-rm'd.
277 */
278 ++nReset;
279 if(!file_isfile_or_link(blob_str(&relName))){
280 if(bDryRun==0){
281 vfile_to_disk(0, id, 0, 0);
282 if(bVerbose){
283 fossil_print("Restored missing file: %b\n", &relName);
284 }
285 }else{
286 fossil_print("Dry-run: not restoring missing file: %b\n", &relName);
287 }
288 }
289 if(bVerbose){
290 fossil_print("Un-removed: %b\n", &relName);
291 }
292 }else{
293 /* un-add... */
294 ++nReset;
295 if(bVerbose){
296 fossil_print("Un-added: %b\n", &relName);
297 }
298 }
299 blob_reset(&relName);
300 }
301 db_finalize(&stmt);
302 if(nReset>0){
303 if(bIsAdd==0){
304 if(bDryRun==0){
305 db_exec_sql("UPDATE vfile SET deleted=0 WHERE deleted<>0");
306 }
307 fossil_print("Un-removed %d file(s).\n", nReset);
308 }else{
309 if(bDryRun==0){
310 db_exec_sql("DELETE FROM vfile WHERE rid=0");
311 }
312 fossil_print("Un-added %d file(s).\n", nReset);
313 }
314 }
315 db_end_transaction(bDryRun ? 1 : 0);
316 }
317
318
319 /*
320 ** COMMAND: add
321 **
322 ** Usage: %fossil add ?OPTIONS? FILE1 ?FILE2 ...?
323 **
324 ** Make arrangements to add one or more files or directories to the
325 ** current checkout at the next [[commit]].
326 **
327 ** When adding files or directories recursively, filenames that begin
328 ** with "." are excluded by default. To include such files, add
329 ** the "--dotfiles" option to the command-line.
330 **
@@ -269,19 +342,28 @@
342 ** be treated case sensitive or not. If the option is not given, the default
343 ** depends on the global setting, or the operating system default, if not set.
344 **
345 ** Options:
346 **
347 ** --case-sensitive BOOL Override the case-sensitive setting.
348 ** --dotfiles include files beginning with a dot (".")
349 ** -f|--force Add files without prompting
350 ** --ignore CSG Ignore unmanaged files matching patterns from
351 ** the Comma Separated Glob (CSG) pattern list
352 ** --clean CSG Also ignore files matching patterns from
353 ** the Comma Separated Glob (CSG) list
354 ** --reset Reset the ADDED state of a checkout, such
355 ** that all newly-added (but not yet committed)
356 ** files are no longer added. No flags other
357 ** than --verbose and --dry-run may be used
358 ** with --reset.
359 **
360 ** The following options are only valid with --reset:
361 ** -v|--verbose Outputs information about each --reset file.
362 ** -n|--dry-run Display instead of run actions.
363 **
364 ** See also: [[addremove]], [[rm]]
365 */
366 void add_cmd(void){
367 int i; /* Loop counter */
368 int vid; /* Currently checked out version */
369 int nRoot; /* Full path characters in g.zLocalRoot */
@@ -288,10 +370,19 @@
370 const char *zCleanFlag; /* The --clean option or clean-glob setting */
371 const char *zIgnoreFlag; /* The --ignore option or ignore-glob setting */
372 Glob *pIgnore, *pClean; /* Ignore everything matching the glob patterns */
373 unsigned scanFlags = 0; /* Flags passed to vfile_scan() */
374 int forceFlag;
375
376 if(0!=find_option("reset",0,0)){
377 int const verboseFlag = find_option("verbose","v",0)!=0;
378 int const dryRunFlag = find_option("dry-run","n",0)!=0;
379 db_must_be_within_tree();
380 verify_all_options();
381 addremove_reset(1, dryRunFlag, verboseFlag);
382 return;
383 }
384
385 zCleanFlag = find_option("clean",0,1);
386 zIgnoreFlag = find_option("ignore",0,1);
387 forceFlag = find_option("force","f",0)!=0;
388 if( find_option("dotfiles",0,0)!=0 ) scanFlags |= SCAN_ALL;
@@ -442,22 +533,36 @@
533 ** --soft Skip removing files from the checkout.
534 ** This supersedes the --hard option.
535 ** --hard Remove files from the checkout.
536 ** --case-sensitive <BOOL> Override the case-sensitive setting.
537 ** -n|--dry-run If given, display instead of run actions.
538 ** --reset Reset the DELETED state of a checkout, such
539 ** that all newly-rm'd (but not yet committed)
540 ** files are no longer removed. No flags other
541 ** than --verbose or --dry-run may be used with
542 ** --reset.
543 ** --verbose|-v Outputs information about each --reset file.
544 ** Only usable with --reset.
545 **
546 ** See also: [[addremove]], [[add]]
547 */
548 void delete_cmd(void){
549 int i;
550 int removeFiles;
551 int dryRunFlag = find_option("dry-run","n",0)!=0;
552 int softFlag;
553 int hardFlag;
554 Stmt loop;
555
556 if(0!=find_option("reset",0,0)){
557 int const verboseFlag = find_option("verbose","v",0)!=0;
558 db_must_be_within_tree();
559 verify_all_options();
560 addremove_reset(0, dryRunFlag, verboseFlag);
561 return;
562 }
563
564 softFlag = find_option("soft",0,0)!=0;
565 hardFlag = find_option("hard",0,0)!=0;
566
567 /* We should be done with options.. */
568 verify_all_options();
@@ -469,15 +574,11 @@
574 }else if( softFlag ){
575 removeFiles = 0;
576 }else if( hardFlag ){
577 removeFiles = 1;
578 }else{
 
579 removeFiles = db_get_boolean("mv-rm-files",0);
 
 
 
580 }
581 db_multi_exec("CREATE TEMP TABLE sfile(pathname TEXT PRIMARY KEY %s)",
582 filename_collation());
583 for(i=2; i<g.argc; i++){
584 Blob treeName;
@@ -588,22 +689,22 @@
689 /*
690 ** COMMAND: addremove
691 **
692 ** Usage: %fossil addremove ?OPTIONS?
693 **
694 ** Do all necessary "[[add]]" and "[[rm]]" commands to synchronize the
695 ** repository with the content of the working checkout:
696 **
697 ** * All files in the checkout but not in the repository (that is,
698 ** all files displayed using the "extras" command) are added as
699 ** if by the "[[add]]" command.
700 **
701 ** * All files in the repository but missing from the checkout (that is,
702 ** all files that show as MISSING with the "status" command) are
703 ** removed as if by the "[[rm]]" command.
704 **
705 ** The command does not "[[commit]]". You must run the "[[commit]]" separately
706 ** as a separate step.
707 **
708 ** Files and directories whose names begin with "." are ignored unless
709 ** the --dotfiles option is used.
710 **
@@ -616,25 +717,33 @@
717 ** anything.
718 **
719 ** This command can be used to track third party software.
720 **
721 ** Options:
722 ** --case-sensitive BOOL Override the case-sensitive setting.
723 ** --dotfiles Include files beginning with a dot (".")
724 ** --ignore CSG Ignore unmanaged files matching patterns from
725 ** the Comma Separated Glob (CSG) list
726 ** --clean CSG Also ignore files matching patterns from
727 ** the Comma Separated Glob (CSG) list
728 ** -n|--dry-run If given, display instead of run actions.
729 ** --reset Reset the ADDED/DELETED state of a checkout,
730 ** such that all newly-added (but not yet committed)
731 ** files are no longer added and all newly-removed
732 ** (but not yet committed) files are no longer
733 ** removed. No flags other than --verbose and
734 ** --dry-run may be used with --reset.
735 ** --verbose|-v Outputs information about each --reset file.
736 ** Only usable with --reset.
737 **
738 ** See also: [[add]], [[rm]]
739 */
740 void addremove_cmd(void){
741 Blob path;
742 const char *zCleanFlag;
743 const char *zIgnoreFlag;
744 unsigned scanFlags;
745 int dryRunFlag = find_option("dry-run","n",0)!=0;
746 int n;
747 Stmt q;
748 int vid;
749 int nAdd = 0;
@@ -643,10 +752,23 @@
752
753 if( !dryRunFlag ){
754 dryRunFlag = find_option("test",0,0)!=0; /* deprecated */
755 }
756
757 if(0!=find_option("reset",0,0)){
758 int const verboseFlag = find_option("verbose","v",0)!=0;
759 db_must_be_within_tree();
760 verify_all_options();
761 addremove_reset(0, dryRunFlag, verboseFlag);
762 addremove_reset(1, dryRunFlag, verboseFlag);
763 return;
764 }
765
766 zCleanFlag = find_option("clean",0,1);
767 zIgnoreFlag = find_option("ignore",0,1);
768 scanFlags = find_option("dotfiles",0,0)!=0 ? SCAN_ALL : 0;
769
770 /* We should be done with options.. */
771 verify_all_options();
772
773 /* Fail if unprocessed arguments are present, in case user expect the
774 ** addremove command to accept a list of file or directory.
@@ -710,11 +832,10 @@
832 /* show command summary */
833 fossil_print("added %d files, deleted %d files\n", nAdd, nDelete);
834
835 db_end_transaction(dryRunFlag);
836 }
 
837
838 /*
839 ** Rename a single file.
840 **
841 ** The original name of the file is zOrig. The new filename is zNew.
@@ -832,11 +953,11 @@
953 ** Move or rename one or more files or directories within the repository tree.
954 ** You can either rename a file or directory or move it to another subdirectory.
955 **
956 ** The 'mv' command does NOT normally rename or move the files on disk.
957 ** This command merely records the fact that file names have changed so
958 ** that appropriate notations can be made at the next [[commit]].
959 ** However, the default behavior of this command may be overridden via
960 ** command line options listed below and/or the 'mv-rm-files' setting.
961 **
962 ** The 'rename' command never renames or moves files on disk, even when the
963 ** command line options and/or the 'mv-rm-files' setting would otherwise
@@ -845,17 +966,17 @@
966 ** WARNING: If the "--hard" option is specified -OR- the "mv-rm-files"
967 ** setting is non-zero, files WILL BE renamed or moved on disk
968 ** as well. This does NOT apply to the 'rename' command.
969 **
970 ** Options:
971 ** --soft Skip moving files within the checkout.
972 ** This supersedes the --hard option.
973 ** --hard Move files within the checkout.
974 ** --case-sensitive <BOOL> Override the case-sensitive setting.
975 ** -n|--dry-run If given, display instead of run actions.
976 **
977 ** See also: [[changes]], [[status]]
978 */
979 void mv_cmd(void){
980 int i;
981 int vid;
982 int moveFiles;
@@ -890,15 +1011,11 @@
1011 }else if( softFlag ){
1012 moveFiles = 0;
1013 }else if( hardFlag ){
1014 moveFiles = 1;
1015 }else{
 
1016 moveFiles = db_get_boolean("mv-rm-files",0);
 
 
 
1017 }
1018 file_tree_name(zDest, &dest, 0, 1);
1019 db_multi_exec(
1020 "UPDATE vfile SET origname=pathname WHERE origname IS NULL;"
1021 );
@@ -947,11 +1064,11 @@
1064 const char *zPath = db_column_text(&q, 0);
1065 int nPath = db_column_bytes(&q, 0);
1066 const char *zTail;
1067 if( nPath==nOrig ){
1068 zTail = file_tail(zPath);
1069 }else if( origType!=0 && destType==1 ){
1070 zTail = &zPath[nOrig-strlen(file_tail(zOrig))];
1071 }else{
1072 zTail = &zPath[nOrig+1];
1073 }
1074 db_multi_exec(
1075
1076 DDED src/ajax.c
+19
--- a/src/ajax.c
+++ b/src/ajax.c
@@ -0,0 +1,19 @@
1
+/*
2
+** Copyright (c) 2020 D. Richard Hipp
3
+**
4
+** This program is free software; you can redistribute it and/or
5
+** modify it under the terms of the Simplified BSD License (also
6
+** known as the "2-Clause License" or "FreeB11, 1
7
+}
8
+ 0, diffFlags if(DIFF_SIDEBYSIDE & diffFlags)else{
9
+ CX("wiki emit_script_tag(0,0);
10
+ CX("\n"emit_script_tag(1,0stylere; you can redistri/*
11
+** Copyright (c) 2020 D. Richard Hipp
12
+**
13
+** This program is free software; you can redistribute it and/or
14
+** modify it under the terms of the Simplified BSD License (also
15
+** known as the "2-Clause License" or "FreeB11, 1
16
+}
17
+ 0, diffFlags if(DIFF_SIDEBYSIDE & diffFlags)else{
18
+ CX("wiki emit_script_tag(0,0);
19
+ CX("\n"emit_script_tag(1,0style
--- a/src/ajax.c
+++ b/src/ajax.c
@@ -0,0 +1,19 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
--- a/src/ajax.c
+++ b/src/ajax.c
@@ -0,0 +1,19 @@
1 /*
2 ** Copyright (c) 2020 D. Richard Hipp
3 **
4 ** This program is free software; you can redistribute it and/or
5 ** modify it under the terms of the Simplified BSD License (also
6 ** known as the "2-Clause License" or "FreeB11, 1
7 }
8 0, diffFlags if(DIFF_SIDEBYSIDE & diffFlags)else{
9 CX("wiki emit_script_tag(0,0);
10 CX("\n"emit_script_tag(1,0stylere; you can redistri/*
11 ** Copyright (c) 2020 D. Richard Hipp
12 **
13 ** This program is free software; you can redistribute it and/or
14 ** modify it under the terms of the Simplified BSD License (also
15 ** known as the "2-Clause License" or "FreeB11, 1
16 }
17 0, diffFlags if(DIFF_SIDEBYSIDE & diffFlags)else{
18 CX("wiki emit_script_tag(0,0);
19 CX("\n"emit_script_tag(1,0style
+463 -200
--- src/alerts.c
+++ src/alerts.c
@@ -46,10 +46,11 @@
4646
@ --
4747
@ -- The ssub field is a string where each character indicates a particular
4848
@ -- type of event to subscribe to. Choices:
4949
@ -- a - Announcements
5050
@ -- c - Check-ins
51
+@ -- f - Forum posts
5152
@ -- t - Ticket changes
5253
@ -- w - Wiki changes
5354
@ -- Probably different codes will be added in the future. In the future
5455
@ -- we might also add a separate table that allows subscribing to email
5556
@ -- notifications for specific branches or tags or tickets.
@@ -114,11 +115,11 @@
114115
if( bOnlyIfEnabled
115116
&& fossil_strcmp(db_get("email-send-method",0),"off")==0
116117
){
117118
return; /* Don't create table for disabled email */
118119
}
119
- db_multi_exec(zAlertInit/*works-like:""*/);
120
+ db_exec_sql(zAlertInit);
120121
alert_triggers_enable();
121122
}else if( !db_table_has_column("repository","pending_alert","sentMod") ){
122123
db_multi_exec(
123124
"ALTER TABLE repository.pending_alert"
124125
" ADD COLUMN sentMod BOOLEAN DEFAULT false;"
@@ -183,11 +184,11 @@
183184
** is an administrator.
184185
*/
185186
void alert_submenu_common(void){
186187
if( g.perm.Admin ){
187188
if( fossil_strcmp(g.zPath,"subscribers") ){
188
- style_submenu_element("List Subscribers","%R/subscribers");
189
+ style_submenu_element("Subscribers","%R/subscribers");
189190
}
190191
if( fossil_strcmp(g.zPath,"subscribe") ){
191192
style_submenu_element("Add New Subscriber","%R/subscribe");
192193
}
193194
}
@@ -238,10 +239,17 @@
238239
@ This is URL used as the basename for hyperlinks included in
239240
@ email alert text. Omit the trailing "/".
240241
@ Suggested value: "%h(g.zBaseURL)"
241242
@ (Property: "email-url")</p>
242243
@ <hr>
244
+
245
+ entry_attribute("Administrator email address", 40, "email-admin",
246
+ "eadmin", "", 0);
247
+ @ <p>This is the email for the human administrator for the system.
248
+ @ Abuse and trouble reports and password reset requests are send here.
249
+ @ (Property: "email-admin")</p>
250
+ @ <hr>
243251
244252
entry_attribute("\"Return-Path\" email address", 20, "email-self",
245253
"eself", "", 0);
246254
@ <p><b>Required.</b>
247255
@ This is the email to which email notification bounces should be sent.
@@ -297,17 +305,10 @@
297305
@ append a colon and TCP port number (ex: smtp.example.com:587).
298306
@ The default TCP port number is 25.
299307
@ (Property: "email-send-relayhost")</p>
300308
@ <hr>
301309
302
- entry_attribute("Administrator email address", 40, "email-admin",
303
- "eadmin", "", 0);
304
- @ <p>This is the email for the human administrator for the system.
305
- @ Abuse and trouble reports are send here.
306
- @ (Property: "email-admin")</p>
307
- @ <hr>
308
-
309310
@ <p><input type="submit" name="submit" value="Apply Changes" /></p>
310311
@ </div></form>
311312
db_end_transaction(0);
312313
style_footer();
313314
}
@@ -574,22 +575,18 @@
574575
}
575576
return 0;
576577
}
577578
578579
/*
579
-** Make a copy of the input string up to but not including the
580
-** first cTerm character.
581
-**
582
-** Verify that the string really that is to be copied really is a
583
-** valid email address. If it is not, then return NULL.
584
-**
585
-** This routine is more restrictive than necessary. It does not
586
-** allow comments, IP address, quoted strings, or certain uncommon
587
-** characters. The only non-alphanumerics allowed in the local
588
-** part are "_", "+", "-" and "+".
589
-*/
590
-char *email_copy_addr(const char *z, char cTerm ){
580
+** Determine whether or not the input string is a valid email address.
581
+** Only look at character up to but not including the first \000 or
582
+** the first cTerm character, whichever comes first.
583
+**
584
+** Return the length of the email addresss string in bytes if the email
585
+** address is valid. If the email address is misformed, return 0.
586
+*/
587
+int email_address_is_valid(const char *z, char cTerm){
591588
int i;
592589
int nAt = 0;
593590
int nDot = 0;
594591
char c;
595592
if( z[0]=='.' ) return 0; /* Local part cannot begin with "." */
@@ -619,13 +616,28 @@
619616
}
620617
}
621618
if( c!=cTerm ) return 0; /* Missing terminator */
622619
if( nAt==0 ) return 0; /* No "@" found anywhere */
623620
if( nDot==0 ) return 0; /* No "." in the domain */
621
+ return i;
622
+}
624623
625
- /* If we reach this point, the email address is valid */
626
- return mprintf("%.*s", i, z);
624
+/*
625
+** Make a copy of the input string up to but not including the
626
+** first cTerm character.
627
+**
628
+** Verify that the string really that is to be copied really is a
629
+** valid email address. If it is not, then return NULL.
630
+**
631
+** This routine is more restrictive than necessary. It does not
632
+** allow comments, IP address, quoted strings, or certain uncommon
633
+** characters. The only non-alphanumerics allowed in the local
634
+** part are "_", "+", "-" and "+".
635
+*/
636
+char *email_copy_addr(const char *z, char cTerm ){
637
+ int i = email_address_is_valid(z, cTerm);
638
+ return i==0 ? 0 : mprintf("%.*s", i, z);
627639
}
628640
629641
/*
630642
** Scan the input string for a valid email address enclosed in <...>
631643
** If the string contains one or more email addresses, extract the first
@@ -659,10 +671,38 @@
659671
char *zOut = alert_find_emailaddr(zIn);
660672
if( zOut ){
661673
sqlite3_result_text(context, zOut, -1, fossil_free);
662674
}
663675
}
676
+
677
+/*
678
+** SQL function: display_name(X)
679
+**
680
+** If X is a string, search for a user name at the beginning of that
681
+** string. The user name must be followed by an email address. If
682
+** found, return the user name. If not found, return NULL.
683
+**
684
+** This routine is used to extract the display name from the USER.INFO
685
+** field.
686
+*/
687
+void alert_display_name_func(
688
+ sqlite3_context *context,
689
+ int argc,
690
+ sqlite3_value **argv
691
+){
692
+ const char *zIn = (const char*)sqlite3_value_text(argv[0]);
693
+ int i;
694
+ if( zIn==0 ) return;
695
+ while( fossil_isspace(zIn[0]) ) zIn++;
696
+ for(i=0; zIn[i] && zIn[i]!='<' && zIn[i]!='\n'; i++){}
697
+ if( zIn[i]=='<' ){
698
+ while( i>0 && fossil_isspace(zIn[i-1]) ){ i--; }
699
+ if( i>0 ){
700
+ sqlite3_result_text(context, zIn, i, SQLITE_TRANSIENT);
701
+ }
702
+ }
703
+}
664704
665705
/*
666706
** Return the hostname portion of an email address - the part following
667707
** the @
668708
*/
@@ -762,11 +802,11 @@
762802
** Date:
763803
** Message-Id:
764804
** Content-Type:
765805
** Content-Transfer-Encoding:
766806
** MIME-Version:
767
-** X-Fossil-From:
807
+** Sender:
768808
**
769809
** The caller maintains ownership of the input Blobs. This routine will
770810
** read the Blobs and send them onward to the email system, but it will
771811
** not free them.
772812
**
@@ -774,14 +814,14 @@
774814
** in the pHdr parameter.
775815
**
776816
** If the zFromName argument is not NULL, then it should be a human-readable
777817
** name or handle for the sender. In that case, "From:" becomes a made-up
778818
** email address based on a hash of zFromName and the domain of email-self,
779
-** and an additional "X-Fossil-From:" field is inserted with the email-self
780
-** address. Downstream software might use the X-Fossil-From header to set
819
+** and an additional "Sender:" field is inserted with the email-self
820
+** address. Downstream software might use the Sender header to set
781821
** the envelope-from address of the email. If zFromName is a NULL pointer,
782
-** then the "From:" is set to the email-self value and X-Fossil-From is
822
+** then the "From:" is set to the email-self value and Sender is
783823
** omitted.
784824
*/
785825
void alert_send(
786826
AlertSender *p, /* Emailer context */
787827
Blob *pHdr, /* Email header (incomplete) */
@@ -794,26 +834,26 @@
794834
fossil_print("Sending email\n");
795835
}
796836
if( fossil_strcmp(p->zDest, "off")==0 ){
797837
return;
798838
}
839
+ blob_init(&all, 0, 0);
799840
if( fossil_strcmp(p->zDest, "blob")==0 ){
800841
pOut = &p->out;
801842
if( blob_size(pOut) ){
802843
blob_appendf(pOut, "%.72c\n", '=');
803844
}
804845
}else{
805
- blob_init(&all, 0, 0);
806846
pOut = &all;
807847
}
808848
blob_append(pOut, blob_buffer(pHdr), blob_size(pHdr));
809849
if( p->zFrom==0 || p->zFrom[0]==0 ){
810850
return; /* email-self is not set. Error will be reported separately */
811851
}else if( zFromName ){
812852
blob_appendf(pOut, "From: %s <%s@%s>\r\n",
813853
zFromName, alert_mailbox_name(zFromName), alert_hostname(p->zFrom));
814
- blob_appendf(pOut, "X-Fossil-From: <%s>\r\n", p->zFrom);
854
+ blob_appendf(pOut, "Sender: <%s>\r\n", p->zFrom);
815855
}else{
816856
blob_appendf(pOut, "From: <%s>\r\n", p->zFrom);
817857
}
818858
blob_appendf(pOut, "Date: %z\r\n", cgi_rfc822_datestamp(time(0)));
819859
if( strstr(blob_str(pHdr), "\r\nMessage-Id:")==0 ){
@@ -879,10 +919,26 @@
879919
fossil_print("%s", blob_str(&all));
880920
}
881921
blob_reset(&all);
882922
}
883923
924
+/*
925
+** SETTING: email-url width=40
926
+** This URL is used as the basename for hyperlinks included in email alert
927
+** text. Omit the trailing "/".
928
+*/
929
+/*
930
+** SETTING: email-admin width=40
931
+** This is the email address for the human administrator for the system.
932
+** Abuse and trouble reports and password reset requests are send here.
933
+*/
934
+/*
935
+** SETTING: email-subname width=16
936
+** This is a short name used to identifies the repository in the Subject:
937
+** line of email alerts. Traditionally this name is included in square
938
+** brackets. Examples: "[fossil-src]", "[sqlite-src]".
939
+*/
884940
/*
885941
** SETTING: email-send-method width=5 default=off
886942
** Determine the method used to send email. Allowed values are
887943
** "off", "relay", "pipe", "dir", "db", and "stdout". The "off" value
888944
** means no email is ever sent. The "relay" value means emails are sent
@@ -1152,10 +1208,19 @@
11521208
int i, j, n;
11531209
char c;
11541210
11551211
*peErr = 0;
11561212
*pzErr = 0;
1213
+
1214
+ /* Verify the captcha first */
1215
+ if( needCaptcha ){
1216
+ if( !captcha_is_correct(1) ){
1217
+ *peErr = 2;
1218
+ *pzErr = mprintf("incorrect security code");
1219
+ return 0;
1220
+ }
1221
+ }
11571222
11581223
/* Check the validity of the email address.
11591224
**
11601225
** (1) Exactly one '@' character.
11611226
** (2) No other characters besides [a-zA-Z0-9._+-]
@@ -1163,11 +1228,15 @@
11631228
** The local part is currently more restrictive than RFC 5322 allows:
11641229
** https://stackoverflow.com/a/2049510/142454 We will expand this as
11651230
** necessary.
11661231
*/
11671232
zEAddr = P("e");
1168
- if( zEAddr==0 ) return 0;
1233
+ if( zEAddr==0 ){
1234
+ *peErr = 1;
1235
+ *pzErr = mprintf("required");
1236
+ return 0;
1237
+ }
11691238
for(i=j=n=0; (c = zEAddr[i])!=0; i++){
11701239
if( c=='@' ){
11711240
n = i;
11721241
j++;
11731242
continue;
@@ -1193,14 +1262,13 @@
11931262
*peErr = 1;
11941263
*pzErr = mprintf("email domain too short");
11951264
return 0;
11961265
}
11971266
1198
- /* Verify the captcha */
1199
- if( needCaptcha && !captcha_is_correct(1) ){
1200
- *peErr = 2;
1201
- *pzErr = mprintf("incorrect security code");
1267
+ if( authorized_subscription_email(zEAddr)==0 ){
1268
+ *peErr = 1;
1269
+ *pzErr = mprintf("not an authorized email address");
12021270
return 0;
12031271
}
12041272
12051273
/* Check to make sure the email address is available for reuse */
12061274
if( db_exists("SELECT 1 FROM subscriber WHERE semail=%Q", zEAddr) ){
@@ -1259,11 +1327,11 @@
12591327
** page. To allow anonymous passers-by to sign up for email
12601328
** notification, set Email-Alerts on user "nobody" or "anonymous".
12611329
*/
12621330
void subscribe_page(void){
12631331
int needCaptcha;
1264
- unsigned int uSeed;
1332
+ unsigned int uSeed = 0;
12651333
const char *zDecoded;
12661334
char *zCaptcha = 0;
12671335
char *zErr = 0;
12681336
int eErr = 0;
12691337
int di;
@@ -1291,10 +1359,14 @@
12911359
/* Everybody else jumps to the page to administer their own
12921360
** account only. */
12931361
cgi_redirectf("%R/alerts");
12941362
return;
12951363
}
1364
+ }
1365
+ if( !g.perm.Admin && !db_get_boolean("anon-subscribe",1) ){
1366
+ register_page();
1367
+ return;
12961368
}
12971369
alert_submenu_common();
12981370
needCaptcha = !login_is_individual();
12991371
if( P("submit")
13001372
&& cgi_csrf_safe(1)
@@ -1312,10 +1384,11 @@
13121384
if( PB("sa") ) ssub[nsub++] = 'a';
13131385
if( g.perm.Read && PB("sc") ) ssub[nsub++] = 'c';
13141386
if( g.perm.RdForum && PB("sf") ) ssub[nsub++] = 'f';
13151387
if( g.perm.RdTkt && PB("st") ) ssub[nsub++] = 't';
13161388
if( g.perm.RdWiki && PB("sw") ) ssub[nsub++] = 'w';
1389
+ if( g.perm.RdForum && PB("sx") ) ssub[nsub++] = 'x';
13171390
ssub[nsub] = 0;
13181391
db_multi_exec(
13191392
"INSERT INTO subscriber(semail,suname,"
13201393
" sverified,sdonotcall,sdigest,ssub,sctime,mtime,smip)"
13211394
"VALUES(%Q,%Q,%d,0,%d,%Q,now(),now(),%Q)",
@@ -1332,11 +1405,15 @@
13321405
id);
13331406
if( !needCaptcha ){
13341407
/* The new subscription has been added on behalf of a logged-in user.
13351408
** No verification is required. Jump immediately to /alerts page.
13361409
*/
1337
- cgi_redirectf("%R/alerts/%s", zCode);
1410
+ if( g.perm.Admin ){
1411
+ cgi_redirectf("%R/alerts/%.32s", zCode);
1412
+ }else{
1413
+ cgi_redirectf("%R/alerts");
1414
+ }
13381415
return;
13391416
}else{
13401417
/* We need to send a verification email */
13411418
Blob hdr, body;
13421419
AlertSender *pSender = alert_sender_new(0,0);
@@ -1354,11 +1431,11 @@
13541431
@ <blockquote><pre>
13551432
@ %h(pSender->zErr)
13561433
@ </pre></blockquote>
13571434
}else{
13581435
@ <p>An email has been sent to "%h(zEAddr)". That email contains a
1359
- @ hyperlink that you must click on in order to activate your
1436
+ @ hyperlink that you must click to activate your
13601437
@ subscription.</p>
13611438
}
13621439
alert_sender_free(pSender);
13631440
style_footer();
13641441
}
@@ -1386,16 +1463,23 @@
13861463
if( eErr==1 ){
13871464
@ <tr><td><td><span class='loginError'>&uarr; %h(zErr)</span></td></tr>
13881465
}
13891466
@ </tr>
13901467
if( needCaptcha ){
1391
- uSeed = captcha_seed();
1468
+ const char *zInit = "";
1469
+ if( P("captchaseed")!=0 && eErr!=2 ){
1470
+ uSeed = strtoul(P("captchaseed"),0,10);
1471
+ zInit = P("captcha");
1472
+ }else{
1473
+ uSeed = captcha_seed();
1474
+ }
13921475
zDecoded = captcha_decode(uSeed);
13931476
zCaptcha = captcha_render(zDecoded);
13941477
@ <tr>
13951478
@ <td class="form_label">Security Code:</td>
1396
- @ <td><input type="text" name="captcha" value="" size="30">
1479
+ @ <td><input type="text" name="captcha" value="%h(zInit)" size="30">
1480
+ captcha_speakit_button(uSeed, "Speak the code");
13971481
@ <input type="hidden" name="captchaseed" value="%u(uSeed)"></td>
13981482
@ </tr>
13991483
if( eErr==2 ){
14001484
@ <tr><td><td><span class='loginError'>&uarr; %h(zErr)</span></td></tr>
14011485
}
@@ -1421,10 +1505,12 @@
14211505
@ Check-ins</label><br>
14221506
}
14231507
if( g.perm.RdForum ){
14241508
@ <label><input type="checkbox" name="sf" %s(PCK("sf"))> \
14251509
@ Forum Posts</label><br>
1510
+ @ <label><input type="checkbox" name="sx" %s(PCK("sx"))> \
1511
+ @ Forum Edits</label><br>
14261512
}
14271513
if( g.perm.RdTkt ){
14281514
@ <label><input type="checkbox" name="st" %s(PCK("st"))> \
14291515
@ Ticket changes</label><br>
14301516
}
@@ -1461,11 +1547,11 @@
14611547
@ </table>
14621548
if( needCaptcha ){
14631549
@ <div class="captcha"><table class="captcha"><tr><td><pre class="captcha">
14641550
@ %h(zCaptcha)
14651551
@ </pre>
1466
- @ Enter the 8 characters above in the "Security Code" box
1552
+ @ Enter the 8 characters above in the "Security Code" box<br/>
14671553
@ </td></tr></table></div>
14681554
}
14691555
@ </form>
14701556
fossil_free(zErr);
14711557
style_footer();
@@ -1474,21 +1560,20 @@
14741560
/*
14751561
** Either shutdown or completely delete a subscription entry given
14761562
** by the hex value zName. Then paint a webpage that explains that
14771563
** the entry has been removed.
14781564
*/
1479
-static void alert_unsubscribe(const char *zName){
1565
+static void alert_unsubscribe(int sid){
14801566
char *zEmail;
14811567
zEmail = db_text(0, "SELECT semail FROM subscriber"
1482
- " WHERE subscriberCode=hextoblob(%Q)", zName);
1568
+ " WHERE subscriberId=%d", sid);
14831569
if( zEmail==0 ){
14841570
style_header("Unsubscribe Fail");
14851571
@ <p>Unable to locate a subscriber with the requested key</p>
14861572
}else{
14871573
db_multi_exec(
1488
- "DELETE FROM subscriber WHERE subscriberCode=hextoblob(%Q)",
1489
- zName
1574
+ "DELETE FROM subscriber WHERE subscriberId=%d", sid
14901575
);
14911576
style_header("Unsubscribed");
14921577
@ <p>The "%h(zEmail)" email address has been delisted.
14931578
@ All traces of that email address have been removed</p>
14941579
}
@@ -1499,108 +1584,149 @@
14991584
/*
15001585
** WEBPAGE: alerts
15011586
**
15021587
** Edit email alert and notification settings.
15031588
**
1504
-** The subscriber is identified in either of two ways:
1505
-**
1506
-** (1) The name= query parameter contains the subscriberCode.
1507
-**
1508
-** (2) The user is logged into an account other than "nobody" or
1509
-** "anonymous". In that case the notification settings
1510
-** associated with that account can be edited without needing
1511
-** to know the subscriber code.
1512
-*/
1513
-void alert_page(void){
1514
- const char *zName = P("name");
1515
- Stmt q;
1516
- int sa, sc, sf, st, sw;
1517
- int sdigest, sdonotcall, sverified;
1518
- const char *ssub;
1519
- const char *semail;
1520
- const char *smip;
1521
- const char *suname;
1522
- const char *mtime;
1523
- const char *sctime;
1524
- int eErr = 0;
1525
- char *zErr = 0;
1526
-
1527
- if( alert_webpages_disabled() ) return;
1528
- login_check_credentials();
1529
- if( !g.perm.EmailAlert ){
1530
- login_needed(g.anon.EmailAlert);
1531
- return;
1532
- }
1533
- if( zName==0 && login_is_individual() ){
1534
- zName = db_text(0, "SELECT hex(subscriberCode) FROM subscriber"
1535
- " WHERE suname=%Q", g.zLogin);
1536
- }
1537
- if( zName==0 || !validate16(zName, -1) ){
1538
- cgi_redirect("subscribe");
1539
- return;
1540
- }
1541
- alert_submenu_common();
1542
- if( P("submit")!=0 && cgi_csrf_safe(1) ){
1543
- int sdonotcall = PB("sdonotcall");
1544
- int sdigest = PB("sdigest");
1545
- char ssub[10];
1546
- int nsub = 0;
1547
- if( PB("sa") ) ssub[nsub++] = 'a';
1548
- if( g.perm.Read && PB("sc") ) ssub[nsub++] = 'c';
1549
- if( g.perm.RdForum && PB("sf") ) ssub[nsub++] = 'f';
1550
- if( g.perm.RdTkt && PB("st") ) ssub[nsub++] = 't';
1551
- if( g.perm.RdWiki && PB("sw") ) ssub[nsub++] = 'w';
1552
- ssub[nsub] = 0;
1553
- if( g.perm.Admin ){
1554
- const char *suname = PT("suname");
1555
- int sverified = PB("sverified");
1556
- if( suname && suname[0]==0 ) suname = 0;
1557
- db_multi_exec(
1558
- "UPDATE subscriber SET"
1559
- " sdonotcall=%d,"
1560
- " sdigest=%d,"
1561
- " ssub=%Q,"
1562
- " mtime=strftime('%%s','now'),"
1563
- " smip=%Q,"
1564
- " suname=%Q,"
1565
- " sverified=%d"
1566
- " WHERE subscriberCode=hextoblob(%Q)",
1567
- sdonotcall,
1568
- sdigest,
1569
- ssub,
1570
- g.zIpAddr,
1571
- suname,
1572
- sverified,
1573
- zName
1574
- );
1575
- }else{
1576
- db_multi_exec(
1577
- "UPDATE subscriber SET"
1578
- " sdonotcall=%d,"
1579
- " sdigest=%d,"
1580
- " ssub=%Q,"
1581
- " mtime=strftime('%%s','now'),"
1582
- " smip=%Q"
1583
- " WHERE subscriberCode=hextoblob(%Q)",
1584
- sdonotcall,
1585
- sdigest,
1586
- ssub,
1587
- g.zIpAddr,
1588
- zName
1589
- );
1590
- }
1589
+** The subscriber is identified in several ways:
1590
+**
1591
+** * The name= query parameter contains the complete subscriberCode.
1592
+** This only happens when the user receives a verification
1593
+** email and clicks on the link in the email. When a
1594
+** compilete subscriberCode is seen on the name= query parameter,
1595
+** that constitutes verification of the email address.
1596
+**
1597
+** * The sid= query parameter contains an integer subscriberId.
1598
+** This only works for the administrator. It allows the
1599
+** administrator to edit any subscription.
1600
+**
1601
+** * The user is logged into an account other than "nobody" or
1602
+** "anonymous". In that case the notification settings
1603
+** associated with that account can be edited without needing
1604
+** to know the subscriber code.
1605
+**
1606
+** * The name= query parameter contains a 32-digit prefix of
1607
+** subscriber code. (Subscriber codes are normally 64 hex digits
1608
+** in length.) This uniquely identifies the subscriber without
1609
+** revealing the complete subscriber code, and hence without
1610
+** verifying the email address.
1611
+*/
1612
+void alert_page(void){
1613
+ const char *zName = 0; /* Value of the name= query parameter */
1614
+ Stmt q; /* For querying the database */
1615
+ int sa, sc, sf, st, sw, sx; /* Types of notifications requested */
1616
+ int sdigest = 0, sdonotcall = 0, sverified = 0; /* Other fields */
1617
+ int isLogin; /* True if logged in as an individual */
1618
+ const char *ssub = 0; /* Subscription flags */
1619
+ const char *semail = 0; /* Email address */
1620
+ const char *smip; /* */
1621
+ const char *suname = 0; /* Corresponding user.login value */
1622
+ const char *mtime; /* */
1623
+ const char *sctime; /* Time subscription created */
1624
+ int eErr = 0; /* Type of error */
1625
+ char *zErr = 0; /* Error message text */
1626
+ int sid = 0; /* Subscriber ID */
1627
+ int nName; /* Length of zName in bytes */
1628
+ char *zHalfCode; /* prefix of subscriberCode */
1629
+
1630
+ db_begin_transaction();
1631
+ if( alert_webpages_disabled() ){
1632
+ db_commit_transaction();
1633
+ return;
1634
+ }
1635
+ login_check_credentials();
1636
+ if( !g.perm.EmailAlert ){
1637
+ db_commit_transaction();
1638
+ login_needed(g.anon.EmailAlert);
1639
+ /*NOTREACHED*/
1640
+ }
1641
+ isLogin = login_is_individual();
1642
+ zName = P("name");
1643
+ nName = zName ? (int)strlen(zName) : 0;
1644
+ if( g.perm.Admin && P("sid")!=0 ){
1645
+ sid = atoi(P("sid"));
1646
+ }
1647
+ if( sid==0 && nName>=32 ){
1648
+ sid = db_int(0,
1649
+ "SELECT CASE WHEN hex(subscriberCode) LIKE (%Q||'%%')"
1650
+ " THEN subscriberId ELSE 0 END"
1651
+ " FROM subscriber WHERE subscriberCode>=hextoblob(%Q)"
1652
+ " LIMIT 1", zName, zName);
1653
+ }
1654
+ if( sid==0 && isLogin ){
1655
+ sid = db_int(0, "SELECT subscriberId FROM subscriber"
1656
+ " WHERE suname=%Q", g.zLogin);
1657
+ }
1658
+ if( sid==0 ){
1659
+ db_commit_transaction();
1660
+ cgi_redirect("subscribe");
1661
+ /*NOTREACHED*/
1662
+ }
1663
+ alert_submenu_common();
1664
+ if( P("submit")!=0 && cgi_csrf_safe(1) ){
1665
+ char newSsub[10];
1666
+ int nsub = 0;
1667
+ Blob update;
1668
+
1669
+ sdonotcall = PB("sdonotcall");
1670
+ sdigest = PB("sdigest");
1671
+ semail = P("semail");
1672
+ if( PB("sa") ) newSsub[nsub++] = 'a';
1673
+ if( g.perm.Read && PB("sc") ) newSsub[nsub++] = 'c';
1674
+ if( g.perm.RdForum && PB("sf") ) newSsub[nsub++] = 'f';
1675
+ if( g.perm.RdTkt && PB("st") ) newSsub[nsub++] = 't';
1676
+ if( g.perm.RdWiki && PB("sw") ) newSsub[nsub++] = 'w';
1677
+ if( g.perm.RdForum && PB("sx") ) newSsub[nsub++] = 'x';
1678
+ newSsub[nsub] = 0;
1679
+ ssub = newSsub;
1680
+ blob_init(&update, "UPDATE subscriber SET", -1);
1681
+ blob_append_sql(&update,
1682
+ " sdonotcall=%d,"
1683
+ " sdigest=%d,"
1684
+ " ssub=%Q,"
1685
+ " mtime=strftime('%%s','now'),"
1686
+ " smip=%Q",
1687
+ sdonotcall,
1688
+ sdigest,
1689
+ ssub,
1690
+ g.zIpAddr
1691
+ );
1692
+ if( g.perm.Admin ){
1693
+ suname = PT("suname");
1694
+ sverified = PB("sverified");
1695
+ if( suname && suname[0]==0 ) suname = 0;
1696
+ blob_append_sql(&update,
1697
+ ", suname=%Q,"
1698
+ " sverified=%d",
1699
+ suname,
1700
+ sverified
1701
+ );
1702
+ }
1703
+ if( isLogin ){
1704
+ if( semail==0 || email_address_is_valid(semail,0)==0 ){
1705
+ eErr = 8;
1706
+ }
1707
+ blob_append_sql(&update, ", semail=%Q", semail);
1708
+ }
1709
+ blob_append_sql(&update," WHERE subscriberId=%d", sid);
1710
+ if( eErr==0 ){
1711
+ db_exec_sql(blob_str(&update));
1712
+ ssub = 0;
1713
+ }
1714
+ blob_reset(&update);
15911715
}
15921716
if( P("delete")!=0 && cgi_csrf_safe(1) ){
15931717
if( !PB("dodelete") ){
15941718
eErr = 9;
15951719
zErr = mprintf("Select this checkbox and press \"Unsubscribe\" again to"
15961720
" unsubscribe");
15971721
}else{
1598
- alert_unsubscribe(zName);
1599
- return;
1722
+ alert_unsubscribe(sid);
1723
+ db_commit_transaction();
1724
+ return;
16001725
}
16011726
}
1727
+ style_header("Update Subscription");
16021728
db_prepare(&q,
16031729
"SELECT"
16041730
" semail," /* 0 */
16051731
" sverified," /* 1 */
16061732
" sdonotcall," /* 2 */
@@ -1607,52 +1733,92 @@
16071733
" sdigest," /* 3 */
16081734
" ssub," /* 4 */
16091735
" smip," /* 5 */
16101736
" suname," /* 6 */
16111737
" datetime(mtime,'unixepoch')," /* 7 */
1612
- " datetime(sctime,'unixepoch')" /* 8 */
1613
- " FROM subscriber WHERE subscriberCode=hextoblob(%Q)", zName);
1738
+ " datetime(sctime,'unixepoch')," /* 8 */
1739
+ " hex(subscriberCode)" /* 9 */
1740
+ " FROM subscriber WHERE subscriberId=%d", sid);
16141741
if( db_step(&q)!=SQLITE_ROW ){
16151742
db_finalize(&q);
1743
+ db_commit_transaction();
16161744
cgi_redirect("subscribe");
1617
- return;
1618
- }
1619
- style_header("Update Subscription");
1620
- semail = db_column_text(&q, 0);
1621
- sverified = db_column_int(&q, 1);
1622
- sdonotcall = db_column_int(&q, 2);
1623
- sdigest = db_column_int(&q, 3);
1624
- ssub = db_column_text(&q, 4);
1745
+ /*NOTREACHED*/
1746
+ }
1747
+ if( ssub==0 ){
1748
+ semail = db_column_text(&q, 0);
1749
+ sdonotcall = db_column_int(&q, 2);
1750
+ sdigest = db_column_int(&q, 3);
1751
+ ssub = db_column_text(&q, 4);
1752
+ }
1753
+ if( suname==0 ){
1754
+ suname = db_column_text(&q, 6);
1755
+ sverified = db_column_int(&q, 1);
1756
+ }
16251757
sa = strchr(ssub,'a')!=0;
16261758
sc = strchr(ssub,'c')!=0;
16271759
sf = strchr(ssub,'f')!=0;
16281760
st = strchr(ssub,'t')!=0;
16291761
sw = strchr(ssub,'w')!=0;
1762
+ sx = strchr(ssub,'x')!=0;
16301763
smip = db_column_text(&q, 5);
1631
- suname = db_column_text(&q, 6);
16321764
mtime = db_column_text(&q, 7);
16331765
sctime = db_column_text(&q, 8);
16341766
if( !g.perm.Admin && !sverified ){
1635
- db_multi_exec(
1636
- "UPDATE subscriber SET sverified=1 WHERE subscriberCode=hextoblob(%Q)",
1637
- zName);
1638
- @ <h1>Your email alert subscription has been verified!</h1>
1639
- @ <p>Use the form below to update your subscription information.</p>
1640
- @ <p>Hint: Bookmark this page so that you can more easily update
1641
- @ your subscription information in the future</p>
1767
+ if( nName==64 ){
1768
+ db_multi_exec(
1769
+ "UPDATE subscriber SET sverified=1"
1770
+ " WHERE subscriberCode=hextoblob(%Q)",
1771
+ zName);
1772
+ if( db_get_boolean("selfreg-verify",0) ){
1773
+ char *zNewCap = db_get("default-perms","u");
1774
+ db_multi_exec(
1775
+ "UPDATE user"
1776
+ " SET cap=%Q"
1777
+ " WHERE cap='7' AND login=("
1778
+ " SELECT suname FROM subscriber"
1779
+ " WHERE subscriberCode=hextoblob(%Q))",
1780
+ zNewCap, zName
1781
+ );
1782
+ login_set_capabilities(zNewCap, 0);
1783
+ }
1784
+ @ <h1>Your email alert subscription has been verified!</h1>
1785
+ @ <p>Use the form below to update your subscription information.</p>
1786
+ @ <p>Hint: Bookmark this page so that you can more easily update
1787
+ @ your subscription information in the future</p>
1788
+ }else{
1789
+ @ <h2>Your email address is unverified</h2>
1790
+ @ <p>You should have received an email message containing a link
1791
+ @ that you must visit to verify your account. No email notifications
1792
+ @ will be sent until your email address has been verified.</p>
1793
+ }
16421794
}else{
16431795
@ <p>Make changes to the email subscription shown below and
16441796
@ press "Submit".</p>
16451797
}
16461798
form_begin(0, "%R/alerts");
1647
- @ <input type="hidden" name="name" value="%h(zName)">
1799
+ zHalfCode = db_text("x","SELECT hex(substr(subscriberCode,1,16))"
1800
+ " FROM subscriber WHERE subscriberId=%d", sid);
1801
+ @ <input type="hidden" name="name" value="%h(zHalfCode)">
16481802
@ <table class="subscribe">
16491803
@ <tr>
16501804
@ <td class="form_label">Email&nbsp;Address:</td>
1651
- @ <td>%h(semail)</td>
1805
+ if( isLogin ){
1806
+ @ <td><input type="text" name="semail" value="%h(semail)" size="30">\
1807
+ if( eErr==8 ){
1808
+ @ <span class='loginError'>&larr; not a valid email address!</span>
1809
+ }else if( g.perm.Admin ){
1810
+ @ &nbsp;&nbsp;<a href="%R/announce?to=%t(semail)">\
1811
+ @ (Send a message to %h(semail))</a>\
1812
+ }
1813
+ @ </td>
1814
+ }else{
1815
+ @ <td>%h(semail)</td>
1816
+ }
16521817
@ </tr>
16531818
if( g.perm.Admin ){
1819
+ int uid;
16541820
@ <tr>
16551821
@ <td class='form_label'>Created:</td>
16561822
@ <td>%h(sctime)</td>
16571823
@ </tr>
16581824
@ <tr>
@@ -1662,13 +1828,21 @@
16621828
@ <tr>
16631829
@ <td class='form_label'>IP Address:</td>
16641830
@ <td>%h(smip)</td>
16651831
@ </tr>
16661832
@ <tr>
1833
+ @ <td class='form_label'>Subscriber&nbsp;Code:</td>
1834
+ @ <td>%h(db_column_text(&q,9))</td>
1835
+ @ <tr>
16671836
@ <td class="form_label">User:</td>
16681837
@ <td><input type="text" name="suname" value="%h(suname?suname:"")" \
1669
- @ size="30"></td>
1838
+ @ size="30">\
1839
+ uid = db_int(0, "SELECT uid FROM user WHERE login=%Q", suname);
1840
+ if( uid ){
1841
+ @ &nbsp;&nbsp;<a href='%R/setup_uedit?id=%d(uid)'>\
1842
+ @ (login info for %h(suname))</a>\
1843
+ }
16701844
@ </tr>
16711845
}
16721846
@ <tr>
16731847
@ <td class="form_label">Topics:</td>
16741848
@ <td><label><input type="checkbox" name="sa" %s(sa?"checked":"")>\
@@ -1678,10 +1852,12 @@
16781852
@ Check-ins</label><br>
16791853
}
16801854
if( g.perm.RdForum ){
16811855
@ <label><input type="checkbox" name="sf" %s(sf?"checked":"")>\
16821856
@ Forum Posts</label><br>
1857
+ @ <label><input type="checkbox" name="sx" %s(sx?"checked":"")>\
1858
+ @ Forum Edits</label><br>
16831859
}
16841860
if( g.perm.RdTkt ){
16851861
@ <label><input type="checkbox" name="st" %s(st?"checked":"")>\
16861862
@ Ticket changes</label><br>
16871863
}
@@ -1695,19 +1871,15 @@
16951871
@ <td><select size="1" name="sdigest">
16961872
@ <option value="0" %s(sdigest?"":"selected")>Individual Emails</option>
16971873
@ <option value="1" %s(sdigest?"selected":"")>Daily Digest</option>
16981874
@ </select></td>
16991875
@ </tr>
1700
-#if 0
1701
- @ <label><input type="checkbox" name="sdigest" %s(sdigest?"checked":"")>\
1702
- @ Daily digest only</label><br>
1703
-#endif
17041876
if( g.perm.Admin ){
17051877
@ <tr>
17061878
@ <td class="form_label">Admin Options:</td><td>
17071879
@ <label><input type="checkbox" name="sdonotcall" \
1708
- @ %s(sdonotcall?"checked":"")> Do not call</label><br>
1880
+ @ %s(sdonotcall?"checked":"")> Do not disturb</label><br>
17091881
@ <label><input type="checkbox" name="sverified" \
17101882
@ %s(sverified?"checked":"")>\
17111883
@ Verified</label></td></tr>
17121884
}
17131885
if( eErr==9 ){
@@ -1726,10 +1898,12 @@
17261898
@ </table>
17271899
@ </form>
17281900
fossil_free(zErr);
17291901
db_finalize(&q);
17301902
style_footer();
1903
+ db_commit_transaction();
1904
+ return;
17311905
}
17321906
17331907
/* This is the message that gets sent to describe how to change
17341908
** or modify a subscription
17351909
*/
@@ -1760,25 +1934,26 @@
17601934
*/
17611935
void unsubscribe_page(void){
17621936
const char *zName = P("name");
17631937
char *zErr = 0;
17641938
int eErr = 0;
1765
- unsigned int uSeed;
1939
+ unsigned int uSeed = 0;
17661940
const char *zDecoded;
17671941
char *zCaptcha = 0;
17681942
int dx;
17691943
int bSubmit;
17701944
const char *zEAddr;
17711945
char *zCode = 0;
1946
+ int sid = 0;
17721947
17731948
/* If a valid subscriber code is supplied, then unsubscribe immediately.
17741949
*/
17751950
if( zName
1776
- && db_exists("SELECT 1 FROM subscriber WHERE subscriberCode=hextoblob(%Q)",
1777
- zName)
1951
+ && (sid = db_int(0, "SELECT subscriberId FROM subscriber"
1952
+ " WHERE subscriberCode=hextoblob(%Q)", zName))!=0
17781953
){
1779
- alert_unsubscribe(zName);
1954
+ alert_unsubscribe(sid);
17801955
return;
17811956
}
17821957
17831958
/* Logged in users are redirected to the /alerts page */
17841959
login_check_credentials();
@@ -1855,10 +2030,11 @@
18552030
zDecoded = captcha_decode(uSeed);
18562031
zCaptcha = captcha_render(zDecoded);
18572032
@ <tr>
18582033
@ <td class="form_label">Security Code:</td>
18592034
@ <td><input type="text" name="captcha" value="" size="30">
2035
+ captcha_speakit_button(uSeed, "Speak the code");
18602036
@ <input type="hidden" name="captchaseed" value="%u(uSeed)"></td>
18612037
if( eErr==2 ){
18622038
@ <td><span class="loginError">&larr; %h(zErr)</span></td>
18632039
}
18642040
@ </tr>
@@ -1874,11 +2050,11 @@
18742050
@ </tr>
18752051
@ </table>
18762052
@ <div class="captcha"><table class="captcha"><tr><td><pre class="captcha">
18772053
@ %h(zCaptcha)
18782054
@ </pre>
1879
- @ Enter the 8 characters above in the "Security Code" box
2055
+ @ Enter the 8 characters above in the "Security Code" box<br/>
18802056
@ </td></tr></table></div>
18812057
@ </form>
18822058
fossil_free(zErr);
18832059
style_footer();
18842060
}
@@ -1885,37 +2061,69 @@
18852061
18862062
/*
18872063
** WEBPAGE: subscribers
18882064
**
18892065
** This page, accessible to administrators only,
1890
-** shows a list of email notification email addresses.
2066
+** shows a list of subscriber email addresses.
18912067
** Clicking on an email takes one to the /alerts page
18922068
** for that email where the delivery settings can be
18932069
** modified.
18942070
*/
18952071
void subscriber_list_page(void){
18962072
Blob sql;
18972073
Stmt q;
18982074
sqlite3_int64 iNow;
2075
+ int nTotal;
2076
+ int nPending;
2077
+ int nDel = 0;
18992078
if( alert_webpages_disabled() ) return;
19002079
login_check_credentials();
19012080
if( !g.perm.Admin ){
19022081
login_needed(0);
19032082
return;
19042083
}
19052084
alert_submenu_common();
2085
+ style_submenu_element("Users","setup_ulist");
19062086
style_header("Subscriber List");
2087
+ nTotal = db_int(0, "SELECT count(*) FROM subscriber");
2088
+ nPending = db_int(0, "SELECT count(*) FROM subscriber WHERE NOT sverified");
2089
+ if( nPending>0 && P("purge") && cgi_csrf_safe(0) ){
2090
+ int nNewPending;
2091
+ db_multi_exec(
2092
+ "DELETE FROM subscriber"
2093
+ " WHERE NOT sverified AND mtime<0+strftime('%%s','now','-1 day')"
2094
+ );
2095
+ nNewPending = db_int(0, "SELECT count(*) FROM subscriber"
2096
+ " WHERE NOT sverified");
2097
+ nDel = nPending - nNewPending;
2098
+ nPending = nNewPending;
2099
+ nTotal -= nDel;
2100
+ }
2101
+ if( nPending>0 ){
2102
+ @ <h1>%,d(nTotal) Subscribers, %,d(nPending) Pending</h1>
2103
+ if( nDel==0 && 0<db_int(0,"SELECT count(*) FROM subscriber"
2104
+ " WHERE NOT sverified AND mtime<0+strftime('%%s','now','-1 day')")
2105
+ ){
2106
+ style_submenu_element("Purge Pending","subscribers?purge");
2107
+ }
2108
+ }else{
2109
+ @ <h1>%,d(nTotal) Subscribers</h1>
2110
+ }
2111
+ if( nDel>0 ){
2112
+ @ <p>*** %d(nDel) pending subscriptions deleted ***</p>
2113
+ }
19072114
blob_init(&sql, 0, 0);
19082115
blob_append_sql(&sql,
1909
- "SELECT hex(subscriberCode)," /* 0 */
2116
+ "SELECT subscriberId," /* 0 */
19102117
" semail," /* 1 */
19112118
" ssub," /* 2 */
19122119
" suname," /* 3 */
19132120
" sverified," /* 4 */
19142121
" sdigest," /* 5 */
19152122
" mtime," /* 6 */
1916
- " date(sctime,'unixepoch')" /* 7 */
2123
+ " date(sctime,'unixepoch')," /* 7 */
2124
+ " (SELECT uid FROM user WHERE login=subscriber.suname)" /* 8 */
19172125
" FROM subscriber"
19182126
);
19192127
if( P("only")!=0 ){
19202128
blob_append_sql(&sql, " WHERE ssub LIKE '%%%q%%'", P("only"));
19212129
style_submenu_element("Show All","%R/subscribers");
@@ -1937,16 +2145,22 @@
19372145
@ </tr>
19382146
@ </thead><tbody>
19392147
while( db_step(&q)==SQLITE_ROW ){
19402148
sqlite3_int64 iMtime = db_column_int64(&q, 6);
19412149
double rAge = (iNow - iMtime)/86400.0;
2150
+ int uid = db_column_int(&q, 8);
2151
+ const char *zUname = db_column_text(&q, 3);
19422152
@ <tr>
1943
- @ <td><a href='%R/alerts/%s(db_column_text(&q,0))'>\
2153
+ @ <td><a href='%R/alerts?sid=%d(db_column_int(&q,0))'>\
19442154
@ %h(db_column_text(&q,1))</a></td>
19452155
@ <td>%h(db_column_text(&q,2))</td>
19462156
@ <td>%s(db_column_int(&q,5)?"digest":"")</td>
1947
- @ <td>%h(db_column_text(&q,3))</td>
2157
+ if( uid ){
2158
+ @ <td><a href='%R/setup_uedit?id=%d(uid)'>%h(zUname)</a>
2159
+ }else{
2160
+ @ <td>%h(zUname)</td>
2161
+ }
19482162
@ <td>%s(db_column_int(&q,4)?"yes":"pending")</td>
19492163
@ <td data-sortkey='%010llx(iMtime)'>%z(human_readable_age(rAge))</td>
19502164
@ <td>%h(db_column_text(&q,7))</td>
19512165
@ </tr>
19522166
}
@@ -1958,13 +2172,21 @@
19582172
19592173
#if LOCAL_INTERFACE
19602174
/*
19612175
** A single event that might appear in an alert is recorded as an
19622176
** instance of the following object.
2177
+**
2178
+** type values:
2179
+**
2180
+** c A new check-in
2181
+** f An original forum post
2182
+** x An edit to a prior forum post
2183
+** t A new ticket or a change to an existing ticket
2184
+** w A change to a wiki page
19632185
*/
19642186
struct EmailEvent {
1965
- int type; /* 'c', 'f', 'm', 't', 'w' */
2187
+ int type; /* 'c', 'f', 't', 'w', 'x' */
19662188
int needMod; /* Pending moderator approval */
19672189
Blob hdr; /* Header content, for forum entries */
19682190
Blob txt; /* Text description to appear in an alert */
19692191
char *zFromName; /* Human name of the sender */
19702192
EmailEvent *pNext; /* Next in chronological order */
@@ -2039,20 +2261,20 @@
20392261
p->needMod = db_column_int(&q, 4);
20402262
p->zFromName = 0;
20412263
p->pNext = 0;
20422264
switch( p->type ){
20432265
case 'c': zType = "Check-In"; break;
2044
- case 'f': zType = "Forum post"; break;
2266
+ /* case 'f': -- forum posts omitted from this loop. See below */
20452267
case 't': zType = "Ticket Change"; break;
20462268
case 'w': zType = "Wiki Edit"; break;
20472269
}
20482270
blob_init(&p->hdr, 0, 0);
20492271
blob_init(&p->txt, 0, 0);
20502272
blob_appendf(&p->txt,"== %s %s ==\n%s\n%s/info/%.20s\n",
20512273
db_column_text(&q,1),
20522274
zType,
2053
- db_column_text(&q,2),
2275
+ db_column_text(&q, 2),
20542276
zUrl,
20552277
db_column_text(&q,0)
20562278
);
20572279
if( p->needMod ){
20582280
blob_appendf(&p->txt,
@@ -2078,17 +2300,28 @@
20782300
** is a normal email alert. Construct full-text forum post alerts
20792301
** using a format that enables them to be sent as separate emails.
20802302
*/
20812303
db_prepare(&q,
20822304
"SELECT"
2083
- " forumpost.fpid," /* 0 */
2084
- " (SELECT uuid FROM blob WHERE rid=forumpost.fpid)," /* 1 */
2085
- " datetime(event.mtime)," /* 2 */
2086
- " substr(comment,instr(comment,':')+2)," /* 3 */
2087
- " (SELECT uuid FROM blob WHERE rid=forumpost.firt)," /* 4 */
2088
- " wantalert.needMod," /* 5 */
2089
- " coalesce(trim(substr(info,1,instr(info,'<')-1)),euser,user)" /* 6 */
2305
+ " forumpost.fpid," /* 0: fpid */
2306
+ " (SELECT uuid FROM blob WHERE rid=forumpost.fpid)," /* 1: hash */
2307
+ " datetime(event.mtime)," /* 2: date/time */
2308
+ " substr(comment,instr(comment,':')+2)," /* 3: comment */
2309
+ " (WITH thread(fpid,fprev) AS ("
2310
+ " SELECT fpid,fprev FROM forumpost AS tx"
2311
+ " WHERE tx.froot=forumpost.froot),"
2312
+ " basepid(fpid,bpid) AS ("
2313
+ " SELECT fpid, fpid FROM thread WHERE fprev IS NULL"
2314
+ " UNION ALL"
2315
+ " SELECT thread.fpid, basepid.bpid FROM basepid, thread"
2316
+ " WHERE basepid.fpid=thread.fprev)"
2317
+ " SELECT uuid FROM blob, basepid"
2318
+ " WHERE basepid.fpid=forumpost.firt"
2319
+ " AND blob.rid=basepid.bpid)," /* 4: in-reply-to */
2320
+ " wantalert.needMod," /* 5: moderated */
2321
+ " coalesce(display_name(info),euser,user)," /* 6: user */
2322
+ " forumpost.fprev IS NULL" /* 7: is an edit */
20902323
" FROM temp.wantalert, event, forumpost"
20912324
" LEFT JOIN user ON (login=coalesce(euser,user))"
20922325
" WHERE event.objid=substr(wantalert.eventId,2)+0"
20932326
" AND eventId GLOB 'f*'"
20942327
" AND forumpost.fpid=event.objid"
@@ -2104,11 +2337,11 @@
21042337
const char *z;
21052338
if( pPost==0 ) continue;
21062339
p = fossil_malloc( sizeof(EmailEvent) );
21072340
pLast->pNext = p;
21082341
pLast = p;
2109
- p->type = 'f';
2342
+ p->type = db_column_int(&q,7) ? 'f' : 'x';
21102343
p->needMod = db_column_int(&q, 5);
21112344
z = db_column_text(&q,6);
21122345
p->zFromName = z && z[0] ? fossil_strdup(z) : 0;
21132346
p->pNext = 0;
21142347
blob_init(&p->hdr, 0, 0);
@@ -2321,13 +2554,14 @@
23212554
** the process malfunctions or crashes, some notifications may never
23222555
** be sent. But that is better than some recurring bug causing
23232556
** subscribers to be flooded with repeated notifications every 60
23242557
** seconds!
23252558
*/
2326
-void alert_send_alerts(u32 flags){
2559
+int alert_send_alerts(u32 flags){
23272560
EmailEvent *pEvents, *p;
23282561
int nEvent = 0;
2562
+ int nSent = 0;
23292563
Stmt q;
23302564
const char *zDigest = "false";
23312565
Blob hdr, body;
23322566
const char *zUrl;
23332567
const char *zRepoName;
@@ -2436,13 +2670,13 @@
24362670
** if the recipient is a moderator for that type of event. Setup
24372671
** and Admin users always get notified. */
24382672
char xType = '*';
24392673
if( strpbrk(zCap,"as")==0 ){
24402674
switch( p->type ){
2441
- case 'f': xType = '5'; break;
2442
- case 't': xType = 'q'; break;
2443
- case 'w': xType = 'l'; break;
2675
+ case 'x': case 'f': xType = '5'; break;
2676
+ case 't': xType = 'q'; break;
2677
+ case 'w': xType = 'l'; break;
24442678
}
24452679
if( strchr(zCap,xType)==0 ) continue;
24462680
}
24472681
}else if( strchr(zCap,'s')!=0 || strchr(zCap,'a')!=0 ){
24482682
/* Setup and admin users can get any notification that does not
@@ -2450,14 +2684,14 @@
24502684
}else{
24512685
/* Other users only see the alert if they have sufficient
24522686
** privilege to view the event itself */
24532687
char xType = '*';
24542688
switch( p->type ){
2455
- case 'c': xType = 'o'; break;
2456
- case 'f': xType = '2'; break;
2457
- case 't': xType = 'r'; break;
2458
- case 'w': xType = 'j'; break;
2689
+ case 'c': xType = 'o'; break;
2690
+ case 'x': case 'f': xType = '2'; break;
2691
+ case 't': xType = 'r'; break;
2692
+ case 'w': xType = 'j'; break;
24592693
}
24602694
if( strchr(zCap,xType)==0 ) continue;
24612695
}
24622696
if( blob_size(&p->hdr)>0 ){
24632697
/* This alert should be sent as a separate email */
@@ -2467,10 +2701,11 @@
24672701
blob_append(&fhdr, blob_buffer(&p->hdr), blob_size(&p->hdr));
24682702
blob_init(&fbody, blob_buffer(&p->txt), blob_size(&p->txt));
24692703
blob_appendf(&fbody, "\n-- \nSubscription info: %s/alerts/%s\n",
24702704
zUrl, zCode);
24712705
alert_send(pSender,&fhdr,&fbody,p->zFromName);
2706
+ nSent++;
24722707
blob_reset(&fhdr);
24732708
blob_reset(&fbody);
24742709
}else{
24752710
/* Events other than forum posts are gathered together into
24762711
** a single email message */
@@ -2490,10 +2725,11 @@
24902725
}
24912726
if( nHit==0 ) continue;
24922727
blob_appendf(&body,"\n-- \nSubscription info: %s/alerts/%s\n",
24932728
zUrl, zCode);
24942729
alert_send(pSender,&hdr,&body,0);
2730
+ nSent++;
24952731
blob_truncate(&hdr, 0);
24962732
blob_truncate(&body, 0);
24972733
}
24982734
blob_reset(&hdr);
24992735
blob_reset(&body);
@@ -2506,10 +2742,11 @@
25062742
db_multi_exec("DELETE FROM pending_alert WHERE sentDigest AND sentSep;");
25072743
25082744
send_alert_done:
25092745
alert_sender_free(pSender);
25102746
if( g.fSqlTrace ) fossil_trace("-- END alert_send_alerts(%u)\n", flags);
2747
+ return nSent;
25112748
}
25122749
25132750
/*
25142751
** Do backoffice processing for email notifications. In other words,
25152752
** check to see if any email notifications need to occur, and then
@@ -2519,19 +2756,21 @@
25192756
**
25202757
** The mFlags option is zero or more of the SENDALERT_* flags. Normally
25212758
** this flag is zero, but the test-set-alert command sets it to
25222759
** SENDALERT_TRACE.
25232760
*/
2524
-void alert_backoffice(u32 mFlags){
2761
+int alert_backoffice(u32 mFlags){
25252762
int iJulianDay;
2526
- if( !alert_tables_exist() ) return;
2527
- alert_send_alerts(mFlags);
2763
+ int nSent = 0;
2764
+ if( !alert_tables_exist() ) return 0;
2765
+ nSent = alert_send_alerts(mFlags);
25282766
iJulianDay = db_int(0, "SELECT julianday('now')");
25292767
if( iJulianDay>db_get_int("email-last-digest",0) ){
25302768
db_set_int("email-last-digest",iJulianDay,0);
2531
- alert_send_alerts(SENDALERT_DIGEST|mFlags);
2769
+ nSent += alert_send_alerts(SENDALERT_DIGEST|mFlags);
25322770
}
2771
+ return nSent;
25332772
}
25342773
25352774
/*
25362775
** WEBPAGE: contact_admin
25372776
**
@@ -2594,10 +2833,11 @@
25942833
@ <table class="subscribe">
25952834
if( zCaptcha ){
25962835
@ <tr>
25972836
@ <td class="form_label">Security&nbsp;Code:</td>
25982837
@ <td><input type="text" name="captcha" value="" size="10">
2838
+ captcha_speakit_button(uSeed, "Speak the code");
25992839
@ <input type="hidden" name="captchaseed" value="%u(uSeed)"></td>
26002840
@ </tr>
26012841
}
26022842
@ <tr>
26032843
@ <td class="form_label">Your&nbsp;Email&nbsp;Address:</td>
@@ -2620,11 +2860,11 @@
26202860
@ </table>
26212861
if( zCaptcha ){
26222862
@ <div class="captcha"><table class="captcha"><tr><td><pre class="captcha">
26232863
@ %h(zCaptcha)
26242864
@ </pre>
2625
- @ Enter the 8 characters above in the "Security Code" box
2865
+ @ Enter the 8 characters above in the "Security Code" box<br/>
26262866
@ </td></tr></table></div>
26272867
}
26282868
@ </form>
26292869
style_footer();
26302870
}
@@ -2638,10 +2878,11 @@
26382878
char *zErr;
26392879
const char *zTo = PT("to");
26402880
char *zSubject = PT("subject");
26412881
int bAll = PB("all");
26422882
int bAA = PB("aa");
2883
+ int bMods = PB("mods");
26432884
const char *zSub = db_get("email-subname", "[Fossil Repo]");
26442885
int bTest2 = fossil_strcmp(P("name"),"test2")==0;
26452886
Blob hdr, body;
26462887
blob_init(&body, 0, 0);
26472888
blob_init(&hdr, 0, 0);
@@ -2649,17 +2890,29 @@
26492890
pSender = alert_sender_new(bTest2 ? "blob" : 0, 0);
26502891
if( zTo[0] ){
26512892
blob_appendf(&hdr, "To: <%s>\r\nSubject: %s %s\r\n", zTo, zSub, zSubject);
26522893
alert_send(pSender, &hdr, &body, 0);
26532894
}
2654
- if( bAll || bAA ){
2895
+ if( bAll || bAA || bMods ){
26552896
Stmt q;
26562897
int nUsed = blob_size(&body);
26572898
const char *zURL = db_get("email-url",0);
2658
- db_prepare(&q, "SELECT semail, hex(subscriberCode) FROM subscriber "
2659
- " WHERE sverified AND NOT sdonotcall %s",
2660
- bAll ? "" : " AND ssub LIKE '%a%'");
2899
+ if( bAll ){
2900
+ db_prepare(&q, "SELECT semail, hex(subscriberCode) FROM subscriber "
2901
+ " WHERE sverified AND NOT sdonotcall");
2902
+ }else if( bAA ){
2903
+ db_prepare(&q, "SELECT semail, hex(subscriberCode) FROM subscriber "
2904
+ " WHERE sverified AND NOT sdonotcall"
2905
+ " AND ssub LIKE '%%a%%'");
2906
+ }else if( bMods ){
2907
+ db_prepare(&q,
2908
+ "SELECT semail, hex(subscriberCode)"
2909
+ " FROM subscriber, user "
2910
+ " WHERE sverified AND NOT sdonotcall"
2911
+ " AND suname=login"
2912
+ " AND fullcap(cap) GLOB '*5*'");
2913
+ }
26612914
while( db_step(&q)==SQLITE_ROW ){
26622915
const char *zCode = db_column_text(&q, 1);
26632916
zTo = db_column_text(&q, 0);
26642917
blob_truncate(&hdr, 0);
26652918
blob_appendf(&hdr, "To: <%s>\r\nSubject: %s %s\r\n", zTo, zSub, zSubject);
@@ -2716,11 +2969,12 @@
27162969
@ <p>The following error was reported by the system:
27172970
@ <blockquote><pre>
27182971
@ %h(zErr)
27192972
@ </pre></blockquote>
27202973
}else{
2721
- @ <p>The announcement has been sent.</p>
2974
+ @ <p>The announcement has been sent.
2975
+ @ <a href="%h(PD("REQUEST_URI","/"))">Send another</a></p>
27222976
}
27232977
style_footer();
27242978
return;
27252979
} else if( !alert_enabled() ){
27262980
style_header("Cannot Send Announcement");
@@ -2734,21 +2988,26 @@
27342988
@ <form method="POST">
27352989
@ <table class="subscribe">
27362990
if( g.perm.Admin ){
27372991
int aa = PB("aa");
27382992
int all = PB("all");
2993
+ int aMod = PB("mods");
27392994
const char *aack = aa ? "checked" : "";
27402995
const char *allck = all ? "checked" : "";
2996
+ const char *modck = aMod ? "checked" : "";
27412997
@ <tr>
27422998
@ <td class="form_label">To:</td>
27432999
@ <td><input type="text" name="to" value="%h(PT("to"))" size="30"><br>
27443000
@ <label><input type="checkbox" name="aa" %s(aack)> \
27453001
@ All "announcement" subscribers</label> \
27463002
@ <a href="%R/subscribers?only=a" target="_blank">(list)</a><br>
27473003
@ <label><input type="checkbox" name="all" %s(allck)> \
27483004
@ All subscribers</label> \
2749
- @ <a href="%R/subscribers" target="_blank">(list)</a><br></td>
3005
+ @ <a href="%R/subscribers" target="_blank">(list)</a><br>
3006
+ @ <label><input type="checkbox" name="mods" %s(modck)> \
3007
+ @ All moderators</label> \
3008
+ @ <a href="%R/setup_ulist?with=5" target="_blank">(list)</a><br></td>
27503009
@ </tr>
27513010
}
27523011
@ <tr>
27533012
@ <td class="form_label">Subject:</td>
27543013
@ <td><input type="text" name="subject" value="%h(PT("subject"))"\
@@ -2759,11 +3018,15 @@
27593018
@ <td><textarea name="msg" cols="80" rows="10" wrap="virtual">\
27603019
@ %h(PT("msg"))</textarea>
27613020
@ </tr>
27623021
@ <tr>
27633022
@ <td></td>
2764
- @ <td><input type="submit" name="submit" value="Send Message">
3023
+ if( fossil_strcmp(P("name"),"test2")==0 ){
3024
+ @ <td><input type="submit" name="submit" value="Dry Run">
3025
+ }else{
3026
+ @ <td><input type="submit" name="submit" value="Send Message">
3027
+ }
27653028
@ </tr>
27663029
@ </table>
27673030
@ </form>
27683031
style_footer();
27693032
}
27703033
--- src/alerts.c
+++ src/alerts.c
@@ -46,10 +46,11 @@
46 @ --
47 @ -- The ssub field is a string where each character indicates a particular
48 @ -- type of event to subscribe to. Choices:
49 @ -- a - Announcements
50 @ -- c - Check-ins
 
51 @ -- t - Ticket changes
52 @ -- w - Wiki changes
53 @ -- Probably different codes will be added in the future. In the future
54 @ -- we might also add a separate table that allows subscribing to email
55 @ -- notifications for specific branches or tags or tickets.
@@ -114,11 +115,11 @@
114 if( bOnlyIfEnabled
115 && fossil_strcmp(db_get("email-send-method",0),"off")==0
116 ){
117 return; /* Don't create table for disabled email */
118 }
119 db_multi_exec(zAlertInit/*works-like:""*/);
120 alert_triggers_enable();
121 }else if( !db_table_has_column("repository","pending_alert","sentMod") ){
122 db_multi_exec(
123 "ALTER TABLE repository.pending_alert"
124 " ADD COLUMN sentMod BOOLEAN DEFAULT false;"
@@ -183,11 +184,11 @@
183 ** is an administrator.
184 */
185 void alert_submenu_common(void){
186 if( g.perm.Admin ){
187 if( fossil_strcmp(g.zPath,"subscribers") ){
188 style_submenu_element("List Subscribers","%R/subscribers");
189 }
190 if( fossil_strcmp(g.zPath,"subscribe") ){
191 style_submenu_element("Add New Subscriber","%R/subscribe");
192 }
193 }
@@ -238,10 +239,17 @@
238 @ This is URL used as the basename for hyperlinks included in
239 @ email alert text. Omit the trailing "/".
240 @ Suggested value: "%h(g.zBaseURL)"
241 @ (Property: "email-url")</p>
242 @ <hr>
 
 
 
 
 
 
 
243
244 entry_attribute("\"Return-Path\" email address", 20, "email-self",
245 "eself", "", 0);
246 @ <p><b>Required.</b>
247 @ This is the email to which email notification bounces should be sent.
@@ -297,17 +305,10 @@
297 @ append a colon and TCP port number (ex: smtp.example.com:587).
298 @ The default TCP port number is 25.
299 @ (Property: "email-send-relayhost")</p>
300 @ <hr>
301
302 entry_attribute("Administrator email address", 40, "email-admin",
303 "eadmin", "", 0);
304 @ <p>This is the email for the human administrator for the system.
305 @ Abuse and trouble reports are send here.
306 @ (Property: "email-admin")</p>
307 @ <hr>
308
309 @ <p><input type="submit" name="submit" value="Apply Changes" /></p>
310 @ </div></form>
311 db_end_transaction(0);
312 style_footer();
313 }
@@ -574,22 +575,18 @@
574 }
575 return 0;
576 }
577
578 /*
579 ** Make a copy of the input string up to but not including the
580 ** first cTerm character.
581 **
582 ** Verify that the string really that is to be copied really is a
583 ** valid email address. If it is not, then return NULL.
584 **
585 ** This routine is more restrictive than necessary. It does not
586 ** allow comments, IP address, quoted strings, or certain uncommon
587 ** characters. The only non-alphanumerics allowed in the local
588 ** part are "_", "+", "-" and "+".
589 */
590 char *email_copy_addr(const char *z, char cTerm ){
591 int i;
592 int nAt = 0;
593 int nDot = 0;
594 char c;
595 if( z[0]=='.' ) return 0; /* Local part cannot begin with "." */
@@ -619,13 +616,28 @@
619 }
620 }
621 if( c!=cTerm ) return 0; /* Missing terminator */
622 if( nAt==0 ) return 0; /* No "@" found anywhere */
623 if( nDot==0 ) return 0; /* No "." in the domain */
 
 
624
625 /* If we reach this point, the email address is valid */
626 return mprintf("%.*s", i, z);
 
 
 
 
 
 
 
 
 
 
 
 
 
627 }
628
629 /*
630 ** Scan the input string for a valid email address enclosed in <...>
631 ** If the string contains one or more email addresses, extract the first
@@ -659,10 +671,38 @@
659 char *zOut = alert_find_emailaddr(zIn);
660 if( zOut ){
661 sqlite3_result_text(context, zOut, -1, fossil_free);
662 }
663 }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
664
665 /*
666 ** Return the hostname portion of an email address - the part following
667 ** the @
668 */
@@ -762,11 +802,11 @@
762 ** Date:
763 ** Message-Id:
764 ** Content-Type:
765 ** Content-Transfer-Encoding:
766 ** MIME-Version:
767 ** X-Fossil-From:
768 **
769 ** The caller maintains ownership of the input Blobs. This routine will
770 ** read the Blobs and send them onward to the email system, but it will
771 ** not free them.
772 **
@@ -774,14 +814,14 @@
774 ** in the pHdr parameter.
775 **
776 ** If the zFromName argument is not NULL, then it should be a human-readable
777 ** name or handle for the sender. In that case, "From:" becomes a made-up
778 ** email address based on a hash of zFromName and the domain of email-self,
779 ** and an additional "X-Fossil-From:" field is inserted with the email-self
780 ** address. Downstream software might use the X-Fossil-From header to set
781 ** the envelope-from address of the email. If zFromName is a NULL pointer,
782 ** then the "From:" is set to the email-self value and X-Fossil-From is
783 ** omitted.
784 */
785 void alert_send(
786 AlertSender *p, /* Emailer context */
787 Blob *pHdr, /* Email header (incomplete) */
@@ -794,26 +834,26 @@
794 fossil_print("Sending email\n");
795 }
796 if( fossil_strcmp(p->zDest, "off")==0 ){
797 return;
798 }
 
799 if( fossil_strcmp(p->zDest, "blob")==0 ){
800 pOut = &p->out;
801 if( blob_size(pOut) ){
802 blob_appendf(pOut, "%.72c\n", '=');
803 }
804 }else{
805 blob_init(&all, 0, 0);
806 pOut = &all;
807 }
808 blob_append(pOut, blob_buffer(pHdr), blob_size(pHdr));
809 if( p->zFrom==0 || p->zFrom[0]==0 ){
810 return; /* email-self is not set. Error will be reported separately */
811 }else if( zFromName ){
812 blob_appendf(pOut, "From: %s <%s@%s>\r\n",
813 zFromName, alert_mailbox_name(zFromName), alert_hostname(p->zFrom));
814 blob_appendf(pOut, "X-Fossil-From: <%s>\r\n", p->zFrom);
815 }else{
816 blob_appendf(pOut, "From: <%s>\r\n", p->zFrom);
817 }
818 blob_appendf(pOut, "Date: %z\r\n", cgi_rfc822_datestamp(time(0)));
819 if( strstr(blob_str(pHdr), "\r\nMessage-Id:")==0 ){
@@ -879,10 +919,26 @@
879 fossil_print("%s", blob_str(&all));
880 }
881 blob_reset(&all);
882 }
883
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
884 /*
885 ** SETTING: email-send-method width=5 default=off
886 ** Determine the method used to send email. Allowed values are
887 ** "off", "relay", "pipe", "dir", "db", and "stdout". The "off" value
888 ** means no email is ever sent. The "relay" value means emails are sent
@@ -1152,10 +1208,19 @@
1152 int i, j, n;
1153 char c;
1154
1155 *peErr = 0;
1156 *pzErr = 0;
 
 
 
 
 
 
 
 
 
1157
1158 /* Check the validity of the email address.
1159 **
1160 ** (1) Exactly one '@' character.
1161 ** (2) No other characters besides [a-zA-Z0-9._+-]
@@ -1163,11 +1228,15 @@
1163 ** The local part is currently more restrictive than RFC 5322 allows:
1164 ** https://stackoverflow.com/a/2049510/142454 We will expand this as
1165 ** necessary.
1166 */
1167 zEAddr = P("e");
1168 if( zEAddr==0 ) return 0;
 
 
 
 
1169 for(i=j=n=0; (c = zEAddr[i])!=0; i++){
1170 if( c=='@' ){
1171 n = i;
1172 j++;
1173 continue;
@@ -1193,14 +1262,13 @@
1193 *peErr = 1;
1194 *pzErr = mprintf("email domain too short");
1195 return 0;
1196 }
1197
1198 /* Verify the captcha */
1199 if( needCaptcha && !captcha_is_correct(1) ){
1200 *peErr = 2;
1201 *pzErr = mprintf("incorrect security code");
1202 return 0;
1203 }
1204
1205 /* Check to make sure the email address is available for reuse */
1206 if( db_exists("SELECT 1 FROM subscriber WHERE semail=%Q", zEAddr) ){
@@ -1259,11 +1327,11 @@
1259 ** page. To allow anonymous passers-by to sign up for email
1260 ** notification, set Email-Alerts on user "nobody" or "anonymous".
1261 */
1262 void subscribe_page(void){
1263 int needCaptcha;
1264 unsigned int uSeed;
1265 const char *zDecoded;
1266 char *zCaptcha = 0;
1267 char *zErr = 0;
1268 int eErr = 0;
1269 int di;
@@ -1291,10 +1359,14 @@
1291 /* Everybody else jumps to the page to administer their own
1292 ** account only. */
1293 cgi_redirectf("%R/alerts");
1294 return;
1295 }
 
 
 
 
1296 }
1297 alert_submenu_common();
1298 needCaptcha = !login_is_individual();
1299 if( P("submit")
1300 && cgi_csrf_safe(1)
@@ -1312,10 +1384,11 @@
1312 if( PB("sa") ) ssub[nsub++] = 'a';
1313 if( g.perm.Read && PB("sc") ) ssub[nsub++] = 'c';
1314 if( g.perm.RdForum && PB("sf") ) ssub[nsub++] = 'f';
1315 if( g.perm.RdTkt && PB("st") ) ssub[nsub++] = 't';
1316 if( g.perm.RdWiki && PB("sw") ) ssub[nsub++] = 'w';
 
1317 ssub[nsub] = 0;
1318 db_multi_exec(
1319 "INSERT INTO subscriber(semail,suname,"
1320 " sverified,sdonotcall,sdigest,ssub,sctime,mtime,smip)"
1321 "VALUES(%Q,%Q,%d,0,%d,%Q,now(),now(),%Q)",
@@ -1332,11 +1405,15 @@
1332 id);
1333 if( !needCaptcha ){
1334 /* The new subscription has been added on behalf of a logged-in user.
1335 ** No verification is required. Jump immediately to /alerts page.
1336 */
1337 cgi_redirectf("%R/alerts/%s", zCode);
 
 
 
 
1338 return;
1339 }else{
1340 /* We need to send a verification email */
1341 Blob hdr, body;
1342 AlertSender *pSender = alert_sender_new(0,0);
@@ -1354,11 +1431,11 @@
1354 @ <blockquote><pre>
1355 @ %h(pSender->zErr)
1356 @ </pre></blockquote>
1357 }else{
1358 @ <p>An email has been sent to "%h(zEAddr)". That email contains a
1359 @ hyperlink that you must click on in order to activate your
1360 @ subscription.</p>
1361 }
1362 alert_sender_free(pSender);
1363 style_footer();
1364 }
@@ -1386,16 +1463,23 @@
1386 if( eErr==1 ){
1387 @ <tr><td><td><span class='loginError'>&uarr; %h(zErr)</span></td></tr>
1388 }
1389 @ </tr>
1390 if( needCaptcha ){
1391 uSeed = captcha_seed();
 
 
 
 
 
 
1392 zDecoded = captcha_decode(uSeed);
1393 zCaptcha = captcha_render(zDecoded);
1394 @ <tr>
1395 @ <td class="form_label">Security Code:</td>
1396 @ <td><input type="text" name="captcha" value="" size="30">
 
1397 @ <input type="hidden" name="captchaseed" value="%u(uSeed)"></td>
1398 @ </tr>
1399 if( eErr==2 ){
1400 @ <tr><td><td><span class='loginError'>&uarr; %h(zErr)</span></td></tr>
1401 }
@@ -1421,10 +1505,12 @@
1421 @ Check-ins</label><br>
1422 }
1423 if( g.perm.RdForum ){
1424 @ <label><input type="checkbox" name="sf" %s(PCK("sf"))> \
1425 @ Forum Posts</label><br>
 
 
1426 }
1427 if( g.perm.RdTkt ){
1428 @ <label><input type="checkbox" name="st" %s(PCK("st"))> \
1429 @ Ticket changes</label><br>
1430 }
@@ -1461,11 +1547,11 @@
1461 @ </table>
1462 if( needCaptcha ){
1463 @ <div class="captcha"><table class="captcha"><tr><td><pre class="captcha">
1464 @ %h(zCaptcha)
1465 @ </pre>
1466 @ Enter the 8 characters above in the "Security Code" box
1467 @ </td></tr></table></div>
1468 }
1469 @ </form>
1470 fossil_free(zErr);
1471 style_footer();
@@ -1474,21 +1560,20 @@
1474 /*
1475 ** Either shutdown or completely delete a subscription entry given
1476 ** by the hex value zName. Then paint a webpage that explains that
1477 ** the entry has been removed.
1478 */
1479 static void alert_unsubscribe(const char *zName){
1480 char *zEmail;
1481 zEmail = db_text(0, "SELECT semail FROM subscriber"
1482 " WHERE subscriberCode=hextoblob(%Q)", zName);
1483 if( zEmail==0 ){
1484 style_header("Unsubscribe Fail");
1485 @ <p>Unable to locate a subscriber with the requested key</p>
1486 }else{
1487 db_multi_exec(
1488 "DELETE FROM subscriber WHERE subscriberCode=hextoblob(%Q)",
1489 zName
1490 );
1491 style_header("Unsubscribed");
1492 @ <p>The "%h(zEmail)" email address has been delisted.
1493 @ All traces of that email address have been removed</p>
1494 }
@@ -1499,108 +1584,149 @@
1499 /*
1500 ** WEBPAGE: alerts
1501 **
1502 ** Edit email alert and notification settings.
1503 **
1504 ** The subscriber is identified in either of two ways:
1505 **
1506 ** (1) The name= query parameter contains the subscriberCode.
1507 **
1508 ** (2) The user is logged into an account other than "nobody" or
1509 ** "anonymous". In that case the notification settings
1510 ** associated with that account can be edited without needing
1511 ** to know the subscriber code.
1512 */
1513 void alert_page(void){
1514 const char *zName = P("name");
1515 Stmt q;
1516 int sa, sc, sf, st, sw;
1517 int sdigest, sdonotcall, sverified;
1518 const char *ssub;
1519 const char *semail;
1520 const char *smip;
1521 const char *suname;
1522 const char *mtime;
1523 const char *sctime;
1524 int eErr = 0;
1525 char *zErr = 0;
1526
1527 if( alert_webpages_disabled() ) return;
1528 login_check_credentials();
1529 if( !g.perm.EmailAlert ){
1530 login_needed(g.anon.EmailAlert);
1531 return;
1532 }
1533 if( zName==0 && login_is_individual() ){
1534 zName = db_text(0, "SELECT hex(subscriberCode) FROM subscriber"
1535 " WHERE suname=%Q", g.zLogin);
1536 }
1537 if( zName==0 || !validate16(zName, -1) ){
1538 cgi_redirect("subscribe");
1539 return;
1540 }
1541 alert_submenu_common();
1542 if( P("submit")!=0 && cgi_csrf_safe(1) ){
1543 int sdonotcall = PB("sdonotcall");
1544 int sdigest = PB("sdigest");
1545 char ssub[10];
1546 int nsub = 0;
1547 if( PB("sa") ) ssub[nsub++] = 'a';
1548 if( g.perm.Read && PB("sc") ) ssub[nsub++] = 'c';
1549 if( g.perm.RdForum && PB("sf") ) ssub[nsub++] = 'f';
1550 if( g.perm.RdTkt && PB("st") ) ssub[nsub++] = 't';
1551 if( g.perm.RdWiki && PB("sw") ) ssub[nsub++] = 'w';
1552 ssub[nsub] = 0;
1553 if( g.perm.Admin ){
1554 const char *suname = PT("suname");
1555 int sverified = PB("sverified");
1556 if( suname && suname[0]==0 ) suname = 0;
1557 db_multi_exec(
1558 "UPDATE subscriber SET"
1559 " sdonotcall=%d,"
1560 " sdigest=%d,"
1561 " ssub=%Q,"
1562 " mtime=strftime('%%s','now'),"
1563 " smip=%Q,"
1564 " suname=%Q,"
1565 " sverified=%d"
1566 " WHERE subscriberCode=hextoblob(%Q)",
1567 sdonotcall,
1568 sdigest,
1569 ssub,
1570 g.zIpAddr,
1571 suname,
1572 sverified,
1573 zName
1574 );
1575 }else{
1576 db_multi_exec(
1577 "UPDATE subscriber SET"
1578 " sdonotcall=%d,"
1579 " sdigest=%d,"
1580 " ssub=%Q,"
1581 " mtime=strftime('%%s','now'),"
1582 " smip=%Q"
1583 " WHERE subscriberCode=hextoblob(%Q)",
1584 sdonotcall,
1585 sdigest,
1586 ssub,
1587 g.zIpAddr,
1588 zName
1589 );
1590 }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1591 }
1592 if( P("delete")!=0 && cgi_csrf_safe(1) ){
1593 if( !PB("dodelete") ){
1594 eErr = 9;
1595 zErr = mprintf("Select this checkbox and press \"Unsubscribe\" again to"
1596 " unsubscribe");
1597 }else{
1598 alert_unsubscribe(zName);
1599 return;
 
1600 }
1601 }
 
1602 db_prepare(&q,
1603 "SELECT"
1604 " semail," /* 0 */
1605 " sverified," /* 1 */
1606 " sdonotcall," /* 2 */
@@ -1607,52 +1733,92 @@
1607 " sdigest," /* 3 */
1608 " ssub," /* 4 */
1609 " smip," /* 5 */
1610 " suname," /* 6 */
1611 " datetime(mtime,'unixepoch')," /* 7 */
1612 " datetime(sctime,'unixepoch')" /* 8 */
1613 " FROM subscriber WHERE subscriberCode=hextoblob(%Q)", zName);
 
1614 if( db_step(&q)!=SQLITE_ROW ){
1615 db_finalize(&q);
 
1616 cgi_redirect("subscribe");
1617 return;
1618 }
1619 style_header("Update Subscription");
1620 semail = db_column_text(&q, 0);
1621 sverified = db_column_int(&q, 1);
1622 sdonotcall = db_column_int(&q, 2);
1623 sdigest = db_column_int(&q, 3);
1624 ssub = db_column_text(&q, 4);
 
 
 
 
1625 sa = strchr(ssub,'a')!=0;
1626 sc = strchr(ssub,'c')!=0;
1627 sf = strchr(ssub,'f')!=0;
1628 st = strchr(ssub,'t')!=0;
1629 sw = strchr(ssub,'w')!=0;
 
1630 smip = db_column_text(&q, 5);
1631 suname = db_column_text(&q, 6);
1632 mtime = db_column_text(&q, 7);
1633 sctime = db_column_text(&q, 8);
1634 if( !g.perm.Admin && !sverified ){
1635 db_multi_exec(
1636 "UPDATE subscriber SET sverified=1 WHERE subscriberCode=hextoblob(%Q)",
1637 zName);
1638 @ <h1>Your email alert subscription has been verified!</h1>
1639 @ <p>Use the form below to update your subscription information.</p>
1640 @ <p>Hint: Bookmark this page so that you can more easily update
1641 @ your subscription information in the future</p>
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1642 }else{
1643 @ <p>Make changes to the email subscription shown below and
1644 @ press "Submit".</p>
1645 }
1646 form_begin(0, "%R/alerts");
1647 @ <input type="hidden" name="name" value="%h(zName)">
 
 
1648 @ <table class="subscribe">
1649 @ <tr>
1650 @ <td class="form_label">Email&nbsp;Address:</td>
1651 @ <td>%h(semail)</td>
 
 
 
 
 
 
 
 
 
 
 
1652 @ </tr>
1653 if( g.perm.Admin ){
 
1654 @ <tr>
1655 @ <td class='form_label'>Created:</td>
1656 @ <td>%h(sctime)</td>
1657 @ </tr>
1658 @ <tr>
@@ -1662,13 +1828,21 @@
1662 @ <tr>
1663 @ <td class='form_label'>IP Address:</td>
1664 @ <td>%h(smip)</td>
1665 @ </tr>
1666 @ <tr>
 
 
 
1667 @ <td class="form_label">User:</td>
1668 @ <td><input type="text" name="suname" value="%h(suname?suname:"")" \
1669 @ size="30"></td>
 
 
 
 
 
1670 @ </tr>
1671 }
1672 @ <tr>
1673 @ <td class="form_label">Topics:</td>
1674 @ <td><label><input type="checkbox" name="sa" %s(sa?"checked":"")>\
@@ -1678,10 +1852,12 @@
1678 @ Check-ins</label><br>
1679 }
1680 if( g.perm.RdForum ){
1681 @ <label><input type="checkbox" name="sf" %s(sf?"checked":"")>\
1682 @ Forum Posts</label><br>
 
 
1683 }
1684 if( g.perm.RdTkt ){
1685 @ <label><input type="checkbox" name="st" %s(st?"checked":"")>\
1686 @ Ticket changes</label><br>
1687 }
@@ -1695,19 +1871,15 @@
1695 @ <td><select size="1" name="sdigest">
1696 @ <option value="0" %s(sdigest?"":"selected")>Individual Emails</option>
1697 @ <option value="1" %s(sdigest?"selected":"")>Daily Digest</option>
1698 @ </select></td>
1699 @ </tr>
1700 #if 0
1701 @ <label><input type="checkbox" name="sdigest" %s(sdigest?"checked":"")>\
1702 @ Daily digest only</label><br>
1703 #endif
1704 if( g.perm.Admin ){
1705 @ <tr>
1706 @ <td class="form_label">Admin Options:</td><td>
1707 @ <label><input type="checkbox" name="sdonotcall" \
1708 @ %s(sdonotcall?"checked":"")> Do not call</label><br>
1709 @ <label><input type="checkbox" name="sverified" \
1710 @ %s(sverified?"checked":"")>\
1711 @ Verified</label></td></tr>
1712 }
1713 if( eErr==9 ){
@@ -1726,10 +1898,12 @@
1726 @ </table>
1727 @ </form>
1728 fossil_free(zErr);
1729 db_finalize(&q);
1730 style_footer();
 
 
1731 }
1732
1733 /* This is the message that gets sent to describe how to change
1734 ** or modify a subscription
1735 */
@@ -1760,25 +1934,26 @@
1760 */
1761 void unsubscribe_page(void){
1762 const char *zName = P("name");
1763 char *zErr = 0;
1764 int eErr = 0;
1765 unsigned int uSeed;
1766 const char *zDecoded;
1767 char *zCaptcha = 0;
1768 int dx;
1769 int bSubmit;
1770 const char *zEAddr;
1771 char *zCode = 0;
 
1772
1773 /* If a valid subscriber code is supplied, then unsubscribe immediately.
1774 */
1775 if( zName
1776 && db_exists("SELECT 1 FROM subscriber WHERE subscriberCode=hextoblob(%Q)",
1777 zName)
1778 ){
1779 alert_unsubscribe(zName);
1780 return;
1781 }
1782
1783 /* Logged in users are redirected to the /alerts page */
1784 login_check_credentials();
@@ -1855,10 +2030,11 @@
1855 zDecoded = captcha_decode(uSeed);
1856 zCaptcha = captcha_render(zDecoded);
1857 @ <tr>
1858 @ <td class="form_label">Security Code:</td>
1859 @ <td><input type="text" name="captcha" value="" size="30">
 
1860 @ <input type="hidden" name="captchaseed" value="%u(uSeed)"></td>
1861 if( eErr==2 ){
1862 @ <td><span class="loginError">&larr; %h(zErr)</span></td>
1863 }
1864 @ </tr>
@@ -1874,11 +2050,11 @@
1874 @ </tr>
1875 @ </table>
1876 @ <div class="captcha"><table class="captcha"><tr><td><pre class="captcha">
1877 @ %h(zCaptcha)
1878 @ </pre>
1879 @ Enter the 8 characters above in the "Security Code" box
1880 @ </td></tr></table></div>
1881 @ </form>
1882 fossil_free(zErr);
1883 style_footer();
1884 }
@@ -1885,37 +2061,69 @@
1885
1886 /*
1887 ** WEBPAGE: subscribers
1888 **
1889 ** This page, accessible to administrators only,
1890 ** shows a list of email notification email addresses.
1891 ** Clicking on an email takes one to the /alerts page
1892 ** for that email where the delivery settings can be
1893 ** modified.
1894 */
1895 void subscriber_list_page(void){
1896 Blob sql;
1897 Stmt q;
1898 sqlite3_int64 iNow;
 
 
 
1899 if( alert_webpages_disabled() ) return;
1900 login_check_credentials();
1901 if( !g.perm.Admin ){
1902 login_needed(0);
1903 return;
1904 }
1905 alert_submenu_common();
 
1906 style_header("Subscriber List");
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1907 blob_init(&sql, 0, 0);
1908 blob_append_sql(&sql,
1909 "SELECT hex(subscriberCode)," /* 0 */
1910 " semail," /* 1 */
1911 " ssub," /* 2 */
1912 " suname," /* 3 */
1913 " sverified," /* 4 */
1914 " sdigest," /* 5 */
1915 " mtime," /* 6 */
1916 " date(sctime,'unixepoch')" /* 7 */
 
1917 " FROM subscriber"
1918 );
1919 if( P("only")!=0 ){
1920 blob_append_sql(&sql, " WHERE ssub LIKE '%%%q%%'", P("only"));
1921 style_submenu_element("Show All","%R/subscribers");
@@ -1937,16 +2145,22 @@
1937 @ </tr>
1938 @ </thead><tbody>
1939 while( db_step(&q)==SQLITE_ROW ){
1940 sqlite3_int64 iMtime = db_column_int64(&q, 6);
1941 double rAge = (iNow - iMtime)/86400.0;
 
 
1942 @ <tr>
1943 @ <td><a href='%R/alerts/%s(db_column_text(&q,0))'>\
1944 @ %h(db_column_text(&q,1))</a></td>
1945 @ <td>%h(db_column_text(&q,2))</td>
1946 @ <td>%s(db_column_int(&q,5)?"digest":"")</td>
1947 @ <td>%h(db_column_text(&q,3))</td>
 
 
 
 
1948 @ <td>%s(db_column_int(&q,4)?"yes":"pending")</td>
1949 @ <td data-sortkey='%010llx(iMtime)'>%z(human_readable_age(rAge))</td>
1950 @ <td>%h(db_column_text(&q,7))</td>
1951 @ </tr>
1952 }
@@ -1958,13 +2172,21 @@
1958
1959 #if LOCAL_INTERFACE
1960 /*
1961 ** A single event that might appear in an alert is recorded as an
1962 ** instance of the following object.
 
 
 
 
 
 
 
 
1963 */
1964 struct EmailEvent {
1965 int type; /* 'c', 'f', 'm', 't', 'w' */
1966 int needMod; /* Pending moderator approval */
1967 Blob hdr; /* Header content, for forum entries */
1968 Blob txt; /* Text description to appear in an alert */
1969 char *zFromName; /* Human name of the sender */
1970 EmailEvent *pNext; /* Next in chronological order */
@@ -2039,20 +2261,20 @@
2039 p->needMod = db_column_int(&q, 4);
2040 p->zFromName = 0;
2041 p->pNext = 0;
2042 switch( p->type ){
2043 case 'c': zType = "Check-In"; break;
2044 case 'f': zType = "Forum post"; break;
2045 case 't': zType = "Ticket Change"; break;
2046 case 'w': zType = "Wiki Edit"; break;
2047 }
2048 blob_init(&p->hdr, 0, 0);
2049 blob_init(&p->txt, 0, 0);
2050 blob_appendf(&p->txt,"== %s %s ==\n%s\n%s/info/%.20s\n",
2051 db_column_text(&q,1),
2052 zType,
2053 db_column_text(&q,2),
2054 zUrl,
2055 db_column_text(&q,0)
2056 );
2057 if( p->needMod ){
2058 blob_appendf(&p->txt,
@@ -2078,17 +2300,28 @@
2078 ** is a normal email alert. Construct full-text forum post alerts
2079 ** using a format that enables them to be sent as separate emails.
2080 */
2081 db_prepare(&q,
2082 "SELECT"
2083 " forumpost.fpid," /* 0 */
2084 " (SELECT uuid FROM blob WHERE rid=forumpost.fpid)," /* 1 */
2085 " datetime(event.mtime)," /* 2 */
2086 " substr(comment,instr(comment,':')+2)," /* 3 */
2087 " (SELECT uuid FROM blob WHERE rid=forumpost.firt)," /* 4 */
2088 " wantalert.needMod," /* 5 */
2089 " coalesce(trim(substr(info,1,instr(info,'<')-1)),euser,user)" /* 6 */
 
 
 
 
 
 
 
 
 
 
 
2090 " FROM temp.wantalert, event, forumpost"
2091 " LEFT JOIN user ON (login=coalesce(euser,user))"
2092 " WHERE event.objid=substr(wantalert.eventId,2)+0"
2093 " AND eventId GLOB 'f*'"
2094 " AND forumpost.fpid=event.objid"
@@ -2104,11 +2337,11 @@
2104 const char *z;
2105 if( pPost==0 ) continue;
2106 p = fossil_malloc( sizeof(EmailEvent) );
2107 pLast->pNext = p;
2108 pLast = p;
2109 p->type = 'f';
2110 p->needMod = db_column_int(&q, 5);
2111 z = db_column_text(&q,6);
2112 p->zFromName = z && z[0] ? fossil_strdup(z) : 0;
2113 p->pNext = 0;
2114 blob_init(&p->hdr, 0, 0);
@@ -2321,13 +2554,14 @@
2321 ** the process malfunctions or crashes, some notifications may never
2322 ** be sent. But that is better than some recurring bug causing
2323 ** subscribers to be flooded with repeated notifications every 60
2324 ** seconds!
2325 */
2326 void alert_send_alerts(u32 flags){
2327 EmailEvent *pEvents, *p;
2328 int nEvent = 0;
 
2329 Stmt q;
2330 const char *zDigest = "false";
2331 Blob hdr, body;
2332 const char *zUrl;
2333 const char *zRepoName;
@@ -2436,13 +2670,13 @@
2436 ** if the recipient is a moderator for that type of event. Setup
2437 ** and Admin users always get notified. */
2438 char xType = '*';
2439 if( strpbrk(zCap,"as")==0 ){
2440 switch( p->type ){
2441 case 'f': xType = '5'; break;
2442 case 't': xType = 'q'; break;
2443 case 'w': xType = 'l'; break;
2444 }
2445 if( strchr(zCap,xType)==0 ) continue;
2446 }
2447 }else if( strchr(zCap,'s')!=0 || strchr(zCap,'a')!=0 ){
2448 /* Setup and admin users can get any notification that does not
@@ -2450,14 +2684,14 @@
2450 }else{
2451 /* Other users only see the alert if they have sufficient
2452 ** privilege to view the event itself */
2453 char xType = '*';
2454 switch( p->type ){
2455 case 'c': xType = 'o'; break;
2456 case 'f': xType = '2'; break;
2457 case 't': xType = 'r'; break;
2458 case 'w': xType = 'j'; break;
2459 }
2460 if( strchr(zCap,xType)==0 ) continue;
2461 }
2462 if( blob_size(&p->hdr)>0 ){
2463 /* This alert should be sent as a separate email */
@@ -2467,10 +2701,11 @@
2467 blob_append(&fhdr, blob_buffer(&p->hdr), blob_size(&p->hdr));
2468 blob_init(&fbody, blob_buffer(&p->txt), blob_size(&p->txt));
2469 blob_appendf(&fbody, "\n-- \nSubscription info: %s/alerts/%s\n",
2470 zUrl, zCode);
2471 alert_send(pSender,&fhdr,&fbody,p->zFromName);
 
2472 blob_reset(&fhdr);
2473 blob_reset(&fbody);
2474 }else{
2475 /* Events other than forum posts are gathered together into
2476 ** a single email message */
@@ -2490,10 +2725,11 @@
2490 }
2491 if( nHit==0 ) continue;
2492 blob_appendf(&body,"\n-- \nSubscription info: %s/alerts/%s\n",
2493 zUrl, zCode);
2494 alert_send(pSender,&hdr,&body,0);
 
2495 blob_truncate(&hdr, 0);
2496 blob_truncate(&body, 0);
2497 }
2498 blob_reset(&hdr);
2499 blob_reset(&body);
@@ -2506,10 +2742,11 @@
2506 db_multi_exec("DELETE FROM pending_alert WHERE sentDigest AND sentSep;");
2507
2508 send_alert_done:
2509 alert_sender_free(pSender);
2510 if( g.fSqlTrace ) fossil_trace("-- END alert_send_alerts(%u)\n", flags);
 
2511 }
2512
2513 /*
2514 ** Do backoffice processing for email notifications. In other words,
2515 ** check to see if any email notifications need to occur, and then
@@ -2519,19 +2756,21 @@
2519 **
2520 ** The mFlags option is zero or more of the SENDALERT_* flags. Normally
2521 ** this flag is zero, but the test-set-alert command sets it to
2522 ** SENDALERT_TRACE.
2523 */
2524 void alert_backoffice(u32 mFlags){
2525 int iJulianDay;
2526 if( !alert_tables_exist() ) return;
2527 alert_send_alerts(mFlags);
 
2528 iJulianDay = db_int(0, "SELECT julianday('now')");
2529 if( iJulianDay>db_get_int("email-last-digest",0) ){
2530 db_set_int("email-last-digest",iJulianDay,0);
2531 alert_send_alerts(SENDALERT_DIGEST|mFlags);
2532 }
 
2533 }
2534
2535 /*
2536 ** WEBPAGE: contact_admin
2537 **
@@ -2594,10 +2833,11 @@
2594 @ <table class="subscribe">
2595 if( zCaptcha ){
2596 @ <tr>
2597 @ <td class="form_label">Security&nbsp;Code:</td>
2598 @ <td><input type="text" name="captcha" value="" size="10">
 
2599 @ <input type="hidden" name="captchaseed" value="%u(uSeed)"></td>
2600 @ </tr>
2601 }
2602 @ <tr>
2603 @ <td class="form_label">Your&nbsp;Email&nbsp;Address:</td>
@@ -2620,11 +2860,11 @@
2620 @ </table>
2621 if( zCaptcha ){
2622 @ <div class="captcha"><table class="captcha"><tr><td><pre class="captcha">
2623 @ %h(zCaptcha)
2624 @ </pre>
2625 @ Enter the 8 characters above in the "Security Code" box
2626 @ </td></tr></table></div>
2627 }
2628 @ </form>
2629 style_footer();
2630 }
@@ -2638,10 +2878,11 @@
2638 char *zErr;
2639 const char *zTo = PT("to");
2640 char *zSubject = PT("subject");
2641 int bAll = PB("all");
2642 int bAA = PB("aa");
 
2643 const char *zSub = db_get("email-subname", "[Fossil Repo]");
2644 int bTest2 = fossil_strcmp(P("name"),"test2")==0;
2645 Blob hdr, body;
2646 blob_init(&body, 0, 0);
2647 blob_init(&hdr, 0, 0);
@@ -2649,17 +2890,29 @@
2649 pSender = alert_sender_new(bTest2 ? "blob" : 0, 0);
2650 if( zTo[0] ){
2651 blob_appendf(&hdr, "To: <%s>\r\nSubject: %s %s\r\n", zTo, zSub, zSubject);
2652 alert_send(pSender, &hdr, &body, 0);
2653 }
2654 if( bAll || bAA ){
2655 Stmt q;
2656 int nUsed = blob_size(&body);
2657 const char *zURL = db_get("email-url",0);
2658 db_prepare(&q, "SELECT semail, hex(subscriberCode) FROM subscriber "
2659 " WHERE sverified AND NOT sdonotcall %s",
2660 bAll ? "" : " AND ssub LIKE '%a%'");
 
 
 
 
 
 
 
 
 
 
 
 
2661 while( db_step(&q)==SQLITE_ROW ){
2662 const char *zCode = db_column_text(&q, 1);
2663 zTo = db_column_text(&q, 0);
2664 blob_truncate(&hdr, 0);
2665 blob_appendf(&hdr, "To: <%s>\r\nSubject: %s %s\r\n", zTo, zSub, zSubject);
@@ -2716,11 +2969,12 @@
2716 @ <p>The following error was reported by the system:
2717 @ <blockquote><pre>
2718 @ %h(zErr)
2719 @ </pre></blockquote>
2720 }else{
2721 @ <p>The announcement has been sent.</p>
 
2722 }
2723 style_footer();
2724 return;
2725 } else if( !alert_enabled() ){
2726 style_header("Cannot Send Announcement");
@@ -2734,21 +2988,26 @@
2734 @ <form method="POST">
2735 @ <table class="subscribe">
2736 if( g.perm.Admin ){
2737 int aa = PB("aa");
2738 int all = PB("all");
 
2739 const char *aack = aa ? "checked" : "";
2740 const char *allck = all ? "checked" : "";
 
2741 @ <tr>
2742 @ <td class="form_label">To:</td>
2743 @ <td><input type="text" name="to" value="%h(PT("to"))" size="30"><br>
2744 @ <label><input type="checkbox" name="aa" %s(aack)> \
2745 @ All "announcement" subscribers</label> \
2746 @ <a href="%R/subscribers?only=a" target="_blank">(list)</a><br>
2747 @ <label><input type="checkbox" name="all" %s(allck)> \
2748 @ All subscribers</label> \
2749 @ <a href="%R/subscribers" target="_blank">(list)</a><br></td>
 
 
 
2750 @ </tr>
2751 }
2752 @ <tr>
2753 @ <td class="form_label">Subject:</td>
2754 @ <td><input type="text" name="subject" value="%h(PT("subject"))"\
@@ -2759,11 +3018,15 @@
2759 @ <td><textarea name="msg" cols="80" rows="10" wrap="virtual">\
2760 @ %h(PT("msg"))</textarea>
2761 @ </tr>
2762 @ <tr>
2763 @ <td></td>
2764 @ <td><input type="submit" name="submit" value="Send Message">
 
 
 
 
2765 @ </tr>
2766 @ </table>
2767 @ </form>
2768 style_footer();
2769 }
2770
--- src/alerts.c
+++ src/alerts.c
@@ -46,10 +46,11 @@
46 @ --
47 @ -- The ssub field is a string where each character indicates a particular
48 @ -- type of event to subscribe to. Choices:
49 @ -- a - Announcements
50 @ -- c - Check-ins
51 @ -- f - Forum posts
52 @ -- t - Ticket changes
53 @ -- w - Wiki changes
54 @ -- Probably different codes will be added in the future. In the future
55 @ -- we might also add a separate table that allows subscribing to email
56 @ -- notifications for specific branches or tags or tickets.
@@ -114,11 +115,11 @@
115 if( bOnlyIfEnabled
116 && fossil_strcmp(db_get("email-send-method",0),"off")==0
117 ){
118 return; /* Don't create table for disabled email */
119 }
120 db_exec_sql(zAlertInit);
121 alert_triggers_enable();
122 }else if( !db_table_has_column("repository","pending_alert","sentMod") ){
123 db_multi_exec(
124 "ALTER TABLE repository.pending_alert"
125 " ADD COLUMN sentMod BOOLEAN DEFAULT false;"
@@ -183,11 +184,11 @@
184 ** is an administrator.
185 */
186 void alert_submenu_common(void){
187 if( g.perm.Admin ){
188 if( fossil_strcmp(g.zPath,"subscribers") ){
189 style_submenu_element("Subscribers","%R/subscribers");
190 }
191 if( fossil_strcmp(g.zPath,"subscribe") ){
192 style_submenu_element("Add New Subscriber","%R/subscribe");
193 }
194 }
@@ -238,10 +239,17 @@
239 @ This is URL used as the basename for hyperlinks included in
240 @ email alert text. Omit the trailing "/".
241 @ Suggested value: "%h(g.zBaseURL)"
242 @ (Property: "email-url")</p>
243 @ <hr>
244
245 entry_attribute("Administrator email address", 40, "email-admin",
246 "eadmin", "", 0);
247 @ <p>This is the email for the human administrator for the system.
248 @ Abuse and trouble reports and password reset requests are send here.
249 @ (Property: "email-admin")</p>
250 @ <hr>
251
252 entry_attribute("\"Return-Path\" email address", 20, "email-self",
253 "eself", "", 0);
254 @ <p><b>Required.</b>
255 @ This is the email to which email notification bounces should be sent.
@@ -297,17 +305,10 @@
305 @ append a colon and TCP port number (ex: smtp.example.com:587).
306 @ The default TCP port number is 25.
307 @ (Property: "email-send-relayhost")</p>
308 @ <hr>
309
 
 
 
 
 
 
 
310 @ <p><input type="submit" name="submit" value="Apply Changes" /></p>
311 @ </div></form>
312 db_end_transaction(0);
313 style_footer();
314 }
@@ -574,22 +575,18 @@
575 }
576 return 0;
577 }
578
579 /*
580 ** Determine whether or not the input string is a valid email address.
581 ** Only look at character up to but not including the first \000 or
582 ** the first cTerm character, whichever comes first.
583 **
584 ** Return the length of the email addresss string in bytes if the email
585 ** address is valid. If the email address is misformed, return 0.
586 */
587 int email_address_is_valid(const char *z, char cTerm){
 
 
 
 
588 int i;
589 int nAt = 0;
590 int nDot = 0;
591 char c;
592 if( z[0]=='.' ) return 0; /* Local part cannot begin with "." */
@@ -619,13 +616,28 @@
616 }
617 }
618 if( c!=cTerm ) return 0; /* Missing terminator */
619 if( nAt==0 ) return 0; /* No "@" found anywhere */
620 if( nDot==0 ) return 0; /* No "." in the domain */
621 return i;
622 }
623
624 /*
625 ** Make a copy of the input string up to but not including the
626 ** first cTerm character.
627 **
628 ** Verify that the string really that is to be copied really is a
629 ** valid email address. If it is not, then return NULL.
630 **
631 ** This routine is more restrictive than necessary. It does not
632 ** allow comments, IP address, quoted strings, or certain uncommon
633 ** characters. The only non-alphanumerics allowed in the local
634 ** part are "_", "+", "-" and "+".
635 */
636 char *email_copy_addr(const char *z, char cTerm ){
637 int i = email_address_is_valid(z, cTerm);
638 return i==0 ? 0 : mprintf("%.*s", i, z);
639 }
640
641 /*
642 ** Scan the input string for a valid email address enclosed in <...>
643 ** If the string contains one or more email addresses, extract the first
@@ -659,10 +671,38 @@
671 char *zOut = alert_find_emailaddr(zIn);
672 if( zOut ){
673 sqlite3_result_text(context, zOut, -1, fossil_free);
674 }
675 }
676
677 /*
678 ** SQL function: display_name(X)
679 **
680 ** If X is a string, search for a user name at the beginning of that
681 ** string. The user name must be followed by an email address. If
682 ** found, return the user name. If not found, return NULL.
683 **
684 ** This routine is used to extract the display name from the USER.INFO
685 ** field.
686 */
687 void alert_display_name_func(
688 sqlite3_context *context,
689 int argc,
690 sqlite3_value **argv
691 ){
692 const char *zIn = (const char*)sqlite3_value_text(argv[0]);
693 int i;
694 if( zIn==0 ) return;
695 while( fossil_isspace(zIn[0]) ) zIn++;
696 for(i=0; zIn[i] && zIn[i]!='<' && zIn[i]!='\n'; i++){}
697 if( zIn[i]=='<' ){
698 while( i>0 && fossil_isspace(zIn[i-1]) ){ i--; }
699 if( i>0 ){
700 sqlite3_result_text(context, zIn, i, SQLITE_TRANSIENT);
701 }
702 }
703 }
704
705 /*
706 ** Return the hostname portion of an email address - the part following
707 ** the @
708 */
@@ -762,11 +802,11 @@
802 ** Date:
803 ** Message-Id:
804 ** Content-Type:
805 ** Content-Transfer-Encoding:
806 ** MIME-Version:
807 ** Sender:
808 **
809 ** The caller maintains ownership of the input Blobs. This routine will
810 ** read the Blobs and send them onward to the email system, but it will
811 ** not free them.
812 **
@@ -774,14 +814,14 @@
814 ** in the pHdr parameter.
815 **
816 ** If the zFromName argument is not NULL, then it should be a human-readable
817 ** name or handle for the sender. In that case, "From:" becomes a made-up
818 ** email address based on a hash of zFromName and the domain of email-self,
819 ** and an additional "Sender:" field is inserted with the email-self
820 ** address. Downstream software might use the Sender header to set
821 ** the envelope-from address of the email. If zFromName is a NULL pointer,
822 ** then the "From:" is set to the email-self value and Sender is
823 ** omitted.
824 */
825 void alert_send(
826 AlertSender *p, /* Emailer context */
827 Blob *pHdr, /* Email header (incomplete) */
@@ -794,26 +834,26 @@
834 fossil_print("Sending email\n");
835 }
836 if( fossil_strcmp(p->zDest, "off")==0 ){
837 return;
838 }
839 blob_init(&all, 0, 0);
840 if( fossil_strcmp(p->zDest, "blob")==0 ){
841 pOut = &p->out;
842 if( blob_size(pOut) ){
843 blob_appendf(pOut, "%.72c\n", '=');
844 }
845 }else{
 
846 pOut = &all;
847 }
848 blob_append(pOut, blob_buffer(pHdr), blob_size(pHdr));
849 if( p->zFrom==0 || p->zFrom[0]==0 ){
850 return; /* email-self is not set. Error will be reported separately */
851 }else if( zFromName ){
852 blob_appendf(pOut, "From: %s <%s@%s>\r\n",
853 zFromName, alert_mailbox_name(zFromName), alert_hostname(p->zFrom));
854 blob_appendf(pOut, "Sender: <%s>\r\n", p->zFrom);
855 }else{
856 blob_appendf(pOut, "From: <%s>\r\n", p->zFrom);
857 }
858 blob_appendf(pOut, "Date: %z\r\n", cgi_rfc822_datestamp(time(0)));
859 if( strstr(blob_str(pHdr), "\r\nMessage-Id:")==0 ){
@@ -879,10 +919,26 @@
919 fossil_print("%s", blob_str(&all));
920 }
921 blob_reset(&all);
922 }
923
924 /*
925 ** SETTING: email-url width=40
926 ** This URL is used as the basename for hyperlinks included in email alert
927 ** text. Omit the trailing "/".
928 */
929 /*
930 ** SETTING: email-admin width=40
931 ** This is the email address for the human administrator for the system.
932 ** Abuse and trouble reports and password reset requests are send here.
933 */
934 /*
935 ** SETTING: email-subname width=16
936 ** This is a short name used to identifies the repository in the Subject:
937 ** line of email alerts. Traditionally this name is included in square
938 ** brackets. Examples: "[fossil-src]", "[sqlite-src]".
939 */
940 /*
941 ** SETTING: email-send-method width=5 default=off
942 ** Determine the method used to send email. Allowed values are
943 ** "off", "relay", "pipe", "dir", "db", and "stdout". The "off" value
944 ** means no email is ever sent. The "relay" value means emails are sent
@@ -1152,10 +1208,19 @@
1208 int i, j, n;
1209 char c;
1210
1211 *peErr = 0;
1212 *pzErr = 0;
1213
1214 /* Verify the captcha first */
1215 if( needCaptcha ){
1216 if( !captcha_is_correct(1) ){
1217 *peErr = 2;
1218 *pzErr = mprintf("incorrect security code");
1219 return 0;
1220 }
1221 }
1222
1223 /* Check the validity of the email address.
1224 **
1225 ** (1) Exactly one '@' character.
1226 ** (2) No other characters besides [a-zA-Z0-9._+-]
@@ -1163,11 +1228,15 @@
1228 ** The local part is currently more restrictive than RFC 5322 allows:
1229 ** https://stackoverflow.com/a/2049510/142454 We will expand this as
1230 ** necessary.
1231 */
1232 zEAddr = P("e");
1233 if( zEAddr==0 ){
1234 *peErr = 1;
1235 *pzErr = mprintf("required");
1236 return 0;
1237 }
1238 for(i=j=n=0; (c = zEAddr[i])!=0; i++){
1239 if( c=='@' ){
1240 n = i;
1241 j++;
1242 continue;
@@ -1193,14 +1262,13 @@
1262 *peErr = 1;
1263 *pzErr = mprintf("email domain too short");
1264 return 0;
1265 }
1266
1267 if( authorized_subscription_email(zEAddr)==0 ){
1268 *peErr = 1;
1269 *pzErr = mprintf("not an authorized email address");
 
1270 return 0;
1271 }
1272
1273 /* Check to make sure the email address is available for reuse */
1274 if( db_exists("SELECT 1 FROM subscriber WHERE semail=%Q", zEAddr) ){
@@ -1259,11 +1327,11 @@
1327 ** page. To allow anonymous passers-by to sign up for email
1328 ** notification, set Email-Alerts on user "nobody" or "anonymous".
1329 */
1330 void subscribe_page(void){
1331 int needCaptcha;
1332 unsigned int uSeed = 0;
1333 const char *zDecoded;
1334 char *zCaptcha = 0;
1335 char *zErr = 0;
1336 int eErr = 0;
1337 int di;
@@ -1291,10 +1359,14 @@
1359 /* Everybody else jumps to the page to administer their own
1360 ** account only. */
1361 cgi_redirectf("%R/alerts");
1362 return;
1363 }
1364 }
1365 if( !g.perm.Admin && !db_get_boolean("anon-subscribe",1) ){
1366 register_page();
1367 return;
1368 }
1369 alert_submenu_common();
1370 needCaptcha = !login_is_individual();
1371 if( P("submit")
1372 && cgi_csrf_safe(1)
@@ -1312,10 +1384,11 @@
1384 if( PB("sa") ) ssub[nsub++] = 'a';
1385 if( g.perm.Read && PB("sc") ) ssub[nsub++] = 'c';
1386 if( g.perm.RdForum && PB("sf") ) ssub[nsub++] = 'f';
1387 if( g.perm.RdTkt && PB("st") ) ssub[nsub++] = 't';
1388 if( g.perm.RdWiki && PB("sw") ) ssub[nsub++] = 'w';
1389 if( g.perm.RdForum && PB("sx") ) ssub[nsub++] = 'x';
1390 ssub[nsub] = 0;
1391 db_multi_exec(
1392 "INSERT INTO subscriber(semail,suname,"
1393 " sverified,sdonotcall,sdigest,ssub,sctime,mtime,smip)"
1394 "VALUES(%Q,%Q,%d,0,%d,%Q,now(),now(),%Q)",
@@ -1332,11 +1405,15 @@
1405 id);
1406 if( !needCaptcha ){
1407 /* The new subscription has been added on behalf of a logged-in user.
1408 ** No verification is required. Jump immediately to /alerts page.
1409 */
1410 if( g.perm.Admin ){
1411 cgi_redirectf("%R/alerts/%.32s", zCode);
1412 }else{
1413 cgi_redirectf("%R/alerts");
1414 }
1415 return;
1416 }else{
1417 /* We need to send a verification email */
1418 Blob hdr, body;
1419 AlertSender *pSender = alert_sender_new(0,0);
@@ -1354,11 +1431,11 @@
1431 @ <blockquote><pre>
1432 @ %h(pSender->zErr)
1433 @ </pre></blockquote>
1434 }else{
1435 @ <p>An email has been sent to "%h(zEAddr)". That email contains a
1436 @ hyperlink that you must click to activate your
1437 @ subscription.</p>
1438 }
1439 alert_sender_free(pSender);
1440 style_footer();
1441 }
@@ -1386,16 +1463,23 @@
1463 if( eErr==1 ){
1464 @ <tr><td><td><span class='loginError'>&uarr; %h(zErr)</span></td></tr>
1465 }
1466 @ </tr>
1467 if( needCaptcha ){
1468 const char *zInit = "";
1469 if( P("captchaseed")!=0 && eErr!=2 ){
1470 uSeed = strtoul(P("captchaseed"),0,10);
1471 zInit = P("captcha");
1472 }else{
1473 uSeed = captcha_seed();
1474 }
1475 zDecoded = captcha_decode(uSeed);
1476 zCaptcha = captcha_render(zDecoded);
1477 @ <tr>
1478 @ <td class="form_label">Security Code:</td>
1479 @ <td><input type="text" name="captcha" value="%h(zInit)" size="30">
1480 captcha_speakit_button(uSeed, "Speak the code");
1481 @ <input type="hidden" name="captchaseed" value="%u(uSeed)"></td>
1482 @ </tr>
1483 if( eErr==2 ){
1484 @ <tr><td><td><span class='loginError'>&uarr; %h(zErr)</span></td></tr>
1485 }
@@ -1421,10 +1505,12 @@
1505 @ Check-ins</label><br>
1506 }
1507 if( g.perm.RdForum ){
1508 @ <label><input type="checkbox" name="sf" %s(PCK("sf"))> \
1509 @ Forum Posts</label><br>
1510 @ <label><input type="checkbox" name="sx" %s(PCK("sx"))> \
1511 @ Forum Edits</label><br>
1512 }
1513 if( g.perm.RdTkt ){
1514 @ <label><input type="checkbox" name="st" %s(PCK("st"))> \
1515 @ Ticket changes</label><br>
1516 }
@@ -1461,11 +1547,11 @@
1547 @ </table>
1548 if( needCaptcha ){
1549 @ <div class="captcha"><table class="captcha"><tr><td><pre class="captcha">
1550 @ %h(zCaptcha)
1551 @ </pre>
1552 @ Enter the 8 characters above in the "Security Code" box<br/>
1553 @ </td></tr></table></div>
1554 }
1555 @ </form>
1556 fossil_free(zErr);
1557 style_footer();
@@ -1474,21 +1560,20 @@
1560 /*
1561 ** Either shutdown or completely delete a subscription entry given
1562 ** by the hex value zName. Then paint a webpage that explains that
1563 ** the entry has been removed.
1564 */
1565 static void alert_unsubscribe(int sid){
1566 char *zEmail;
1567 zEmail = db_text(0, "SELECT semail FROM subscriber"
1568 " WHERE subscriberId=%d", sid);
1569 if( zEmail==0 ){
1570 style_header("Unsubscribe Fail");
1571 @ <p>Unable to locate a subscriber with the requested key</p>
1572 }else{
1573 db_multi_exec(
1574 "DELETE FROM subscriber WHERE subscriberId=%d", sid
 
1575 );
1576 style_header("Unsubscribed");
1577 @ <p>The "%h(zEmail)" email address has been delisted.
1578 @ All traces of that email address have been removed</p>
1579 }
@@ -1499,108 +1584,149 @@
1584 /*
1585 ** WEBPAGE: alerts
1586 **
1587 ** Edit email alert and notification settings.
1588 **
1589 ** The subscriber is identified in several ways:
1590 **
1591 ** * The name= query parameter contains the complete subscriberCode.
1592 ** This only happens when the user receives a verification
1593 ** email and clicks on the link in the email. When a
1594 ** compilete subscriberCode is seen on the name= query parameter,
1595 ** that constitutes verification of the email address.
1596 **
1597 ** * The sid= query parameter contains an integer subscriberId.
1598 ** This only works for the administrator. It allows the
1599 ** administrator to edit any subscription.
1600 **
1601 ** * The user is logged into an account other than "nobody" or
1602 ** "anonymous". In that case the notification settings
1603 ** associated with that account can be edited without needing
1604 ** to know the subscriber code.
1605 **
1606 ** * The name= query parameter contains a 32-digit prefix of
1607 ** subscriber code. (Subscriber codes are normally 64 hex digits
1608 ** in length.) This uniquely identifies the subscriber without
1609 ** revealing the complete subscriber code, and hence without
1610 ** verifying the email address.
1611 */
1612 void alert_page(void){
1613 const char *zName = 0; /* Value of the name= query parameter */
1614 Stmt q; /* For querying the database */
1615 int sa, sc, sf, st, sw, sx; /* Types of notifications requested */
1616 int sdigest = 0, sdonotcall = 0, sverified = 0; /* Other fields */
1617 int isLogin; /* True if logged in as an individual */
1618 const char *ssub = 0; /* Subscription flags */
1619 const char *semail = 0; /* Email address */
1620 const char *smip; /* */
1621 const char *suname = 0; /* Corresponding user.login value */
1622 const char *mtime; /* */
1623 const char *sctime; /* Time subscription created */
1624 int eErr = 0; /* Type of error */
1625 char *zErr = 0; /* Error message text */
1626 int sid = 0; /* Subscriber ID */
1627 int nName; /* Length of zName in bytes */
1628 char *zHalfCode; /* prefix of subscriberCode */
1629
1630 db_begin_transaction();
1631 if( alert_webpages_disabled() ){
1632 db_commit_transaction();
1633 return;
1634 }
1635 login_check_credentials();
1636 if( !g.perm.EmailAlert ){
1637 db_commit_transaction();
1638 login_needed(g.anon.EmailAlert);
1639 /*NOTREACHED*/
1640 }
1641 isLogin = login_is_individual();
1642 zName = P("name");
1643 nName = zName ? (int)strlen(zName) : 0;
1644 if( g.perm.Admin && P("sid")!=0 ){
1645 sid = atoi(P("sid"));
1646 }
1647 if( sid==0 && nName>=32 ){
1648 sid = db_int(0,
1649 "SELECT CASE WHEN hex(subscriberCode) LIKE (%Q||'%%')"
1650 " THEN subscriberId ELSE 0 END"
1651 " FROM subscriber WHERE subscriberCode>=hextoblob(%Q)"
1652 " LIMIT 1", zName, zName);
1653 }
1654 if( sid==0 && isLogin ){
1655 sid = db_int(0, "SELECT subscriberId FROM subscriber"
1656 " WHERE suname=%Q", g.zLogin);
1657 }
1658 if( sid==0 ){
1659 db_commit_transaction();
1660 cgi_redirect("subscribe");
1661 /*NOTREACHED*/
1662 }
1663 alert_submenu_common();
1664 if( P("submit")!=0 && cgi_csrf_safe(1) ){
1665 char newSsub[10];
1666 int nsub = 0;
1667 Blob update;
1668
1669 sdonotcall = PB("sdonotcall");
1670 sdigest = PB("sdigest");
1671 semail = P("semail");
1672 if( PB("sa") ) newSsub[nsub++] = 'a';
1673 if( g.perm.Read && PB("sc") ) newSsub[nsub++] = 'c';
1674 if( g.perm.RdForum && PB("sf") ) newSsub[nsub++] = 'f';
1675 if( g.perm.RdTkt && PB("st") ) newSsub[nsub++] = 't';
1676 if( g.perm.RdWiki && PB("sw") ) newSsub[nsub++] = 'w';
1677 if( g.perm.RdForum && PB("sx") ) newSsub[nsub++] = 'x';
1678 newSsub[nsub] = 0;
1679 ssub = newSsub;
1680 blob_init(&update, "UPDATE subscriber SET", -1);
1681 blob_append_sql(&update,
1682 " sdonotcall=%d,"
1683 " sdigest=%d,"
1684 " ssub=%Q,"
1685 " mtime=strftime('%%s','now'),"
1686 " smip=%Q",
1687 sdonotcall,
1688 sdigest,
1689 ssub,
1690 g.zIpAddr
1691 );
1692 if( g.perm.Admin ){
1693 suname = PT("suname");
1694 sverified = PB("sverified");
1695 if( suname && suname[0]==0 ) suname = 0;
1696 blob_append_sql(&update,
1697 ", suname=%Q,"
1698 " sverified=%d",
1699 suname,
1700 sverified
1701 );
1702 }
1703 if( isLogin ){
1704 if( semail==0 || email_address_is_valid(semail,0)==0 ){
1705 eErr = 8;
1706 }
1707 blob_append_sql(&update, ", semail=%Q", semail);
1708 }
1709 blob_append_sql(&update," WHERE subscriberId=%d", sid);
1710 if( eErr==0 ){
1711 db_exec_sql(blob_str(&update));
1712 ssub = 0;
1713 }
1714 blob_reset(&update);
1715 }
1716 if( P("delete")!=0 && cgi_csrf_safe(1) ){
1717 if( !PB("dodelete") ){
1718 eErr = 9;
1719 zErr = mprintf("Select this checkbox and press \"Unsubscribe\" again to"
1720 " unsubscribe");
1721 }else{
1722 alert_unsubscribe(sid);
1723 db_commit_transaction();
1724 return;
1725 }
1726 }
1727 style_header("Update Subscription");
1728 db_prepare(&q,
1729 "SELECT"
1730 " semail," /* 0 */
1731 " sverified," /* 1 */
1732 " sdonotcall," /* 2 */
@@ -1607,52 +1733,92 @@
1733 " sdigest," /* 3 */
1734 " ssub," /* 4 */
1735 " smip," /* 5 */
1736 " suname," /* 6 */
1737 " datetime(mtime,'unixepoch')," /* 7 */
1738 " datetime(sctime,'unixepoch')," /* 8 */
1739 " hex(subscriberCode)" /* 9 */
1740 " FROM subscriber WHERE subscriberId=%d", sid);
1741 if( db_step(&q)!=SQLITE_ROW ){
1742 db_finalize(&q);
1743 db_commit_transaction();
1744 cgi_redirect("subscribe");
1745 /*NOTREACHED*/
1746 }
1747 if( ssub==0 ){
1748 semail = db_column_text(&q, 0);
1749 sdonotcall = db_column_int(&q, 2);
1750 sdigest = db_column_int(&q, 3);
1751 ssub = db_column_text(&q, 4);
1752 }
1753 if( suname==0 ){
1754 suname = db_column_text(&q, 6);
1755 sverified = db_column_int(&q, 1);
1756 }
1757 sa = strchr(ssub,'a')!=0;
1758 sc = strchr(ssub,'c')!=0;
1759 sf = strchr(ssub,'f')!=0;
1760 st = strchr(ssub,'t')!=0;
1761 sw = strchr(ssub,'w')!=0;
1762 sx = strchr(ssub,'x')!=0;
1763 smip = db_column_text(&q, 5);
 
1764 mtime = db_column_text(&q, 7);
1765 sctime = db_column_text(&q, 8);
1766 if( !g.perm.Admin && !sverified ){
1767 if( nName==64 ){
1768 db_multi_exec(
1769 "UPDATE subscriber SET sverified=1"
1770 " WHERE subscriberCode=hextoblob(%Q)",
1771 zName);
1772 if( db_get_boolean("selfreg-verify",0) ){
1773 char *zNewCap = db_get("default-perms","u");
1774 db_multi_exec(
1775 "UPDATE user"
1776 " SET cap=%Q"
1777 " WHERE cap='7' AND login=("
1778 " SELECT suname FROM subscriber"
1779 " WHERE subscriberCode=hextoblob(%Q))",
1780 zNewCap, zName
1781 );
1782 login_set_capabilities(zNewCap, 0);
1783 }
1784 @ <h1>Your email alert subscription has been verified!</h1>
1785 @ <p>Use the form below to update your subscription information.</p>
1786 @ <p>Hint: Bookmark this page so that you can more easily update
1787 @ your subscription information in the future</p>
1788 }else{
1789 @ <h2>Your email address is unverified</h2>
1790 @ <p>You should have received an email message containing a link
1791 @ that you must visit to verify your account. No email notifications
1792 @ will be sent until your email address has been verified.</p>
1793 }
1794 }else{
1795 @ <p>Make changes to the email subscription shown below and
1796 @ press "Submit".</p>
1797 }
1798 form_begin(0, "%R/alerts");
1799 zHalfCode = db_text("x","SELECT hex(substr(subscriberCode,1,16))"
1800 " FROM subscriber WHERE subscriberId=%d", sid);
1801 @ <input type="hidden" name="name" value="%h(zHalfCode)">
1802 @ <table class="subscribe">
1803 @ <tr>
1804 @ <td class="form_label">Email&nbsp;Address:</td>
1805 if( isLogin ){
1806 @ <td><input type="text" name="semail" value="%h(semail)" size="30">\
1807 if( eErr==8 ){
1808 @ <span class='loginError'>&larr; not a valid email address!</span>
1809 }else if( g.perm.Admin ){
1810 @ &nbsp;&nbsp;<a href="%R/announce?to=%t(semail)">\
1811 @ (Send a message to %h(semail))</a>\
1812 }
1813 @ </td>
1814 }else{
1815 @ <td>%h(semail)</td>
1816 }
1817 @ </tr>
1818 if( g.perm.Admin ){
1819 int uid;
1820 @ <tr>
1821 @ <td class='form_label'>Created:</td>
1822 @ <td>%h(sctime)</td>
1823 @ </tr>
1824 @ <tr>
@@ -1662,13 +1828,21 @@
1828 @ <tr>
1829 @ <td class='form_label'>IP Address:</td>
1830 @ <td>%h(smip)</td>
1831 @ </tr>
1832 @ <tr>
1833 @ <td class='form_label'>Subscriber&nbsp;Code:</td>
1834 @ <td>%h(db_column_text(&q,9))</td>
1835 @ <tr>
1836 @ <td class="form_label">User:</td>
1837 @ <td><input type="text" name="suname" value="%h(suname?suname:"")" \
1838 @ size="30">\
1839 uid = db_int(0, "SELECT uid FROM user WHERE login=%Q", suname);
1840 if( uid ){
1841 @ &nbsp;&nbsp;<a href='%R/setup_uedit?id=%d(uid)'>\
1842 @ (login info for %h(suname))</a>\
1843 }
1844 @ </tr>
1845 }
1846 @ <tr>
1847 @ <td class="form_label">Topics:</td>
1848 @ <td><label><input type="checkbox" name="sa" %s(sa?"checked":"")>\
@@ -1678,10 +1852,12 @@
1852 @ Check-ins</label><br>
1853 }
1854 if( g.perm.RdForum ){
1855 @ <label><input type="checkbox" name="sf" %s(sf?"checked":"")>\
1856 @ Forum Posts</label><br>
1857 @ <label><input type="checkbox" name="sx" %s(sx?"checked":"")>\
1858 @ Forum Edits</label><br>
1859 }
1860 if( g.perm.RdTkt ){
1861 @ <label><input type="checkbox" name="st" %s(st?"checked":"")>\
1862 @ Ticket changes</label><br>
1863 }
@@ -1695,19 +1871,15 @@
1871 @ <td><select size="1" name="sdigest">
1872 @ <option value="0" %s(sdigest?"":"selected")>Individual Emails</option>
1873 @ <option value="1" %s(sdigest?"selected":"")>Daily Digest</option>
1874 @ </select></td>
1875 @ </tr>
 
 
 
 
1876 if( g.perm.Admin ){
1877 @ <tr>
1878 @ <td class="form_label">Admin Options:</td><td>
1879 @ <label><input type="checkbox" name="sdonotcall" \
1880 @ %s(sdonotcall?"checked":"")> Do not disturb</label><br>
1881 @ <label><input type="checkbox" name="sverified" \
1882 @ %s(sverified?"checked":"")>\
1883 @ Verified</label></td></tr>
1884 }
1885 if( eErr==9 ){
@@ -1726,10 +1898,12 @@
1898 @ </table>
1899 @ </form>
1900 fossil_free(zErr);
1901 db_finalize(&q);
1902 style_footer();
1903 db_commit_transaction();
1904 return;
1905 }
1906
1907 /* This is the message that gets sent to describe how to change
1908 ** or modify a subscription
1909 */
@@ -1760,25 +1934,26 @@
1934 */
1935 void unsubscribe_page(void){
1936 const char *zName = P("name");
1937 char *zErr = 0;
1938 int eErr = 0;
1939 unsigned int uSeed = 0;
1940 const char *zDecoded;
1941 char *zCaptcha = 0;
1942 int dx;
1943 int bSubmit;
1944 const char *zEAddr;
1945 char *zCode = 0;
1946 int sid = 0;
1947
1948 /* If a valid subscriber code is supplied, then unsubscribe immediately.
1949 */
1950 if( zName
1951 && (sid = db_int(0, "SELECT subscriberId FROM subscriber"
1952 " WHERE subscriberCode=hextoblob(%Q)", zName))!=0
1953 ){
1954 alert_unsubscribe(sid);
1955 return;
1956 }
1957
1958 /* Logged in users are redirected to the /alerts page */
1959 login_check_credentials();
@@ -1855,10 +2030,11 @@
2030 zDecoded = captcha_decode(uSeed);
2031 zCaptcha = captcha_render(zDecoded);
2032 @ <tr>
2033 @ <td class="form_label">Security Code:</td>
2034 @ <td><input type="text" name="captcha" value="" size="30">
2035 captcha_speakit_button(uSeed, "Speak the code");
2036 @ <input type="hidden" name="captchaseed" value="%u(uSeed)"></td>
2037 if( eErr==2 ){
2038 @ <td><span class="loginError">&larr; %h(zErr)</span></td>
2039 }
2040 @ </tr>
@@ -1874,11 +2050,11 @@
2050 @ </tr>
2051 @ </table>
2052 @ <div class="captcha"><table class="captcha"><tr><td><pre class="captcha">
2053 @ %h(zCaptcha)
2054 @ </pre>
2055 @ Enter the 8 characters above in the "Security Code" box<br/>
2056 @ </td></tr></table></div>
2057 @ </form>
2058 fossil_free(zErr);
2059 style_footer();
2060 }
@@ -1885,37 +2061,69 @@
2061
2062 /*
2063 ** WEBPAGE: subscribers
2064 **
2065 ** This page, accessible to administrators only,
2066 ** shows a list of subscriber email addresses.
2067 ** Clicking on an email takes one to the /alerts page
2068 ** for that email where the delivery settings can be
2069 ** modified.
2070 */
2071 void subscriber_list_page(void){
2072 Blob sql;
2073 Stmt q;
2074 sqlite3_int64 iNow;
2075 int nTotal;
2076 int nPending;
2077 int nDel = 0;
2078 if( alert_webpages_disabled() ) return;
2079 login_check_credentials();
2080 if( !g.perm.Admin ){
2081 login_needed(0);
2082 return;
2083 }
2084 alert_submenu_common();
2085 style_submenu_element("Users","setup_ulist");
2086 style_header("Subscriber List");
2087 nTotal = db_int(0, "SELECT count(*) FROM subscriber");
2088 nPending = db_int(0, "SELECT count(*) FROM subscriber WHERE NOT sverified");
2089 if( nPending>0 && P("purge") && cgi_csrf_safe(0) ){
2090 int nNewPending;
2091 db_multi_exec(
2092 "DELETE FROM subscriber"
2093 " WHERE NOT sverified AND mtime<0+strftime('%%s','now','-1 day')"
2094 );
2095 nNewPending = db_int(0, "SELECT count(*) FROM subscriber"
2096 " WHERE NOT sverified");
2097 nDel = nPending - nNewPending;
2098 nPending = nNewPending;
2099 nTotal -= nDel;
2100 }
2101 if( nPending>0 ){
2102 @ <h1>%,d(nTotal) Subscribers, %,d(nPending) Pending</h1>
2103 if( nDel==0 && 0<db_int(0,"SELECT count(*) FROM subscriber"
2104 " WHERE NOT sverified AND mtime<0+strftime('%%s','now','-1 day')")
2105 ){
2106 style_submenu_element("Purge Pending","subscribers?purge");
2107 }
2108 }else{
2109 @ <h1>%,d(nTotal) Subscribers</h1>
2110 }
2111 if( nDel>0 ){
2112 @ <p>*** %d(nDel) pending subscriptions deleted ***</p>
2113 }
2114 blob_init(&sql, 0, 0);
2115 blob_append_sql(&sql,
2116 "SELECT subscriberId," /* 0 */
2117 " semail," /* 1 */
2118 " ssub," /* 2 */
2119 " suname," /* 3 */
2120 " sverified," /* 4 */
2121 " sdigest," /* 5 */
2122 " mtime," /* 6 */
2123 " date(sctime,'unixepoch')," /* 7 */
2124 " (SELECT uid FROM user WHERE login=subscriber.suname)" /* 8 */
2125 " FROM subscriber"
2126 );
2127 if( P("only")!=0 ){
2128 blob_append_sql(&sql, " WHERE ssub LIKE '%%%q%%'", P("only"));
2129 style_submenu_element("Show All","%R/subscribers");
@@ -1937,16 +2145,22 @@
2145 @ </tr>
2146 @ </thead><tbody>
2147 while( db_step(&q)==SQLITE_ROW ){
2148 sqlite3_int64 iMtime = db_column_int64(&q, 6);
2149 double rAge = (iNow - iMtime)/86400.0;
2150 int uid = db_column_int(&q, 8);
2151 const char *zUname = db_column_text(&q, 3);
2152 @ <tr>
2153 @ <td><a href='%R/alerts?sid=%d(db_column_int(&q,0))'>\
2154 @ %h(db_column_text(&q,1))</a></td>
2155 @ <td>%h(db_column_text(&q,2))</td>
2156 @ <td>%s(db_column_int(&q,5)?"digest":"")</td>
2157 if( uid ){
2158 @ <td><a href='%R/setup_uedit?id=%d(uid)'>%h(zUname)</a>
2159 }else{
2160 @ <td>%h(zUname)</td>
2161 }
2162 @ <td>%s(db_column_int(&q,4)?"yes":"pending")</td>
2163 @ <td data-sortkey='%010llx(iMtime)'>%z(human_readable_age(rAge))</td>
2164 @ <td>%h(db_column_text(&q,7))</td>
2165 @ </tr>
2166 }
@@ -1958,13 +2172,21 @@
2172
2173 #if LOCAL_INTERFACE
2174 /*
2175 ** A single event that might appear in an alert is recorded as an
2176 ** instance of the following object.
2177 **
2178 ** type values:
2179 **
2180 ** c A new check-in
2181 ** f An original forum post
2182 ** x An edit to a prior forum post
2183 ** t A new ticket or a change to an existing ticket
2184 ** w A change to a wiki page
2185 */
2186 struct EmailEvent {
2187 int type; /* 'c', 'f', 't', 'w', 'x' */
2188 int needMod; /* Pending moderator approval */
2189 Blob hdr; /* Header content, for forum entries */
2190 Blob txt; /* Text description to appear in an alert */
2191 char *zFromName; /* Human name of the sender */
2192 EmailEvent *pNext; /* Next in chronological order */
@@ -2039,20 +2261,20 @@
2261 p->needMod = db_column_int(&q, 4);
2262 p->zFromName = 0;
2263 p->pNext = 0;
2264 switch( p->type ){
2265 case 'c': zType = "Check-In"; break;
2266 /* case 'f': -- forum posts omitted from this loop. See below */
2267 case 't': zType = "Ticket Change"; break;
2268 case 'w': zType = "Wiki Edit"; break;
2269 }
2270 blob_init(&p->hdr, 0, 0);
2271 blob_init(&p->txt, 0, 0);
2272 blob_appendf(&p->txt,"== %s %s ==\n%s\n%s/info/%.20s\n",
2273 db_column_text(&q,1),
2274 zType,
2275 db_column_text(&q, 2),
2276 zUrl,
2277 db_column_text(&q,0)
2278 );
2279 if( p->needMod ){
2280 blob_appendf(&p->txt,
@@ -2078,17 +2300,28 @@
2300 ** is a normal email alert. Construct full-text forum post alerts
2301 ** using a format that enables them to be sent as separate emails.
2302 */
2303 db_prepare(&q,
2304 "SELECT"
2305 " forumpost.fpid," /* 0: fpid */
2306 " (SELECT uuid FROM blob WHERE rid=forumpost.fpid)," /* 1: hash */
2307 " datetime(event.mtime)," /* 2: date/time */
2308 " substr(comment,instr(comment,':')+2)," /* 3: comment */
2309 " (WITH thread(fpid,fprev) AS ("
2310 " SELECT fpid,fprev FROM forumpost AS tx"
2311 " WHERE tx.froot=forumpost.froot),"
2312 " basepid(fpid,bpid) AS ("
2313 " SELECT fpid, fpid FROM thread WHERE fprev IS NULL"
2314 " UNION ALL"
2315 " SELECT thread.fpid, basepid.bpid FROM basepid, thread"
2316 " WHERE basepid.fpid=thread.fprev)"
2317 " SELECT uuid FROM blob, basepid"
2318 " WHERE basepid.fpid=forumpost.firt"
2319 " AND blob.rid=basepid.bpid)," /* 4: in-reply-to */
2320 " wantalert.needMod," /* 5: moderated */
2321 " coalesce(display_name(info),euser,user)," /* 6: user */
2322 " forumpost.fprev IS NULL" /* 7: is an edit */
2323 " FROM temp.wantalert, event, forumpost"
2324 " LEFT JOIN user ON (login=coalesce(euser,user))"
2325 " WHERE event.objid=substr(wantalert.eventId,2)+0"
2326 " AND eventId GLOB 'f*'"
2327 " AND forumpost.fpid=event.objid"
@@ -2104,11 +2337,11 @@
2337 const char *z;
2338 if( pPost==0 ) continue;
2339 p = fossil_malloc( sizeof(EmailEvent) );
2340 pLast->pNext = p;
2341 pLast = p;
2342 p->type = db_column_int(&q,7) ? 'f' : 'x';
2343 p->needMod = db_column_int(&q, 5);
2344 z = db_column_text(&q,6);
2345 p->zFromName = z && z[0] ? fossil_strdup(z) : 0;
2346 p->pNext = 0;
2347 blob_init(&p->hdr, 0, 0);
@@ -2321,13 +2554,14 @@
2554 ** the process malfunctions or crashes, some notifications may never
2555 ** be sent. But that is better than some recurring bug causing
2556 ** subscribers to be flooded with repeated notifications every 60
2557 ** seconds!
2558 */
2559 int alert_send_alerts(u32 flags){
2560 EmailEvent *pEvents, *p;
2561 int nEvent = 0;
2562 int nSent = 0;
2563 Stmt q;
2564 const char *zDigest = "false";
2565 Blob hdr, body;
2566 const char *zUrl;
2567 const char *zRepoName;
@@ -2436,13 +2670,13 @@
2670 ** if the recipient is a moderator for that type of event. Setup
2671 ** and Admin users always get notified. */
2672 char xType = '*';
2673 if( strpbrk(zCap,"as")==0 ){
2674 switch( p->type ){
2675 case 'x': case 'f': xType = '5'; break;
2676 case 't': xType = 'q'; break;
2677 case 'w': xType = 'l'; break;
2678 }
2679 if( strchr(zCap,xType)==0 ) continue;
2680 }
2681 }else if( strchr(zCap,'s')!=0 || strchr(zCap,'a')!=0 ){
2682 /* Setup and admin users can get any notification that does not
@@ -2450,14 +2684,14 @@
2684 }else{
2685 /* Other users only see the alert if they have sufficient
2686 ** privilege to view the event itself */
2687 char xType = '*';
2688 switch( p->type ){
2689 case 'c': xType = 'o'; break;
2690 case 'x': case 'f': xType = '2'; break;
2691 case 't': xType = 'r'; break;
2692 case 'w': xType = 'j'; break;
2693 }
2694 if( strchr(zCap,xType)==0 ) continue;
2695 }
2696 if( blob_size(&p->hdr)>0 ){
2697 /* This alert should be sent as a separate email */
@@ -2467,10 +2701,11 @@
2701 blob_append(&fhdr, blob_buffer(&p->hdr), blob_size(&p->hdr));
2702 blob_init(&fbody, blob_buffer(&p->txt), blob_size(&p->txt));
2703 blob_appendf(&fbody, "\n-- \nSubscription info: %s/alerts/%s\n",
2704 zUrl, zCode);
2705 alert_send(pSender,&fhdr,&fbody,p->zFromName);
2706 nSent++;
2707 blob_reset(&fhdr);
2708 blob_reset(&fbody);
2709 }else{
2710 /* Events other than forum posts are gathered together into
2711 ** a single email message */
@@ -2490,10 +2725,11 @@
2725 }
2726 if( nHit==0 ) continue;
2727 blob_appendf(&body,"\n-- \nSubscription info: %s/alerts/%s\n",
2728 zUrl, zCode);
2729 alert_send(pSender,&hdr,&body,0);
2730 nSent++;
2731 blob_truncate(&hdr, 0);
2732 blob_truncate(&body, 0);
2733 }
2734 blob_reset(&hdr);
2735 blob_reset(&body);
@@ -2506,10 +2742,11 @@
2742 db_multi_exec("DELETE FROM pending_alert WHERE sentDigest AND sentSep;");
2743
2744 send_alert_done:
2745 alert_sender_free(pSender);
2746 if( g.fSqlTrace ) fossil_trace("-- END alert_send_alerts(%u)\n", flags);
2747 return nSent;
2748 }
2749
2750 /*
2751 ** Do backoffice processing for email notifications. In other words,
2752 ** check to see if any email notifications need to occur, and then
@@ -2519,19 +2756,21 @@
2756 **
2757 ** The mFlags option is zero or more of the SENDALERT_* flags. Normally
2758 ** this flag is zero, but the test-set-alert command sets it to
2759 ** SENDALERT_TRACE.
2760 */
2761 int alert_backoffice(u32 mFlags){
2762 int iJulianDay;
2763 int nSent = 0;
2764 if( !alert_tables_exist() ) return 0;
2765 nSent = alert_send_alerts(mFlags);
2766 iJulianDay = db_int(0, "SELECT julianday('now')");
2767 if( iJulianDay>db_get_int("email-last-digest",0) ){
2768 db_set_int("email-last-digest",iJulianDay,0);
2769 nSent += alert_send_alerts(SENDALERT_DIGEST|mFlags);
2770 }
2771 return nSent;
2772 }
2773
2774 /*
2775 ** WEBPAGE: contact_admin
2776 **
@@ -2594,10 +2833,11 @@
2833 @ <table class="subscribe">
2834 if( zCaptcha ){
2835 @ <tr>
2836 @ <td class="form_label">Security&nbsp;Code:</td>
2837 @ <td><input type="text" name="captcha" value="" size="10">
2838 captcha_speakit_button(uSeed, "Speak the code");
2839 @ <input type="hidden" name="captchaseed" value="%u(uSeed)"></td>
2840 @ </tr>
2841 }
2842 @ <tr>
2843 @ <td class="form_label">Your&nbsp;Email&nbsp;Address:</td>
@@ -2620,11 +2860,11 @@
2860 @ </table>
2861 if( zCaptcha ){
2862 @ <div class="captcha"><table class="captcha"><tr><td><pre class="captcha">
2863 @ %h(zCaptcha)
2864 @ </pre>
2865 @ Enter the 8 characters above in the "Security Code" box<br/>
2866 @ </td></tr></table></div>
2867 }
2868 @ </form>
2869 style_footer();
2870 }
@@ -2638,10 +2878,11 @@
2878 char *zErr;
2879 const char *zTo = PT("to");
2880 char *zSubject = PT("subject");
2881 int bAll = PB("all");
2882 int bAA = PB("aa");
2883 int bMods = PB("mods");
2884 const char *zSub = db_get("email-subname", "[Fossil Repo]");
2885 int bTest2 = fossil_strcmp(P("name"),"test2")==0;
2886 Blob hdr, body;
2887 blob_init(&body, 0, 0);
2888 blob_init(&hdr, 0, 0);
@@ -2649,17 +2890,29 @@
2890 pSender = alert_sender_new(bTest2 ? "blob" : 0, 0);
2891 if( zTo[0] ){
2892 blob_appendf(&hdr, "To: <%s>\r\nSubject: %s %s\r\n", zTo, zSub, zSubject);
2893 alert_send(pSender, &hdr, &body, 0);
2894 }
2895 if( bAll || bAA || bMods ){
2896 Stmt q;
2897 int nUsed = blob_size(&body);
2898 const char *zURL = db_get("email-url",0);
2899 if( bAll ){
2900 db_prepare(&q, "SELECT semail, hex(subscriberCode) FROM subscriber "
2901 " WHERE sverified AND NOT sdonotcall");
2902 }else if( bAA ){
2903 db_prepare(&q, "SELECT semail, hex(subscriberCode) FROM subscriber "
2904 " WHERE sverified AND NOT sdonotcall"
2905 " AND ssub LIKE '%%a%%'");
2906 }else if( bMods ){
2907 db_prepare(&q,
2908 "SELECT semail, hex(subscriberCode)"
2909 " FROM subscriber, user "
2910 " WHERE sverified AND NOT sdonotcall"
2911 " AND suname=login"
2912 " AND fullcap(cap) GLOB '*5*'");
2913 }
2914 while( db_step(&q)==SQLITE_ROW ){
2915 const char *zCode = db_column_text(&q, 1);
2916 zTo = db_column_text(&q, 0);
2917 blob_truncate(&hdr, 0);
2918 blob_appendf(&hdr, "To: <%s>\r\nSubject: %s %s\r\n", zTo, zSub, zSubject);
@@ -2716,11 +2969,12 @@
2969 @ <p>The following error was reported by the system:
2970 @ <blockquote><pre>
2971 @ %h(zErr)
2972 @ </pre></blockquote>
2973 }else{
2974 @ <p>The announcement has been sent.
2975 @ <a href="%h(PD("REQUEST_URI","/"))">Send another</a></p>
2976 }
2977 style_footer();
2978 return;
2979 } else if( !alert_enabled() ){
2980 style_header("Cannot Send Announcement");
@@ -2734,21 +2988,26 @@
2988 @ <form method="POST">
2989 @ <table class="subscribe">
2990 if( g.perm.Admin ){
2991 int aa = PB("aa");
2992 int all = PB("all");
2993 int aMod = PB("mods");
2994 const char *aack = aa ? "checked" : "";
2995 const char *allck = all ? "checked" : "";
2996 const char *modck = aMod ? "checked" : "";
2997 @ <tr>
2998 @ <td class="form_label">To:</td>
2999 @ <td><input type="text" name="to" value="%h(PT("to"))" size="30"><br>
3000 @ <label><input type="checkbox" name="aa" %s(aack)> \
3001 @ All "announcement" subscribers</label> \
3002 @ <a href="%R/subscribers?only=a" target="_blank">(list)</a><br>
3003 @ <label><input type="checkbox" name="all" %s(allck)> \
3004 @ All subscribers</label> \
3005 @ <a href="%R/subscribers" target="_blank">(list)</a><br>
3006 @ <label><input type="checkbox" name="mods" %s(modck)> \
3007 @ All moderators</label> \
3008 @ <a href="%R/setup_ulist?with=5" target="_blank">(list)</a><br></td>
3009 @ </tr>
3010 }
3011 @ <tr>
3012 @ <td class="form_label">Subject:</td>
3013 @ <td><input type="text" name="subject" value="%h(PT("subject"))"\
@@ -2759,11 +3018,15 @@
3018 @ <td><textarea name="msg" cols="80" rows="10" wrap="virtual">\
3019 @ %h(PT("msg"))</textarea>
3020 @ </tr>
3021 @ <tr>
3022 @ <td></td>
3023 if( fossil_strcmp(P("name"),"test2")==0 ){
3024 @ <td><input type="submit" name="submit" value="Dry Run">
3025 }else{
3026 @ <td><input type="submit" name="submit" value="Send Message">
3027 }
3028 @ </tr>
3029 @ </table>
3030 @ </form>
3031 style_footer();
3032 }
3033
+23 -39
--- src/allrepo.c
+++ src/allrepo.c
@@ -19,52 +19,26 @@
1919
*/
2020
#include "config.h"
2121
#include "allrepo.h"
2222
#include <assert.h>
2323
24
-/*
25
-** The input string is a filename. Return a new copy of this
26
-** filename if the filename requires quoting due to special characters
27
-** such as spaces in the name.
28
-**
29
-** If the filename cannot be safely quoted, return a NULL pointer.
30
-**
31
-** Space to hold the returned string is obtained from malloc. A new
32
-** string is returned even if no quoting is needed.
33
-*/
34
-static char *quoteFilename(const char *zFilename){
35
- int i, c;
36
- int needQuote = 0;
37
- for(i=0; (c = zFilename[i])!=0; i++){
38
- if( c=='"' ) return 0;
39
- if( fossil_isspace(c) ) needQuote = 1;
40
- if( c=='\\' && zFilename[i+1]==0 ) return 0;
41
- if( c=='$' ) return 0;
42
- }
43
- if( needQuote ){
44
- return mprintf("\"%s\"", zFilename);
45
- }else{
46
- return mprintf("%s", zFilename);
47
- }
48
-}
49
-
5024
/*
5125
** Build a string that contains all of the command-line options
5226
** specified as arguments. If the option name begins with "+" then
5327
** it takes an argument. Without the "+" it does not.
5428
*/
55
-static void collect_argument(Blob *pExtra, const char *zArg, const char *zShort){
29
+static void collect_argument(Blob *pExtra,const char *zArg,const char *zShort){
5630
const char *z = find_option(zArg, zShort, 0);
5731
if( z!=0 ){
5832
blob_appendf(pExtra, " %s", z);
5933
}
6034
}
6135
static void collect_argument_value(Blob *pExtra, const char *zArg){
6236
const char *zValue = find_option(zArg, 0, 1);
6337
if( zValue ){
6438
if( zValue[0] ){
65
- blob_appendf(pExtra, " --%s %s", zArg, zValue);
39
+ blob_appendf(pExtra, " --%s %$", zArg, zValue);
6640
}else{
6741
blob_appendf(pExtra, " --%s \"\"", zArg);
6842
}
6943
}
7044
}
@@ -88,10 +62,13 @@
8862
** On Win32 systems, the file is named "_fossil" and is located in
8963
** %LOCALAPPDATA%, %APPDATA% or %HOMEPATH%.
9064
**
9165
** Available operations are:
9266
**
67
+** backup Backup all repositories. The argument must the name of
68
+** a directory into which all backup repositories are written.
69
+**
9370
** cache Manages the cache used for potentially expensive web
9471
** pages. Any additional arguments are passed on verbatim
9572
** to the cache command.
9673
**
9774
** changes Shows all local checkouts that have uncommitted changes.
@@ -128,15 +105,15 @@
128105
** supported by the rebuild command itself, if any are
129106
** present, are passed along verbatim. The --force and
130107
** --randomize options are not supported.
131108
**
132109
** sync Run a "sync" on all repositories. Only the --verbose
133
-** option is supported.
110
+** and --unversioned options are supported.
134111
**
135
-** setting Run the "setting", "set", or "unset" commands on all
136
-** set repositories. These command are particularly useful in
137
-** unset conjunction with the "max-loadavg" setting which cannot
112
+** set|unset Run the "setting", "set", or "unset" commands on all
113
+** repositories. These command are particularly useful in
114
+** conjunction with the "max-loadavg" setting which cannot
138115
** otherwise be set globally.
139116
**
140117
** server Run the "ui" or "server" commands on all repositories.
141118
** ui The root URI gives a listing of all repos.
142119
**
@@ -169,12 +146,10 @@
169146
void all_cmd(void){
170147
int n;
171148
Stmt q;
172149
const char *zCmd;
173150
char *zSyscmd;
174
- char *zFossil;
175
- char *zQFilename;
176151
Blob extra;
177152
int useCheckouts = 0;
178153
int quiet = 0;
179154
int dryRunFlag = 0;
180155
int showFile = find_option("showfile",0,0)!=0;
@@ -202,10 +177,20 @@
202177
return;
203178
}
204179
if( strncmp(zCmd, "list", n)==0 || strncmp(zCmd,"ls",n)==0 ){
205180
zCmd = "list";
206181
useCheckouts = find_option("ckout","c",0)!=0;
182
+ }else if( strncmp(zCmd, "backup", n)==0 ){
183
+ char *zDest;
184
+ zCmd = "backup -R";
185
+ collect_argument(&extra, "overwrite",0);
186
+ if( g.argc!=4 ) usage("backup DIRECTORY");
187
+ zDest = g.argv[3];
188
+ if( file_isdir(zDest, ExtFILE)!=1 ){
189
+ fossil_fatal("argument to \"fossil all backup\" must be a directory");
190
+ }
191
+ blob_appendf(&extra, " %$", zDest);
207192
}else if( strncmp(zCmd, "clean", n)==0 ){
208193
zCmd = "clean --chdir";
209194
collect_argument(&extra, "allckouts",0);
210195
collect_argument_value(&extra, "case-sensitive");
211196
collect_argument_value(&extra, "clean");
@@ -283,11 +268,13 @@
283268
}else if( strncmp(zCmd, "sync", n)==0 ){
284269
zCmd = "sync -autourl -R";
285270
collect_argument(&extra, "verbose","v");
286271
collect_argument(&extra, "unversioned","u");
287272
}else if( strncmp(zCmd, "test-integrity", n)==0 ){
273
+ collect_argument(&extra, "db-only", "d");
288274
collect_argument(&extra, "parse", 0);
275
+ collect_argument(&extra, "quick", "q");
289276
zCmd = "test-integrity";
290277
}else if( strncmp(zCmd, "test-orphans", n)==0 ){
291278
zCmd = "test-orphans -R";
292279
}else if( strncmp(zCmd, "test-missing", n)==0 ){
293280
zCmd = "test-missing -q -R";
@@ -368,11 +355,10 @@
368355
fossil_fatal("\"all\" subcommand should be one of: "
369356
"add cache changes clean dbstat extras fts-config ignore "
370357
"info list ls pull push rebuild server setting sync ui unset");
371358
}
372359
verify_all_options();
373
- zFossil = quoteFilename(g.nameOfExe);
374360
db_multi_exec("CREATE TEMP TABLE repolist(name,tag);");
375361
if( useCheckouts ){
376362
db_multi_exec(
377363
"INSERT INTO repolist "
378364
"SELECT DISTINCT substr(name, 7), name COLLATE nocase"
@@ -410,13 +396,12 @@
410396
continue;
411397
}else if( showFile ){
412398
fossil_print("%s: %s\n", useCheckouts ? "checkout" : "repository",
413399
zFilename);
414400
}
415
- zQFilename = quoteFilename(zFilename);
416
- zSyscmd = mprintf("%s %s %s%s",
417
- zFossil, zCmd, zQFilename, blob_str(&extra));
401
+ zSyscmd = mprintf("%$ %s %$%s",
402
+ g.nameOfExe, zCmd, zFilename, blob_str(&extra));
418403
if( showLabel ){
419404
int len = (int)strlen(zFilename);
420405
int nStar = 80 - (len + 15);
421406
if( nStar<2 ) nStar = 1;
422407
fossil_print("%.13c %s %.*c\n", '*', zFilename, nStar, '*');
@@ -426,11 +411,10 @@
426411
fossil_print("%s\n", zSyscmd);
427412
fflush(stdout);
428413
}
429414
rc = dryRunFlag ? 0 : fossil_system(zSyscmd);
430415
free(zSyscmd);
431
- free(zQFilename);
432416
if( stopOnError && rc ){
433417
break;
434418
}
435419
}
436420
db_finalize(&q);
437421
--- src/allrepo.c
+++ src/allrepo.c
@@ -19,52 +19,26 @@
19 */
20 #include "config.h"
21 #include "allrepo.h"
22 #include <assert.h>
23
24 /*
25 ** The input string is a filename. Return a new copy of this
26 ** filename if the filename requires quoting due to special characters
27 ** such as spaces in the name.
28 **
29 ** If the filename cannot be safely quoted, return a NULL pointer.
30 **
31 ** Space to hold the returned string is obtained from malloc. A new
32 ** string is returned even if no quoting is needed.
33 */
34 static char *quoteFilename(const char *zFilename){
35 int i, c;
36 int needQuote = 0;
37 for(i=0; (c = zFilename[i])!=0; i++){
38 if( c=='"' ) return 0;
39 if( fossil_isspace(c) ) needQuote = 1;
40 if( c=='\\' && zFilename[i+1]==0 ) return 0;
41 if( c=='$' ) return 0;
42 }
43 if( needQuote ){
44 return mprintf("\"%s\"", zFilename);
45 }else{
46 return mprintf("%s", zFilename);
47 }
48 }
49
50 /*
51 ** Build a string that contains all of the command-line options
52 ** specified as arguments. If the option name begins with "+" then
53 ** it takes an argument. Without the "+" it does not.
54 */
55 static void collect_argument(Blob *pExtra, const char *zArg, const char *zShort){
56 const char *z = find_option(zArg, zShort, 0);
57 if( z!=0 ){
58 blob_appendf(pExtra, " %s", z);
59 }
60 }
61 static void collect_argument_value(Blob *pExtra, const char *zArg){
62 const char *zValue = find_option(zArg, 0, 1);
63 if( zValue ){
64 if( zValue[0] ){
65 blob_appendf(pExtra, " --%s %s", zArg, zValue);
66 }else{
67 blob_appendf(pExtra, " --%s \"\"", zArg);
68 }
69 }
70 }
@@ -88,10 +62,13 @@
88 ** On Win32 systems, the file is named "_fossil" and is located in
89 ** %LOCALAPPDATA%, %APPDATA% or %HOMEPATH%.
90 **
91 ** Available operations are:
92 **
 
 
 
93 ** cache Manages the cache used for potentially expensive web
94 ** pages. Any additional arguments are passed on verbatim
95 ** to the cache command.
96 **
97 ** changes Shows all local checkouts that have uncommitted changes.
@@ -128,15 +105,15 @@
128 ** supported by the rebuild command itself, if any are
129 ** present, are passed along verbatim. The --force and
130 ** --randomize options are not supported.
131 **
132 ** sync Run a "sync" on all repositories. Only the --verbose
133 ** option is supported.
134 **
135 ** setting Run the "setting", "set", or "unset" commands on all
136 ** set repositories. These command are particularly useful in
137 ** unset conjunction with the "max-loadavg" setting which cannot
138 ** otherwise be set globally.
139 **
140 ** server Run the "ui" or "server" commands on all repositories.
141 ** ui The root URI gives a listing of all repos.
142 **
@@ -169,12 +146,10 @@
169 void all_cmd(void){
170 int n;
171 Stmt q;
172 const char *zCmd;
173 char *zSyscmd;
174 char *zFossil;
175 char *zQFilename;
176 Blob extra;
177 int useCheckouts = 0;
178 int quiet = 0;
179 int dryRunFlag = 0;
180 int showFile = find_option("showfile",0,0)!=0;
@@ -202,10 +177,20 @@
202 return;
203 }
204 if( strncmp(zCmd, "list", n)==0 || strncmp(zCmd,"ls",n)==0 ){
205 zCmd = "list";
206 useCheckouts = find_option("ckout","c",0)!=0;
 
 
 
 
 
 
 
 
 
 
207 }else if( strncmp(zCmd, "clean", n)==0 ){
208 zCmd = "clean --chdir";
209 collect_argument(&extra, "allckouts",0);
210 collect_argument_value(&extra, "case-sensitive");
211 collect_argument_value(&extra, "clean");
@@ -283,11 +268,13 @@
283 }else if( strncmp(zCmd, "sync", n)==0 ){
284 zCmd = "sync -autourl -R";
285 collect_argument(&extra, "verbose","v");
286 collect_argument(&extra, "unversioned","u");
287 }else if( strncmp(zCmd, "test-integrity", n)==0 ){
 
288 collect_argument(&extra, "parse", 0);
 
289 zCmd = "test-integrity";
290 }else if( strncmp(zCmd, "test-orphans", n)==0 ){
291 zCmd = "test-orphans -R";
292 }else if( strncmp(zCmd, "test-missing", n)==0 ){
293 zCmd = "test-missing -q -R";
@@ -368,11 +355,10 @@
368 fossil_fatal("\"all\" subcommand should be one of: "
369 "add cache changes clean dbstat extras fts-config ignore "
370 "info list ls pull push rebuild server setting sync ui unset");
371 }
372 verify_all_options();
373 zFossil = quoteFilename(g.nameOfExe);
374 db_multi_exec("CREATE TEMP TABLE repolist(name,tag);");
375 if( useCheckouts ){
376 db_multi_exec(
377 "INSERT INTO repolist "
378 "SELECT DISTINCT substr(name, 7), name COLLATE nocase"
@@ -410,13 +396,12 @@
410 continue;
411 }else if( showFile ){
412 fossil_print("%s: %s\n", useCheckouts ? "checkout" : "repository",
413 zFilename);
414 }
415 zQFilename = quoteFilename(zFilename);
416 zSyscmd = mprintf("%s %s %s%s",
417 zFossil, zCmd, zQFilename, blob_str(&extra));
418 if( showLabel ){
419 int len = (int)strlen(zFilename);
420 int nStar = 80 - (len + 15);
421 if( nStar<2 ) nStar = 1;
422 fossil_print("%.13c %s %.*c\n", '*', zFilename, nStar, '*');
@@ -426,11 +411,10 @@
426 fossil_print("%s\n", zSyscmd);
427 fflush(stdout);
428 }
429 rc = dryRunFlag ? 0 : fossil_system(zSyscmd);
430 free(zSyscmd);
431 free(zQFilename);
432 if( stopOnError && rc ){
433 break;
434 }
435 }
436 db_finalize(&q);
437
--- src/allrepo.c
+++ src/allrepo.c
@@ -19,52 +19,26 @@
19 */
20 #include "config.h"
21 #include "allrepo.h"
22 #include <assert.h>
23
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
24 /*
25 ** Build a string that contains all of the command-line options
26 ** specified as arguments. If the option name begins with "+" then
27 ** it takes an argument. Without the "+" it does not.
28 */
29 static void collect_argument(Blob *pExtra,const char *zArg,const char *zShort){
30 const char *z = find_option(zArg, zShort, 0);
31 if( z!=0 ){
32 blob_appendf(pExtra, " %s", z);
33 }
34 }
35 static void collect_argument_value(Blob *pExtra, const char *zArg){
36 const char *zValue = find_option(zArg, 0, 1);
37 if( zValue ){
38 if( zValue[0] ){
39 blob_appendf(pExtra, " --%s %$", zArg, zValue);
40 }else{
41 blob_appendf(pExtra, " --%s \"\"", zArg);
42 }
43 }
44 }
@@ -88,10 +62,13 @@
62 ** On Win32 systems, the file is named "_fossil" and is located in
63 ** %LOCALAPPDATA%, %APPDATA% or %HOMEPATH%.
64 **
65 ** Available operations are:
66 **
67 ** backup Backup all repositories. The argument must the name of
68 ** a directory into which all backup repositories are written.
69 **
70 ** cache Manages the cache used for potentially expensive web
71 ** pages. Any additional arguments are passed on verbatim
72 ** to the cache command.
73 **
74 ** changes Shows all local checkouts that have uncommitted changes.
@@ -128,15 +105,15 @@
105 ** supported by the rebuild command itself, if any are
106 ** present, are passed along verbatim. The --force and
107 ** --randomize options are not supported.
108 **
109 ** sync Run a "sync" on all repositories. Only the --verbose
110 ** and --unversioned options are supported.
111 **
112 ** set|unset Run the "setting", "set", or "unset" commands on all
113 ** repositories. These command are particularly useful in
114 ** conjunction with the "max-loadavg" setting which cannot
115 ** otherwise be set globally.
116 **
117 ** server Run the "ui" or "server" commands on all repositories.
118 ** ui The root URI gives a listing of all repos.
119 **
@@ -169,12 +146,10 @@
146 void all_cmd(void){
147 int n;
148 Stmt q;
149 const char *zCmd;
150 char *zSyscmd;
 
 
151 Blob extra;
152 int useCheckouts = 0;
153 int quiet = 0;
154 int dryRunFlag = 0;
155 int showFile = find_option("showfile",0,0)!=0;
@@ -202,10 +177,20 @@
177 return;
178 }
179 if( strncmp(zCmd, "list", n)==0 || strncmp(zCmd,"ls",n)==0 ){
180 zCmd = "list";
181 useCheckouts = find_option("ckout","c",0)!=0;
182 }else if( strncmp(zCmd, "backup", n)==0 ){
183 char *zDest;
184 zCmd = "backup -R";
185 collect_argument(&extra, "overwrite",0);
186 if( g.argc!=4 ) usage("backup DIRECTORY");
187 zDest = g.argv[3];
188 if( file_isdir(zDest, ExtFILE)!=1 ){
189 fossil_fatal("argument to \"fossil all backup\" must be a directory");
190 }
191 blob_appendf(&extra, " %$", zDest);
192 }else if( strncmp(zCmd, "clean", n)==0 ){
193 zCmd = "clean --chdir";
194 collect_argument(&extra, "allckouts",0);
195 collect_argument_value(&extra, "case-sensitive");
196 collect_argument_value(&extra, "clean");
@@ -283,11 +268,13 @@
268 }else if( strncmp(zCmd, "sync", n)==0 ){
269 zCmd = "sync -autourl -R";
270 collect_argument(&extra, "verbose","v");
271 collect_argument(&extra, "unversioned","u");
272 }else if( strncmp(zCmd, "test-integrity", n)==0 ){
273 collect_argument(&extra, "db-only", "d");
274 collect_argument(&extra, "parse", 0);
275 collect_argument(&extra, "quick", "q");
276 zCmd = "test-integrity";
277 }else if( strncmp(zCmd, "test-orphans", n)==0 ){
278 zCmd = "test-orphans -R";
279 }else if( strncmp(zCmd, "test-missing", n)==0 ){
280 zCmd = "test-missing -q -R";
@@ -368,11 +355,10 @@
355 fossil_fatal("\"all\" subcommand should be one of: "
356 "add cache changes clean dbstat extras fts-config ignore "
357 "info list ls pull push rebuild server setting sync ui unset");
358 }
359 verify_all_options();
 
360 db_multi_exec("CREATE TEMP TABLE repolist(name,tag);");
361 if( useCheckouts ){
362 db_multi_exec(
363 "INSERT INTO repolist "
364 "SELECT DISTINCT substr(name, 7), name COLLATE nocase"
@@ -410,13 +396,12 @@
396 continue;
397 }else if( showFile ){
398 fossil_print("%s: %s\n", useCheckouts ? "checkout" : "repository",
399 zFilename);
400 }
401 zSyscmd = mprintf("%$ %s %$%s",
402 g.nameOfExe, zCmd, zFilename, blob_str(&extra));
 
403 if( showLabel ){
404 int len = (int)strlen(zFilename);
405 int nStar = 80 - (len + 15);
406 if( nStar<2 ) nStar = 1;
407 fossil_print("%.13c %s %.*c\n", '*', zFilename, nStar, '*');
@@ -426,11 +411,10 @@
411 fossil_print("%s\n", zSyscmd);
412 fflush(stdout);
413 }
414 rc = dryRunFlag ? 0 : fossil_system(zSyscmd);
415 free(zSyscmd);
 
416 if( stopOnError && rc ){
417 break;
418 }
419 }
420 db_finalize(&q);
421
+33 -28
--- src/attach.c
+++ src/attach.c
@@ -23,19 +23,22 @@
2323
2424
/*
2525
** WEBPAGE: attachlist
2626
** List attachments.
2727
**
28
-** tkt=TICKETUUID
28
+** tkt=HASH
2929
** page=WIKIPAGE
30
+** technote=HASH
31
+**
32
+** At most one of technote=, tkt= or page= may be supplied.
33
+**
34
+** If none are given, all attachments are listed. If one is given, only
35
+** attachments for the designated technote, ticket or wiki page are shown.
3036
**
31
-** At most one of technote=, tkt= or page= are supplied.
32
-** If none is given, all attachments are listed. If one is given,
33
-** only attachments for the designated technote, ticket or wiki page
34
-** are shown. TECHNOTEUUID and TICKETUUID may be just a prefix of the
35
-** relevant technical note or ticket, in which case all attachments
36
-** of all technical notes or tickets with the prefix will be listed.
37
+** HASH may be just a prefix of the relevant technical note or ticket
38
+** artifact hash, in which case all attachments of all technical notes or
39
+** tickets with the prefix will be listed.
3740
*/
3841
void attachlist_page(void){
3942
const char *zPage = P("page");
4043
const char *zTkt = P("tkt");
4144
const char *zTechNote = P("technote");
@@ -152,15 +155,16 @@
152155
** WEBPAGE: attachdownload
153156
** WEBPAGE: attachimage
154157
** WEBPAGE: attachview
155158
**
156159
** Download or display an attachment.
160
+**
157161
** Query parameters:
158162
**
159
-** tkt=TICKETUUID
163
+** tkt=HASH
160164
** page=WIKIPAGE
161
-** technote=TECHNOTEUUID
165
+** technote=HASH
162166
** file=FILENAME
163167
** attachid=ID
164168
**
165169
*/
166170
void attachview_page(void){
@@ -250,11 +254,11 @@
250254
/*
251255
** Commit a new attachment into the repository
252256
*/
253257
void attach_commit(
254258
const char *zName, /* The filename of the attachment */
255
- const char *zTarget, /* The artifact uuid to attach to */
259
+ const char *zTarget, /* The artifact hash to attach to */
256260
const char *aContent, /* The content of the attachment */
257261
int szContent, /* The length of the attachment */
258262
int needModerator, /* Moderate the attachment? */
259263
const char *zComment /* The comment for the attachment */
260264
){
@@ -305,13 +309,13 @@
305309
306310
/*
307311
** WEBPAGE: attachadd
308312
** Add a new attachment.
309313
**
310
-** tkt=TICKETUUID
314
+** tkt=HASH
311315
** page=WIKIPAGE
312
-** technote=TECHNOTEUUID
316
+** technote=HASH
313317
** from=URL
314318
**
315319
*/
316320
void attachadd_page(void){
317321
const char *zPage = P("page");
@@ -420,14 +424,14 @@
420424
*/
421425
void ainfo_page(void){
422426
int rid; /* RID for the control artifact */
423427
int ridSrc; /* RID for the attached file */
424428
char *zDate; /* Date attached */
425
- const char *zUuid; /* UUID of the control artifact */
429
+ const char *zUuid; /* Hash of the control artifact */
426430
Manifest *pAttach; /* Parse of the control artifact */
427431
const char *zTarget; /* Wiki, ticket or tech note attached to */
428
- const char *zSrc; /* UUID of the attached file */
432
+ const char *zSrc; /* Hash of the attached file */
429433
const char *zName; /* Name of the attached file */
430434
const char *zDesc; /* Description of the attached file */
431435
const char *zWikiName = 0; /* Wiki page name when attached to Wiki */
432436
const char *zTNUuid = 0; /* Tech Note ID when attached to tech note */
433437
const char *zTktUuid = 0; /* Ticket ID when attached to a ticket */
@@ -545,11 +549,11 @@
545549
cgi_redirectf("%R/wiki?name=%t", zWikiName);
546550
}
547551
return;
548552
}
549553
if( strcmp(zModAction,"approve")==0 ){
550
- moderation_approve(rid);
554
+ moderation_approve('a', rid);
551555
}
552556
}
553557
style_header("Attachment Details");
554558
style_submenu_element("Raw", "%R/artifact/%s", zUuid);
555559
if(fShowContent){
@@ -681,22 +685,23 @@
681685
/*
682686
** COMMAND: attachment*
683687
**
684688
** Usage: %fossil attachment add ?PAGENAME? FILENAME ?OPTIONS?
685689
**
686
-** Add an attachment to an existing wiki page or tech note.
687
-**
688
-** Options:
689
-** -t|--technote DATETIME Specifies the timestamp of
690
-** the technote to which the attachment
691
-** is to be made. The attachment will be
692
-** to the most recently modified tech note
693
-** with the specified timestamp.
694
-** -t|--technote TECHNOTE-ID Specifies the technote to be
695
-** updated by its technote id.
696
-**
697
-** One of PAGENAME, DATETIME or TECHNOTE-ID must be specified.
690
+** Add an attachment to an existing wiki page or tech note.
691
+** Options:
692
+**
693
+** -t|--technote DATETIME Specifies the timestamp of
694
+** the technote to which the attachment
695
+** is to be made. The attachment will be
696
+** to the most recently modified tech note
697
+** with the specified timestamp.
698
+**
699
+** -t|--technote TECHNOTE-ID Specifies the technote to be
700
+** updated by its technote id.
701
+**
702
+** One of PAGENAME, DATETIME or TECHNOTE-ID must be specified.
698703
**
699704
** DATETIME may be "now" or "YYYY-MM-DDTHH:MM:SS.SSS". If in
700705
** year-month-day form, it may be truncated, the "T" may be replaced by
701706
** a space, and it may also name a timezone offset from UTC as "-HH:MM"
702707
** (westward) or "+HH:MM" (eastward). Either no timezone suffix or "Z"
@@ -763,11 +768,11 @@
763768
}
764769
blob_read_from_file(&content, zFile, ExtFILE);
765770
user_select();
766771
attach_commit(
767772
zFile, /* The filename of the attachment */
768
- zTarget, /* The artifact uuid to attach to */
773
+ zTarget, /* The artifact hash to attach to */
769774
blob_buffer(&content), /* The content of the attachment */
770775
blob_size(&content), /* The length of the attachment */
771776
0, /* No need to moderate the attachment */
772777
"" /* Empty attachment comment */
773778
);
774779
775780
ADDED src/backlink.c
--- src/attach.c
+++ src/attach.c
@@ -23,19 +23,22 @@
23
24 /*
25 ** WEBPAGE: attachlist
26 ** List attachments.
27 **
28 ** tkt=TICKETUUID
29 ** page=WIKIPAGE
 
 
 
 
 
 
30 **
31 ** At most one of technote=, tkt= or page= are supplied.
32 ** If none is given, all attachments are listed. If one is given,
33 ** only attachments for the designated technote, ticket or wiki page
34 ** are shown. TECHNOTEUUID and TICKETUUID may be just a prefix of the
35 ** relevant technical note or ticket, in which case all attachments
36 ** of all technical notes or tickets with the prefix will be listed.
37 */
38 void attachlist_page(void){
39 const char *zPage = P("page");
40 const char *zTkt = P("tkt");
41 const char *zTechNote = P("technote");
@@ -152,15 +155,16 @@
152 ** WEBPAGE: attachdownload
153 ** WEBPAGE: attachimage
154 ** WEBPAGE: attachview
155 **
156 ** Download or display an attachment.
 
157 ** Query parameters:
158 **
159 ** tkt=TICKETUUID
160 ** page=WIKIPAGE
161 ** technote=TECHNOTEUUID
162 ** file=FILENAME
163 ** attachid=ID
164 **
165 */
166 void attachview_page(void){
@@ -250,11 +254,11 @@
250 /*
251 ** Commit a new attachment into the repository
252 */
253 void attach_commit(
254 const char *zName, /* The filename of the attachment */
255 const char *zTarget, /* The artifact uuid to attach to */
256 const char *aContent, /* The content of the attachment */
257 int szContent, /* The length of the attachment */
258 int needModerator, /* Moderate the attachment? */
259 const char *zComment /* The comment for the attachment */
260 ){
@@ -305,13 +309,13 @@
305
306 /*
307 ** WEBPAGE: attachadd
308 ** Add a new attachment.
309 **
310 ** tkt=TICKETUUID
311 ** page=WIKIPAGE
312 ** technote=TECHNOTEUUID
313 ** from=URL
314 **
315 */
316 void attachadd_page(void){
317 const char *zPage = P("page");
@@ -420,14 +424,14 @@
420 */
421 void ainfo_page(void){
422 int rid; /* RID for the control artifact */
423 int ridSrc; /* RID for the attached file */
424 char *zDate; /* Date attached */
425 const char *zUuid; /* UUID of the control artifact */
426 Manifest *pAttach; /* Parse of the control artifact */
427 const char *zTarget; /* Wiki, ticket or tech note attached to */
428 const char *zSrc; /* UUID of the attached file */
429 const char *zName; /* Name of the attached file */
430 const char *zDesc; /* Description of the attached file */
431 const char *zWikiName = 0; /* Wiki page name when attached to Wiki */
432 const char *zTNUuid = 0; /* Tech Note ID when attached to tech note */
433 const char *zTktUuid = 0; /* Ticket ID when attached to a ticket */
@@ -545,11 +549,11 @@
545 cgi_redirectf("%R/wiki?name=%t", zWikiName);
546 }
547 return;
548 }
549 if( strcmp(zModAction,"approve")==0 ){
550 moderation_approve(rid);
551 }
552 }
553 style_header("Attachment Details");
554 style_submenu_element("Raw", "%R/artifact/%s", zUuid);
555 if(fShowContent){
@@ -681,22 +685,23 @@
681 /*
682 ** COMMAND: attachment*
683 **
684 ** Usage: %fossil attachment add ?PAGENAME? FILENAME ?OPTIONS?
685 **
686 ** Add an attachment to an existing wiki page or tech note.
687 **
688 ** Options:
689 ** -t|--technote DATETIME Specifies the timestamp of
690 ** the technote to which the attachment
691 ** is to be made. The attachment will be
692 ** to the most recently modified tech note
693 ** with the specified timestamp.
694 ** -t|--technote TECHNOTE-ID Specifies the technote to be
695 ** updated by its technote id.
696 **
697 ** One of PAGENAME, DATETIME or TECHNOTE-ID must be specified.
 
698 **
699 ** DATETIME may be "now" or "YYYY-MM-DDTHH:MM:SS.SSS". If in
700 ** year-month-day form, it may be truncated, the "T" may be replaced by
701 ** a space, and it may also name a timezone offset from UTC as "-HH:MM"
702 ** (westward) or "+HH:MM" (eastward). Either no timezone suffix or "Z"
@@ -763,11 +768,11 @@
763 }
764 blob_read_from_file(&content, zFile, ExtFILE);
765 user_select();
766 attach_commit(
767 zFile, /* The filename of the attachment */
768 zTarget, /* The artifact uuid to attach to */
769 blob_buffer(&content), /* The content of the attachment */
770 blob_size(&content), /* The length of the attachment */
771 0, /* No need to moderate the attachment */
772 "" /* Empty attachment comment */
773 );
774
775 DDED src/backlink.c
--- src/attach.c
+++ src/attach.c
@@ -23,19 +23,22 @@
23
24 /*
25 ** WEBPAGE: attachlist
26 ** List attachments.
27 **
28 ** tkt=HASH
29 ** page=WIKIPAGE
30 ** technote=HASH
31 **
32 ** At most one of technote=, tkt= or page= may be supplied.
33 **
34 ** If none are given, all attachments are listed. If one is given, only
35 ** attachments for the designated technote, ticket or wiki page are shown.
36 **
37 ** HASH may be just a prefix of the relevant technical note or ticket
38 ** artifact hash, in which case all attachments of all technical notes or
39 ** tickets with the prefix will be listed.
 
 
 
40 */
41 void attachlist_page(void){
42 const char *zPage = P("page");
43 const char *zTkt = P("tkt");
44 const char *zTechNote = P("technote");
@@ -152,15 +155,16 @@
155 ** WEBPAGE: attachdownload
156 ** WEBPAGE: attachimage
157 ** WEBPAGE: attachview
158 **
159 ** Download or display an attachment.
160 **
161 ** Query parameters:
162 **
163 ** tkt=HASH
164 ** page=WIKIPAGE
165 ** technote=HASH
166 ** file=FILENAME
167 ** attachid=ID
168 **
169 */
170 void attachview_page(void){
@@ -250,11 +254,11 @@
254 /*
255 ** Commit a new attachment into the repository
256 */
257 void attach_commit(
258 const char *zName, /* The filename of the attachment */
259 const char *zTarget, /* The artifact hash to attach to */
260 const char *aContent, /* The content of the attachment */
261 int szContent, /* The length of the attachment */
262 int needModerator, /* Moderate the attachment? */
263 const char *zComment /* The comment for the attachment */
264 ){
@@ -305,13 +309,13 @@
309
310 /*
311 ** WEBPAGE: attachadd
312 ** Add a new attachment.
313 **
314 ** tkt=HASH
315 ** page=WIKIPAGE
316 ** technote=HASH
317 ** from=URL
318 **
319 */
320 void attachadd_page(void){
321 const char *zPage = P("page");
@@ -420,14 +424,14 @@
424 */
425 void ainfo_page(void){
426 int rid; /* RID for the control artifact */
427 int ridSrc; /* RID for the attached file */
428 char *zDate; /* Date attached */
429 const char *zUuid; /* Hash of the control artifact */
430 Manifest *pAttach; /* Parse of the control artifact */
431 const char *zTarget; /* Wiki, ticket or tech note attached to */
432 const char *zSrc; /* Hash of the attached file */
433 const char *zName; /* Name of the attached file */
434 const char *zDesc; /* Description of the attached file */
435 const char *zWikiName = 0; /* Wiki page name when attached to Wiki */
436 const char *zTNUuid = 0; /* Tech Note ID when attached to tech note */
437 const char *zTktUuid = 0; /* Ticket ID when attached to a ticket */
@@ -545,11 +549,11 @@
549 cgi_redirectf("%R/wiki?name=%t", zWikiName);
550 }
551 return;
552 }
553 if( strcmp(zModAction,"approve")==0 ){
554 moderation_approve('a', rid);
555 }
556 }
557 style_header("Attachment Details");
558 style_submenu_element("Raw", "%R/artifact/%s", zUuid);
559 if(fShowContent){
@@ -681,22 +685,23 @@
685 /*
686 ** COMMAND: attachment*
687 **
688 ** Usage: %fossil attachment add ?PAGENAME? FILENAME ?OPTIONS?
689 **
690 ** Add an attachment to an existing wiki page or tech note.
691 ** Options:
692 **
693 ** -t|--technote DATETIME Specifies the timestamp of
694 ** the technote to which the attachment
695 ** is to be made. The attachment will be
696 ** to the most recently modified tech note
697 ** with the specified timestamp.
698 **
699 ** -t|--technote TECHNOTE-ID Specifies the technote to be
700 ** updated by its technote id.
701 **
702 ** One of PAGENAME, DATETIME or TECHNOTE-ID must be specified.
703 **
704 ** DATETIME may be "now" or "YYYY-MM-DDTHH:MM:SS.SSS". If in
705 ** year-month-day form, it may be truncated, the "T" may be replaced by
706 ** a space, and it may also name a timezone offset from UTC as "-HH:MM"
707 ** (westward) or "+HH:MM" (eastward). Either no timezone suffix or "Z"
@@ -763,11 +768,11 @@
768 }
769 blob_read_from_file(&content, zFile, ExtFILE);
770 user_select();
771 attach_commit(
772 zFile, /* The filename of the attachment */
773 zTarget, /* The artifact hash to attach to */
774 blob_buffer(&content), /* The content of the attachment */
775 blob_size(&content), /* The length of the attachment */
776 0, /* No need to moderate the attachment */
777 "" /* Empty attachment comment */
778 );
779
780 DDED src/backlink.c
--- a/src/backlink.c
+++ b/src/backlink.c
@@ -0,0 +1,6 @@
1
+/*
2
+** Copyright (c) 2020 D. Richard Hipp
3
+**
4
+** This program is free software; you can redistribute it and/or
5
+** modify it under the terms of the Simplified BSD License (also
6
+** known as the "2-Clau
--- a/src/backlink.c
+++ b/src/backlink.c
@@ -0,0 +1,6 @@
 
 
 
 
 
 
--- a/src/backlink.c
+++ b/src/backlink.c
@@ -0,0 +1,6 @@
1 /*
2 ** Copyright (c) 2020 D. Richard Hipp
3 **
4 ** This program is free software; you can redistribute it and/or
5 ** modify it under the terms of the Simplified BSD License (also
6 ** known as the "2-Clau
+184 -23
--- src/backoffice.c
+++ src/backoffice.c
@@ -19,10 +19,11 @@
1919
** occur after user interaction with the repository. Examples of
2020
** backoffice processing includes:
2121
**
2222
** * Sending alerts and notifications
2323
** * Processing the email queue
24
+** * Handling post-receive hooks
2425
** * Automatically syncing to peer repositories
2526
**
2627
** Backoffice processing is automatically started whenever there are
2728
** changes to the repository. The backoffice process dies off after
2829
** a period of inactivity.
@@ -77,10 +78,12 @@
7778
#else
7879
# include <unistd.h>
7980
# include <sys/types.h>
8081
# include <signal.h>
8182
# include <errno.h>
83
+# include <sys/time.h>
84
+# include <sys/resource.h>
8285
# include <fcntl.h>
8386
# define GETPID getpid
8487
#endif
8588
#include <time.h>
8689
@@ -121,13 +124,37 @@
121124
** should run if backoffice process is needed. It is set by the
122125
** backoffice_check_if_needed() routine which must be run while the database
123126
** file is open. Later, after the database is closed, the
124127
** backoffice_run_if_needed() will consult this variable to see if it
125128
** should be a no-op.
129
+**
130
+** The magic string "x" in this variable means "do not run the backoffice".
126131
*/
127132
static char *backofficeDb = 0;
128133
134
+/*
135
+** Log backoffice activity to a file named here. If not NULL, this
136
+** overrides the "backoffice-logfile" setting of the database. If NULL,
137
+** the "backoffice-logfile" setting is used instead.
138
+*/
139
+static const char *backofficeLogfile = 0;
140
+
141
+/*
142
+** Write the log message into this open file.
143
+*/
144
+static FILE *backofficeFILE = 0;
145
+
146
+/*
147
+** Write backoffice log messages on this BLOB. to this connection:
148
+*/
149
+static Blob *backofficeBlob = 0;
150
+
151
+/*
152
+** Non-zero for extra logging detail.
153
+*/
154
+static int backofficeLogDetail = 0;
155
+
129156
/* End of state variables
130157
****************************************************************************/
131158
132159
/*
133160
** This function emits a diagnostic message related to the processing in
@@ -277,11 +304,11 @@
277304
}
278305
#endif
279306
280307
/*
281308
** Check to see if the process identified by pid is alive. If
282
-** we cannot prove the the process is dead, return true.
309
+** we cannot prove that the process is dead, return true.
283310
*/
284311
static int backofficeProcessExists(sqlite3_uint64 pid){
285312
#if defined(_WIN32)
286313
return pid>0 && backofficeWin32ProcessExists((DWORD)pid)!=0;
287314
#else
@@ -289,11 +316,11 @@
289316
#endif
290317
}
291318
292319
/*
293320
** Check to see if the process identified by pid has finished. If
294
-** we cannot prove the the process is still running, return true.
321
+** we cannot prove that the process is still running, return true.
295322
*/
296323
static int backofficeProcessDone(sqlite3_uint64 pid){
297324
#if defined(_WIN32)
298325
return pid<=0 || backofficeWin32ProcessExists((DWORD)pid)==0;
299326
#else
@@ -514,73 +541,178 @@
514541
}
515542
}
516543
}
517544
return;
518545
}
546
+
547
+/*
548
+** Append to a message to the backoffice log, if the log is open.
549
+*/
550
+void backoffice_log(const char *zFormat, ...){
551
+ va_list ap;
552
+ if( backofficeBlob==0 ) return;
553
+ blob_append_char(backofficeBlob, ' ');
554
+ va_start(ap, zFormat);
555
+ blob_vappendf(backofficeBlob, zFormat, ap);
556
+ va_end(ap);
557
+}
558
+
559
+#if !defined(_WIN32)
560
+/*
561
+** Capture routine for signals while running backoffice.
562
+*/
563
+static void backoffice_signal_handler(int sig){
564
+ const char *zSig = 0;
565
+ if( sig==SIGSEGV ) zSig = "SIGSEGV";
566
+ if( sig==SIGFPE ) zSig = "SIGFPE";
567
+ if( sig==SIGABRT ) zSig = "SIGABRT";
568
+ if( sig==SIGILL ) zSig = "SIGILL";
569
+ if( zSig==0 ){
570
+ backoffice_log("signal-%d", sig);
571
+ }else{
572
+ backoffice_log("%s", zSig);
573
+ }
574
+ fprintf(backofficeFILE, "%s\n", blob_str(backofficeBlob));
575
+ fflush(backofficeFILE);
576
+ exit(1);
577
+}
578
+#endif
579
+
580
+#if !defined(_WIN32)
581
+/*
582
+** Convert a struct timeval into an integer number of microseconds
583
+*/
584
+static long long int tvms(struct timeval *p){
585
+ return ((long long int)p->tv_sec)*1000000 + (long long int)p->tv_usec;
586
+}
587
+#endif
588
+
519589
520590
/*
521591
** This routine runs to do the backoffice processing. When adding new
522592
** backoffice processing tasks, add them here.
523593
*/
524594
void backoffice_work(void){
525595
/* Log the backoffice run for testing purposes. For production deployments
526596
** the "backoffice-logfile" property should be unset and the following code
527597
** should be a no-op. */
528
- char *zLog = db_get("backoffice-logfile",0);
529
- if( zLog && zLog[0] ){
530
- FILE *pLog = fossil_fopen(zLog, "a");
531
- if( pLog ){
532
- char *zDate = db_text(0, "SELECT datetime('now');");
533
- fprintf(pLog, "%s (%d) backoffice running\n", zDate, GETPID());
534
- fclose(pLog);
535
- }
598
+ const char *zLog = backofficeLogfile;
599
+ Blob log;
600
+ int nThis;
601
+ int nTotal = 0;
602
+#if !defined(_WIN32)
603
+ struct timeval sStart, sEnd;
604
+#endif
605
+ if( zLog==0 ) zLog = db_get("backoffice-logfile",0);
606
+ if( zLog && zLog[0] && (backofficeFILE = fossil_fopen(zLog,"a"))!=0 ){
607
+ int i;
608
+ char *zName = db_get("project-name",0);
609
+#if !defined(_WIN32)
610
+ gettimeofday(&sStart, 0);
611
+ signal(SIGSEGV, backoffice_signal_handler);
612
+ signal(SIGABRT, backoffice_signal_handler);
613
+ signal(SIGFPE, backoffice_signal_handler);
614
+ signal(SIGILL, backoffice_signal_handler);
615
+#endif
616
+ if( zName==0 ){
617
+ zName = (char*)file_tail(g.zRepositoryName);
618
+ if( zName==0 ) zName = "(unnamed)";
619
+ }else{
620
+ /* Convert all spaces in the "project-name" into dashes */
621
+ for(i=0; zName[i]; i++){ if( zName[i]==' ' ) zName[i] = '-'; }
622
+ }
623
+ blob_init(&log, 0, 0);
624
+ backofficeBlob = &log;
625
+ blob_appendf(&log, "%s %s", db_text(0, "SELECT datetime('now')"), zName);
536626
}
537627
538628
/* Here is where the actual work of the backoffice happens */
539
- alert_backoffice(0);
540
- smtp_cleanup();
629
+ nThis = alert_backoffice(0);
630
+ if( nThis ){ backoffice_log("%d alerts", nThis); nTotal += nThis; }
631
+ nThis = smtp_cleanup();
632
+ if( nThis ){ backoffice_log("%d SMTPs", nThis); nTotal += nThis; }
633
+ nThis = hook_backoffice();
634
+ if( nThis ){ backoffice_log("%d hooks", nThis); nTotal += nThis; }
635
+
636
+ /* Close the log */
637
+ if( backofficeFILE ){
638
+ if( nTotal || backofficeLogDetail ){
639
+ if( nTotal==0 ) backoffice_log("no-op");
640
+#if !defined(_WIN32)
641
+ gettimeofday(&sEnd,0);
642
+ backoffice_log("elapse-time %d us", tvms(&sEnd) - tvms(&sStart));
643
+#endif
644
+ fprintf(backofficeFILE, "%s\n", blob_str(backofficeBlob));
645
+ }
646
+ fclose(backofficeFILE);
647
+ }
541648
}
542649
543650
/*
544651
** COMMAND: backoffice*
545652
**
546
-** Usage: backoffice [OPTIONS...] [REPOSITORIES...]
653
+** Usage: %fossil backoffice [OPTIONS...] [REPOSITORIES...]
547654
**
548655
** Run backoffice processing on the repositories listed. If no
549656
** repository is specified, run it on the repository of the local checkout.
550657
**
551658
** This might be done by a cron job or similar to make sure backoffice
552659
** processing happens periodically. Or, the --poll option can be used
553660
** to run this command as a daemon that will periodically invoke backoffice
554
-** on collection of repositories.
661
+** on a collection of repositories.
662
+**
663
+** If only a single repository is named and --poll is omitted, then the
664
+** backoffice work is done in-process. But if there are multiple respositories
665
+** or if --poll is used, a separate sub-process is started for each poll of
666
+** each repository.
555667
**
556
-** OPTIONS:
668
+** Standard options:
557669
**
558670
** --debug Show what this command is doing.
559671
**
560
-** --nodelay Do not queue up or wait for a backoffice job
561
-** to complete. If no work is available or if
562
-** backoffice has run recently, return immediately.
563
-** The --nodelay option is implied if more than
564
-** one repository is listed on the command-line.
672
+** --logfile FILE Append a log of backoffice actions onto FILE.
673
+**
674
+** --min N When polling, invoke backoffice at least
675
+** once every N seconds even if the repository
676
+** never changes. 0 or negative means disable
677
+** this feature. Default: 3600 (once per hour).
565678
**
566679
** --poll N Repeat backoffice calls for repositories that
567680
** change in appoximately N-second intervals.
568681
** N less than 1 turns polling off (the default).
682
+** Recommended polling interval: 60 seconds.
569683
**
570684
** --trace Enable debugging output on stderr
685
+**
686
+** Options intended for internal use only which may change or be
687
+** discontinued in future releases:
688
+**
689
+** --nodelay Do not queue up or wait for a backoffice job
690
+** to complete. If no work is available or if
691
+** backoffice has run recently, return immediately.
692
+**
693
+** --nolease Always run backoffice, even if there is a lease
694
+** conflict. This option implies --nodelay. This
695
+** option is added to secondary backoffice commands
696
+** that are invoked by the --poll option.
571697
*/
572698
void backoffice_command(void){
573699
int nPoll;
700
+ int nMin;
574701
const char *zPoll;
575702
int bDebug = 0;
703
+ int bNoLease = 0;
576704
unsigned int nCmd = 0;
577705
if( find_option("trace",0,0)!=0 ) g.fAnyTrace = 1;
578706
if( find_option("nodelay",0,0)!=0 ) backofficeNoDelay = 1;
707
+ backofficeLogfile = find_option("logfile",0,1);
579708
zPoll = find_option("poll",0,1);
580709
nPoll = zPoll ? atoi(zPoll) : 0;
710
+ zPoll = find_option("min",0,1);
711
+ nMin = zPoll ? atoi(zPoll) : 3600;
581712
bDebug = find_option("debug",0,0)!=0;
713
+ bNoLease = find_option("nolease",0,0)!=0;
582714
583715
/* Silently consume the -R or --repository flag, leaving behind its
584716
** argument. This is for legacy compatibility. Older versions of the
585717
** backoffice command only ran on a single repository that was specified
586718
** using the -R option. */
@@ -592,28 +724,48 @@
592724
** or we are polling. In either case, each backoffice should be run
593725
** using a separate sub-process */
594726
int i;
595727
time_t iNow = 0;
596728
time_t ix;
729
+ i64 *aLastRun = fossil_malloc( sizeof(i64)*g.argc );
730
+ memset(aLastRun, 0, sizeof(i64)*g.argc );
597731
while( 1 /* exit via "break;" */){
598732
time_t iNext = time(0);
599733
for(i=2; i<g.argc; i++){
600734
Blob cmd;
601
- if( !file_isfile(g.argv[i], ExtFILE) ) continue;
602
- if( iNow && iNow>file_mtime(g.argv[i],ExtFILE) ) continue;
735
+ if( !file_isfile(g.argv[i], ExtFILE) ){
736
+ continue; /* Repo no longer exists. Ignore it. */
737
+ }
738
+ if( iNow
739
+ && iNow>file_mtime(g.argv[i], ExtFILE)
740
+ && (nMin<=0 || aLastRun[i]+nMin>iNow)
741
+ ){
742
+ continue; /* Not yet time to run this one */
743
+ }
603744
blob_init(&cmd, 0, 0);
604745
blob_append_escaped_arg(&cmd, g.nameOfExe);
605746
blob_append(&cmd, " backoffice --nodelay", -1);
606747
if( g.fAnyTrace ){
607748
blob_append(&cmd, " --trace", -1);
608749
}
750
+ if( bDebug ){
751
+ blob_append(&cmd, " --debug", -1);
752
+ }
753
+ if( nPoll>0 ){
754
+ blob_append(&cmd, " --nolease", -1);
755
+ }
756
+ if( backofficeLogfile ){
757
+ blob_append(&cmd, " --logfile", -1);
758
+ blob_append_escaped_arg(&cmd, backofficeLogfile);
759
+ }
609760
blob_append_escaped_arg(&cmd, g.argv[i]);
610761
nCmd++;
611762
if( bDebug ){
612763
fossil_print("COMMAND[%u]: %s\n", nCmd, blob_str(&cmd));
613764
}
614765
fossil_system(blob_str(&cmd));
766
+ aLastRun[i] = iNext;
615767
blob_reset(&cmd);
616768
}
617769
if( nPoll<1 ) break;
618770
iNow = iNext;
619771
ix = time(0);
@@ -622,16 +774,25 @@
622774
if( bDebug )fossil_print("SLEEP: %lld\n", nMS);
623775
sqlite3_sleep((int)nMS);
624776
}
625777
}
626778
}else{
779
+ /* Not polling and only one repository named. Backoffice is run
780
+ ** once by this process, which then exits */
627781
if( g.argc==3 ){
628782
g.zRepositoryOption = g.argv[2];
629783
g.argc--;
630784
}
631785
db_find_and_open_repository(0,0);
632
- backoffice_thread();
786
+ if( bDebug ){
787
+ backofficeLogDetail = 1;
788
+ }
789
+ if( bNoLease ){
790
+ backoffice_work();
791
+ }else{
792
+ backoffice_thread();
793
+ }
633794
}
634795
}
635796
636797
/*
637798
** This is the main interface to backoffice from the rest of the system.
638799
--- src/backoffice.c
+++ src/backoffice.c
@@ -19,10 +19,11 @@
19 ** occur after user interaction with the repository. Examples of
20 ** backoffice processing includes:
21 **
22 ** * Sending alerts and notifications
23 ** * Processing the email queue
 
24 ** * Automatically syncing to peer repositories
25 **
26 ** Backoffice processing is automatically started whenever there are
27 ** changes to the repository. The backoffice process dies off after
28 ** a period of inactivity.
@@ -77,10 +78,12 @@
77 #else
78 # include <unistd.h>
79 # include <sys/types.h>
80 # include <signal.h>
81 # include <errno.h>
 
 
82 # include <fcntl.h>
83 # define GETPID getpid
84 #endif
85 #include <time.h>
86
@@ -121,13 +124,37 @@
121 ** should run if backoffice process is needed. It is set by the
122 ** backoffice_check_if_needed() routine which must be run while the database
123 ** file is open. Later, after the database is closed, the
124 ** backoffice_run_if_needed() will consult this variable to see if it
125 ** should be a no-op.
 
 
126 */
127 static char *backofficeDb = 0;
128
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
129 /* End of state variables
130 ****************************************************************************/
131
132 /*
133 ** This function emits a diagnostic message related to the processing in
@@ -277,11 +304,11 @@
277 }
278 #endif
279
280 /*
281 ** Check to see if the process identified by pid is alive. If
282 ** we cannot prove the the process is dead, return true.
283 */
284 static int backofficeProcessExists(sqlite3_uint64 pid){
285 #if defined(_WIN32)
286 return pid>0 && backofficeWin32ProcessExists((DWORD)pid)!=0;
287 #else
@@ -289,11 +316,11 @@
289 #endif
290 }
291
292 /*
293 ** Check to see if the process identified by pid has finished. If
294 ** we cannot prove the the process is still running, return true.
295 */
296 static int backofficeProcessDone(sqlite3_uint64 pid){
297 #if defined(_WIN32)
298 return pid<=0 || backofficeWin32ProcessExists((DWORD)pid)==0;
299 #else
@@ -514,73 +541,178 @@
514 }
515 }
516 }
517 return;
518 }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
519
520 /*
521 ** This routine runs to do the backoffice processing. When adding new
522 ** backoffice processing tasks, add them here.
523 */
524 void backoffice_work(void){
525 /* Log the backoffice run for testing purposes. For production deployments
526 ** the "backoffice-logfile" property should be unset and the following code
527 ** should be a no-op. */
528 char *zLog = db_get("backoffice-logfile",0);
529 if( zLog && zLog[0] ){
530 FILE *pLog = fossil_fopen(zLog, "a");
531 if( pLog ){
532 char *zDate = db_text(0, "SELECT datetime('now');");
533 fprintf(pLog, "%s (%d) backoffice running\n", zDate, GETPID());
534 fclose(pLog);
535 }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
536 }
537
538 /* Here is where the actual work of the backoffice happens */
539 alert_backoffice(0);
540 smtp_cleanup();
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
541 }
542
543 /*
544 ** COMMAND: backoffice*
545 **
546 ** Usage: backoffice [OPTIONS...] [REPOSITORIES...]
547 **
548 ** Run backoffice processing on the repositories listed. If no
549 ** repository is specified, run it on the repository of the local checkout.
550 **
551 ** This might be done by a cron job or similar to make sure backoffice
552 ** processing happens periodically. Or, the --poll option can be used
553 ** to run this command as a daemon that will periodically invoke backoffice
554 ** on collection of repositories.
 
 
 
 
 
555 **
556 ** OPTIONS:
557 **
558 ** --debug Show what this command is doing.
559 **
560 ** --nodelay Do not queue up or wait for a backoffice job
561 ** to complete. If no work is available or if
562 ** backoffice has run recently, return immediately.
563 ** The --nodelay option is implied if more than
564 ** one repository is listed on the command-line.
 
565 **
566 ** --poll N Repeat backoffice calls for repositories that
567 ** change in appoximately N-second intervals.
568 ** N less than 1 turns polling off (the default).
 
569 **
570 ** --trace Enable debugging output on stderr
 
 
 
 
 
 
 
 
 
 
 
 
571 */
572 void backoffice_command(void){
573 int nPoll;
 
574 const char *zPoll;
575 int bDebug = 0;
 
576 unsigned int nCmd = 0;
577 if( find_option("trace",0,0)!=0 ) g.fAnyTrace = 1;
578 if( find_option("nodelay",0,0)!=0 ) backofficeNoDelay = 1;
 
579 zPoll = find_option("poll",0,1);
580 nPoll = zPoll ? atoi(zPoll) : 0;
 
 
581 bDebug = find_option("debug",0,0)!=0;
 
582
583 /* Silently consume the -R or --repository flag, leaving behind its
584 ** argument. This is for legacy compatibility. Older versions of the
585 ** backoffice command only ran on a single repository that was specified
586 ** using the -R option. */
@@ -592,28 +724,48 @@
592 ** or we are polling. In either case, each backoffice should be run
593 ** using a separate sub-process */
594 int i;
595 time_t iNow = 0;
596 time_t ix;
 
 
597 while( 1 /* exit via "break;" */){
598 time_t iNext = time(0);
599 for(i=2; i<g.argc; i++){
600 Blob cmd;
601 if( !file_isfile(g.argv[i], ExtFILE) ) continue;
602 if( iNow && iNow>file_mtime(g.argv[i],ExtFILE) ) continue;
 
 
 
 
 
 
 
603 blob_init(&cmd, 0, 0);
604 blob_append_escaped_arg(&cmd, g.nameOfExe);
605 blob_append(&cmd, " backoffice --nodelay", -1);
606 if( g.fAnyTrace ){
607 blob_append(&cmd, " --trace", -1);
608 }
 
 
 
 
 
 
 
 
 
 
609 blob_append_escaped_arg(&cmd, g.argv[i]);
610 nCmd++;
611 if( bDebug ){
612 fossil_print("COMMAND[%u]: %s\n", nCmd, blob_str(&cmd));
613 }
614 fossil_system(blob_str(&cmd));
 
615 blob_reset(&cmd);
616 }
617 if( nPoll<1 ) break;
618 iNow = iNext;
619 ix = time(0);
@@ -622,16 +774,25 @@
622 if( bDebug )fossil_print("SLEEP: %lld\n", nMS);
623 sqlite3_sleep((int)nMS);
624 }
625 }
626 }else{
 
 
627 if( g.argc==3 ){
628 g.zRepositoryOption = g.argv[2];
629 g.argc--;
630 }
631 db_find_and_open_repository(0,0);
632 backoffice_thread();
 
 
 
 
 
 
 
633 }
634 }
635
636 /*
637 ** This is the main interface to backoffice from the rest of the system.
638
--- src/backoffice.c
+++ src/backoffice.c
@@ -19,10 +19,11 @@
19 ** occur after user interaction with the repository. Examples of
20 ** backoffice processing includes:
21 **
22 ** * Sending alerts and notifications
23 ** * Processing the email queue
24 ** * Handling post-receive hooks
25 ** * Automatically syncing to peer repositories
26 **
27 ** Backoffice processing is automatically started whenever there are
28 ** changes to the repository. The backoffice process dies off after
29 ** a period of inactivity.
@@ -77,10 +78,12 @@
78 #else
79 # include <unistd.h>
80 # include <sys/types.h>
81 # include <signal.h>
82 # include <errno.h>
83 # include <sys/time.h>
84 # include <sys/resource.h>
85 # include <fcntl.h>
86 # define GETPID getpid
87 #endif
88 #include <time.h>
89
@@ -121,13 +124,37 @@
124 ** should run if backoffice process is needed. It is set by the
125 ** backoffice_check_if_needed() routine which must be run while the database
126 ** file is open. Later, after the database is closed, the
127 ** backoffice_run_if_needed() will consult this variable to see if it
128 ** should be a no-op.
129 **
130 ** The magic string "x" in this variable means "do not run the backoffice".
131 */
132 static char *backofficeDb = 0;
133
134 /*
135 ** Log backoffice activity to a file named here. If not NULL, this
136 ** overrides the "backoffice-logfile" setting of the database. If NULL,
137 ** the "backoffice-logfile" setting is used instead.
138 */
139 static const char *backofficeLogfile = 0;
140
141 /*
142 ** Write the log message into this open file.
143 */
144 static FILE *backofficeFILE = 0;
145
146 /*
147 ** Write backoffice log messages on this BLOB. to this connection:
148 */
149 static Blob *backofficeBlob = 0;
150
151 /*
152 ** Non-zero for extra logging detail.
153 */
154 static int backofficeLogDetail = 0;
155
156 /* End of state variables
157 ****************************************************************************/
158
159 /*
160 ** This function emits a diagnostic message related to the processing in
@@ -277,11 +304,11 @@
304 }
305 #endif
306
307 /*
308 ** Check to see if the process identified by pid is alive. If
309 ** we cannot prove that the process is dead, return true.
310 */
311 static int backofficeProcessExists(sqlite3_uint64 pid){
312 #if defined(_WIN32)
313 return pid>0 && backofficeWin32ProcessExists((DWORD)pid)!=0;
314 #else
@@ -289,11 +316,11 @@
316 #endif
317 }
318
319 /*
320 ** Check to see if the process identified by pid has finished. If
321 ** we cannot prove that the process is still running, return true.
322 */
323 static int backofficeProcessDone(sqlite3_uint64 pid){
324 #if defined(_WIN32)
325 return pid<=0 || backofficeWin32ProcessExists((DWORD)pid)==0;
326 #else
@@ -514,73 +541,178 @@
541 }
542 }
543 }
544 return;
545 }
546
547 /*
548 ** Append to a message to the backoffice log, if the log is open.
549 */
550 void backoffice_log(const char *zFormat, ...){
551 va_list ap;
552 if( backofficeBlob==0 ) return;
553 blob_append_char(backofficeBlob, ' ');
554 va_start(ap, zFormat);
555 blob_vappendf(backofficeBlob, zFormat, ap);
556 va_end(ap);
557 }
558
559 #if !defined(_WIN32)
560 /*
561 ** Capture routine for signals while running backoffice.
562 */
563 static void backoffice_signal_handler(int sig){
564 const char *zSig = 0;
565 if( sig==SIGSEGV ) zSig = "SIGSEGV";
566 if( sig==SIGFPE ) zSig = "SIGFPE";
567 if( sig==SIGABRT ) zSig = "SIGABRT";
568 if( sig==SIGILL ) zSig = "SIGILL";
569 if( zSig==0 ){
570 backoffice_log("signal-%d", sig);
571 }else{
572 backoffice_log("%s", zSig);
573 }
574 fprintf(backofficeFILE, "%s\n", blob_str(backofficeBlob));
575 fflush(backofficeFILE);
576 exit(1);
577 }
578 #endif
579
580 #if !defined(_WIN32)
581 /*
582 ** Convert a struct timeval into an integer number of microseconds
583 */
584 static long long int tvms(struct timeval *p){
585 return ((long long int)p->tv_sec)*1000000 + (long long int)p->tv_usec;
586 }
587 #endif
588
589
590 /*
591 ** This routine runs to do the backoffice processing. When adding new
592 ** backoffice processing tasks, add them here.
593 */
594 void backoffice_work(void){
595 /* Log the backoffice run for testing purposes. For production deployments
596 ** the "backoffice-logfile" property should be unset and the following code
597 ** should be a no-op. */
598 const char *zLog = backofficeLogfile;
599 Blob log;
600 int nThis;
601 int nTotal = 0;
602 #if !defined(_WIN32)
603 struct timeval sStart, sEnd;
604 #endif
605 if( zLog==0 ) zLog = db_get("backoffice-logfile",0);
606 if( zLog && zLog[0] && (backofficeFILE = fossil_fopen(zLog,"a"))!=0 ){
607 int i;
608 char *zName = db_get("project-name",0);
609 #if !defined(_WIN32)
610 gettimeofday(&sStart, 0);
611 signal(SIGSEGV, backoffice_signal_handler);
612 signal(SIGABRT, backoffice_signal_handler);
613 signal(SIGFPE, backoffice_signal_handler);
614 signal(SIGILL, backoffice_signal_handler);
615 #endif
616 if( zName==0 ){
617 zName = (char*)file_tail(g.zRepositoryName);
618 if( zName==0 ) zName = "(unnamed)";
619 }else{
620 /* Convert all spaces in the "project-name" into dashes */
621 for(i=0; zName[i]; i++){ if( zName[i]==' ' ) zName[i] = '-'; }
622 }
623 blob_init(&log, 0, 0);
624 backofficeBlob = &log;
625 blob_appendf(&log, "%s %s", db_text(0, "SELECT datetime('now')"), zName);
626 }
627
628 /* Here is where the actual work of the backoffice happens */
629 nThis = alert_backoffice(0);
630 if( nThis ){ backoffice_log("%d alerts", nThis); nTotal += nThis; }
631 nThis = smtp_cleanup();
632 if( nThis ){ backoffice_log("%d SMTPs", nThis); nTotal += nThis; }
633 nThis = hook_backoffice();
634 if( nThis ){ backoffice_log("%d hooks", nThis); nTotal += nThis; }
635
636 /* Close the log */
637 if( backofficeFILE ){
638 if( nTotal || backofficeLogDetail ){
639 if( nTotal==0 ) backoffice_log("no-op");
640 #if !defined(_WIN32)
641 gettimeofday(&sEnd,0);
642 backoffice_log("elapse-time %d us", tvms(&sEnd) - tvms(&sStart));
643 #endif
644 fprintf(backofficeFILE, "%s\n", blob_str(backofficeBlob));
645 }
646 fclose(backofficeFILE);
647 }
648 }
649
650 /*
651 ** COMMAND: backoffice*
652 **
653 ** Usage: %fossil backoffice [OPTIONS...] [REPOSITORIES...]
654 **
655 ** Run backoffice processing on the repositories listed. If no
656 ** repository is specified, run it on the repository of the local checkout.
657 **
658 ** This might be done by a cron job or similar to make sure backoffice
659 ** processing happens periodically. Or, the --poll option can be used
660 ** to run this command as a daemon that will periodically invoke backoffice
661 ** on a collection of repositories.
662 **
663 ** If only a single repository is named and --poll is omitted, then the
664 ** backoffice work is done in-process. But if there are multiple respositories
665 ** or if --poll is used, a separate sub-process is started for each poll of
666 ** each repository.
667 **
668 ** Standard options:
669 **
670 ** --debug Show what this command is doing.
671 **
672 ** --logfile FILE Append a log of backoffice actions onto FILE.
673 **
674 ** --min N When polling, invoke backoffice at least
675 ** once every N seconds even if the repository
676 ** never changes. 0 or negative means disable
677 ** this feature. Default: 3600 (once per hour).
678 **
679 ** --poll N Repeat backoffice calls for repositories that
680 ** change in appoximately N-second intervals.
681 ** N less than 1 turns polling off (the default).
682 ** Recommended polling interval: 60 seconds.
683 **
684 ** --trace Enable debugging output on stderr
685 **
686 ** Options intended for internal use only which may change or be
687 ** discontinued in future releases:
688 **
689 ** --nodelay Do not queue up or wait for a backoffice job
690 ** to complete. If no work is available or if
691 ** backoffice has run recently, return immediately.
692 **
693 ** --nolease Always run backoffice, even if there is a lease
694 ** conflict. This option implies --nodelay. This
695 ** option is added to secondary backoffice commands
696 ** that are invoked by the --poll option.
697 */
698 void backoffice_command(void){
699 int nPoll;
700 int nMin;
701 const char *zPoll;
702 int bDebug = 0;
703 int bNoLease = 0;
704 unsigned int nCmd = 0;
705 if( find_option("trace",0,0)!=0 ) g.fAnyTrace = 1;
706 if( find_option("nodelay",0,0)!=0 ) backofficeNoDelay = 1;
707 backofficeLogfile = find_option("logfile",0,1);
708 zPoll = find_option("poll",0,1);
709 nPoll = zPoll ? atoi(zPoll) : 0;
710 zPoll = find_option("min",0,1);
711 nMin = zPoll ? atoi(zPoll) : 3600;
712 bDebug = find_option("debug",0,0)!=0;
713 bNoLease = find_option("nolease",0,0)!=0;
714
715 /* Silently consume the -R or --repository flag, leaving behind its
716 ** argument. This is for legacy compatibility. Older versions of the
717 ** backoffice command only ran on a single repository that was specified
718 ** using the -R option. */
@@ -592,28 +724,48 @@
724 ** or we are polling. In either case, each backoffice should be run
725 ** using a separate sub-process */
726 int i;
727 time_t iNow = 0;
728 time_t ix;
729 i64 *aLastRun = fossil_malloc( sizeof(i64)*g.argc );
730 memset(aLastRun, 0, sizeof(i64)*g.argc );
731 while( 1 /* exit via "break;" */){
732 time_t iNext = time(0);
733 for(i=2; i<g.argc; i++){
734 Blob cmd;
735 if( !file_isfile(g.argv[i], ExtFILE) ){
736 continue; /* Repo no longer exists. Ignore it. */
737 }
738 if( iNow
739 && iNow>file_mtime(g.argv[i], ExtFILE)
740 && (nMin<=0 || aLastRun[i]+nMin>iNow)
741 ){
742 continue; /* Not yet time to run this one */
743 }
744 blob_init(&cmd, 0, 0);
745 blob_append_escaped_arg(&cmd, g.nameOfExe);
746 blob_append(&cmd, " backoffice --nodelay", -1);
747 if( g.fAnyTrace ){
748 blob_append(&cmd, " --trace", -1);
749 }
750 if( bDebug ){
751 blob_append(&cmd, " --debug", -1);
752 }
753 if( nPoll>0 ){
754 blob_append(&cmd, " --nolease", -1);
755 }
756 if( backofficeLogfile ){
757 blob_append(&cmd, " --logfile", -1);
758 blob_append_escaped_arg(&cmd, backofficeLogfile);
759 }
760 blob_append_escaped_arg(&cmd, g.argv[i]);
761 nCmd++;
762 if( bDebug ){
763 fossil_print("COMMAND[%u]: %s\n", nCmd, blob_str(&cmd));
764 }
765 fossil_system(blob_str(&cmd));
766 aLastRun[i] = iNext;
767 blob_reset(&cmd);
768 }
769 if( nPoll<1 ) break;
770 iNow = iNext;
771 ix = time(0);
@@ -622,16 +774,25 @@
774 if( bDebug )fossil_print("SLEEP: %lld\n", nMS);
775 sqlite3_sleep((int)nMS);
776 }
777 }
778 }else{
779 /* Not polling and only one repository named. Backoffice is run
780 ** once by this process, which then exits */
781 if( g.argc==3 ){
782 g.zRepositoryOption = g.argv[2];
783 g.argc--;
784 }
785 db_find_and_open_repository(0,0);
786 if( bDebug ){
787 backofficeLogDetail = 1;
788 }
789 if( bNoLease ){
790 backoffice_work();
791 }else{
792 backoffice_thread();
793 }
794 }
795 }
796
797 /*
798 ** This is the main interface to backoffice from the rest of the system.
799
+169 -77
--- src/bisect.c
+++ src/bisect.c
@@ -37,17 +37,30 @@
3737
void bisect_path(void){
3838
PathNode *p;
3939
bisect.bad = db_lget_int("bisect-bad", 0);
4040
bisect.good = db_lget_int("bisect-good", 0);
4141
if( bisect.good>0 && bisect.bad==0 ){
42
- path_shortest(bisect.good, bisect.good, 0, 0);
42
+ path_shortest(bisect.good, bisect.good, 0, 0, 0);
4343
}else if( bisect.bad>0 && bisect.good==0 ){
44
- path_shortest(bisect.bad, bisect.bad, 0, 0);
44
+ path_shortest(bisect.bad, bisect.bad, 0, 0, 0);
4545
}else if( bisect.bad==0 && bisect.good==0 ){
4646
fossil_fatal("neither \"good\" nor \"bad\" versions have been identified");
4747
}else{
48
- p = path_shortest(bisect.good, bisect.bad, bisect_option("direct-only"), 0);
48
+ Bag skip;
49
+ int bDirect = bisect_option("direct-only");
50
+ char *zLog = db_lget("bisect-log","");
51
+ Blob log, id;
52
+ bag_init(&skip);
53
+ blob_init(&log, zLog, -1);
54
+ while( blob_token(&log, &id) ){
55
+ if( blob_str(&id)[0]=='s' ){
56
+ bag_insert(&skip, atoi(blob_str(&id)+1));
57
+ }
58
+ }
59
+ blob_reset(&log);
60
+ p = path_shortest(bisect.good, bisect.bad, bDirect, 0, &skip);
61
+ bag_clear(&skip);
4962
if( p==0 ){
5063
char *zBad = db_text(0,"SELECT uuid FROM blob WHERE rid=%d",bisect.bad);
5164
char *zGood = db_text(0,"SELECT uuid FROM blob WHERE rid=%d",bisect.good);
5265
fossil_fatal("no path from good ([%S]) to bad ([%S]) or back",
5366
zGood, zBad);
@@ -78,11 +91,16 @@
7891
unsigned int i;
7992
int r = -1;
8093
for(i=0; i<count(aBisectOption); i++){
8194
if( fossil_strcmp(zName, aBisectOption[i].zName)==0 ){
8295
char *zLabel = mprintf("bisect-%s", zName);
83
- char *z = db_lget(zLabel, (char*)aBisectOption[i].zDefault);
96
+ char *z;
97
+ if( g.localOpen ){
98
+ z = db_lget(zLabel, (char*)aBisectOption[i].zDefault);
99
+ }else{
100
+ z = (char*)aBisectOption[i].zDefault;
101
+ }
84102
if( is_truth(z) ) r = 1;
85103
if( is_false(z) ) r = 0;
86104
if( r<0 ) r = is_truth(aBisectOption[i].zDefault);
87105
free(zLabel);
88106
break;
@@ -167,29 +185,51 @@
167185
db_multi_exec(
168186
"REPLACE INTO vvar(name,value) VALUES('bisect-log',"
169187
"COALESCE((SELECT value||' ' FROM vvar WHERE name='bisect-log'),'')"
170188
" || '%d')", rid);
171189
}
190
+
191
+/*
192
+** Append a new skip entry to the bisect log.
193
+*/
194
+static void bisect_append_skip(int rid){
195
+ db_multi_exec(
196
+ "UPDATE vvar SET value=value||' s%d' WHERE name='bisect-log'", rid
197
+ );
198
+}
172199
173200
/*
174201
** Create a TEMP table named "bilog" that contains the complete history
175202
** of the current bisect.
203
+**
204
+** If iCurrent>0 then it is the RID of the current checkout and is included
205
+** in the history table.
206
+**
207
+** If zDesc is not NULL, then it is the bid= query parameter to /timeline
208
+** that describes a bisect. Use the information in zDesc rather than in
209
+** the bisect-log variable.
210
+**
211
+** If bDetail is true, then also include information about every node
212
+** in between the inner-most GOOD and BAD nodes.
176213
*/
177
-int bisect_create_bilog_table(int iCurrent, const char *zDesc){
214
+int bisect_create_bilog_table(int iCurrent, const char *zDesc, int bDetail){
178215
char *zLog;
179216
Blob log, id;
180217
Stmt q;
181218
int cnt = 0;
219
+ int lastGood = -1;
220
+ int lastBad = -1;
182221
183222
if( zDesc!=0 ){
184223
blob_init(&log, 0, 0);
185
- while( zDesc[0]=='y' || zDesc[0]=='n' ){
224
+ while( zDesc[0]=='y' || zDesc[0]=='n' || zDesc[0]=='s' ){
186225
int i;
187226
char c;
188227
int rid;
189228
if( blob_size(&log) ) blob_append(&log, " ", 1);
190229
if( zDesc[0]=='n' ) blob_append(&log, "-", 1);
230
+ if( zDesc[0]=='s' ) blob_append(&log, "s", 1);
191231
for(i=1; ((c = zDesc[i])>='0' && c<='9') || (c>='a' && c<='f'); i++){}
192232
if( i==1 ) break;
193233
rid = db_int(0,
194234
"SELECT rid FROM blob"
195235
" WHERE uuid LIKE '%.*q%%'"
@@ -204,30 +244,58 @@
204244
zLog = db_lget("bisect-log","");
205245
blob_init(&log, zLog, -1);
206246
}
207247
db_multi_exec(
208248
"CREATE TEMP TABLE bilog("
209
- " seq INTEGER PRIMARY KEY," /* Sequence of events */
249
+ " rid INTEGER PRIMARY KEY," /* Sequence of events */
210250
" stat TEXT," /* Type of occurrence */
211
- " rid INTEGER UNIQUE" /* Check-in number */
251
+ " seq INTEGER UNIQUE" /* Check-in number */
212252
");"
213253
);
214254
db_prepare(&q, "INSERT OR IGNORE INTO bilog(seq,stat,rid)"
215255
" VALUES(:seq,:stat,:rid)");
216256
while( blob_token(&log, &id) ){
217
- int rid = atoi(blob_str(&id));
257
+ int rid;
218258
db_bind_int(&q, ":seq", ++cnt);
219
- db_bind_text(&q, ":stat", rid>0 ? "GOOD" : "BAD");
220
- db_bind_int(&q, ":rid", rid>=0 ? rid : -rid);
259
+ if( blob_str(&id)[0]=='s' ){
260
+ rid = atoi(blob_str(&id)+1);
261
+ db_bind_text(&q, ":stat", "SKIP");
262
+ db_bind_int(&q, ":rid", rid);
263
+ }else{
264
+ rid = atoi(blob_str(&id));
265
+ if( rid>0 ){
266
+ db_bind_text(&q, ":stat","GOOD");
267
+ db_bind_int(&q, ":rid", rid);
268
+ lastGood = rid;
269
+ }else{
270
+ db_bind_text(&q, ":stat", "BAD");
271
+ db_bind_int(&q, ":rid", -rid);
272
+ lastBad = -rid;
273
+ }
274
+ }
221275
db_step(&q);
222276
db_reset(&q);
223277
}
224278
if( iCurrent>0 ){
225279
db_bind_int(&q, ":seq", ++cnt);
226280
db_bind_text(&q, ":stat", "CURRENT");
227281
db_bind_int(&q, ":rid", iCurrent);
228282
db_step(&q);
283
+ db_reset(&q);
284
+ }
285
+ if( bDetail && lastGood>0 && lastBad>0 ){
286
+ PathNode *p;
287
+ p = path_shortest(lastGood, lastBad, bisect_option("direct-only"),0, 0);
288
+ while( p ){
289
+ db_bind_null(&q, ":seq");
290
+ db_bind_null(&q, ":stat");
291
+ db_bind_int(&q, ":rid", p->rid);
292
+ db_step(&q);
293
+ db_reset(&q);
294
+ p = p->u.pTo;
295
+ }
296
+ path_reset();
229297
}
230298
db_finalize(&q);
231299
return 1;
232300
}
233301
@@ -244,14 +312,25 @@
244312
Blob log;
245313
Blob link = BLOB_INITIALIZER;
246314
Blob id;
247315
blob_init(&log, zLog, -1);
248316
while( blob_token(&log, &id) ){
249
- int rid = atoi(blob_str(&id));
250
- char *zUuid = db_text(0,"SELECT lower(uuid) FROM blob WHERE rid=%d",
251
- rid<0 ? -rid : rid);
252
- blob_appendf(&link, "%c%.10s", rid<0 ? 'n' : 'y', zUuid);
317
+ const char *zUuid;
318
+ int rid;
319
+ char cPrefix = 'y';
320
+ if( blob_str(&id)[0]=='s' ){
321
+ rid = atoi(blob_str(&id)+1);
322
+ cPrefix = 's';
323
+ }else{
324
+ rid = atoi(blob_str(&id));
325
+ if( rid<0 ){
326
+ cPrefix = 'n';
327
+ rid = -rid;
328
+ }
329
+ }
330
+ zUuid = db_text(0,"SELECT lower(uuid) FROM blob WHERE rid=%d", rid);
331
+ blob_appendf(&link, "%c%.10s", cPrefix, zUuid);
253332
}
254333
zResult = mprintf("%s", blob_str(&link));
255334
blob_reset(&link);
256335
blob_reset(&log);
257336
blob_reset(&id);
@@ -263,11 +342,11 @@
263342
** sorted either chronologically by bisect time, or by check-in time.
264343
*/
265344
static void bisect_chart(int sortByCkinTime){
266345
Stmt q;
267346
int iCurrent = db_lget_int("checkout",0);
268
- bisect_create_bilog_table(iCurrent, 0);
347
+ bisect_create_bilog_table(iCurrent, 0, 0);
269348
db_prepare(&q,
270349
"SELECT bilog.seq, bilog.stat,"
271350
" substr(blob.uuid,1,16), datetime(event.mtime),"
272351
" blob.rid==%d"
273352
" FROM bilog, blob, event"
@@ -302,77 +381,72 @@
302381
/*
303382
** COMMAND: bisect
304383
**
305384
** Usage: %fossil bisect SUBCOMMAND ...
306385
**
307
-** Run various subcommands useful for searching for bugs.
308
-**
309
-** fossil bisect bad ?VERSION?
310
-**
311
-** Identify version VERSION as non-working. If VERSION is omitted,
312
-** the current checkout is marked as non-working.
313
-**
314
-** fossil bisect good ?VERSION?
315
-**
316
-** Identify version VERSION as working. If VERSION is omitted,
317
-** the current checkout is marked as working.
318
-**
319
-** fossil bisect log
320
-** fossil bisect chart
321
-**
322
-** Show a log of "good" and "bad" versions. "bisect log" shows the
323
-** events in the order that they were tested. "bisect chart" shows
324
-** them in order of check-in.
325
-**
326
-** fossil bisect next
327
-**
328
-** Update to the next version that is halfway between the working and
329
-** non-working versions.
330
-**
331
-** fossil bisect options ?NAME? ?VALUE?
332
-**
333
-** List all bisect options, or the value of a single option, or set the
334
-** value of a bisect option.
335
-**
336
-** fossil bisect reset
337
-**
338
-** Reinitialize a bisect session. This cancels prior bisect history
339
-** and allows a bisect session to start over from the beginning.
340
-**
341
-** fossil bisect vlist|ls|status ?-a|--all?
342
-**
343
-** List the versions in between "bad" and "good".
344
-**
345
-** fossil bisect ui
346
-**
347
-** Like "fossil ui" except start on a timeline that shows only the
348
-** check-ins that are part of the current bisect.
349
-**
350
-** fossil bisect undo
351
-**
352
-** Undo the most recent "good" or "bad" command.
353
-**
354
-** Summary:
355
-**
356
-** fossil bisect bad ?VERSION?
357
-** fossil bisect good ?VERSION?
358
-** fossil bisect log
359
-** fossil bisect chart
360
-** fossil bisect next
361
-** fossil bisect options
362
-** fossil bisect reset
363
-** fossil bisect status
364
-** fossil bisect ui
365
-** fossil bisect undo
386
+** Run various subcommands useful for searching back through the change
387
+** history for a particular checkin that causes or fixes a problem.
388
+**
389
+** > fossil bisect bad ?VERSION?
390
+**
391
+** Identify version VERSION as non-working. If VERSION is omitted,
392
+** the current checkout is marked as non-working.
393
+**
394
+** > fossil bisect good ?VERSION?
395
+**
396
+** Identify version VERSION as working. If VERSION is omitted,
397
+** the current checkout is marked as working.
398
+**
399
+** > fossil bisect log
400
+** > fossil bisect chart
401
+**
402
+** Show a log of "good", "bad", and "skip" versions. "bisect log"
403
+** shows the events in the order that they were tested.
404
+** "bisect chart" shows them in order of check-in.
405
+**
406
+** > fossil bisect next
407
+**
408
+** Update to the next version that is halfway between the working and
409
+** non-working versions.
410
+**
411
+** > fossil bisect options ?NAME? ?VALUE?
412
+**
413
+** List all bisect options, or the value of a single option, or set the
414
+** value of a bisect option.
415
+**
416
+** > fossil bisect reset
417
+**
418
+** Reinitialize a bisect session. This cancels prior bisect history
419
+** and allows a bisect session to start over from the beginning.
420
+**
421
+** > fossil bisect skip ?VERSION?
422
+**
423
+** Cause VERSION (or the current checkout if VERSION is omitted) to
424
+** be ignored for the purpose of the current bisect. This might
425
+** be done, for example, because VERSION does not compile correctly
426
+** or is otherwise unsuitable to participate in this bisect.
427
+**
428
+** > fossil bisect vlist|ls|status ?-a|--all?
429
+**
430
+** List the versions in between the inner-most "bad" and "good".
431
+**
432
+** > fossil bisect ui
433
+**
434
+** Like "fossil ui" except start on a timeline that shows only the
435
+** check-ins that are part of the current bisect.
436
+**
437
+** > fossil bisect undo
438
+**
439
+** Undo the most recent "good", "bad", or "skip" command.
366440
*/
367441
void bisect_cmd(void){
368442
int n;
369443
const char *zCmd;
370444
int foundCmd = 0;
371445
db_must_be_within_tree();
372446
if( g.argc<3 ){
373
- usage("bad|good|log|next|options|reset|status|undo");
447
+ usage("bad|good|log|next|options|reset|skip|status|undo");
374448
}
375449
zCmd = g.argv[2];
376450
n = strlen(zCmd);
377451
if( n==0 ) zCmd = "-";
378452
if( strncmp(zCmd, "bad", n)==0 ){
@@ -399,10 +473,28 @@
399473
ridGood = name_to_typed_rid(g.argv[3], "ci");
400474
}
401475
if( ridGood>0 ){
402476
bisect_append_log(ridGood);
403477
if( bisect_option("auto-next") && db_lget_int("bisect-bad",0)>0 ){
478
+ zCmd = "next";
479
+ n = 4;
480
+ }
481
+ }
482
+ }else if( strncmp(zCmd, "skip", n)==0 ){
483
+ int ridSkip;
484
+ foundCmd = 1;
485
+ if( g.argc==3 ){
486
+ ridSkip = db_lget_int("checkout",0);
487
+ }else{
488
+ ridSkip = name_to_typed_rid(g.argv[3], "ci");
489
+ }
490
+ if( ridSkip>0 ){
491
+ bisect_append_skip(ridSkip);
492
+ if( bisect_option("auto-next")
493
+ && db_lget_int("bisect-bad",0)>0
494
+ && db_lget_int("bisect-good",0)>0
495
+ ){
404496
zCmd = "next";
405497
n = 4;
406498
}
407499
}
408500
}else if( strncmp(zCmd, "undo", n)==0 ){
@@ -448,11 +540,11 @@
448540
bisect_path();
449541
pMid = path_midpoint();
450542
if( pMid==0 ){
451543
fossil_print("bisect complete\n");
452544
}else{
453
- int nSpan = path_length();
545
+ int nSpan = path_length_not_hidden();
454546
int nStep = path_search_depth();
455547
g.argv[1] = "update";
456548
g.argv[2] = db_text(0, "SELECT uuid FROM blob WHERE rid=%d", pMid->rid);
457549
g.argc = 3;
458550
g.fNoSync = 1;
459551
--- src/bisect.c
+++ src/bisect.c
@@ -37,17 +37,30 @@
37 void bisect_path(void){
38 PathNode *p;
39 bisect.bad = db_lget_int("bisect-bad", 0);
40 bisect.good = db_lget_int("bisect-good", 0);
41 if( bisect.good>0 && bisect.bad==0 ){
42 path_shortest(bisect.good, bisect.good, 0, 0);
43 }else if( bisect.bad>0 && bisect.good==0 ){
44 path_shortest(bisect.bad, bisect.bad, 0, 0);
45 }else if( bisect.bad==0 && bisect.good==0 ){
46 fossil_fatal("neither \"good\" nor \"bad\" versions have been identified");
47 }else{
48 p = path_shortest(bisect.good, bisect.bad, bisect_option("direct-only"), 0);
 
 
 
 
 
 
 
 
 
 
 
 
 
49 if( p==0 ){
50 char *zBad = db_text(0,"SELECT uuid FROM blob WHERE rid=%d",bisect.bad);
51 char *zGood = db_text(0,"SELECT uuid FROM blob WHERE rid=%d",bisect.good);
52 fossil_fatal("no path from good ([%S]) to bad ([%S]) or back",
53 zGood, zBad);
@@ -78,11 +91,16 @@
78 unsigned int i;
79 int r = -1;
80 for(i=0; i<count(aBisectOption); i++){
81 if( fossil_strcmp(zName, aBisectOption[i].zName)==0 ){
82 char *zLabel = mprintf("bisect-%s", zName);
83 char *z = db_lget(zLabel, (char*)aBisectOption[i].zDefault);
 
 
 
 
 
84 if( is_truth(z) ) r = 1;
85 if( is_false(z) ) r = 0;
86 if( r<0 ) r = is_truth(aBisectOption[i].zDefault);
87 free(zLabel);
88 break;
@@ -167,29 +185,51 @@
167 db_multi_exec(
168 "REPLACE INTO vvar(name,value) VALUES('bisect-log',"
169 "COALESCE((SELECT value||' ' FROM vvar WHERE name='bisect-log'),'')"
170 " || '%d')", rid);
171 }
 
 
 
 
 
 
 
 
 
172
173 /*
174 ** Create a TEMP table named "bilog" that contains the complete history
175 ** of the current bisect.
 
 
 
 
 
 
 
 
 
 
176 */
177 int bisect_create_bilog_table(int iCurrent, const char *zDesc){
178 char *zLog;
179 Blob log, id;
180 Stmt q;
181 int cnt = 0;
 
 
182
183 if( zDesc!=0 ){
184 blob_init(&log, 0, 0);
185 while( zDesc[0]=='y' || zDesc[0]=='n' ){
186 int i;
187 char c;
188 int rid;
189 if( blob_size(&log) ) blob_append(&log, " ", 1);
190 if( zDesc[0]=='n' ) blob_append(&log, "-", 1);
 
191 for(i=1; ((c = zDesc[i])>='0' && c<='9') || (c>='a' && c<='f'); i++){}
192 if( i==1 ) break;
193 rid = db_int(0,
194 "SELECT rid FROM blob"
195 " WHERE uuid LIKE '%.*q%%'"
@@ -204,30 +244,58 @@
204 zLog = db_lget("bisect-log","");
205 blob_init(&log, zLog, -1);
206 }
207 db_multi_exec(
208 "CREATE TEMP TABLE bilog("
209 " seq INTEGER PRIMARY KEY," /* Sequence of events */
210 " stat TEXT," /* Type of occurrence */
211 " rid INTEGER UNIQUE" /* Check-in number */
212 ");"
213 );
214 db_prepare(&q, "INSERT OR IGNORE INTO bilog(seq,stat,rid)"
215 " VALUES(:seq,:stat,:rid)");
216 while( blob_token(&log, &id) ){
217 int rid = atoi(blob_str(&id));
218 db_bind_int(&q, ":seq", ++cnt);
219 db_bind_text(&q, ":stat", rid>0 ? "GOOD" : "BAD");
220 db_bind_int(&q, ":rid", rid>=0 ? rid : -rid);
 
 
 
 
 
 
 
 
 
 
 
 
 
 
221 db_step(&q);
222 db_reset(&q);
223 }
224 if( iCurrent>0 ){
225 db_bind_int(&q, ":seq", ++cnt);
226 db_bind_text(&q, ":stat", "CURRENT");
227 db_bind_int(&q, ":rid", iCurrent);
228 db_step(&q);
 
 
 
 
 
 
 
 
 
 
 
 
 
 
229 }
230 db_finalize(&q);
231 return 1;
232 }
233
@@ -244,14 +312,25 @@
244 Blob log;
245 Blob link = BLOB_INITIALIZER;
246 Blob id;
247 blob_init(&log, zLog, -1);
248 while( blob_token(&log, &id) ){
249 int rid = atoi(blob_str(&id));
250 char *zUuid = db_text(0,"SELECT lower(uuid) FROM blob WHERE rid=%d",
251 rid<0 ? -rid : rid);
252 blob_appendf(&link, "%c%.10s", rid<0 ? 'n' : 'y', zUuid);
 
 
 
 
 
 
 
 
 
 
 
253 }
254 zResult = mprintf("%s", blob_str(&link));
255 blob_reset(&link);
256 blob_reset(&log);
257 blob_reset(&id);
@@ -263,11 +342,11 @@
263 ** sorted either chronologically by bisect time, or by check-in time.
264 */
265 static void bisect_chart(int sortByCkinTime){
266 Stmt q;
267 int iCurrent = db_lget_int("checkout",0);
268 bisect_create_bilog_table(iCurrent, 0);
269 db_prepare(&q,
270 "SELECT bilog.seq, bilog.stat,"
271 " substr(blob.uuid,1,16), datetime(event.mtime),"
272 " blob.rid==%d"
273 " FROM bilog, blob, event"
@@ -302,77 +381,72 @@
302 /*
303 ** COMMAND: bisect
304 **
305 ** Usage: %fossil bisect SUBCOMMAND ...
306 **
307 ** Run various subcommands useful for searching for bugs.
308 **
309 ** fossil bisect bad ?VERSION?
310 **
311 ** Identify version VERSION as non-working. If VERSION is omitted,
312 ** the current checkout is marked as non-working.
313 **
314 ** fossil bisect good ?VERSION?
315 **
316 ** Identify version VERSION as working. If VERSION is omitted,
317 ** the current checkout is marked as working.
318 **
319 ** fossil bisect log
320 ** fossil bisect chart
321 **
322 ** Show a log of "good" and "bad" versions. "bisect log" shows the
323 ** events in the order that they were tested. "bisect chart" shows
324 ** them in order of check-in.
325 **
326 ** fossil bisect next
327 **
328 ** Update to the next version that is halfway between the working and
329 ** non-working versions.
330 **
331 ** fossil bisect options ?NAME? ?VALUE?
332 **
333 ** List all bisect options, or the value of a single option, or set the
334 ** value of a bisect option.
335 **
336 ** fossil bisect reset
337 **
338 ** Reinitialize a bisect session. This cancels prior bisect history
339 ** and allows a bisect session to start over from the beginning.
340 **
341 ** fossil bisect vlist|ls|status ?-a|--all?
342 **
343 ** List the versions in between "bad" and "good".
344 **
345 ** fossil bisect ui
346 **
347 ** Like "fossil ui" except start on a timeline that shows only the
348 ** check-ins that are part of the current bisect.
349 **
350 ** fossil bisect undo
351 **
352 ** Undo the most recent "good" or "bad" command.
353 **
354 ** Summary:
355 **
356 ** fossil bisect bad ?VERSION?
357 ** fossil bisect good ?VERSION?
358 ** fossil bisect log
359 ** fossil bisect chart
360 ** fossil bisect next
361 ** fossil bisect options
362 ** fossil bisect reset
363 ** fossil bisect status
364 ** fossil bisect ui
365 ** fossil bisect undo
366 */
367 void bisect_cmd(void){
368 int n;
369 const char *zCmd;
370 int foundCmd = 0;
371 db_must_be_within_tree();
372 if( g.argc<3 ){
373 usage("bad|good|log|next|options|reset|status|undo");
374 }
375 zCmd = g.argv[2];
376 n = strlen(zCmd);
377 if( n==0 ) zCmd = "-";
378 if( strncmp(zCmd, "bad", n)==0 ){
@@ -399,10 +473,28 @@
399 ridGood = name_to_typed_rid(g.argv[3], "ci");
400 }
401 if( ridGood>0 ){
402 bisect_append_log(ridGood);
403 if( bisect_option("auto-next") && db_lget_int("bisect-bad",0)>0 ){
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
404 zCmd = "next";
405 n = 4;
406 }
407 }
408 }else if( strncmp(zCmd, "undo", n)==0 ){
@@ -448,11 +540,11 @@
448 bisect_path();
449 pMid = path_midpoint();
450 if( pMid==0 ){
451 fossil_print("bisect complete\n");
452 }else{
453 int nSpan = path_length();
454 int nStep = path_search_depth();
455 g.argv[1] = "update";
456 g.argv[2] = db_text(0, "SELECT uuid FROM blob WHERE rid=%d", pMid->rid);
457 g.argc = 3;
458 g.fNoSync = 1;
459
--- src/bisect.c
+++ src/bisect.c
@@ -37,17 +37,30 @@
37 void bisect_path(void){
38 PathNode *p;
39 bisect.bad = db_lget_int("bisect-bad", 0);
40 bisect.good = db_lget_int("bisect-good", 0);
41 if( bisect.good>0 && bisect.bad==0 ){
42 path_shortest(bisect.good, bisect.good, 0, 0, 0);
43 }else if( bisect.bad>0 && bisect.good==0 ){
44 path_shortest(bisect.bad, bisect.bad, 0, 0, 0);
45 }else if( bisect.bad==0 && bisect.good==0 ){
46 fossil_fatal("neither \"good\" nor \"bad\" versions have been identified");
47 }else{
48 Bag skip;
49 int bDirect = bisect_option("direct-only");
50 char *zLog = db_lget("bisect-log","");
51 Blob log, id;
52 bag_init(&skip);
53 blob_init(&log, zLog, -1);
54 while( blob_token(&log, &id) ){
55 if( blob_str(&id)[0]=='s' ){
56 bag_insert(&skip, atoi(blob_str(&id)+1));
57 }
58 }
59 blob_reset(&log);
60 p = path_shortest(bisect.good, bisect.bad, bDirect, 0, &skip);
61 bag_clear(&skip);
62 if( p==0 ){
63 char *zBad = db_text(0,"SELECT uuid FROM blob WHERE rid=%d",bisect.bad);
64 char *zGood = db_text(0,"SELECT uuid FROM blob WHERE rid=%d",bisect.good);
65 fossil_fatal("no path from good ([%S]) to bad ([%S]) or back",
66 zGood, zBad);
@@ -78,11 +91,16 @@
91 unsigned int i;
92 int r = -1;
93 for(i=0; i<count(aBisectOption); i++){
94 if( fossil_strcmp(zName, aBisectOption[i].zName)==0 ){
95 char *zLabel = mprintf("bisect-%s", zName);
96 char *z;
97 if( g.localOpen ){
98 z = db_lget(zLabel, (char*)aBisectOption[i].zDefault);
99 }else{
100 z = (char*)aBisectOption[i].zDefault;
101 }
102 if( is_truth(z) ) r = 1;
103 if( is_false(z) ) r = 0;
104 if( r<0 ) r = is_truth(aBisectOption[i].zDefault);
105 free(zLabel);
106 break;
@@ -167,29 +185,51 @@
185 db_multi_exec(
186 "REPLACE INTO vvar(name,value) VALUES('bisect-log',"
187 "COALESCE((SELECT value||' ' FROM vvar WHERE name='bisect-log'),'')"
188 " || '%d')", rid);
189 }
190
191 /*
192 ** Append a new skip entry to the bisect log.
193 */
194 static void bisect_append_skip(int rid){
195 db_multi_exec(
196 "UPDATE vvar SET value=value||' s%d' WHERE name='bisect-log'", rid
197 );
198 }
199
200 /*
201 ** Create a TEMP table named "bilog" that contains the complete history
202 ** of the current bisect.
203 **
204 ** If iCurrent>0 then it is the RID of the current checkout and is included
205 ** in the history table.
206 **
207 ** If zDesc is not NULL, then it is the bid= query parameter to /timeline
208 ** that describes a bisect. Use the information in zDesc rather than in
209 ** the bisect-log variable.
210 **
211 ** If bDetail is true, then also include information about every node
212 ** in between the inner-most GOOD and BAD nodes.
213 */
214 int bisect_create_bilog_table(int iCurrent, const char *zDesc, int bDetail){
215 char *zLog;
216 Blob log, id;
217 Stmt q;
218 int cnt = 0;
219 int lastGood = -1;
220 int lastBad = -1;
221
222 if( zDesc!=0 ){
223 blob_init(&log, 0, 0);
224 while( zDesc[0]=='y' || zDesc[0]=='n' || zDesc[0]=='s' ){
225 int i;
226 char c;
227 int rid;
228 if( blob_size(&log) ) blob_append(&log, " ", 1);
229 if( zDesc[0]=='n' ) blob_append(&log, "-", 1);
230 if( zDesc[0]=='s' ) blob_append(&log, "s", 1);
231 for(i=1; ((c = zDesc[i])>='0' && c<='9') || (c>='a' && c<='f'); i++){}
232 if( i==1 ) break;
233 rid = db_int(0,
234 "SELECT rid FROM blob"
235 " WHERE uuid LIKE '%.*q%%'"
@@ -204,30 +244,58 @@
244 zLog = db_lget("bisect-log","");
245 blob_init(&log, zLog, -1);
246 }
247 db_multi_exec(
248 "CREATE TEMP TABLE bilog("
249 " rid INTEGER PRIMARY KEY," /* Sequence of events */
250 " stat TEXT," /* Type of occurrence */
251 " seq INTEGER UNIQUE" /* Check-in number */
252 ");"
253 );
254 db_prepare(&q, "INSERT OR IGNORE INTO bilog(seq,stat,rid)"
255 " VALUES(:seq,:stat,:rid)");
256 while( blob_token(&log, &id) ){
257 int rid;
258 db_bind_int(&q, ":seq", ++cnt);
259 if( blob_str(&id)[0]=='s' ){
260 rid = atoi(blob_str(&id)+1);
261 db_bind_text(&q, ":stat", "SKIP");
262 db_bind_int(&q, ":rid", rid);
263 }else{
264 rid = atoi(blob_str(&id));
265 if( rid>0 ){
266 db_bind_text(&q, ":stat","GOOD");
267 db_bind_int(&q, ":rid", rid);
268 lastGood = rid;
269 }else{
270 db_bind_text(&q, ":stat", "BAD");
271 db_bind_int(&q, ":rid", -rid);
272 lastBad = -rid;
273 }
274 }
275 db_step(&q);
276 db_reset(&q);
277 }
278 if( iCurrent>0 ){
279 db_bind_int(&q, ":seq", ++cnt);
280 db_bind_text(&q, ":stat", "CURRENT");
281 db_bind_int(&q, ":rid", iCurrent);
282 db_step(&q);
283 db_reset(&q);
284 }
285 if( bDetail && lastGood>0 && lastBad>0 ){
286 PathNode *p;
287 p = path_shortest(lastGood, lastBad, bisect_option("direct-only"),0, 0);
288 while( p ){
289 db_bind_null(&q, ":seq");
290 db_bind_null(&q, ":stat");
291 db_bind_int(&q, ":rid", p->rid);
292 db_step(&q);
293 db_reset(&q);
294 p = p->u.pTo;
295 }
296 path_reset();
297 }
298 db_finalize(&q);
299 return 1;
300 }
301
@@ -244,14 +312,25 @@
312 Blob log;
313 Blob link = BLOB_INITIALIZER;
314 Blob id;
315 blob_init(&log, zLog, -1);
316 while( blob_token(&log, &id) ){
317 const char *zUuid;
318 int rid;
319 char cPrefix = 'y';
320 if( blob_str(&id)[0]=='s' ){
321 rid = atoi(blob_str(&id)+1);
322 cPrefix = 's';
323 }else{
324 rid = atoi(blob_str(&id));
325 if( rid<0 ){
326 cPrefix = 'n';
327 rid = -rid;
328 }
329 }
330 zUuid = db_text(0,"SELECT lower(uuid) FROM blob WHERE rid=%d", rid);
331 blob_appendf(&link, "%c%.10s", cPrefix, zUuid);
332 }
333 zResult = mprintf("%s", blob_str(&link));
334 blob_reset(&link);
335 blob_reset(&log);
336 blob_reset(&id);
@@ -263,11 +342,11 @@
342 ** sorted either chronologically by bisect time, or by check-in time.
343 */
344 static void bisect_chart(int sortByCkinTime){
345 Stmt q;
346 int iCurrent = db_lget_int("checkout",0);
347 bisect_create_bilog_table(iCurrent, 0, 0);
348 db_prepare(&q,
349 "SELECT bilog.seq, bilog.stat,"
350 " substr(blob.uuid,1,16), datetime(event.mtime),"
351 " blob.rid==%d"
352 " FROM bilog, blob, event"
@@ -302,77 +381,72 @@
381 /*
382 ** COMMAND: bisect
383 **
384 ** Usage: %fossil bisect SUBCOMMAND ...
385 **
386 ** Run various subcommands useful for searching back through the change
387 ** history for a particular checkin that causes or fixes a problem.
388 **
389 ** > fossil bisect bad ?VERSION?
390 **
391 ** Identify version VERSION as non-working. If VERSION is omitted,
392 ** the current checkout is marked as non-working.
393 **
394 ** > fossil bisect good ?VERSION?
395 **
396 ** Identify version VERSION as working. If VERSION is omitted,
397 ** the current checkout is marked as working.
398 **
399 ** > fossil bisect log
400 ** > fossil bisect chart
401 **
402 ** Show a log of "good", "bad", and "skip" versions. "bisect log"
403 ** shows the events in the order that they were tested.
404 ** "bisect chart" shows them in order of check-in.
405 **
406 ** > fossil bisect next
407 **
408 ** Update to the next version that is halfway between the working and
409 ** non-working versions.
410 **
411 ** > fossil bisect options ?NAME? ?VALUE?
412 **
413 ** List all bisect options, or the value of a single option, or set the
414 ** value of a bisect option.
415 **
416 ** > fossil bisect reset
417 **
418 ** Reinitialize a bisect session. This cancels prior bisect history
419 ** and allows a bisect session to start over from the beginning.
420 **
421 ** > fossil bisect skip ?VERSION?
422 **
423 ** Cause VERSION (or the current checkout if VERSION is omitted) to
424 ** be ignored for the purpose of the current bisect. This might
425 ** be done, for example, because VERSION does not compile correctly
426 ** or is otherwise unsuitable to participate in this bisect.
427 **
428 ** > fossil bisect vlist|ls|status ?-a|--all?
429 **
430 ** List the versions in between the inner-most "bad" and "good".
431 **
432 ** > fossil bisect ui
433 **
434 ** Like "fossil ui" except start on a timeline that shows only the
435 ** check-ins that are part of the current bisect.
436 **
437 ** > fossil bisect undo
438 **
439 ** Undo the most recent "good", "bad", or "skip" command.
 
 
 
 
 
440 */
441 void bisect_cmd(void){
442 int n;
443 const char *zCmd;
444 int foundCmd = 0;
445 db_must_be_within_tree();
446 if( g.argc<3 ){
447 usage("bad|good|log|next|options|reset|skip|status|undo");
448 }
449 zCmd = g.argv[2];
450 n = strlen(zCmd);
451 if( n==0 ) zCmd = "-";
452 if( strncmp(zCmd, "bad", n)==0 ){
@@ -399,10 +473,28 @@
473 ridGood = name_to_typed_rid(g.argv[3], "ci");
474 }
475 if( ridGood>0 ){
476 bisect_append_log(ridGood);
477 if( bisect_option("auto-next") && db_lget_int("bisect-bad",0)>0 ){
478 zCmd = "next";
479 n = 4;
480 }
481 }
482 }else if( strncmp(zCmd, "skip", n)==0 ){
483 int ridSkip;
484 foundCmd = 1;
485 if( g.argc==3 ){
486 ridSkip = db_lget_int("checkout",0);
487 }else{
488 ridSkip = name_to_typed_rid(g.argv[3], "ci");
489 }
490 if( ridSkip>0 ){
491 bisect_append_skip(ridSkip);
492 if( bisect_option("auto-next")
493 && db_lget_int("bisect-bad",0)>0
494 && db_lget_int("bisect-good",0)>0
495 ){
496 zCmd = "next";
497 n = 4;
498 }
499 }
500 }else if( strncmp(zCmd, "undo", n)==0 ){
@@ -448,11 +540,11 @@
540 bisect_path();
541 pMid = path_midpoint();
542 if( pMid==0 ){
543 fossil_print("bisect complete\n");
544 }else{
545 int nSpan = path_length_not_hidden();
546 int nStep = path_search_depth();
547 g.argv[1] = "update";
548 g.argv[2] = db_text(0, "SELECT uuid FROM blob WHERE rid=%d", pMid->rid);
549 g.argc = 3;
550 g.fNoSync = 1;
551
+76 -6
--- src/blob.c
+++ src/blob.c
@@ -477,10 +477,29 @@
477477
void blob_resize(Blob *pBlob, unsigned int newSize){
478478
pBlob->xRealloc(pBlob, newSize+1);
479479
pBlob->nUsed = newSize;
480480
pBlob->aData[newSize] = 0;
481481
}
482
+
483
+/*
484
+** Ensures that the given blob has at least the given amount of memory
485
+** allocated to it. Does not modify pBlob->nUsed nor will it reduce
486
+** the currently-allocated amount of memory.
487
+**
488
+** For semantic compatibility with blob_append_full(), if newSize is
489
+** >=0x7fff000 (~2GB) then this function will trigger blob_panic(). If
490
+** it didn't, it would be possible to bypass that hard-coded limit via
491
+** this function.
492
+*/
493
+void blob_reserve(Blob *pBlob, unsigned int newSize){
494
+ if(newSize>=0x7fff0000 ){
495
+ blob_panic();
496
+ }else if(newSize>pBlob->nUsed){
497
+ pBlob->xRealloc(pBlob, newSize);
498
+ pBlob->aData[newSize] = 0;
499
+ }
500
+}
482501
483502
/*
484503
** Make sure a blob is nul-terminated and is not a pointer to unmanaged
485504
** space. Return a pointer to the data.
486505
*/
@@ -1167,11 +1186,10 @@
11671186
blob_reset(&b3);
11681187
}
11691188
fossil_print("ok\n");
11701189
}
11711190
1172
-#if defined(_WIN32) || defined(__CYGWIN__)
11731191
/*
11741192
** Convert every \n character in the given blob into \r\n.
11751193
*/
11761194
void blob_add_cr(Blob *p){
11771195
char *z = p->aData;
@@ -1191,11 +1209,10 @@
11911209
if( (z[--j] = z[--i]) =='\n' ){
11921210
z[--j] = '\r';
11931211
}
11941212
}
11951213
}
1196
-#endif
11971214
11981215
/*
11991216
** Remove every \r character from the given blob, replacing each one with
12001217
** a \n character if it was not already part of a \r\n pair.
12011218
*/
@@ -1284,35 +1301,88 @@
12841301
char c;
12851302
int needEscape = 0;
12861303
int n = blob_size(pBlob);
12871304
char *z = blob_buffer(pBlob);
12881305
#if defined(_WIN32)
1306
+ const char cDirSep = '\\'; /* Use \ as directory separator */
12891307
const char cQuote = '"'; /* Use "..." quoting on windows */
1308
+ const char cEscape = '^'; /* Use ^X escaping on windows */
12901309
#else
1310
+ const char cDirSep = '/'; /* Use / as directory separator */
12911311
const char cQuote = '\''; /* Use '...' quoting on unix */
1312
+ const char cEscape = '\\'; /* Use \X escaping on unix */
12921313
#endif
12931314
12941315
for(i=0; (c = zIn[i])!=0; i++){
12951316
if( c==cQuote || (unsigned char)c<' ' ||
1296
- c=='\\' || c==';' || c=='*' || c=='?' || c=='[' ){
1317
+ c==cEscape || c==';' || c=='*' || c=='?' || c=='[' ){
12971318
Blob bad;
12981319
blob_token(pBlob, &bad);
12991320
fossil_fatal("the [%s] argument to the \"%s\" command contains "
13001321
"a character (ascii 0x%02x) that is a security risk",
13011322
zIn, blob_str(&bad), c);
13021323
}
1303
- if( !needEscape && !fossil_isalnum(c) && c!='/' && c!='.' && c!='_' ){
1324
+ if( !needEscape && !fossil_isalnum(c) && c!=cDirSep && c!='.' && c!='_' ){
13041325
needEscape = 1;
13051326
}
13061327
}
13071328
if( n>0 && !fossil_isspace(z[n-1]) ){
13081329
blob_append_char(pBlob, ' ');
13091330
}
13101331
if( needEscape ) blob_append_char(pBlob, cQuote);
1311
- if( zIn[0]=='-' ) blob_append(pBlob, "./", 2);
1332
+ if( zIn[0]=='-' ){
1333
+ blob_append_char(pBlob, '.');
1334
+ blob_append_char(pBlob, cDirSep);
1335
+#if defined(_WIN32)
1336
+ }else if( zIn[0]=='/' ){
1337
+ blob_append_char(pBlob, '.');
1338
+#endif
1339
+ }
1340
+#if defined(_WIN32)
1341
+ if( needEscape ){
1342
+ for(i=0; (c = zIn[i])!=0; i++){
1343
+ if( c==cQuote ) blob_append_char(pBlob, cDirSep);
1344
+ blob_append_char(pBlob, c);
1345
+ }
1346
+ }else{
1347
+ blob_append(pBlob, zIn, -1);
1348
+ }
1349
+#else
13121350
blob_append(pBlob, zIn, -1);
1313
- if( needEscape ) blob_append_char(pBlob, cQuote);
1351
+#endif
1352
+ if( needEscape ){
1353
+#if defined(_WIN32)
1354
+ /* NOTE: Trailing backslash must be doubled before final double quote. */
1355
+ if( pBlob->aData[pBlob->nUsed-1]==cDirSep ){
1356
+ blob_append_char(pBlob, cDirSep);
1357
+ }
1358
+#endif
1359
+ blob_append_char(pBlob, cQuote);
1360
+ }
1361
+}
1362
+
1363
+/*
1364
+** COMMAND: test-escaped-arg
1365
+**
1366
+** Usage %fossil ARG ...
1367
+**
1368
+** Run each argment through blob_append_escaped_arg() and show the
1369
+** result. Append each argument to "fossil test-echo" and run that
1370
+** using fossil_system() to verify that it really does get escaped
1371
+** correctly.
1372
+*/
1373
+void test_escaped_arg__cmd(void){
1374
+ int i;
1375
+ Blob x;
1376
+ blob_init(&x, 0, 0);
1377
+ for(i=2; i<g.argc; i++){
1378
+ fossil_print("%3d [%s]: ", i, g.argv[i]);
1379
+ blob_appendf(&x, "fossil test-echo %$", g.argv[i]);
1380
+ fossil_print("%s\n", blob_str(&x));
1381
+ fossil_system(blob_str(&x));
1382
+ blob_reset(&x);
1383
+ }
13141384
}
13151385
13161386
/*
13171387
** A read(2)-like impl for the Blob class. Reads (copies) up to nLen
13181388
** bytes from pIn, starting at position pIn->iCursor, and copies them
13191389
--- src/blob.c
+++ src/blob.c
@@ -477,10 +477,29 @@
477 void blob_resize(Blob *pBlob, unsigned int newSize){
478 pBlob->xRealloc(pBlob, newSize+1);
479 pBlob->nUsed = newSize;
480 pBlob->aData[newSize] = 0;
481 }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
482
483 /*
484 ** Make sure a blob is nul-terminated and is not a pointer to unmanaged
485 ** space. Return a pointer to the data.
486 */
@@ -1167,11 +1186,10 @@
1167 blob_reset(&b3);
1168 }
1169 fossil_print("ok\n");
1170 }
1171
1172 #if defined(_WIN32) || defined(__CYGWIN__)
1173 /*
1174 ** Convert every \n character in the given blob into \r\n.
1175 */
1176 void blob_add_cr(Blob *p){
1177 char *z = p->aData;
@@ -1191,11 +1209,10 @@
1191 if( (z[--j] = z[--i]) =='\n' ){
1192 z[--j] = '\r';
1193 }
1194 }
1195 }
1196 #endif
1197
1198 /*
1199 ** Remove every \r character from the given blob, replacing each one with
1200 ** a \n character if it was not already part of a \r\n pair.
1201 */
@@ -1284,35 +1301,88 @@
1284 char c;
1285 int needEscape = 0;
1286 int n = blob_size(pBlob);
1287 char *z = blob_buffer(pBlob);
1288 #if defined(_WIN32)
 
1289 const char cQuote = '"'; /* Use "..." quoting on windows */
 
1290 #else
 
1291 const char cQuote = '\''; /* Use '...' quoting on unix */
 
1292 #endif
1293
1294 for(i=0; (c = zIn[i])!=0; i++){
1295 if( c==cQuote || (unsigned char)c<' ' ||
1296 c=='\\' || c==';' || c=='*' || c=='?' || c=='[' ){
1297 Blob bad;
1298 blob_token(pBlob, &bad);
1299 fossil_fatal("the [%s] argument to the \"%s\" command contains "
1300 "a character (ascii 0x%02x) that is a security risk",
1301 zIn, blob_str(&bad), c);
1302 }
1303 if( !needEscape && !fossil_isalnum(c) && c!='/' && c!='.' && c!='_' ){
1304 needEscape = 1;
1305 }
1306 }
1307 if( n>0 && !fossil_isspace(z[n-1]) ){
1308 blob_append_char(pBlob, ' ');
1309 }
1310 if( needEscape ) blob_append_char(pBlob, cQuote);
1311 if( zIn[0]=='-' ) blob_append(pBlob, "./", 2);
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1312 blob_append(pBlob, zIn, -1);
1313 if( needEscape ) blob_append_char(pBlob, cQuote);
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1314 }
1315
1316 /*
1317 ** A read(2)-like impl for the Blob class. Reads (copies) up to nLen
1318 ** bytes from pIn, starting at position pIn->iCursor, and copies them
1319
--- src/blob.c
+++ src/blob.c
@@ -477,10 +477,29 @@
477 void blob_resize(Blob *pBlob, unsigned int newSize){
478 pBlob->xRealloc(pBlob, newSize+1);
479 pBlob->nUsed = newSize;
480 pBlob->aData[newSize] = 0;
481 }
482
483 /*
484 ** Ensures that the given blob has at least the given amount of memory
485 ** allocated to it. Does not modify pBlob->nUsed nor will it reduce
486 ** the currently-allocated amount of memory.
487 **
488 ** For semantic compatibility with blob_append_full(), if newSize is
489 ** >=0x7fff000 (~2GB) then this function will trigger blob_panic(). If
490 ** it didn't, it would be possible to bypass that hard-coded limit via
491 ** this function.
492 */
493 void blob_reserve(Blob *pBlob, unsigned int newSize){
494 if(newSize>=0x7fff0000 ){
495 blob_panic();
496 }else if(newSize>pBlob->nUsed){
497 pBlob->xRealloc(pBlob, newSize);
498 pBlob->aData[newSize] = 0;
499 }
500 }
501
502 /*
503 ** Make sure a blob is nul-terminated and is not a pointer to unmanaged
504 ** space. Return a pointer to the data.
505 */
@@ -1167,11 +1186,10 @@
1186 blob_reset(&b3);
1187 }
1188 fossil_print("ok\n");
1189 }
1190
 
1191 /*
1192 ** Convert every \n character in the given blob into \r\n.
1193 */
1194 void blob_add_cr(Blob *p){
1195 char *z = p->aData;
@@ -1191,11 +1209,10 @@
1209 if( (z[--j] = z[--i]) =='\n' ){
1210 z[--j] = '\r';
1211 }
1212 }
1213 }
 
1214
1215 /*
1216 ** Remove every \r character from the given blob, replacing each one with
1217 ** a \n character if it was not already part of a \r\n pair.
1218 */
@@ -1284,35 +1301,88 @@
1301 char c;
1302 int needEscape = 0;
1303 int n = blob_size(pBlob);
1304 char *z = blob_buffer(pBlob);
1305 #if defined(_WIN32)
1306 const char cDirSep = '\\'; /* Use \ as directory separator */
1307 const char cQuote = '"'; /* Use "..." quoting on windows */
1308 const char cEscape = '^'; /* Use ^X escaping on windows */
1309 #else
1310 const char cDirSep = '/'; /* Use / as directory separator */
1311 const char cQuote = '\''; /* Use '...' quoting on unix */
1312 const char cEscape = '\\'; /* Use \X escaping on unix */
1313 #endif
1314
1315 for(i=0; (c = zIn[i])!=0; i++){
1316 if( c==cQuote || (unsigned char)c<' ' ||
1317 c==cEscape || c==';' || c=='*' || c=='?' || c=='[' ){
1318 Blob bad;
1319 blob_token(pBlob, &bad);
1320 fossil_fatal("the [%s] argument to the \"%s\" command contains "
1321 "a character (ascii 0x%02x) that is a security risk",
1322 zIn, blob_str(&bad), c);
1323 }
1324 if( !needEscape && !fossil_isalnum(c) && c!=cDirSep && c!='.' && c!='_' ){
1325 needEscape = 1;
1326 }
1327 }
1328 if( n>0 && !fossil_isspace(z[n-1]) ){
1329 blob_append_char(pBlob, ' ');
1330 }
1331 if( needEscape ) blob_append_char(pBlob, cQuote);
1332 if( zIn[0]=='-' ){
1333 blob_append_char(pBlob, '.');
1334 blob_append_char(pBlob, cDirSep);
1335 #if defined(_WIN32)
1336 }else if( zIn[0]=='/' ){
1337 blob_append_char(pBlob, '.');
1338 #endif
1339 }
1340 #if defined(_WIN32)
1341 if( needEscape ){
1342 for(i=0; (c = zIn[i])!=0; i++){
1343 if( c==cQuote ) blob_append_char(pBlob, cDirSep);
1344 blob_append_char(pBlob, c);
1345 }
1346 }else{
1347 blob_append(pBlob, zIn, -1);
1348 }
1349 #else
1350 blob_append(pBlob, zIn, -1);
1351 #endif
1352 if( needEscape ){
1353 #if defined(_WIN32)
1354 /* NOTE: Trailing backslash must be doubled before final double quote. */
1355 if( pBlob->aData[pBlob->nUsed-1]==cDirSep ){
1356 blob_append_char(pBlob, cDirSep);
1357 }
1358 #endif
1359 blob_append_char(pBlob, cQuote);
1360 }
1361 }
1362
1363 /*
1364 ** COMMAND: test-escaped-arg
1365 **
1366 ** Usage %fossil ARG ...
1367 **
1368 ** Run each argment through blob_append_escaped_arg() and show the
1369 ** result. Append each argument to "fossil test-echo" and run that
1370 ** using fossil_system() to verify that it really does get escaped
1371 ** correctly.
1372 */
1373 void test_escaped_arg__cmd(void){
1374 int i;
1375 Blob x;
1376 blob_init(&x, 0, 0);
1377 for(i=2; i<g.argc; i++){
1378 fossil_print("%3d [%s]: ", i, g.argv[i]);
1379 blob_appendf(&x, "fossil test-echo %$", g.argv[i]);
1380 fossil_print("%s\n", blob_str(&x));
1381 fossil_system(blob_str(&x));
1382 blob_reset(&x);
1383 }
1384 }
1385
1386 /*
1387 ** A read(2)-like impl for the Blob class. Reads (copies) up to nLen
1388 ** bytes from pIn, starting at position pIn->iCursor, and copies them
1389
+21 -13
--- src/branch.c
+++ src/branch.c
@@ -18,10 +18,24 @@
1818
** This file contains code used to create new branches within a repository.
1919
*/
2020
#include "config.h"
2121
#include "branch.h"
2222
#include <assert.h>
23
+
24
+/*
25
+** Return true if zBr is the branch name associated with check-in with
26
+** blob.uuid value of zUuid
27
+*/
28
+int branch_includes_uuid(const char *zBr, const char *zUuid){
29
+ return db_exists(
30
+ "SELECT 1 FROM tagxref, blob"
31
+ " WHERE blob.uuid=%Q AND tagxref.rid=blob.rid"
32
+ " AND tagxref.value=%Q AND tagxref.tagtype>0"
33
+ " AND tagxref.tagid=%d",
34
+ zUuid, zBr, TAG_BRANCH
35
+ );
36
+}
2337
2438
/*
2539
** If RID refers to a check-in, return the name of the branch for that
2640
** check-in.
2741
**
@@ -144,11 +158,10 @@
144158
blob_appendf(&branch, "T *bgcolor * %F\n", zColor);
145159
}
146160
blob_appendf(&branch, "T *branch * %F\n", zBranch);
147161
blob_appendf(&branch, "T *sym-%F *\n", zBranch);
148162
if( isPrivate ){
149
- blob_appendf(&branch, "T +private *\n");
150163
noSign = 1;
151164
}
152165
153166
/* Cancel all other symbolic tags */
154167
db_prepare(&q,
@@ -245,11 +258,11 @@
245258
@ GROUP BY 1;
246259
;
247260
248261
/* Call this routine to create the TEMP table */
249262
static void brlist_create_temp_table(void){
250
- db_multi_exec(createBrlistQuery/*works-like:""*/);
263
+ db_exec_sql(createBrlistQuery);
251264
}
252265
253266
254267
#if INTERFACE
255268
/*
@@ -334,27 +347,27 @@
334347
** Usage: %fossil branch SUBCOMMAND ... ?OPTIONS?
335348
**
336349
** Run various subcommands to manage branches of the open repository or
337350
** of the repository identified by the -R or --repository option.
338351
**
339
-** fossil branch current
352
+** > fossil branch current
340353
**
341354
** Print the name of the branch for the current check-out
342355
**
343
-** fossil branch info BRANCH-NAME
356
+** > fossil branch info BRANCH-NAME
344357
**
345358
** Print information about a branch
346359
**
347
-** fossil branch list|ls ?OPTIONS?
360
+** > fossil branch list|ls ?OPTIONS?
348361
**
349362
** List all branches. Options:
350363
** -a|--all List all branches. Default show only open branches
351364
** -c|--closed List closed branches.
352365
** -r Reverse the sort order
353366
** -t Show recently changed branches first
354367
**
355
-** fossil branch new BRANCH-NAME BASIS ?OPTIONS?
368
+** > fossil branch new BRANCH-NAME BASIS ?OPTIONS?
356369
**
357370
** Create a new branch BRANCH-NAME off of check-in BASIS.
358371
** Supported options for this subcommand include:
359372
** --private branch is private (i.e., remains local)
360373
** --bgcolor COLOR use COLOR instead of automatic background
@@ -366,18 +379,13 @@
366379
** year-month-day form, it may be truncated, the "T" may be
367380
** replaced by a space, and it may also name a timezone offset
368381
** from UTC as "-HH:MM" (westward) or "+HH:MM" (eastward).
369382
** Either no timezone suffix or "Z" means UTC.
370383
**
371
-** Options:
372
-** -R|--repository FILE Run commands on repository FILE
384
+** Options valid for all subcommands:
373385
**
374
-** Summary:
375
-** fossil branch current
376
-** fossil branch info BRANCHNAME
377
-** fossil branch [list|ls]
378
-** fossil branch new
386
+** -R|--repository FILE Run commands on repository FILE
379387
*/
380388
void branch_cmd(void){
381389
int n;
382390
const char *zCmd = "list";
383391
db_find_and_open_repository(0, 0);
384392
--- src/branch.c
+++ src/branch.c
@@ -18,10 +18,24 @@
18 ** This file contains code used to create new branches within a repository.
19 */
20 #include "config.h"
21 #include "branch.h"
22 #include <assert.h>
 
 
 
 
 
 
 
 
 
 
 
 
 
 
23
24 /*
25 ** If RID refers to a check-in, return the name of the branch for that
26 ** check-in.
27 **
@@ -144,11 +158,10 @@
144 blob_appendf(&branch, "T *bgcolor * %F\n", zColor);
145 }
146 blob_appendf(&branch, "T *branch * %F\n", zBranch);
147 blob_appendf(&branch, "T *sym-%F *\n", zBranch);
148 if( isPrivate ){
149 blob_appendf(&branch, "T +private *\n");
150 noSign = 1;
151 }
152
153 /* Cancel all other symbolic tags */
154 db_prepare(&q,
@@ -245,11 +258,11 @@
245 @ GROUP BY 1;
246 ;
247
248 /* Call this routine to create the TEMP table */
249 static void brlist_create_temp_table(void){
250 db_multi_exec(createBrlistQuery/*works-like:""*/);
251 }
252
253
254 #if INTERFACE
255 /*
@@ -334,27 +347,27 @@
334 ** Usage: %fossil branch SUBCOMMAND ... ?OPTIONS?
335 **
336 ** Run various subcommands to manage branches of the open repository or
337 ** of the repository identified by the -R or --repository option.
338 **
339 ** fossil branch current
340 **
341 ** Print the name of the branch for the current check-out
342 **
343 ** fossil branch info BRANCH-NAME
344 **
345 ** Print information about a branch
346 **
347 ** fossil branch list|ls ?OPTIONS?
348 **
349 ** List all branches. Options:
350 ** -a|--all List all branches. Default show only open branches
351 ** -c|--closed List closed branches.
352 ** -r Reverse the sort order
353 ** -t Show recently changed branches first
354 **
355 ** fossil branch new BRANCH-NAME BASIS ?OPTIONS?
356 **
357 ** Create a new branch BRANCH-NAME off of check-in BASIS.
358 ** Supported options for this subcommand include:
359 ** --private branch is private (i.e., remains local)
360 ** --bgcolor COLOR use COLOR instead of automatic background
@@ -366,18 +379,13 @@
366 ** year-month-day form, it may be truncated, the "T" may be
367 ** replaced by a space, and it may also name a timezone offset
368 ** from UTC as "-HH:MM" (westward) or "+HH:MM" (eastward).
369 ** Either no timezone suffix or "Z" means UTC.
370 **
371 ** Options:
372 ** -R|--repository FILE Run commands on repository FILE
373 **
374 ** Summary:
375 ** fossil branch current
376 ** fossil branch info BRANCHNAME
377 ** fossil branch [list|ls]
378 ** fossil branch new
379 */
380 void branch_cmd(void){
381 int n;
382 const char *zCmd = "list";
383 db_find_and_open_repository(0, 0);
384
--- src/branch.c
+++ src/branch.c
@@ -18,10 +18,24 @@
18 ** This file contains code used to create new branches within a repository.
19 */
20 #include "config.h"
21 #include "branch.h"
22 #include <assert.h>
23
24 /*
25 ** Return true if zBr is the branch name associated with check-in with
26 ** blob.uuid value of zUuid
27 */
28 int branch_includes_uuid(const char *zBr, const char *zUuid){
29 return db_exists(
30 "SELECT 1 FROM tagxref, blob"
31 " WHERE blob.uuid=%Q AND tagxref.rid=blob.rid"
32 " AND tagxref.value=%Q AND tagxref.tagtype>0"
33 " AND tagxref.tagid=%d",
34 zUuid, zBr, TAG_BRANCH
35 );
36 }
37
38 /*
39 ** If RID refers to a check-in, return the name of the branch for that
40 ** check-in.
41 **
@@ -144,11 +158,10 @@
158 blob_appendf(&branch, "T *bgcolor * %F\n", zColor);
159 }
160 blob_appendf(&branch, "T *branch * %F\n", zBranch);
161 blob_appendf(&branch, "T *sym-%F *\n", zBranch);
162 if( isPrivate ){
 
163 noSign = 1;
164 }
165
166 /* Cancel all other symbolic tags */
167 db_prepare(&q,
@@ -245,11 +258,11 @@
258 @ GROUP BY 1;
259 ;
260
261 /* Call this routine to create the TEMP table */
262 static void brlist_create_temp_table(void){
263 db_exec_sql(createBrlistQuery);
264 }
265
266
267 #if INTERFACE
268 /*
@@ -334,27 +347,27 @@
347 ** Usage: %fossil branch SUBCOMMAND ... ?OPTIONS?
348 **
349 ** Run various subcommands to manage branches of the open repository or
350 ** of the repository identified by the -R or --repository option.
351 **
352 ** > fossil branch current
353 **
354 ** Print the name of the branch for the current check-out
355 **
356 ** > fossil branch info BRANCH-NAME
357 **
358 ** Print information about a branch
359 **
360 ** > fossil branch list|ls ?OPTIONS?
361 **
362 ** List all branches. Options:
363 ** -a|--all List all branches. Default show only open branches
364 ** -c|--closed List closed branches.
365 ** -r Reverse the sort order
366 ** -t Show recently changed branches first
367 **
368 ** > fossil branch new BRANCH-NAME BASIS ?OPTIONS?
369 **
370 ** Create a new branch BRANCH-NAME off of check-in BASIS.
371 ** Supported options for this subcommand include:
372 ** --private branch is private (i.e., remains local)
373 ** --bgcolor COLOR use COLOR instead of automatic background
@@ -366,18 +379,13 @@
379 ** year-month-day form, it may be truncated, the "T" may be
380 ** replaced by a space, and it may also name a timezone offset
381 ** from UTC as "-HH:MM" (westward) or "+HH:MM" (eastward).
382 ** Either no timezone suffix or "Z" means UTC.
383 **
384 ** Options valid for all subcommands:
 
385 **
386 ** -R|--repository FILE Run commands on repository FILE
 
 
 
 
387 */
388 void branch_cmd(void){
389 int n;
390 const char *zCmd = "list";
391 db_find_and_open_repository(0, 0);
392
+150 -80
--- src/browse.c
+++ src/browse.c
@@ -59,10 +59,18 @@
5959
zOut = sqlite3_mprintf("/%.*s", i-n, &z[n]);
6060
sqlite3_result_text(context, zOut, i-n+1, sqlite3_free);
6161
}
6262
}
6363
64
+/*
65
+** Flag arguments for hyperlinked_path()
66
+*/
67
+#if INTERFACE
68
+# define LINKPATH_FINFO 0x0001 /* Link final term to /finfo */
69
+# define LINKPATH_FILE 0x0002 /* Link final term to /file */
70
+#endif
71
+
6472
/*
6573
** Given a pathname which is a relative path from the root of
6674
** the repository to a file or directory, compute a string which
6775
** is an HTML rendering of that path with hyperlinks on each
6876
** directory component of the path where the hyperlink redirects
@@ -76,29 +84,36 @@
7684
void hyperlinked_path(
7785
const char *zPath, /* Path to render */
7886
Blob *pOut, /* Write into this blob */
7987
const char *zCI, /* check-in name, or NULL */
8088
const char *zURI, /* "dir" or "tree" */
81
- const char *zREx /* Extra query parameters */
89
+ const char *zREx, /* Extra query parameters */
90
+ unsigned int mFlags /* Extra flags */
8291
){
8392
int i, j;
8493
char *zSep = "";
8594
8695
for(i=0; zPath[i]; i=j){
8796
for(j=i; zPath[j] && zPath[j]!='/'; j++){}
88
- if( zPath[j] && g.perm.Hyperlink ){
89
- if( zCI ){
90
- char *zLink = href("%R/%s?name=%#T%s&ci=%!S", zURI, j, zPath, zREx,zCI);
91
- blob_appendf(pOut, "%s%z%#h</a>",
92
- zSep, zLink, j-i, &zPath[i]);
93
- }else{
94
- char *zLink = href("%R/%s?name=%#T%s", zURI, j, zPath, zREx);
95
- blob_appendf(pOut, "%s%z%#h</a>",
96
- zSep, zLink, j-i, &zPath[i]);
97
- }
98
- }else{
99
- blob_appendf(pOut, "%s%#h", zSep, j-i, &zPath[i]);
97
+ if( zPath[j]==0 ){
98
+ if( mFlags & LINKPATH_FILE ){
99
+ zURI = "file";
100
+ }else if( mFlags & LINKPATH_FINFO ){
101
+ zURI = "finfo";
102
+ }else{
103
+ blob_appendf(pOut, "/%h", zPath+i);
104
+ break;
105
+ }
106
+ }
107
+ if( zCI ){
108
+ char *zLink = href("%R/%s?name=%#T%s&ci=%T", zURI, j, zPath, zREx,zCI);
109
+ blob_appendf(pOut, "%s%z%#h</a>",
110
+ zSep, zLink, j-i, &zPath[i]);
111
+ }else{
112
+ char *zLink = href("%R/%s?name=%#T%s", zURI, j, zPath, zREx);
113
+ blob_appendf(pOut, "%s%z%#h</a>",
114
+ zSep, zLink, j-i, &zPath[i]);
100115
}
101116
zSep = "/";
102117
while( zPath[j]=='/' ){ j++; }
103118
}
104119
}
@@ -122,33 +137,29 @@
122137
*/
123138
void page_dir(void){
124139
char *zD = fossil_strdup(P("name"));
125140
int nD = zD ? strlen(zD)+1 : 0;
126141
int mxLen;
127
- int n;
128142
char *zPrefix;
129143
Stmt q;
130144
const char *zCI = P("ci");
131145
int rid = 0;
132146
char *zUuid = 0;
133
- Blob dirname;
134147
Manifest *pM = 0;
135148
const char *zSubdirLink;
136149
int linkTrunk = 1;
137150
int linkTip = 1;
138151
HQuery sURI;
152
+ int isSymbolicCI = 0; /* ci= is symbolic name, not a hash prefix */
153
+ int isBranchCI = 0; /* True if ci= refers to a branch name */
154
+ char *zHeader = 0;
139155
156
+ if( zCI && strlen(zCI)==0 ){ zCI = 0; }
140157
if( strcmp(PD("type","flat"),"tree")==0 ){ page_tree(); return; }
141158
login_check_credentials();
142159
if( !g.perm.Read ){ login_needed(g.anon.Read); return; }
143160
while( nD>1 && zD[nD-2]=='/' ){ zD[(--nD)-1] = 0; }
144
- style_header("File List");
145
- style_adunit_config(ADUNIT_RIGHT_OK);
146
- sqlite3_create_function(g.db, "pathelement", 2, SQLITE_UTF8, 0,
147
- pathelementFunc, 0, 0);
148
- url_initialize(&sURI, "dir");
149
- cgi_query_parameters_to_url(&sURI);
150161
151162
/* If the name= parameter is an empty string, make it a NULL pointer */
152163
if( zD && strlen(zD)==0 ){ zD = 0; }
153164
154165
/* If a specific check-in is requested, fetch and parse it. If the
@@ -160,53 +171,80 @@
160171
if( pM ){
161172
int trunkRid = symbolic_name_to_rid("tag:trunk", "ci");
162173
linkTrunk = trunkRid && rid != trunkRid;
163174
linkTip = rid != symbolic_name_to_rid("tip", "ci");
164175
zUuid = db_text(0, "SELECT uuid FROM blob WHERE rid=%d", rid);
176
+ isSymbolicCI = (sqlite3_strnicmp(zUuid, zCI, strlen(zCI))!=0);
177
+ isBranchCI = branch_includes_uuid(zCI, zUuid);
178
+ Th_Store("current_checkin", zCI);
165179
}else{
166180
zCI = 0;
167181
}
168182
}
169183
184
+ assert( isSymbolicCI==0 || (zCI!=0 && zCI[0]!=0) );
185
+ if( zD==0 ){
186
+ if( zCI ){
187
+ zHeader = mprintf("Top-level Files of %s", zCI);
188
+ }else{
189
+ zHeader = mprintf("All Top-level Files");
190
+ }
191
+ }else{
192
+ if( zCI ){
193
+ zHeader = mprintf("Files in %s/ of %s", zD, zCI);
194
+ }else{
195
+ zHeader = mprintf("All File in %s/", zD);
196
+ }
197
+ }
198
+ style_header("%s", zHeader);
199
+ fossil_free(zHeader);
200
+ style_adunit_config(ADUNIT_RIGHT_OK);
201
+ sqlite3_create_function(g.db, "pathelement", 2, SQLITE_UTF8, 0,
202
+ pathelementFunc, 0, 0);
203
+ url_initialize(&sURI, "dir");
204
+ cgi_query_parameters_to_url(&sURI);
205
+
170206
/* Compute the title of the page */
171
- blob_zero(&dirname);
172207
if( zD ){
173
- blob_append(&dirname, "in directory ", -1);
174
- hyperlinked_path(zD, &dirname, zCI, "dir", "");
208
+ Blob dirname;
209
+ blob_init(&dirname, 0, 0);
210
+ hyperlinked_path(zD, &dirname, zCI, "dir", "", 0);
211
+ @ <h2>Files in directory %s(blob_str(&dirname)) \
212
+ blob_reset(&dirname);
175213
zPrefix = mprintf("%s/", zD);
176214
style_submenu_element("Top-Level", "%s",
177215
url_render(&sURI, "name", 0, 0, 0));
178216
}else{
179
- blob_append(&dirname, "in the top-level directory", -1);
217
+ @ <h2>Files in the top-level directory \
180218
zPrefix = "";
181219
}
220
+ if( zCI ){
221
+ if( fossil_strcmp(zCI,"tip")==0 ){
222
+ @ from the %z(href("%R/info?name=%T",zCI))latest check-in</a></h2>
223
+ }else if( isBranchCI ){
224
+ @ from the %z(href("%R/info?name=%T",zCI))latest check-in</a> \
225
+ @ of branch %z(href("%R/timeline?r=%T",zCI))%h(zCI)</a></h2>
226
+ }else {
227
+ @ of check-in %z(href("%R/info?name=%T",zCI))%h(zCI)</a></h2>
228
+ }
229
+ zSubdirLink = mprintf("%R/dir?ci=%T&name=%T", zCI, zPrefix);
230
+ if( nD==0 ){
231
+ style_submenu_element("File Ages", "%R/fileage?name=%T", zCI);
232
+ }
233
+ }else{
234
+ @ in any check-in</h2>
235
+ zSubdirLink = mprintf("%R/dir?name=%T", zPrefix);
236
+ }
182237
if( linkTrunk ){
183238
style_submenu_element("Trunk", "%s",
184239
url_render(&sURI, "ci", "trunk", 0, 0));
185240
}
186241
if( linkTip ){
187242
style_submenu_element("Tip", "%s", url_render(&sURI, "ci", "tip", 0, 0));
188243
}
189
- if( zCI ){
190
- @ <h2>Files of check-in [%z(href("vinfo?name=%!S",zUuid))%S(zUuid)</a>]
191
- @ %s(blob_str(&dirname))
192
- if( zD ){
193
- @ &nbsp;&nbsp;%z(href("%R/timeline?chng=%T/*", zD))[history]</a>
194
- }
195
- @ </h2>
196
- zSubdirLink = mprintf("%R/dir?ci=%!S&name=%T", zUuid, zPrefix);
197
- if( nD==0 ){
198
- style_submenu_element("File Ages", "%R/fileage?name=%!S", zUuid);
199
- }
200
- }else{
201
- @ <h2>The union of all files from all check-ins
202
- @ %s(blob_str(&dirname))
203
- if( zD ){
204
- @ &nbsp;&nbsp;%z(href("%R/timeline?chng=%T/*", zD))[history]</a>
205
- }
206
- @ </h2>
207
- zSubdirLink = mprintf("%R/dir?name=%T", zPrefix);
244
+ if( zD ){
245
+ style_submenu_element("History","%R/timeline?chng=%T/*", zD);
208246
}
209247
style_submenu_element("All", "%s", url_render(&sURI, "ci", 0, 0, 0));
210248
style_submenu_element("Tree-View", "%s",
211249
url_render(&sURI, "type", "tree", 0, 0));
212250
@@ -269,15 +307,14 @@
269307
270308
/* Generate a multi-column table listing the contents of zD[]
271309
** directory.
272310
*/
273311
mxLen = db_int(12, "SELECT max(length(x)) FROM localfiles /*scan*/");
274
- n = db_int(1,"SELECT count(*) FROM localfiles; /*scan*/");
275312
if( mxLen<12 ) mxLen = 12;
276313
mxLen += (mxLen+9)/10;
277314
db_prepare(&q, "SELECT x, u FROM localfiles ORDER BY x /*scan*/");
278
- @ <div class="columns" style="columns: %d(mxLen)ex %d(n);">
315
+ @ <div class="columns files" style="columns: %d(mxLen)ex auto">
279316
@ <ul class="browser">
280317
while( db_step(&q)==SQLITE_ROW ){
281318
const char *zFN;
282319
zFN = db_column_text(&q, 0);
283320
if( zFN[0]=='/' ){
@@ -284,12 +321,11 @@
284321
zFN++;
285322
@ <li class="dir">%z(href("%s%T",zSubdirLink,zFN))%h(zFN)</a></li>
286323
}else{
287324
const char *zLink;
288325
if( zCI ){
289
- const char *zUuid = db_column_text(&q, 1);
290
- zLink = href("%R/artifact/%!S",zUuid);
326
+ zLink = href("%R/file?name=%T%T&ci=%T",zPrefix,zFN,zCI);
291327
}else{
292328
zLink = href("%R/finfo?name=%T%T",zPrefix,zFN);
293329
}
294330
@ <li class="%z(fileext_class(zFN))">%z(zLink)%h(zFN)</a></li>
295331
}
@@ -354,10 +390,11 @@
354390
@ </iframe>
355391
}else{
356392
Blob content;
357393
const char *zMime = mimetype_from_name(zName);
358394
content_get(rid, &content);
395
+ safe_html_context(DOCSRC_FILE);
359396
wiki_render_by_mimetype(&content, zMime);
360397
}
361398
}
362399
}
363400
db_finalize(&q);
@@ -614,11 +651,15 @@
614651
HQuery sURI; /* Hyperlink */
615652
int startExpanded; /* True to start out with the tree expanded */
616653
int showDirOnly; /* Show directories only. Omit files */
617654
int nDir = 0; /* Number of directories. Used for ID attributes */
618655
char *zProjectName = db_get("project-name", 0);
656
+ int isSymbolicCI = 0; /* ci= is a symbolic name, not a hash prefix */
657
+ int isBranchCI = 0; /* ci= refers to a branch name */
658
+ char *zHeader = 0;
619659
660
+ if( zCI && strlen(zCI)==0 ){ zCI = 0; }
620661
if( strcmp(PD("type","flat"),"flat")==0 ){ page_dir(); return; }
621662
memset(&sTree, 0, sizeof(sTree));
622663
login_check_credentials();
623664
if( !g.perm.Read ){ login_needed(g.anon.Read); return; }
624665
while( nD>1 && zD[nD-2]=='/' ){ zD[(--nD)-1] = 0; }
@@ -626,14 +667,12 @@
626667
pathelementFunc, 0, 0);
627668
url_initialize(&sURI, "tree");
628669
cgi_query_parameters_to_url(&sURI);
629670
if( PB("nofiles") ){
630671
showDirOnly = 1;
631
- style_header("Folder Hierarchy");
632672
}else{
633673
showDirOnly = 0;
634
- style_header("File Tree");
635674
}
636675
style_adunit_config(ADUNIT_RIGHT_OK);
637676
if( PB("expand") ){
638677
startExpanded = 1;
639678
}else{
@@ -662,37 +701,55 @@
662701
linkTip = rid != symbolic_name_to_rid("tip", "ci");
663702
zUuid = db_text(0, "SELECT uuid FROM blob WHERE rid=%d", rid);
664703
rNow = db_double(0.0, "SELECT mtime FROM event WHERE objid=%d", rid);
665704
zNow = db_text("", "SELECT datetime(mtime,toLocal())"
666705
" FROM event WHERE objid=%d", rid);
706
+ isSymbolicCI = (sqlite3_strnicmp(zUuid, zCI, strlen(zCI)) != 0);
707
+ isBranchCI = branch_includes_uuid(zCI, zUuid);
708
+ Th_Store("current_checkin", zCI);
667709
}else{
668710
zCI = 0;
669711
}
670712
}
671713
if( zCI==0 ){
672714
rNow = db_double(0.0, "SELECT max(mtime) FROM event");
673715
zNow = db_text("", "SELECT datetime(max(mtime),toLocal()) FROM event");
674716
}
717
+
718
+ assert( isSymbolicCI==0 || (zCI!=0 && zCI[0]!=0) );
719
+ if( zD==0 ){
720
+ if( zCI ){
721
+ zHeader = mprintf("Top-level Files of %s", zCI);
722
+ }else{
723
+ zHeader = mprintf("All Top-level Files");
724
+ }
725
+ }else{
726
+ if( zCI ){
727
+ zHeader = mprintf("Files in %s/ of %s", zD, zCI);
728
+ }else{
729
+ zHeader = mprintf("All File in %s/", zD);
730
+ }
731
+ }
732
+ style_header("%s", zHeader);
733
+ fossil_free(zHeader);
675734
676735
/* Compute the title of the page */
677736
blob_zero(&dirname);
678737
if( zD ){
679738
blob_append(&dirname, "within directory ", -1);
680
- hyperlinked_path(zD, &dirname, zCI, "tree", zREx);
739
+ hyperlinked_path(zD, &dirname, zCI, "tree", zREx, 0);
681740
if( zRE ) blob_appendf(&dirname, " matching \"%s\"", zRE);
682741
style_submenu_element("Top-Level", "%s",
683742
url_render(&sURI, "name", 0, 0, 0));
684
- }else{
685
- if( zRE ){
686
- blob_appendf(&dirname, "matching \"%s\"", zRE);
687
- }
743
+ }else if( zRE ){
744
+ blob_appendf(&dirname, "matching \"%s\"", zRE);
688745
}
689746
style_submenu_binary("mtime","Sort By Time","Sort By Filename", 0);
690747
if( zCI ){
691748
style_submenu_element("All", "%s", url_render(&sURI, "ci", 0, 0, 0));
692749
if( nD==0 && !showDirOnly ){
693
- style_submenu_element("File Ages", "%R/fileage?name=%s", zUuid);
750
+ style_submenu_element("File Ages", "%R/fileage?name=%T", zCI);
694751
}
695752
}
696753
if( linkTrunk ){
697754
style_submenu_element("Trunk", "%s",
698755
url_render(&sURI, "ci", "trunk", 0, 0));
@@ -747,10 +804,11 @@
747804
tree_add_node(&sTree, zName, zUuid, mtime);
748805
nFile++;
749806
}
750807
db_finalize(&q);
751808
}
809
+ style_submenu_checkbox("nofiles", "Folders Only", 0, 0);
752810
753811
if( showDirOnly ){
754812
for(nFile=0, p=sTree.pFirst; p; p=p->pNext){
755813
if( p->pChild!=0 && p->nFullName>nD ) nFile++;
756814
}
@@ -757,18 +815,24 @@
757815
zObjType = "Folders";
758816
}else{
759817
zObjType = "Files";
760818
}
761819
762
- style_submenu_checkbox("nofiles", "Folders Only", 0, 0);
763
-
764
- if( zCI ){
765
- @ <h2>%s(zObjType) from
766
- if( sqlite3_strnicmp(zCI, zUuid, (int)strlen(zCI))!=0 ){
767
- @ "%h(zCI)"
768
- }
769
- @ [%z(href("vinfo?name=%!S",zUuid))%S(zUuid)</a>] %s(blob_str(&dirname))
820
+ if( zCI && strcmp(zCI,"tip")==0 ){
821
+ @ <h2>%s(zObjType) in the %z(href("%R/info?name=tip"))latest check-in</a>
822
+ }else if( isBranchCI ){
823
+ @ <h2>%s(zObjType) in the %z(href("%R/info?name=%T",zCI))latest check-in\
824
+ @ </a> for branch %z(href("%R/timeline?r=%T",zCI))%h(zCI)</a>
825
+ if( blob_size(&dirname) ){
826
+ @ and %s(blob_str(&dirname))</h2>
827
+ }
828
+ }else if( zCI ){
829
+ @ <h2>%s(zObjType) for check-in \
830
+ @ %z(href("%R/info?name=%T",zCI))%h(zCI)</a></h2>
831
+ if( blob_size(&dirname) ){
832
+ @ and %s(blob_str(&dirname))</h2>
833
+ }
770834
}else{
771835
int n = db_int(0, "SELECT count(*) FROM plink");
772836
@ <h2>%s(zObjType) from all %d(n) check-ins %s(blob_str(&dirname))
773837
}
774838
if( useMtime ){
@@ -826,11 +890,11 @@
826890
nDir++;
827891
}else if( !showDirOnly ){
828892
const char *zFileClass = fileext_class(p->zName);
829893
char *zLink;
830894
if( zCI ){
831
- zLink = href("%R/artifact/%!S",p->zUuid);
895
+ zLink = href("%R/file?name=%T&ci=%T",p->zFullName,zCI);
832896
}else{
833897
zLink = href("%R/finfo?name=%T",p->zFullName);
834898
}
835899
@ <li class="%z(zFileClass)%s(zLastClass)"><div class="filetreeline">
836900
@ %z(zLink)%h(p->zName)</a>
@@ -847,11 +911,11 @@
847911
}
848912
}
849913
}
850914
@ </ul>
851915
@ </ul></div>
852
- style_load_one_js_file("tree.js");
916
+ builtin_request_js("tree.js");
853917
style_footer();
854918
855919
/* We could free memory used by sTree here if we needed to. But
856920
** the process is about to exit, so doing so would not really accomplish
857921
** anything useful. */
@@ -920,11 +984,11 @@
920984
** mtime on that check-in. If zGlob and *zGlob then only files matching
921985
** the given glob are computed.
922986
*/
923987
int compute_fileage(int vid, const char* zGlob){
924988
Stmt q;
925
- db_multi_exec(zComputeFileAgeSetup /*works-like:"constant"*/);
989
+ db_exec_sql(zComputeFileAgeSetup);
926990
db_prepare(&q, zComputeFileAgeRun /*works-like:"constant"*/);
927991
db_bind_int(&q, ":ckin", vid);
928992
db_bind_text(&q, ":glob", zGlob && zGlob[0] ? zGlob : "*");
929993
db_exec(&q);
930994
db_finalize(&q);
@@ -1003,10 +1067,11 @@
10031067
int rid;
10041068
const char *zName;
10051069
const char *zGlob;
10061070
const char *zUuid;
10071071
const char *zNow; /* Time of check-in */
1072
+ int isBranchCI; /* name= is a branch name */
10081073
int showId = PB("showid");
10091074
Stmt q1, q2;
10101075
double baseTime;
10111076
login_check_credentials();
10121077
if( !g.perm.Read ){ login_needed(g.anon.Read); return; }
@@ -1016,28 +1081,34 @@
10161081
rid = symbolic_name_to_rid(zName, "ci");
10171082
if( rid==0 ){
10181083
fossil_fatal("not a valid check-in: %s", zName);
10191084
}
10201085
zUuid = db_text("", "SELECT uuid FROM blob WHERE rid=%d", rid);
1086
+ isBranchCI = branch_includes_uuid(zName,zUuid);
10211087
baseTime = db_double(0.0,"SELECT mtime FROM event WHERE objid=%d", rid);
10221088
zNow = db_text("", "SELECT datetime(mtime,toLocal()) FROM event"
10231089
" WHERE objid=%d", rid);
10241090
style_submenu_element("Tree-View", "%R/tree?ci=%T&mtime=1&type=tree", zName);
10251091
style_header("File Ages");
10261092
zGlob = P("glob");
10271093
compute_fileage(rid,zGlob);
10281094
db_multi_exec("CREATE INDEX fileage_ix1 ON fileage(mid,pathname);");
10291095
1030
- @ <h1>Files in
1031
- @ %z(href("%R/info/%!S",zUuid))[%S(zUuid)]</a>
1096
+ if( fossil_strcmp(zName,"tip")==0 ){
1097
+ @ <h1>Files in the %z(href("%R/info?name=tip"))latest check-in</a>
1098
+ }else if( isBranchCI ){
1099
+ @ <h1>Files in the %z(href("%R/info?name=%T",zName))latest check-in</a>
1100
+ @ of branch %z(href("%R/timeline?r=%T",zName))%h(zName)</a>
1101
+ }else{
1102
+ @ <h1>Files in check-in %z(href("%R/info?name=%T",zName))%h(zName)</a>
1103
+ }
10321104
if( zGlob && zGlob[0] ){
10331105
@ that match "%h(zGlob)"
10341106
}
10351107
@ ordered by age</h1>
10361108
@
1037
- @ <p>File ages are expressed relative to the
1038
- @ %z(href("%R/ci/%!S",zUuid))[%S(zUuid)]</a> check-in time of
1109
+ @ <p>File ages are expressed relative to the check-in time of
10391110
@ %z(href("%R/timeline?c=%t",zNow))%s(zNow)</a>.</p>
10401111
@
10411112
@ <div class='fileage'><table>
10421113
@ <tr><th>Age</th><th>Files</th><th>Check-in</th></tr>
10431114
db_prepare(&q1,
@@ -1052,14 +1123,13 @@
10521123
" AND blob.rid=event.objid\n"
10531124
" ORDER BY event.mtime DESC;",
10541125
TAG_BRANCH
10551126
);
10561127
db_prepare(&q2,
1057
- "SELECT blob.uuid, filename.name, fileage.fid\n"
1058
- " FROM fileage, blob, filename\n"
1128
+ "SELECT filename.name, fileage.fid\n"
1129
+ " FROM fileage, filename\n"
10591130
" WHERE fileage.mid=:mid AND filename.fnid=fileage.fnid"
1060
- " AND blob.rid=fileage.fid;"
10611131
);
10621132
while( db_step(&q1)==SQLITE_ROW ){
10631133
double age = baseTime - db_column_double(&q1, 0);
10641134
int mid = db_column_int(&q1, 1);
10651135
const char *zUuid = db_column_text(&q1, 2);
@@ -1069,24 +1139,24 @@
10691139
char *zAge = human_readable_age(age);
10701140
@ <tr><td>%s(zAge)</td>
10711141
@ <td>
10721142
db_bind_int(&q2, ":mid", mid);
10731143
while( db_step(&q2)==SQLITE_ROW ){
1074
- const char *zFUuid = db_column_text(&q2,0);
1075
- const char *zFile = db_column_text(&q2,1);
1076
- int fid = db_column_int(&q2,2);
1144
+ const char *zFile = db_column_text(&q2,0);
1145
+ @ %z(href("%R/file?name=%T&ci=%!S",zFile,zUuid))%h(zFile)</a> \
10771146
if( showId ){
1078
- @ %z(href("%R/artifact/%!S",zFUuid))%h(zFile)</a> (%d(fid))<br />
1147
+ int fid = db_column_int(&q2,1);
1148
+ @ (%d(fid))<br />
10791149
}else{
1080
- @ %z(href("%R/artifact/%!S",zFUuid))%h(zFile)</a><br />
1150
+ @ </a><br />
10811151
}
10821152
}
10831153
db_reset(&q2);
10841154
@ </td>
10851155
@ <td>
10861156
@ %W(zComment)
1087
- @ (check-in:&nbsp;%z(href("%R/ci/%!S",zUuid))%S(zUuid)</a>,
1157
+ @ (check-in:&nbsp;%z(href("%R/info/%!S",zUuid))%S(zUuid)</a>,
10881158
if( showId ){
10891159
@ id: %d(mid)
10901160
}
10911161
@ user:&nbsp;%z(href("%R/timeline?u=%t&c=%!S&nd",zUser,zUuid))%h(zUser)</a>,
10921162
@ branch:&nbsp;\
10931163
--- src/browse.c
+++ src/browse.c
@@ -59,10 +59,18 @@
59 zOut = sqlite3_mprintf("/%.*s", i-n, &z[n]);
60 sqlite3_result_text(context, zOut, i-n+1, sqlite3_free);
61 }
62 }
63
 
 
 
 
 
 
 
 
64 /*
65 ** Given a pathname which is a relative path from the root of
66 ** the repository to a file or directory, compute a string which
67 ** is an HTML rendering of that path with hyperlinks on each
68 ** directory component of the path where the hyperlink redirects
@@ -76,29 +84,36 @@
76 void hyperlinked_path(
77 const char *zPath, /* Path to render */
78 Blob *pOut, /* Write into this blob */
79 const char *zCI, /* check-in name, or NULL */
80 const char *zURI, /* "dir" or "tree" */
81 const char *zREx /* Extra query parameters */
 
82 ){
83 int i, j;
84 char *zSep = "";
85
86 for(i=0; zPath[i]; i=j){
87 for(j=i; zPath[j] && zPath[j]!='/'; j++){}
88 if( zPath[j] && g.perm.Hyperlink ){
89 if( zCI ){
90 char *zLink = href("%R/%s?name=%#T%s&ci=%!S", zURI, j, zPath, zREx,zCI);
91 blob_appendf(pOut, "%s%z%#h</a>",
92 zSep, zLink, j-i, &zPath[i]);
93 }else{
94 char *zLink = href("%R/%s?name=%#T%s", zURI, j, zPath, zREx);
95 blob_appendf(pOut, "%s%z%#h</a>",
96 zSep, zLink, j-i, &zPath[i]);
97 }
98 }else{
99 blob_appendf(pOut, "%s%#h", zSep, j-i, &zPath[i]);
 
 
 
 
 
 
100 }
101 zSep = "/";
102 while( zPath[j]=='/' ){ j++; }
103 }
104 }
@@ -122,33 +137,29 @@
122 */
123 void page_dir(void){
124 char *zD = fossil_strdup(P("name"));
125 int nD = zD ? strlen(zD)+1 : 0;
126 int mxLen;
127 int n;
128 char *zPrefix;
129 Stmt q;
130 const char *zCI = P("ci");
131 int rid = 0;
132 char *zUuid = 0;
133 Blob dirname;
134 Manifest *pM = 0;
135 const char *zSubdirLink;
136 int linkTrunk = 1;
137 int linkTip = 1;
138 HQuery sURI;
 
 
 
139
 
140 if( strcmp(PD("type","flat"),"tree")==0 ){ page_tree(); return; }
141 login_check_credentials();
142 if( !g.perm.Read ){ login_needed(g.anon.Read); return; }
143 while( nD>1 && zD[nD-2]=='/' ){ zD[(--nD)-1] = 0; }
144 style_header("File List");
145 style_adunit_config(ADUNIT_RIGHT_OK);
146 sqlite3_create_function(g.db, "pathelement", 2, SQLITE_UTF8, 0,
147 pathelementFunc, 0, 0);
148 url_initialize(&sURI, "dir");
149 cgi_query_parameters_to_url(&sURI);
150
151 /* If the name= parameter is an empty string, make it a NULL pointer */
152 if( zD && strlen(zD)==0 ){ zD = 0; }
153
154 /* If a specific check-in is requested, fetch and parse it. If the
@@ -160,53 +171,80 @@
160 if( pM ){
161 int trunkRid = symbolic_name_to_rid("tag:trunk", "ci");
162 linkTrunk = trunkRid && rid != trunkRid;
163 linkTip = rid != symbolic_name_to_rid("tip", "ci");
164 zUuid = db_text(0, "SELECT uuid FROM blob WHERE rid=%d", rid);
 
 
 
165 }else{
166 zCI = 0;
167 }
168 }
169
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
170 /* Compute the title of the page */
171 blob_zero(&dirname);
172 if( zD ){
173 blob_append(&dirname, "in directory ", -1);
174 hyperlinked_path(zD, &dirname, zCI, "dir", "");
 
 
 
175 zPrefix = mprintf("%s/", zD);
176 style_submenu_element("Top-Level", "%s",
177 url_render(&sURI, "name", 0, 0, 0));
178 }else{
179 blob_append(&dirname, "in the top-level directory", -1);
180 zPrefix = "";
181 }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
182 if( linkTrunk ){
183 style_submenu_element("Trunk", "%s",
184 url_render(&sURI, "ci", "trunk", 0, 0));
185 }
186 if( linkTip ){
187 style_submenu_element("Tip", "%s", url_render(&sURI, "ci", "tip", 0, 0));
188 }
189 if( zCI ){
190 @ <h2>Files of check-in [%z(href("vinfo?name=%!S",zUuid))%S(zUuid)</a>]
191 @ %s(blob_str(&dirname))
192 if( zD ){
193 @ &nbsp;&nbsp;%z(href("%R/timeline?chng=%T/*", zD))[history]</a>
194 }
195 @ </h2>
196 zSubdirLink = mprintf("%R/dir?ci=%!S&name=%T", zUuid, zPrefix);
197 if( nD==0 ){
198 style_submenu_element("File Ages", "%R/fileage?name=%!S", zUuid);
199 }
200 }else{
201 @ <h2>The union of all files from all check-ins
202 @ %s(blob_str(&dirname))
203 if( zD ){
204 @ &nbsp;&nbsp;%z(href("%R/timeline?chng=%T/*", zD))[history]</a>
205 }
206 @ </h2>
207 zSubdirLink = mprintf("%R/dir?name=%T", zPrefix);
208 }
209 style_submenu_element("All", "%s", url_render(&sURI, "ci", 0, 0, 0));
210 style_submenu_element("Tree-View", "%s",
211 url_render(&sURI, "type", "tree", 0, 0));
212
@@ -269,15 +307,14 @@
269
270 /* Generate a multi-column table listing the contents of zD[]
271 ** directory.
272 */
273 mxLen = db_int(12, "SELECT max(length(x)) FROM localfiles /*scan*/");
274 n = db_int(1,"SELECT count(*) FROM localfiles; /*scan*/");
275 if( mxLen<12 ) mxLen = 12;
276 mxLen += (mxLen+9)/10;
277 db_prepare(&q, "SELECT x, u FROM localfiles ORDER BY x /*scan*/");
278 @ <div class="columns" style="columns: %d(mxLen)ex %d(n);">
279 @ <ul class="browser">
280 while( db_step(&q)==SQLITE_ROW ){
281 const char *zFN;
282 zFN = db_column_text(&q, 0);
283 if( zFN[0]=='/' ){
@@ -284,12 +321,11 @@
284 zFN++;
285 @ <li class="dir">%z(href("%s%T",zSubdirLink,zFN))%h(zFN)</a></li>
286 }else{
287 const char *zLink;
288 if( zCI ){
289 const char *zUuid = db_column_text(&q, 1);
290 zLink = href("%R/artifact/%!S",zUuid);
291 }else{
292 zLink = href("%R/finfo?name=%T%T",zPrefix,zFN);
293 }
294 @ <li class="%z(fileext_class(zFN))">%z(zLink)%h(zFN)</a></li>
295 }
@@ -354,10 +390,11 @@
354 @ </iframe>
355 }else{
356 Blob content;
357 const char *zMime = mimetype_from_name(zName);
358 content_get(rid, &content);
 
359 wiki_render_by_mimetype(&content, zMime);
360 }
361 }
362 }
363 db_finalize(&q);
@@ -614,11 +651,15 @@
614 HQuery sURI; /* Hyperlink */
615 int startExpanded; /* True to start out with the tree expanded */
616 int showDirOnly; /* Show directories only. Omit files */
617 int nDir = 0; /* Number of directories. Used for ID attributes */
618 char *zProjectName = db_get("project-name", 0);
 
 
 
619
 
620 if( strcmp(PD("type","flat"),"flat")==0 ){ page_dir(); return; }
621 memset(&sTree, 0, sizeof(sTree));
622 login_check_credentials();
623 if( !g.perm.Read ){ login_needed(g.anon.Read); return; }
624 while( nD>1 && zD[nD-2]=='/' ){ zD[(--nD)-1] = 0; }
@@ -626,14 +667,12 @@
626 pathelementFunc, 0, 0);
627 url_initialize(&sURI, "tree");
628 cgi_query_parameters_to_url(&sURI);
629 if( PB("nofiles") ){
630 showDirOnly = 1;
631 style_header("Folder Hierarchy");
632 }else{
633 showDirOnly = 0;
634 style_header("File Tree");
635 }
636 style_adunit_config(ADUNIT_RIGHT_OK);
637 if( PB("expand") ){
638 startExpanded = 1;
639 }else{
@@ -662,37 +701,55 @@
662 linkTip = rid != symbolic_name_to_rid("tip", "ci");
663 zUuid = db_text(0, "SELECT uuid FROM blob WHERE rid=%d", rid);
664 rNow = db_double(0.0, "SELECT mtime FROM event WHERE objid=%d", rid);
665 zNow = db_text("", "SELECT datetime(mtime,toLocal())"
666 " FROM event WHERE objid=%d", rid);
 
 
 
667 }else{
668 zCI = 0;
669 }
670 }
671 if( zCI==0 ){
672 rNow = db_double(0.0, "SELECT max(mtime) FROM event");
673 zNow = db_text("", "SELECT datetime(max(mtime),toLocal()) FROM event");
674 }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
675
676 /* Compute the title of the page */
677 blob_zero(&dirname);
678 if( zD ){
679 blob_append(&dirname, "within directory ", -1);
680 hyperlinked_path(zD, &dirname, zCI, "tree", zREx);
681 if( zRE ) blob_appendf(&dirname, " matching \"%s\"", zRE);
682 style_submenu_element("Top-Level", "%s",
683 url_render(&sURI, "name", 0, 0, 0));
684 }else{
685 if( zRE ){
686 blob_appendf(&dirname, "matching \"%s\"", zRE);
687 }
688 }
689 style_submenu_binary("mtime","Sort By Time","Sort By Filename", 0);
690 if( zCI ){
691 style_submenu_element("All", "%s", url_render(&sURI, "ci", 0, 0, 0));
692 if( nD==0 && !showDirOnly ){
693 style_submenu_element("File Ages", "%R/fileage?name=%s", zUuid);
694 }
695 }
696 if( linkTrunk ){
697 style_submenu_element("Trunk", "%s",
698 url_render(&sURI, "ci", "trunk", 0, 0));
@@ -747,10 +804,11 @@
747 tree_add_node(&sTree, zName, zUuid, mtime);
748 nFile++;
749 }
750 db_finalize(&q);
751 }
 
752
753 if( showDirOnly ){
754 for(nFile=0, p=sTree.pFirst; p; p=p->pNext){
755 if( p->pChild!=0 && p->nFullName>nD ) nFile++;
756 }
@@ -757,18 +815,24 @@
757 zObjType = "Folders";
758 }else{
759 zObjType = "Files";
760 }
761
762 style_submenu_checkbox("nofiles", "Folders Only", 0, 0);
763
764 if( zCI ){
765 @ <h2>%s(zObjType) from
766 if( sqlite3_strnicmp(zCI, zUuid, (int)strlen(zCI))!=0 ){
767 @ "%h(zCI)"
768 }
769 @ [%z(href("vinfo?name=%!S",zUuid))%S(zUuid)</a>] %s(blob_str(&dirname))
 
 
 
 
 
 
770 }else{
771 int n = db_int(0, "SELECT count(*) FROM plink");
772 @ <h2>%s(zObjType) from all %d(n) check-ins %s(blob_str(&dirname))
773 }
774 if( useMtime ){
@@ -826,11 +890,11 @@
826 nDir++;
827 }else if( !showDirOnly ){
828 const char *zFileClass = fileext_class(p->zName);
829 char *zLink;
830 if( zCI ){
831 zLink = href("%R/artifact/%!S",p->zUuid);
832 }else{
833 zLink = href("%R/finfo?name=%T",p->zFullName);
834 }
835 @ <li class="%z(zFileClass)%s(zLastClass)"><div class="filetreeline">
836 @ %z(zLink)%h(p->zName)</a>
@@ -847,11 +911,11 @@
847 }
848 }
849 }
850 @ </ul>
851 @ </ul></div>
852 style_load_one_js_file("tree.js");
853 style_footer();
854
855 /* We could free memory used by sTree here if we needed to. But
856 ** the process is about to exit, so doing so would not really accomplish
857 ** anything useful. */
@@ -920,11 +984,11 @@
920 ** mtime on that check-in. If zGlob and *zGlob then only files matching
921 ** the given glob are computed.
922 */
923 int compute_fileage(int vid, const char* zGlob){
924 Stmt q;
925 db_multi_exec(zComputeFileAgeSetup /*works-like:"constant"*/);
926 db_prepare(&q, zComputeFileAgeRun /*works-like:"constant"*/);
927 db_bind_int(&q, ":ckin", vid);
928 db_bind_text(&q, ":glob", zGlob && zGlob[0] ? zGlob : "*");
929 db_exec(&q);
930 db_finalize(&q);
@@ -1003,10 +1067,11 @@
1003 int rid;
1004 const char *zName;
1005 const char *zGlob;
1006 const char *zUuid;
1007 const char *zNow; /* Time of check-in */
 
1008 int showId = PB("showid");
1009 Stmt q1, q2;
1010 double baseTime;
1011 login_check_credentials();
1012 if( !g.perm.Read ){ login_needed(g.anon.Read); return; }
@@ -1016,28 +1081,34 @@
1016 rid = symbolic_name_to_rid(zName, "ci");
1017 if( rid==0 ){
1018 fossil_fatal("not a valid check-in: %s", zName);
1019 }
1020 zUuid = db_text("", "SELECT uuid FROM blob WHERE rid=%d", rid);
 
1021 baseTime = db_double(0.0,"SELECT mtime FROM event WHERE objid=%d", rid);
1022 zNow = db_text("", "SELECT datetime(mtime,toLocal()) FROM event"
1023 " WHERE objid=%d", rid);
1024 style_submenu_element("Tree-View", "%R/tree?ci=%T&mtime=1&type=tree", zName);
1025 style_header("File Ages");
1026 zGlob = P("glob");
1027 compute_fileage(rid,zGlob);
1028 db_multi_exec("CREATE INDEX fileage_ix1 ON fileage(mid,pathname);");
1029
1030 @ <h1>Files in
1031 @ %z(href("%R/info/%!S",zUuid))[%S(zUuid)]</a>
 
 
 
 
 
 
1032 if( zGlob && zGlob[0] ){
1033 @ that match "%h(zGlob)"
1034 }
1035 @ ordered by age</h1>
1036 @
1037 @ <p>File ages are expressed relative to the
1038 @ %z(href("%R/ci/%!S",zUuid))[%S(zUuid)]</a> check-in time of
1039 @ %z(href("%R/timeline?c=%t",zNow))%s(zNow)</a>.</p>
1040 @
1041 @ <div class='fileage'><table>
1042 @ <tr><th>Age</th><th>Files</th><th>Check-in</th></tr>
1043 db_prepare(&q1,
@@ -1052,14 +1123,13 @@
1052 " AND blob.rid=event.objid\n"
1053 " ORDER BY event.mtime DESC;",
1054 TAG_BRANCH
1055 );
1056 db_prepare(&q2,
1057 "SELECT blob.uuid, filename.name, fileage.fid\n"
1058 " FROM fileage, blob, filename\n"
1059 " WHERE fileage.mid=:mid AND filename.fnid=fileage.fnid"
1060 " AND blob.rid=fileage.fid;"
1061 );
1062 while( db_step(&q1)==SQLITE_ROW ){
1063 double age = baseTime - db_column_double(&q1, 0);
1064 int mid = db_column_int(&q1, 1);
1065 const char *zUuid = db_column_text(&q1, 2);
@@ -1069,24 +1139,24 @@
1069 char *zAge = human_readable_age(age);
1070 @ <tr><td>%s(zAge)</td>
1071 @ <td>
1072 db_bind_int(&q2, ":mid", mid);
1073 while( db_step(&q2)==SQLITE_ROW ){
1074 const char *zFUuid = db_column_text(&q2,0);
1075 const char *zFile = db_column_text(&q2,1);
1076 int fid = db_column_int(&q2,2);
1077 if( showId ){
1078 @ %z(href("%R/artifact/%!S",zFUuid))%h(zFile)</a> (%d(fid))<br />
 
1079 }else{
1080 @ %z(href("%R/artifact/%!S",zFUuid))%h(zFile)</a><br />
1081 }
1082 }
1083 db_reset(&q2);
1084 @ </td>
1085 @ <td>
1086 @ %W(zComment)
1087 @ (check-in:&nbsp;%z(href("%R/ci/%!S",zUuid))%S(zUuid)</a>,
1088 if( showId ){
1089 @ id: %d(mid)
1090 }
1091 @ user:&nbsp;%z(href("%R/timeline?u=%t&c=%!S&nd",zUser,zUuid))%h(zUser)</a>,
1092 @ branch:&nbsp;\
1093
--- src/browse.c
+++ src/browse.c
@@ -59,10 +59,18 @@
59 zOut = sqlite3_mprintf("/%.*s", i-n, &z[n]);
60 sqlite3_result_text(context, zOut, i-n+1, sqlite3_free);
61 }
62 }
63
64 /*
65 ** Flag arguments for hyperlinked_path()
66 */
67 #if INTERFACE
68 # define LINKPATH_FINFO 0x0001 /* Link final term to /finfo */
69 # define LINKPATH_FILE 0x0002 /* Link final term to /file */
70 #endif
71
72 /*
73 ** Given a pathname which is a relative path from the root of
74 ** the repository to a file or directory, compute a string which
75 ** is an HTML rendering of that path with hyperlinks on each
76 ** directory component of the path where the hyperlink redirects
@@ -76,29 +84,36 @@
84 void hyperlinked_path(
85 const char *zPath, /* Path to render */
86 Blob *pOut, /* Write into this blob */
87 const char *zCI, /* check-in name, or NULL */
88 const char *zURI, /* "dir" or "tree" */
89 const char *zREx, /* Extra query parameters */
90 unsigned int mFlags /* Extra flags */
91 ){
92 int i, j;
93 char *zSep = "";
94
95 for(i=0; zPath[i]; i=j){
96 for(j=i; zPath[j] && zPath[j]!='/'; j++){}
97 if( zPath[j]==0 ){
98 if( mFlags & LINKPATH_FILE ){
99 zURI = "file";
100 }else if( mFlags & LINKPATH_FINFO ){
101 zURI = "finfo";
102 }else{
103 blob_appendf(pOut, "/%h", zPath+i);
104 break;
105 }
106 }
107 if( zCI ){
108 char *zLink = href("%R/%s?name=%#T%s&ci=%T", zURI, j, zPath, zREx,zCI);
109 blob_appendf(pOut, "%s%z%#h</a>",
110 zSep, zLink, j-i, &zPath[i]);
111 }else{
112 char *zLink = href("%R/%s?name=%#T%s", zURI, j, zPath, zREx);
113 blob_appendf(pOut, "%s%z%#h</a>",
114 zSep, zLink, j-i, &zPath[i]);
115 }
116 zSep = "/";
117 while( zPath[j]=='/' ){ j++; }
118 }
119 }
@@ -122,33 +137,29 @@
137 */
138 void page_dir(void){
139 char *zD = fossil_strdup(P("name"));
140 int nD = zD ? strlen(zD)+1 : 0;
141 int mxLen;
 
142 char *zPrefix;
143 Stmt q;
144 const char *zCI = P("ci");
145 int rid = 0;
146 char *zUuid = 0;
 
147 Manifest *pM = 0;
148 const char *zSubdirLink;
149 int linkTrunk = 1;
150 int linkTip = 1;
151 HQuery sURI;
152 int isSymbolicCI = 0; /* ci= is symbolic name, not a hash prefix */
153 int isBranchCI = 0; /* True if ci= refers to a branch name */
154 char *zHeader = 0;
155
156 if( zCI && strlen(zCI)==0 ){ zCI = 0; }
157 if( strcmp(PD("type","flat"),"tree")==0 ){ page_tree(); return; }
158 login_check_credentials();
159 if( !g.perm.Read ){ login_needed(g.anon.Read); return; }
160 while( nD>1 && zD[nD-2]=='/' ){ zD[(--nD)-1] = 0; }
 
 
 
 
 
 
161
162 /* If the name= parameter is an empty string, make it a NULL pointer */
163 if( zD && strlen(zD)==0 ){ zD = 0; }
164
165 /* If a specific check-in is requested, fetch and parse it. If the
@@ -160,53 +171,80 @@
171 if( pM ){
172 int trunkRid = symbolic_name_to_rid("tag:trunk", "ci");
173 linkTrunk = trunkRid && rid != trunkRid;
174 linkTip = rid != symbolic_name_to_rid("tip", "ci");
175 zUuid = db_text(0, "SELECT uuid FROM blob WHERE rid=%d", rid);
176 isSymbolicCI = (sqlite3_strnicmp(zUuid, zCI, strlen(zCI))!=0);
177 isBranchCI = branch_includes_uuid(zCI, zUuid);
178 Th_Store("current_checkin", zCI);
179 }else{
180 zCI = 0;
181 }
182 }
183
184 assert( isSymbolicCI==0 || (zCI!=0 && zCI[0]!=0) );
185 if( zD==0 ){
186 if( zCI ){
187 zHeader = mprintf("Top-level Files of %s", zCI);
188 }else{
189 zHeader = mprintf("All Top-level Files");
190 }
191 }else{
192 if( zCI ){
193 zHeader = mprintf("Files in %s/ of %s", zD, zCI);
194 }else{
195 zHeader = mprintf("All File in %s/", zD);
196 }
197 }
198 style_header("%s", zHeader);
199 fossil_free(zHeader);
200 style_adunit_config(ADUNIT_RIGHT_OK);
201 sqlite3_create_function(g.db, "pathelement", 2, SQLITE_UTF8, 0,
202 pathelementFunc, 0, 0);
203 url_initialize(&sURI, "dir");
204 cgi_query_parameters_to_url(&sURI);
205
206 /* Compute the title of the page */
 
207 if( zD ){
208 Blob dirname;
209 blob_init(&dirname, 0, 0);
210 hyperlinked_path(zD, &dirname, zCI, "dir", "", 0);
211 @ <h2>Files in directory %s(blob_str(&dirname)) \
212 blob_reset(&dirname);
213 zPrefix = mprintf("%s/", zD);
214 style_submenu_element("Top-Level", "%s",
215 url_render(&sURI, "name", 0, 0, 0));
216 }else{
217 @ <h2>Files in the top-level directory \
218 zPrefix = "";
219 }
220 if( zCI ){
221 if( fossil_strcmp(zCI,"tip")==0 ){
222 @ from the %z(href("%R/info?name=%T",zCI))latest check-in</a></h2>
223 }else if( isBranchCI ){
224 @ from the %z(href("%R/info?name=%T",zCI))latest check-in</a> \
225 @ of branch %z(href("%R/timeline?r=%T",zCI))%h(zCI)</a></h2>
226 }else {
227 @ of check-in %z(href("%R/info?name=%T",zCI))%h(zCI)</a></h2>
228 }
229 zSubdirLink = mprintf("%R/dir?ci=%T&name=%T", zCI, zPrefix);
230 if( nD==0 ){
231 style_submenu_element("File Ages", "%R/fileage?name=%T", zCI);
232 }
233 }else{
234 @ in any check-in</h2>
235 zSubdirLink = mprintf("%R/dir?name=%T", zPrefix);
236 }
237 if( linkTrunk ){
238 style_submenu_element("Trunk", "%s",
239 url_render(&sURI, "ci", "trunk", 0, 0));
240 }
241 if( linkTip ){
242 style_submenu_element("Tip", "%s", url_render(&sURI, "ci", "tip", 0, 0));
243 }
244 if( zD ){
245 style_submenu_element("History","%R/timeline?chng=%T/*", zD);
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
246 }
247 style_submenu_element("All", "%s", url_render(&sURI, "ci", 0, 0, 0));
248 style_submenu_element("Tree-View", "%s",
249 url_render(&sURI, "type", "tree", 0, 0));
250
@@ -269,15 +307,14 @@
307
308 /* Generate a multi-column table listing the contents of zD[]
309 ** directory.
310 */
311 mxLen = db_int(12, "SELECT max(length(x)) FROM localfiles /*scan*/");
 
312 if( mxLen<12 ) mxLen = 12;
313 mxLen += (mxLen+9)/10;
314 db_prepare(&q, "SELECT x, u FROM localfiles ORDER BY x /*scan*/");
315 @ <div class="columns files" style="columns: %d(mxLen)ex auto">
316 @ <ul class="browser">
317 while( db_step(&q)==SQLITE_ROW ){
318 const char *zFN;
319 zFN = db_column_text(&q, 0);
320 if( zFN[0]=='/' ){
@@ -284,12 +321,11 @@
321 zFN++;
322 @ <li class="dir">%z(href("%s%T",zSubdirLink,zFN))%h(zFN)</a></li>
323 }else{
324 const char *zLink;
325 if( zCI ){
326 zLink = href("%R/file?name=%T%T&ci=%T",zPrefix,zFN,zCI);
 
327 }else{
328 zLink = href("%R/finfo?name=%T%T",zPrefix,zFN);
329 }
330 @ <li class="%z(fileext_class(zFN))">%z(zLink)%h(zFN)</a></li>
331 }
@@ -354,10 +390,11 @@
390 @ </iframe>
391 }else{
392 Blob content;
393 const char *zMime = mimetype_from_name(zName);
394 content_get(rid, &content);
395 safe_html_context(DOCSRC_FILE);
396 wiki_render_by_mimetype(&content, zMime);
397 }
398 }
399 }
400 db_finalize(&q);
@@ -614,11 +651,15 @@
651 HQuery sURI; /* Hyperlink */
652 int startExpanded; /* True to start out with the tree expanded */
653 int showDirOnly; /* Show directories only. Omit files */
654 int nDir = 0; /* Number of directories. Used for ID attributes */
655 char *zProjectName = db_get("project-name", 0);
656 int isSymbolicCI = 0; /* ci= is a symbolic name, not a hash prefix */
657 int isBranchCI = 0; /* ci= refers to a branch name */
658 char *zHeader = 0;
659
660 if( zCI && strlen(zCI)==0 ){ zCI = 0; }
661 if( strcmp(PD("type","flat"),"flat")==0 ){ page_dir(); return; }
662 memset(&sTree, 0, sizeof(sTree));
663 login_check_credentials();
664 if( !g.perm.Read ){ login_needed(g.anon.Read); return; }
665 while( nD>1 && zD[nD-2]=='/' ){ zD[(--nD)-1] = 0; }
@@ -626,14 +667,12 @@
667 pathelementFunc, 0, 0);
668 url_initialize(&sURI, "tree");
669 cgi_query_parameters_to_url(&sURI);
670 if( PB("nofiles") ){
671 showDirOnly = 1;
 
672 }else{
673 showDirOnly = 0;
 
674 }
675 style_adunit_config(ADUNIT_RIGHT_OK);
676 if( PB("expand") ){
677 startExpanded = 1;
678 }else{
@@ -662,37 +701,55 @@
701 linkTip = rid != symbolic_name_to_rid("tip", "ci");
702 zUuid = db_text(0, "SELECT uuid FROM blob WHERE rid=%d", rid);
703 rNow = db_double(0.0, "SELECT mtime FROM event WHERE objid=%d", rid);
704 zNow = db_text("", "SELECT datetime(mtime,toLocal())"
705 " FROM event WHERE objid=%d", rid);
706 isSymbolicCI = (sqlite3_strnicmp(zUuid, zCI, strlen(zCI)) != 0);
707 isBranchCI = branch_includes_uuid(zCI, zUuid);
708 Th_Store("current_checkin", zCI);
709 }else{
710 zCI = 0;
711 }
712 }
713 if( zCI==0 ){
714 rNow = db_double(0.0, "SELECT max(mtime) FROM event");
715 zNow = db_text("", "SELECT datetime(max(mtime),toLocal()) FROM event");
716 }
717
718 assert( isSymbolicCI==0 || (zCI!=0 && zCI[0]!=0) );
719 if( zD==0 ){
720 if( zCI ){
721 zHeader = mprintf("Top-level Files of %s", zCI);
722 }else{
723 zHeader = mprintf("All Top-level Files");
724 }
725 }else{
726 if( zCI ){
727 zHeader = mprintf("Files in %s/ of %s", zD, zCI);
728 }else{
729 zHeader = mprintf("All File in %s/", zD);
730 }
731 }
732 style_header("%s", zHeader);
733 fossil_free(zHeader);
734
735 /* Compute the title of the page */
736 blob_zero(&dirname);
737 if( zD ){
738 blob_append(&dirname, "within directory ", -1);
739 hyperlinked_path(zD, &dirname, zCI, "tree", zREx, 0);
740 if( zRE ) blob_appendf(&dirname, " matching \"%s\"", zRE);
741 style_submenu_element("Top-Level", "%s",
742 url_render(&sURI, "name", 0, 0, 0));
743 }else if( zRE ){
744 blob_appendf(&dirname, "matching \"%s\"", zRE);
 
 
745 }
746 style_submenu_binary("mtime","Sort By Time","Sort By Filename", 0);
747 if( zCI ){
748 style_submenu_element("All", "%s", url_render(&sURI, "ci", 0, 0, 0));
749 if( nD==0 && !showDirOnly ){
750 style_submenu_element("File Ages", "%R/fileage?name=%T", zCI);
751 }
752 }
753 if( linkTrunk ){
754 style_submenu_element("Trunk", "%s",
755 url_render(&sURI, "ci", "trunk", 0, 0));
@@ -747,10 +804,11 @@
804 tree_add_node(&sTree, zName, zUuid, mtime);
805 nFile++;
806 }
807 db_finalize(&q);
808 }
809 style_submenu_checkbox("nofiles", "Folders Only", 0, 0);
810
811 if( showDirOnly ){
812 for(nFile=0, p=sTree.pFirst; p; p=p->pNext){
813 if( p->pChild!=0 && p->nFullName>nD ) nFile++;
814 }
@@ -757,18 +815,24 @@
815 zObjType = "Folders";
816 }else{
817 zObjType = "Files";
818 }
819
820 if( zCI && strcmp(zCI,"tip")==0 ){
821 @ <h2>%s(zObjType) in the %z(href("%R/info?name=tip"))latest check-in</a>
822 }else if( isBranchCI ){
823 @ <h2>%s(zObjType) in the %z(href("%R/info?name=%T",zCI))latest check-in\
824 @ </a> for branch %z(href("%R/timeline?r=%T",zCI))%h(zCI)</a>
825 if( blob_size(&dirname) ){
826 @ and %s(blob_str(&dirname))</h2>
827 }
828 }else if( zCI ){
829 @ <h2>%s(zObjType) for check-in \
830 @ %z(href("%R/info?name=%T",zCI))%h(zCI)</a></h2>
831 if( blob_size(&dirname) ){
832 @ and %s(blob_str(&dirname))</h2>
833 }
834 }else{
835 int n = db_int(0, "SELECT count(*) FROM plink");
836 @ <h2>%s(zObjType) from all %d(n) check-ins %s(blob_str(&dirname))
837 }
838 if( useMtime ){
@@ -826,11 +890,11 @@
890 nDir++;
891 }else if( !showDirOnly ){
892 const char *zFileClass = fileext_class(p->zName);
893 char *zLink;
894 if( zCI ){
895 zLink = href("%R/file?name=%T&ci=%T",p->zFullName,zCI);
896 }else{
897 zLink = href("%R/finfo?name=%T",p->zFullName);
898 }
899 @ <li class="%z(zFileClass)%s(zLastClass)"><div class="filetreeline">
900 @ %z(zLink)%h(p->zName)</a>
@@ -847,11 +911,11 @@
911 }
912 }
913 }
914 @ </ul>
915 @ </ul></div>
916 builtin_request_js("tree.js");
917 style_footer();
918
919 /* We could free memory used by sTree here if we needed to. But
920 ** the process is about to exit, so doing so would not really accomplish
921 ** anything useful. */
@@ -920,11 +984,11 @@
984 ** mtime on that check-in. If zGlob and *zGlob then only files matching
985 ** the given glob are computed.
986 */
987 int compute_fileage(int vid, const char* zGlob){
988 Stmt q;
989 db_exec_sql(zComputeFileAgeSetup);
990 db_prepare(&q, zComputeFileAgeRun /*works-like:"constant"*/);
991 db_bind_int(&q, ":ckin", vid);
992 db_bind_text(&q, ":glob", zGlob && zGlob[0] ? zGlob : "*");
993 db_exec(&q);
994 db_finalize(&q);
@@ -1003,10 +1067,11 @@
1067 int rid;
1068 const char *zName;
1069 const char *zGlob;
1070 const char *zUuid;
1071 const char *zNow; /* Time of check-in */
1072 int isBranchCI; /* name= is a branch name */
1073 int showId = PB("showid");
1074 Stmt q1, q2;
1075 double baseTime;
1076 login_check_credentials();
1077 if( !g.perm.Read ){ login_needed(g.anon.Read); return; }
@@ -1016,28 +1081,34 @@
1081 rid = symbolic_name_to_rid(zName, "ci");
1082 if( rid==0 ){
1083 fossil_fatal("not a valid check-in: %s", zName);
1084 }
1085 zUuid = db_text("", "SELECT uuid FROM blob WHERE rid=%d", rid);
1086 isBranchCI = branch_includes_uuid(zName,zUuid);
1087 baseTime = db_double(0.0,"SELECT mtime FROM event WHERE objid=%d", rid);
1088 zNow = db_text("", "SELECT datetime(mtime,toLocal()) FROM event"
1089 " WHERE objid=%d", rid);
1090 style_submenu_element("Tree-View", "%R/tree?ci=%T&mtime=1&type=tree", zName);
1091 style_header("File Ages");
1092 zGlob = P("glob");
1093 compute_fileage(rid,zGlob);
1094 db_multi_exec("CREATE INDEX fileage_ix1 ON fileage(mid,pathname);");
1095
1096 if( fossil_strcmp(zName,"tip")==0 ){
1097 @ <h1>Files in the %z(href("%R/info?name=tip"))latest check-in</a>
1098 }else if( isBranchCI ){
1099 @ <h1>Files in the %z(href("%R/info?name=%T",zName))latest check-in</a>
1100 @ of branch %z(href("%R/timeline?r=%T",zName))%h(zName)</a>
1101 }else{
1102 @ <h1>Files in check-in %z(href("%R/info?name=%T",zName))%h(zName)</a>
1103 }
1104 if( zGlob && zGlob[0] ){
1105 @ that match "%h(zGlob)"
1106 }
1107 @ ordered by age</h1>
1108 @
1109 @ <p>File ages are expressed relative to the check-in time of
 
1110 @ %z(href("%R/timeline?c=%t",zNow))%s(zNow)</a>.</p>
1111 @
1112 @ <div class='fileage'><table>
1113 @ <tr><th>Age</th><th>Files</th><th>Check-in</th></tr>
1114 db_prepare(&q1,
@@ -1052,14 +1123,13 @@
1123 " AND blob.rid=event.objid\n"
1124 " ORDER BY event.mtime DESC;",
1125 TAG_BRANCH
1126 );
1127 db_prepare(&q2,
1128 "SELECT filename.name, fileage.fid\n"
1129 " FROM fileage, filename\n"
1130 " WHERE fileage.mid=:mid AND filename.fnid=fileage.fnid"
 
1131 );
1132 while( db_step(&q1)==SQLITE_ROW ){
1133 double age = baseTime - db_column_double(&q1, 0);
1134 int mid = db_column_int(&q1, 1);
1135 const char *zUuid = db_column_text(&q1, 2);
@@ -1069,24 +1139,24 @@
1139 char *zAge = human_readable_age(age);
1140 @ <tr><td>%s(zAge)</td>
1141 @ <td>
1142 db_bind_int(&q2, ":mid", mid);
1143 while( db_step(&q2)==SQLITE_ROW ){
1144 const char *zFile = db_column_text(&q2,0);
1145 @ %z(href("%R/file?name=%T&ci=%!S",zFile,zUuid))%h(zFile)</a> \
 
1146 if( showId ){
1147 int fid = db_column_int(&q2,1);
1148 @ (%d(fid))<br />
1149 }else{
1150 @ </a><br />
1151 }
1152 }
1153 db_reset(&q2);
1154 @ </td>
1155 @ <td>
1156 @ %W(zComment)
1157 @ (check-in:&nbsp;%z(href("%R/info/%!S",zUuid))%S(zUuid)</a>,
1158 if( showId ){
1159 @ id: %d(mid)
1160 }
1161 @ user:&nbsp;%z(href("%R/timeline?u=%t&c=%!S&nd",zUser,zUuid))%h(zUser)</a>,
1162 @ branch:&nbsp;\
1163
+251 -11
--- src/builtin.c
+++ src/builtin.c
@@ -28,13 +28,15 @@
2828
** builtin_data.h file. Include that information here:
2929
*/
3030
#include "builtin_data.h"
3131
3232
/*
33
-** Return a pointer to built-in content
33
+** Return the index in the aBuiltinFiles[] array for the file
34
+** whose name is zFilename. Or return -1 if the file is not
35
+** found.
3436
*/
35
-const unsigned char *builtin_file(const char *zFilename, int *piSize){
37
+static int builtin_file_index(const char *zFilename){
3638
int lwr, upr, i, c;
3739
lwr = 0;
3840
upr = count(aBuiltinFiles) - 1;
3941
while( upr>=lwr ){
4042
i = (upr+lwr)/2;
@@ -42,30 +44,50 @@
4244
if( c<0 ){
4345
lwr = i+1;
4446
}else if( c>0 ){
4547
upr = i-1;
4648
}else{
47
- if( piSize ) *piSize = aBuiltinFiles[i].nByte;
48
- return aBuiltinFiles[i].pData;
49
+ return i;
4950
}
5051
}
51
- if( piSize ) *piSize = 0;
52
- return 0;
52
+ return -1;
53
+}
54
+
55
+/*
56
+** Return a pointer to built-in content
57
+*/
58
+const unsigned char *builtin_file(const char *zFilename, int *piSize){
59
+ int i = builtin_file_index(zFilename);
60
+ if( i>=0 ){
61
+ if( piSize ) *piSize = aBuiltinFiles[i].nByte;
62
+ return aBuiltinFiles[i].pData;
63
+ }else{
64
+ if( piSize ) *piSize = 0;
65
+ return 0;
66
+ }
5367
}
5468
const char *builtin_text(const char *zFilename){
5569
return (char*)builtin_file(zFilename, 0);
5670
}
5771
5872
/*
5973
** COMMAND: test-builtin-list
74
+**
75
+** If -verbose is used, it outputs a line at the end
76
+** with the total item count and size.
6077
**
6178
** List the names and sizes of all built-in resources.
6279
*/
6380
void test_builtin_list(void){
64
- int i;
81
+ int i, size = 0;;
6582
for(i=0; i<count(aBuiltinFiles); i++){
66
- fossil_print("%-30s %6d\n", aBuiltinFiles[i].zName,aBuiltinFiles[i].nByte);
83
+ const int n = aBuiltinFiles[i].nByte;
84
+ fossil_print("%3d. %-45s %6d\n", i+1, aBuiltinFiles[i].zName,n);
85
+ size += n;
86
+ }
87
+ if(find_option("verbose","v",0)!=0){
88
+ fossil_print("%d entries totaling %d bytes\n", i, size);
6789
}
6890
}
6991
7092
/*
7193
** WEBPAGE: test-builtin-files
@@ -73,16 +95,18 @@
7395
** Show all built-in text files.
7496
*/
7597
void test_builtin_list_page(void){
7698
int i;
7799
style_header("Built-in Text Files");
78
- @ <ul>
100
+ @ <ol>
79101
for(i=0; i<count(aBuiltinFiles); i++){
80102
const char *z = aBuiltinFiles[i].zName;
81
- @ <li>%z(href("%R/builtin?name=%T&id=%S",z,MANIFEST_UUID))%h(z)</a>
103
+ char *zUrl = href("%R/builtin?name=%T&id=%.8s&mimetype=text/plain",
104
+ z,fossil_exe_id());
105
+ @ <li>%z(zUrl)%h(z)</a>
82106
}
83
- @ </ul>
107
+ @ </ol>
84108
style_footer();
85109
}
86110
87111
/*
88112
** COMMAND: test-builtin-get
@@ -102,5 +126,221 @@
102126
}
103127
blob_init(&x, (const char*)pData, nByte);
104128
blob_write_to_file(&x, g.argc==4 ? g.argv[3] : "-");
105129
blob_reset(&x);
106130
}
131
+
132
+/*
133
+** Input zList is a list of numeric identifiers for files in
134
+** aBuiltinFiles[]. Return the concatenation of all of those
135
+** files using mimetype zType, or as application/javascript if
136
+** zType is 0.
137
+*/
138
+static void builtin_deliver_multiple_js_files(
139
+ const char *zList, /* List of numeric identifiers */
140
+ const char *zType /* Override mimetype */
141
+){
142
+ Blob *pOut;
143
+ if( zType==0 ) zType = "application/javascript";
144
+ cgi_set_content_type(zType);
145
+ pOut = cgi_output_blob();
146
+ while( zList[0] ){
147
+ int i = atoi(zList);
148
+ if( i>0 && i<=count(aBuiltinFiles) ){
149
+ blob_appendf(pOut, "/* %s */\n", aBuiltinFiles[i-1].zName);
150
+ blob_append(pOut, (const char*)aBuiltinFiles[i-1].pData,
151
+ aBuiltinFiles[i-1].nByte);
152
+ }
153
+ while( fossil_isdigit(zList[0]) ) zList++;
154
+ if( zList[0]==',' ) zList++;
155
+ }
156
+ return;
157
+}
158
+
159
+/*
160
+** WEBPAGE: builtin
161
+**
162
+** Return one of many built-in content files. Query parameters:
163
+**
164
+** name=FILENAME Return the single file whose name is FILENAME.
165
+** mimetype=TYPE Override the mimetype in the returned file to
166
+** be TYPE. If this query parameter is omitted
167
+** (the usual case) then the mimetype is inferred
168
+** from the suffix on FILENAME
169
+** m=IDLIST IDLIST is a comma-separated list of integers
170
+** that specify multiple javascript files to be
171
+** concatenated and returned all at once.
172
+** id=UNIQUEID Version number of the "builtin" files. Used
173
+** for cache control only.
174
+**
175
+** At least one of the name= or m= query parameters must be present.
176
+**
177
+** If the id= query parameter is present, then Fossil assumes that the
178
+** result is immutable and sets a very large cache retention time (1 year).
179
+*/
180
+void builtin_webpage(void){
181
+ Blob out;
182
+ const char *zName = P("name");
183
+ const char *zTxt = 0;
184
+ const char *zId = P("id");
185
+ const char *zType = P("mimetype");
186
+ int nId;
187
+ if( zName ) zTxt = builtin_text(zName);
188
+ if( zTxt==0 ){
189
+ const char *zM = P("m");
190
+ if( zM ){
191
+ if( zId && (nId = (int)strlen(zId))>=8
192
+ && strncmp(zId,fossil_exe_id(),nId)==0
193
+ ){
194
+ g.isConst = 1;
195
+ }
196
+ etag_check(0,0);
197
+ builtin_deliver_multiple_js_files(zM, zType);
198
+ return;
199
+ }
200
+ cgi_set_status(404, "Not Found");
201
+ @ File "%h(zName)" not found
202
+ return;
203
+ }
204
+ if( zType==0 ){
205
+ if( sqlite3_strglob("*.js", zName)==0 ){
206
+ zType = "application/javascript";
207
+ }else{
208
+ zType = mimetype_from_name(zName);
209
+ }
210
+ }
211
+ cgi_set_content_type(zType);
212
+ if( zId
213
+ && (nId = (int)strlen(zId))>=8
214
+ && strncmp(zId,fossil_exe_id(),nId)==0
215
+ ){
216
+ g.isConst = 1;
217
+ }
218
+ etag_check(0,0);
219
+ blob_init(&out, zTxt, -1);
220
+ cgi_set_content(&out);
221
+}
222
+
223
+/* Variables controlling the JS cache.
224
+*/
225
+static struct {
226
+ int aReq[30]; /* Indexes of all requested built-in JS files */
227
+ int nReq; /* Number of slots in aReq[] currently used */
228
+ int nSent; /* Number of slots in aReq[] fulfilled */
229
+ int eDelivery; /* Delivery mechanism */
230
+} builtin;
231
+
232
+#if INTERFACE
233
+/* Various delivery mechanisms. The 0 option is the default.
234
+*/
235
+#define JS_INLINE 0 /* inline, batched together at end of file */
236
+#define JS_SEPARATE 1 /* Separate HTTP request for each JS file */
237
+#define JS_BUNDLED 2 /* One HTTP request to load all JS files */
238
+ /* concatenated together into a bundle */
239
+#endif /* INTERFACE */
240
+
241
+/*
242
+** The argument is a request to change the javascript delivery mode.
243
+** The argument is a string which is a command-line option or CGI
244
+** parameter. Try to match it against one of the delivery options
245
+** and set things up accordingly. Throw an error if no match unless
246
+** bSilent is true.
247
+*/
248
+void builtin_set_js_delivery_mode(const char *zMode, int bSilent){
249
+ if( zMode==0 ) return;
250
+ if( strcmp(zMode, "inline")==0 ){
251
+ builtin.eDelivery = JS_INLINE;
252
+ }else
253
+ if( strcmp(zMode, "separate")==0 ){
254
+ builtin.eDelivery = JS_SEPARATE;
255
+ }else
256
+ if( strcmp(zMode, "bundled")==0 ){
257
+ builtin.eDelivery = JS_BUNDLED;
258
+ }else if( !bSilent ){
259
+ fossil_fatal("unknown javascript delivery mode \"%s\" - should be"
260
+ " one of: inline separate bundled", zMode);
261
+ }
262
+}
263
+
264
+/*
265
+** The caller wants the Javascript file named by zFilename to be
266
+** included in the generated page. Add the file to the queue of
267
+** requested javascript resources, if it is not there already.
268
+**
269
+** The current implementation queues the file to be included in the
270
+** output later. However, the caller should not depend on that
271
+** behavior. In the future, this routine might decide to insert
272
+** the requested javascript inline, immedaitely, or to insert
273
+** a <script src=..> element to reference the javascript as a
274
+** separate resource. The exact behavior might change in the future
275
+** so pages that use this interface must not rely on any particular
276
+** behavior.
277
+**
278
+** All this routine guarantees is that the named javascript file
279
+** will be requested by the browser at some point. This routine
280
+** does not guarantee when the javascript will be included, and it
281
+** does not guarantee whether the javascript will be added inline or
282
+** delivered as a separate resource.
283
+*/
284
+void builtin_request_js(const char *zFilename){
285
+ int i = builtin_file_index(zFilename);
286
+ int j;
287
+ if( i<0 ){
288
+ fossil_panic("unknown javascript file: \"%s\"", zFilename);
289
+ }
290
+ for(j=0; j<builtin.nReq; j++){
291
+ if( builtin.aReq[j]==i ) return; /* Already queued or sent */
292
+ }
293
+ if( builtin.nReq>=count(builtin.aReq) ){
294
+ fossil_panic("too many javascript files requested");
295
+ }
296
+ builtin.aReq[builtin.nReq++] = i;
297
+}
298
+
299
+/*
300
+** Fulfill all pending requests for javascript files.
301
+**
302
+** The current implementation delivers all javascript in-line. However,
303
+** the caller should not depend on this. Future changes to this routine
304
+** might choose to deliver javascript as separate resources.
305
+*/
306
+void builtin_fulfill_js_requests(void){
307
+ if( builtin.nSent>=builtin.nReq ) return; /* nothing to do */
308
+ switch( builtin.eDelivery ){
309
+ case JS_INLINE: {
310
+ CX("<script nonce='%h'>\n",style_nonce());
311
+ do{
312
+ int i = builtin.aReq[builtin.nSent++];
313
+ CX("/* %s */\n", aBuiltinFiles[i].zName);
314
+ cgi_append_content((const char*)aBuiltinFiles[i].pData,
315