Fossil SCM
Merge in trunk; resolve conflicts
Commit
7cfbf66a027855eb4e1d57069f6c44cd16a742cb5dbb32a6b5dbf550fecbbc75
Parent
001eb6d5061a3fc…
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 @@ | ||
| 82 | 82 | ) |
| 83 | 83 | |
| 84 | 84 | file(GLOB project_sources_FILES |
| 85 | 85 | "auto.def" |
| 86 | 86 | "configure" |
| 87 | + "Makefile.in" | |
| 87 | 88 | |
| 88 | 89 | "fossil.1" |
| 89 | 90 | "manifest.uuid" |
| 90 | 91 | "VERSION" |
| 91 | 92 | |
| @@ -151,19 +152,31 @@ | ||
| 151 | 152 | |
| 152 | 153 | separate_arguments(fossil_configure_FLAGS) |
| 153 | 154 | separate_arguments(fossil_build_FLAGS) |
| 154 | 155 | |
| 155 | 156 | 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}") | |
| 157 | 158 | file(TO_NATIVE_PATH "${fossil_DESTDIR}" fossil_DESTDIR) |
| 158 | 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 | + | |
| 159 | 172 | ExternalProject_Add(fossil |
| 160 | 173 | PREFIX fossil |
| 161 | 174 | SOURCE_DIR "${fossil_SOURCE_DIR}" |
| 162 | 175 | CONFIGURE_COMMAND "" |
| 163 | 176 | BINARY_DIR "${fossil_BINARY_DIR}" |
| 164 | - BUILD_COMMAND "${fossil_SOURCE_DIR}/win/buildmsvc.bat" | |
| 177 | + BUILD_COMMAND "${fossil_BINARY_DIR}/build.cmd" | |
| 165 | 178 | ${fossil_configure_FLAGS} |
| 166 | 179 | ${fossil_build_FLAGS} |
| 167 | 180 | all |
| 168 | 181 | install DESTDIR=${fossil_DESTDIR} |
| 169 | 182 | VERBATIM |
| @@ -280,16 +293,12 @@ | ||
| 280 | 293 | WORKING_DIRECTORY "${fossil_BINARY_DIR}" |
| 281 | 294 | COMMENT "Copying data for test-fossil" |
| 282 | 295 | VERBATIM |
| 283 | 296 | ) |
| 284 | 297 | 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 | 298 | WORKING_DIRECTORY "${fossil_TEST_DIR}" |
| 290 | - COMMENT "Setting up repository for test-fossil" | |
| 299 | + COMMENT "Setting up test-fossil" | |
| 291 | 300 | VERBATIM |
| 292 | 301 | ) |
| 293 | 302 | |
| 294 | 303 | |
| 295 | 304 | # Run the test suite. |
| @@ -321,16 +330,10 @@ | ||
| 321 | 330 | |
| 322 | 331 | add_custom_target(test-fossil-clean |
| 323 | 332 | COMMENT "Tearing down test-fossil" |
| 324 | 333 | DEPENDS fossil-install |
| 325 | 334 | ) |
| 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 | 335 | add_custom_command(TARGET test-fossil-clean POST_BUILD |
| 333 | 336 | COMMAND "${CMAKE_COMMAND}" -E remove_directory "${fossil_TEST_DIR}" |
| 334 | 337 | WORKING_DIRECTORY "${fossil_BINARY_DIR}" |
| 335 | 338 | COMMENT "Removing data for test-fossil" |
| 336 | 339 | VERBATIM |
| @@ -362,14 +365,13 @@ | ||
| 362 | 365 | set_property(TEST 03-clean APPEND PROPERTY |
| 363 | 366 | DEPENDS 01-setup) |
| 364 | 367 | |
| 365 | 368 | add_custom_target(check |
| 366 | 369 | COMMAND "${CMAKE_CTEST_COMMAND}" -V |
| 367 | - DEPENDS test-fossil | |
| 368 | 370 | ) |
| 369 | 371 | |
| 370 | 372 | ## INSTALL --------------------------------------------------------------- |
| 371 | 373 | ## |
| 372 | 374 | install(DIRECTORY ${fossil_EXE_DIR}/ |
| 373 | 375 | DESTINATION ${CMAKE_INSTALL_PREFIX}/bin/ |
| 374 | 376 | USE_SOURCE_PERMISSIONS |
| 375 | 377 | ) |
| 376 | 378 |
| --- 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 @@ | ||
| 82 | 82 | ) |
| 83 | 83 | |
| 84 | 84 | file(GLOB project_sources_FILES |
| 85 | 85 | "auto.def" |
| 86 | 86 | "configure" |
| 87 | + "Makefile.in" | |
| 87 | 88 | |
| 88 | 89 | "fossil.1" |
| 89 | 90 | "manifest.uuid" |
| 90 | 91 | "VERSION" |
| 91 | 92 | |
| @@ -151,19 +152,31 @@ | ||
| 151 | 152 | |
| 152 | 153 | separate_arguments(fossil_configure_FLAGS) |
| 153 | 154 | separate_arguments(fossil_build_FLAGS) |
| 154 | 155 | |
| 155 | 156 | 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}") | |
| 157 | 158 | file(TO_NATIVE_PATH "${fossil_DESTDIR}" fossil_DESTDIR) |
| 158 | 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 | + | |
| 159 | 172 | ExternalProject_Add(fossil |
| 160 | 173 | PREFIX fossil |
| 161 | 174 | SOURCE_DIR "${fossil_SOURCE_DIR}" |
| 162 | 175 | CONFIGURE_COMMAND "" |
| 163 | 176 | BINARY_DIR "${fossil_BINARY_DIR}" |
| 164 | - BUILD_COMMAND "${fossil_SOURCE_DIR}/win/buildmsvc.bat" | |
| 177 | + BUILD_COMMAND "${fossil_BINARY_DIR}/build.cmd" | |
| 165 | 178 | ${fossil_configure_FLAGS} |
| 166 | 179 | ${fossil_build_FLAGS} |
| 167 | 180 | all |
| 168 | 181 | install DESTDIR=${fossil_DESTDIR} |
| 169 | 182 | VERBATIM |
| @@ -280,16 +293,12 @@ | ||
| 280 | 293 | WORKING_DIRECTORY "${fossil_BINARY_DIR}" |
| 281 | 294 | COMMENT "Copying data for test-fossil" |
| 282 | 295 | VERBATIM |
| 283 | 296 | ) |
| 284 | 297 | 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 | 298 | WORKING_DIRECTORY "${fossil_TEST_DIR}" |
| 290 | - COMMENT "Setting up repository for test-fossil" | |
| 299 | + COMMENT "Setting up test-fossil" | |
| 291 | 300 | VERBATIM |
| 292 | 301 | ) |
| 293 | 302 | |
| 294 | 303 | |
| 295 | 304 | # Run the test suite. |
| @@ -321,16 +330,10 @@ | ||
| 321 | 330 | |
| 322 | 331 | add_custom_target(test-fossil-clean |
| 323 | 332 | COMMENT "Tearing down test-fossil" |
| 324 | 333 | DEPENDS fossil-install |
| 325 | 334 | ) |
| 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 | 335 | add_custom_command(TARGET test-fossil-clean POST_BUILD |
| 333 | 336 | COMMAND "${CMAKE_COMMAND}" -E remove_directory "${fossil_TEST_DIR}" |
| 334 | 337 | WORKING_DIRECTORY "${fossil_BINARY_DIR}" |
| 335 | 338 | COMMENT "Removing data for test-fossil" |
| 336 | 339 | VERBATIM |
| @@ -362,14 +365,13 @@ | ||
| 362 | 365 | set_property(TEST 03-clean APPEND PROPERTY |
| 363 | 366 | DEPENDS 01-setup) |
| 364 | 367 | |
| 365 | 368 | add_custom_target(check |
| 366 | 369 | COMMAND "${CMAKE_CTEST_COMMAND}" -V |
| 367 | - DEPENDS test-fossil | |
| 368 | 370 | ) |
| 369 | 371 | |
| 370 | 372 | ## INSTALL --------------------------------------------------------------- |
| 371 | 373 | ## |
| 372 | 374 | install(DIRECTORY ${fossil_EXE_DIR}/ |
| 373 | 375 | DESTINATION ${CMAKE_INSTALL_PREFIX}/bin/ |
| 374 | 376 | USE_SOURCE_PERMISSIONS |
| 375 | 377 | ) |
| 376 | 378 |
| --- 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 |
+2
-3
| --- Makefile.classic | ||
| +++ Makefile.classic | ||
| @@ -43,13 +43,10 @@ | ||
| 43 | 43 | # TCC += -DFOSSIL_ENABLE_MINIZ |
| 44 | 44 | |
| 45 | 45 | # To add support for HTTPS |
| 46 | 46 | TCC += -DFOSSIL_ENABLE_SSL |
| 47 | 47 | |
| 48 | -# To enable legacy mv/rm support | |
| 49 | -TCC += -DFOSSIL_ENABLE_LEGACY_MV_RM=1 | |
| 50 | - | |
| 51 | 48 | #### We sometimes add the -static option here so that we can build a |
| 52 | 49 | # static executable that will run in a chroot jail. |
| 53 | 50 | #LIB = -static |
| 54 | 51 | TCC += -DFOSSIL_DYNAMIC_BUILD=1 |
| 55 | 52 | |
| @@ -99,7 +96,9 @@ | ||
| 99 | 96 | TCC.DragonFly += -DUSE_PREAD |
| 100 | 97 | TCC.FreeBSD += -DUSE_PREAD |
| 101 | 98 | TCC.NetBSD += -DUSE_PREAD |
| 102 | 99 | TCC.OpenBSD += -DUSE_PREAD |
| 103 | 100 | TCC += $(TCC.$(HOST_OS)) |
| 101 | + | |
| 102 | +APPNAME = fossil$(E) | |
| 104 | 103 | |
| 105 | 104 | include $(SRCDIR)/main.mk |
| 106 | 105 |
| --- 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 |
+7
| --- Makefile.in | ||
| +++ Makefile.in | ||
| @@ -47,19 +47,26 @@ | ||
| 47 | 47 | USE_LINENOISE = @USE_LINENOISE@ |
| 48 | 48 | USE_MMAN_H = @USE_MMAN_H@ |
| 49 | 49 | USE_SEE = @USE_SEE@ |
| 50 | 50 | FOSSIL_ENABLE_MINIZ = @FOSSIL_ENABLE_MINIZ@ |
| 51 | 51 | APPNAME = fossil |
| 52 | + | |
| 53 | +.PHONY: all tags | |
| 52 | 54 | |
| 53 | 55 | include $(SRCDIR)/main.mk |
| 54 | 56 | |
| 55 | 57 | distclean: clean |
| 56 | 58 | -rm -f autoconfig.h config.log Makefile |
| 59 | + -rm -f cscope.out tags | |
| 57 | 60 | |
| 58 | 61 | reconfig: |
| 59 | 62 | @AUTOREMAKE@ |
| 60 | 63 | |
| 64 | +tags: | |
| 65 | + ctags -R @srcdir@/src | |
| 66 | + @COLLECT_CSCOPE_DATA@ | |
| 67 | + | |
| 61 | 68 | # Automatically reconfigure whenever an autosetup file or one of the |
| 62 | 69 | # make source files change. |
| 63 | 70 | # |
| 64 | 71 | # The "touch" is necessary to avoid a make loop due to a new upstream |
| 65 | 72 | # feature in autosetup (GH 0a71e3c3b7) which rewrites *.in outputs only |
| 66 | 73 |
| --- 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 |
-1
| --- Makefile.osx-jaguar | ||
| +++ Makefile.osx-jaguar | ||
| @@ -57,11 +57,10 @@ | ||
| 57 | 57 | TCC += -DSQLITE_WITHOUT_ZONEMALLOC |
| 58 | 58 | TCC += -D_BSD_SOURCE=1 |
| 59 | 59 | TCC += -DWITHOUT_ICONV |
| 60 | 60 | TCC += -Dsocklen_t=int |
| 61 | 61 | TCC += -DSQLITE_MAX_MMAP_SIZE=0 |
| 62 | -TCC += -DFOSSIL_ENABLE_LEGACY_MV_RM=1 | |
| 63 | 62 | INSTALLDIR = $(DESTDIR)/usr/local/bin |
| 64 | 63 | USE_SYSTEM_SQLITE = |
| 65 | 64 | USE_LINENOISE = 1 |
| 66 | 65 | # FOSSIL_ENABLE_TCL = @FOSSIL_ENABLE_TCL@ |
| 67 | 66 | FOSSIL_ENABLE_TCL = 0 |
| 68 | 67 |
| --- 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 |
M
VERSION
+1
-1
| --- VERSION | ||
| +++ VERSION | ||
| @@ -1,1 +1,1 @@ | ||
| 1 | -2.11 | |
| 1 | +2.12 | |
| 2 | 2 |
| --- VERSION | |
| +++ VERSION | |
| @@ -1,1 +1,1 @@ | |
| 1 | 2.11 |
| 2 |
| --- VERSION | |
| +++ VERSION | |
| @@ -1,1 +1,1 @@ | |
| 1 | 2.12 |
| 2 |
M
auto.def
+10
-10
| --- auto.def | ||
| +++ auto.def | ||
| @@ -8,11 +8,10 @@ | ||
| 8 | 8 | with-miniz=0 => {Use miniz from the source tree} |
| 9 | 9 | with-zlib:path|auto|tree |
| 10 | 10 | => {Look for zlib in the given path, automatically, or in the source tree} |
| 11 | 11 | with-exec-rel-paths=0 |
| 12 | 12 | => {Enable relative paths for external diff/gdiff} |
| 13 | - with-legacy-mv-rm=1 => {Enable legacy behavior for mv/rm (skip checkout files)} | |
| 14 | 13 | with-sanitizer: => {Build with C compiler's -fsanitize=LIST; e.g. address,enum,null,undefined} |
| 15 | 14 | with-th1-docs=0 => {Enable TH1 for embedded documentation pages} |
| 16 | 15 | with-th1-hooks=0 => {Enable TH1 hooks for commands and web pages} |
| 17 | 16 | with-tcl:path => {Enable Tcl integration, with Tcl in the specified path} |
| 18 | 17 | with-tcl-stubs=0 => {Enable Tcl integration via stubs library mechanism} |
| @@ -33,10 +32,17 @@ | ||
| 33 | 32 | cc-check-types uint32_t uint16_t int16_t uint8_t |
| 34 | 33 | } |
| 35 | 34 | |
| 36 | 35 | # Use pread/pwrite system calls in place of seek + read/write if possible |
| 37 | 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 | +} | |
| 38 | 44 | |
| 39 | 45 | # Find tclsh for the test suite. |
| 40 | 46 | # |
| 41 | 47 | # We can't use jimsh for this: the test suite uses features of Tcl that |
| 42 | 48 | # Jim doesn't support, either statically or due to the way it's built by |
| @@ -176,11 +182,11 @@ | ||
| 176 | 182 | user-error $result |
| 177 | 183 | } |
| 178 | 184 | file delete ./conftest__ |
| 179 | 185 | } |
| 180 | 186 | test_system_sqlite |
| 181 | - | |
| 187 | + | |
| 182 | 188 | } |
| 183 | 189 | |
| 184 | 190 | proc is_mingw {} { |
| 185 | 191 | return [string match *mingw* [get-define host]] |
| 186 | 192 | } |
| @@ -231,16 +237,10 @@ | ||
| 231 | 237 | define-append EXTRA_CFLAGS -DFOSSIL_ENABLE_JSON |
| 232 | 238 | define FOSSIL_ENABLE_JSON |
| 233 | 239 | msg-result "JSON support enabled" |
| 234 | 240 | } |
| 235 | 241 | |
| 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 | 242 | if {[opt-bool with-exec-rel-paths]} { |
| 243 | 243 | define-append EXTRA_CFLAGS -DFOSSIL_ENABLE_EXEC_REL_PATHS |
| 244 | 244 | define FOSSIL_ENABLE_EXEC_REL_PATHS |
| 245 | 245 | msg-result "Relative paths in external diff/gdiff enabled" |
| 246 | 246 | } |
| @@ -273,11 +273,11 @@ | ||
| 273 | 273 | |
| 274 | 274 | # Check for libraries that need to be sorted out early |
| 275 | 275 | cc-check-function-in-lib iconv iconv |
| 276 | 276 | |
| 277 | 277 | # 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}}} { | |
| 279 | 279 | msg-checking "Checking for $msg..." |
| 280 | 280 | set rc 0 |
| 281 | 281 | if {[is_mingw]} { |
| 282 | 282 | lappend libs -lgdi32 -lwsock32 -lcrypt32 |
| 283 | 283 | } |
| @@ -351,11 +351,11 @@ | ||
| 351 | 351 | user-error "The OpenSSL in source tree directory does not exist" |
| 352 | 352 | } |
| 353 | 353 | set msg "ssl in $ssldir" |
| 354 | 354 | set cflags "-I$ssldir/include" |
| 355 | 355 | set ldflags "-L$ssldir" |
| 356 | - set ssllibs "$ssldir/libssl.a $ssldir/libcrypto.a" | |
| 356 | + set ssllibs "$ssldir/libssl.a $ssldir/libcrypto.a -lpthread" | |
| 357 | 357 | set found [check-for-openssl "ssl in source tree" "$cflags $ldflags" $ssllibs] |
| 358 | 358 | } else { |
| 359 | 359 | if {$ssldirs in {auto ""}} { |
| 360 | 360 | catch { |
| 361 | 361 | set cflags [exec pkg-config openssl --cflags-only-I] |
| 362 | 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-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 @@ | ||
| 1 | 1 | Built-in Skins |
| 2 | 2 | ============== |
| 3 | 3 | |
| 4 | 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. | |
| 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 | |
| 7 | 12 | |
| 8 | 13 | To improve an existing built-in skin, simply edit the appropriate |
| 9 | 14 | files and recompile. |
| 10 | 15 | |
| 11 | 16 | To add a new skin: |
| @@ -13,12 +18,12 @@ | ||
| 13 | 18 | 1. Create a new subdirectory under skins/. (The new directory is |
| 14 | 19 | called "skins/newskin" below but you should use a new original |
| 15 | 20 | name, of course.) |
| 16 | 21 | |
| 17 | 22 | 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. | |
| 20 | 25 | |
| 21 | 26 | 3. Go to the src/ directory and rerun "tclsh makemake.tcl". This |
| 22 | 27 | step rebuilds the various makefiles so that they have dependencies |
| 23 | 28 | on the skin files you just installed. |
| 24 | 29 | |
| @@ -25,21 +30,23 @@ | ||
| 25 | 30 | 4. Edit the BuiltinSkin[] array near the top of the src/skins.c source |
| 26 | 31 | file so that it describes and references the "newskin" skin. |
| 27 | 32 | |
| 28 | 33 | 5. Type "make" to rebuild. |
| 29 | 34 | |
| 35 | +See the [custom skin documentation](../www/customskin.md) for more information. | |
| 36 | + | |
| 30 | 37 | Development Hints |
| 31 | 38 | ----------------- |
| 32 | 39 | |
| 33 | 40 | 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: | |
| 36 | 44 | |
| 37 | 45 | cp -r skins/default newskin |
| 38 | 46 | fossil ui --skin ./newskin |
| 39 | 47 | |
| 40 | 48 | When the argument to --skin contains one or more '/' characters, the |
| 41 | 49 | 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. | |
| 46 | 53 |
| --- 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 |
+11
-16
| --- skins/ardoise/css.txt | ||
| +++ skins/ardoise/css.txt | ||
| @@ -57,12 +57,10 @@ | ||
| 57 | 57 | span.modpending { |
| 58 | 58 | font-style: italic |
| 59 | 59 | } |
| 60 | 60 | html { |
| 61 | 61 | font-family: sans-serif; |
| 62 | - -ms-text-size-adjust: 100%; | |
| 63 | - -webkit-text-size-adjust: 100% | |
| 64 | 62 | } |
| 65 | 63 | audio, |
| 66 | 64 | canvas, |
| 67 | 65 | progress, |
| 68 | 66 | video { |
| @@ -162,11 +160,10 @@ | ||
| 162 | 160 | } |
| 163 | 161 | button, |
| 164 | 162 | html input[type=button], |
| 165 | 163 | input[type=reset], |
| 166 | 164 | input[type=submit] { |
| 167 | - -webkit-appearance: button; | |
| 168 | 165 | cursor: pointer |
| 169 | 166 | } |
| 170 | 167 | button[disabled], |
| 171 | 168 | html input[disabled] { |
| 172 | 169 | cursor: default |
| @@ -187,17 +184,11 @@ | ||
| 187 | 184 | } |
| 188 | 185 | input[type=number]::-webkit-inner-spin-button, |
| 189 | 186 | input[type=number]::-webkit-outer-spin-button { |
| 190 | 187 | height: auto |
| 191 | 188 | } |
| 192 | -input[type=search] { | |
| 193 | - -webkit-appearance: textfield | |
| 194 | -} | |
| 195 | 189 | input[type=search]::-webkit-search-cancel-button, |
| 196 | -input[type=search]::-webkit-search-decoration { | |
| 197 | - -webkit-appearance: none | |
| 198 | -} | |
| 199 | 190 | fieldset { |
| 200 | 191 | border: 1px solid silver; |
| 201 | 192 | margin: 0 2px |
| 202 | 193 | } |
| 203 | 194 | legend { |
| @@ -291,11 +282,11 @@ | ||
| 291 | 282 | box-sizing: border-box |
| 292 | 283 | } |
| 293 | 284 | .column, |
| 294 | 285 | .columns { |
| 295 | 286 | width: 100%; |
| 296 | - float: left; | |
| 287 | + /*float: left; can break README.md in /dir view*/ | |
| 297 | 288 | box-sizing: border-box |
| 298 | 289 | } |
| 299 | 290 | @media (min-width:400px) { |
| 300 | 291 | .container { |
| 301 | 292 | width: 95%; |
| @@ -487,13 +478,10 @@ | ||
| 487 | 478 | input[type=tel], |
| 488 | 479 | input[type=text], |
| 489 | 480 | input[type=url] { |
| 490 | 481 | box-shadow: none; |
| 491 | 482 | box-sizing: border-box; |
| 492 | - -webkit-appearance: none; | |
| 493 | - -moz-appearance: none; | |
| 494 | - appearance: none | |
| 495 | 483 | } |
| 496 | 484 | input[type=email], |
| 497 | 485 | input[type=number], |
| 498 | 486 | input[type=password], |
| 499 | 487 | input[type=search], |
| @@ -508,10 +496,13 @@ | ||
| 508 | 496 | background-color: #303536; |
| 509 | 497 | border: 0; |
| 510 | 498 | border-radius: 5px; |
| 511 | 499 | box-shadow: none; |
| 512 | 500 | box-sizing: border-box |
| 501 | +} | |
| 502 | +textarea, select { | |
| 503 | + height: initial; | |
| 513 | 504 | } |
| 514 | 505 | input[type=email]:hover, |
| 515 | 506 | input[type=number]:hover, |
| 516 | 507 | input[type=password]:hover, |
| 517 | 508 | input[type=search]:hover, |
| @@ -523,13 +514,10 @@ | ||
| 523 | 514 | color: #eef8ff; |
| 524 | 515 | background-color: #555 |
| 525 | 516 | } |
| 526 | 517 | textarea { |
| 527 | 518 | overflow: auto; |
| 528 | - -webkit-appearance: none; | |
| 529 | - -moz-appearance: none; | |
| 530 | - appearance: none; | |
| 531 | 519 | min-height: 65px; |
| 532 | 520 | padding-top: 6px; |
| 533 | 521 | padding-bottom: 6px |
| 534 | 522 | } |
| 535 | 523 | input[type=email]:focus, |
| @@ -1392,5 +1380,12 @@ | ||
| 1392 | 1380 | .u-cf { |
| 1393 | 1381 | content: ""; |
| 1394 | 1382 | display: table; |
| 1395 | 1383 | clear: both |
| 1396 | 1384 | } |
| 1385 | +div.forumSel { | |
| 1386 | + background-color: #3a3a3a; | |
| 1387 | +} | |
| 1388 | +.debug { | |
| 1389 | + background-color: #330; | |
| 1390 | + border: 2px solid #aa0; | |
| 1391 | +} | |
| 1397 | 1392 |
| --- 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 |
+1
-1
| --- skins/blitz/ticket.txt | ||
| +++ skins/blitz/ticket.txt | ||
| @@ -1,8 +1,8 @@ | ||
| 1 | 1 | <h4>$<title></h4> |
| 2 | 2 | <table class="tktDsp"> |
| 3 | -<tr><td class="tktDspLabel">Ticket UUID</td> | |
| 3 | +<tr><td class="tktDspLabel">Ticket Hash</td> | |
| 4 | 4 | <th1> |
| 5 | 5 | if {[info exists tkt_uuid]} { |
| 6 | 6 | if {[hascap s]} { |
| 7 | 7 | html "<td class='tktDspValue' colspan='3'>$tkt_uuid " |
| 8 | 8 | html "($tkt_id)</td></tr>\n" |
| 9 | 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 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 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 |
+1
-1
| --- skins/blitz_no_logo/ticket.txt | ||
| +++ skins/blitz_no_logo/ticket.txt | ||
| @@ -1,8 +1,8 @@ | ||
| 1 | 1 | <h4>$<title></h4> |
| 2 | 2 | <table class="tktDsp"> |
| 3 | -<tr><td class="tktDspLabel">Ticket UUID</td> | |
| 3 | +<tr><td class="tktDspLabel">Ticket Hash</td> | |
| 4 | 4 | <th1> |
| 5 | 5 | if {[info exists tkt_uuid]} { |
| 6 | 6 | if {[hascap s]} { |
| 7 | 7 | html "<td class='tktDspValue' colspan='3'>$tkt_uuid " |
| 8 | 8 | html "($tkt_id)</td></tr>\n" |
| 9 | 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 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 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 |
+1
-1
| --- skins/bootstrap/header.txt | ||
| +++ skins/bootstrap/header.txt | ||
| @@ -4,11 +4,11 @@ | ||
| 4 | 4 | <base href="$baseurl/$current_page" /> |
| 5 | 5 | <title>$<project_name>: $<title></title> |
| 6 | 6 | <meta name="viewport" content="width=device-width, initial-scale=1.0"> |
| 7 | 7 | <meta http-equiv="Content-Security-Policy" content="$default_csp"/> |
| 8 | 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" /> | |
| 9 | + <link rel="stylesheet" href="$stylesheet_url" type="text/css" media="screen" /> | |
| 10 | 10 | <script nonce="$<nonce>"> |
| 11 | 11 | function gebi(x){ |
| 12 | 12 | if(/^#/.test(x)) x = x.substr(1); |
| 13 | 13 | var e = document.getElementById(x); |
| 14 | 14 | if(!e) throw new Error("Expecting element with ID "+x); |
| 15 | 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="$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 |
+1
-1
| --- skins/default/css.txt | ||
| +++ skins/default/css.txt | ||
| @@ -145,11 +145,11 @@ | ||
| 145 | 145 | border-radius: 5px; |
| 146 | 146 | } |
| 147 | 147 | .content blockquote { |
| 148 | 148 | padding: 0 15px; |
| 149 | 149 | } |
| 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 { | |
| 151 | 151 | background-color: rgba(65, 131, 196, 0.1); |
| 152 | 152 | border-left: 3px solid #254769; |
| 153 | 153 | padding: .1em 1em; |
| 154 | 154 | } |
| 155 | 155 | |
| 156 | 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 { |
| 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 |
+4
-3
| --- skins/default/header.txt | ||
| +++ skins/default/header.txt | ||
| @@ -1,10 +1,10 @@ | ||
| 1 | 1 | <div class="header"> |
| 2 | 2 | <div class="title"><h1>$<project_name></h1>$<title></div> |
| 3 | 3 | <div class="status"><th1> |
| 4 | 4 | if {[info exists login]} { |
| 5 | - html "$login — <a href='$home/login'>Logout</a>\n" | |
| 5 | + html "<a href='$home/login'>$login</a>\n" | |
| 6 | 6 | } else { |
| 7 | 7 | html "<a href='$home/login'>Login</a>\n" |
| 8 | 8 | } |
| 9 | 9 | </th1></div> |
| 10 | 10 | </div> |
| @@ -17,17 +17,18 @@ | ||
| 17 | 17 | html "<a href='$home$url' class='active $cls'>$name</a>\n" |
| 18 | 18 | } else { |
| 19 | 19 | html "<a href='$home$url' class='$cls'>$name</a>\n" |
| 20 | 20 | } |
| 21 | 21 | } |
| 22 | -html "<a id='hbbtn' href='/sitemap'>☰</a>" | |
| 22 | +html "<a id='hbbtn' href='$home/sitemap' aria-label='Site Map'>☰</a>" | |
| 23 | 23 | menulink $index_page Home {} |
| 24 | 24 | if {[anycap jor]} { |
| 25 | 25 | menulink /timeline Timeline {} |
| 26 | 26 | } |
| 27 | 27 | 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 | |
| 29 | 30 | } |
| 30 | 31 | if {[hascap o]} { |
| 31 | 32 | menulink /brlist Branches desktoponly |
| 32 | 33 | menulink /taglist Tags wideonly |
| 33 | 34 | } |
| 34 | 35 |
| --- 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'>☰</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'>☰</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 |
+52
| --- skins/eagle/css.txt | ||
| +++ skins/eagle/css.txt | ||
| @@ -16,10 +16,11 @@ | ||
| 16 | 16 | text-align: center; |
| 17 | 17 | vertical-align: bottom; |
| 18 | 18 | font-weight: bold; |
| 19 | 19 | color: white; |
| 20 | 20 | padding: 5 0 5 0em; |
| 21 | + min-width: 200px; | |
| 21 | 22 | white-space: nowrap; |
| 22 | 23 | } |
| 23 | 24 | |
| 24 | 25 | /* The page title centered at the top of each page */ |
| 25 | 26 | div.title { |
| @@ -353,10 +354,46 @@ | ||
| 353 | 354 | } |
| 354 | 355 | |
| 355 | 356 | .fileage tr:hover { |
| 356 | 357 | background-color: #7EA2D9; |
| 357 | 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 | +} | |
| 358 | 395 | |
| 359 | 396 | .fileage td { |
| 360 | 397 | font-family: "courier new"; |
| 361 | 398 | } |
| 362 | 399 | |
| @@ -373,5 +410,20 @@ | ||
| 373 | 410 | } |
| 374 | 411 | |
| 375 | 412 | .timelineModernCell[id], .timelineColumnarCell[id], .timelineDetailCell[id] { |
| 376 | 413 | background-color: #455978; |
| 377 | 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 | +} | |
| 378 | 430 | |
| 379 | 431 | 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 |
+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 |
| --- 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 @@ | ||
| 22 | 22 | #include "add.h" |
| 23 | 23 | #include <assert.h> |
| 24 | 24 | #include <dirent.h> |
| 25 | 25 | #include "cygsup.h" |
| 26 | 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 | 27 | /* |
| 46 | 28 | ** This routine returns the names of files in a working checkout that |
| 47 | 29 | ** are created by Fossil itself, and hence should not be added, deleted, |
| 48 | 30 | ** or merge, and should be omitted from "clean" and "extras" lists. |
| 49 | 31 | ** |
| @@ -240,18 +222,109 @@ | ||
| 240 | 222 | } |
| 241 | 223 | db_finalize(&loop); |
| 242 | 224 | blob_reset(&repoName); |
| 243 | 225 | return nAdd; |
| 244 | 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 | + | |
| 245 | 318 | |
| 246 | 319 | /* |
| 247 | 320 | ** COMMAND: add |
| 248 | 321 | ** |
| 249 | 322 | ** Usage: %fossil add ?OPTIONS? FILE1 ?FILE2 ...? |
| 250 | 323 | ** |
| 251 | 324 | ** 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]]. | |
| 253 | 326 | ** |
| 254 | 327 | ** When adding files or directories recursively, filenames that begin |
| 255 | 328 | ** with "." are excluded by default. To include such files, add |
| 256 | 329 | ** the "--dotfiles" option to the command-line. |
| 257 | 330 | ** |
| @@ -269,19 +342,28 @@ | ||
| 269 | 342 | ** be treated case sensitive or not. If the option is not given, the default |
| 270 | 343 | ** depends on the global setting, or the operating system default, if not set. |
| 271 | 344 | ** |
| 272 | 345 | ** Options: |
| 273 | 346 | ** |
| 274 | -** --case-sensitive <BOOL> Override the case-sensitive setting. | |
| 347 | +** --case-sensitive BOOL Override the case-sensitive setting. | |
| 275 | 348 | ** --dotfiles include files beginning with a dot (".") |
| 276 | 349 | ** -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. | |
| 281 | 363 | ** |
| 282 | -** See also: addremove, rm | |
| 364 | +** See also: [[addremove]], [[rm]] | |
| 283 | 365 | */ |
| 284 | 366 | void add_cmd(void){ |
| 285 | 367 | int i; /* Loop counter */ |
| 286 | 368 | int vid; /* Currently checked out version */ |
| 287 | 369 | int nRoot; /* Full path characters in g.zLocalRoot */ |
| @@ -288,10 +370,19 @@ | ||
| 288 | 370 | const char *zCleanFlag; /* The --clean option or clean-glob setting */ |
| 289 | 371 | const char *zIgnoreFlag; /* The --ignore option or ignore-glob setting */ |
| 290 | 372 | Glob *pIgnore, *pClean; /* Ignore everything matching the glob patterns */ |
| 291 | 373 | unsigned scanFlags = 0; /* Flags passed to vfile_scan() */ |
| 292 | 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 | + } | |
| 293 | 384 | |
| 294 | 385 | zCleanFlag = find_option("clean",0,1); |
| 295 | 386 | zIgnoreFlag = find_option("ignore",0,1); |
| 296 | 387 | forceFlag = find_option("force","f",0)!=0; |
| 297 | 388 | if( find_option("dotfiles",0,0)!=0 ) scanFlags |= SCAN_ALL; |
| @@ -442,22 +533,36 @@ | ||
| 442 | 533 | ** --soft Skip removing files from the checkout. |
| 443 | 534 | ** This supersedes the --hard option. |
| 444 | 535 | ** --hard Remove files from the checkout. |
| 445 | 536 | ** --case-sensitive <BOOL> Override the case-sensitive setting. |
| 446 | 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. | |
| 447 | 545 | ** |
| 448 | -** See also: addremove, add | |
| 546 | +** See also: [[addremove]], [[add]] | |
| 449 | 547 | */ |
| 450 | 548 | void delete_cmd(void){ |
| 451 | 549 | int i; |
| 452 | 550 | int removeFiles; |
| 453 | - int dryRunFlag; | |
| 551 | + int dryRunFlag = find_option("dry-run","n",0)!=0; | |
| 454 | 552 | int softFlag; |
| 455 | 553 | int hardFlag; |
| 456 | 554 | Stmt loop; |
| 457 | 555 | |
| 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 | + | |
| 459 | 564 | softFlag = find_option("soft",0,0)!=0; |
| 460 | 565 | hardFlag = find_option("hard",0,0)!=0; |
| 461 | 566 | |
| 462 | 567 | /* We should be done with options.. */ |
| 463 | 568 | verify_all_options(); |
| @@ -469,15 +574,11 @@ | ||
| 469 | 574 | }else if( softFlag ){ |
| 470 | 575 | removeFiles = 0; |
| 471 | 576 | }else if( hardFlag ){ |
| 472 | 577 | removeFiles = 1; |
| 473 | 578 | }else{ |
| 474 | -#if FOSSIL_ENABLE_LEGACY_MV_RM | |
| 475 | 579 | removeFiles = db_get_boolean("mv-rm-files",0); |
| 476 | -#else | |
| 477 | - removeFiles = FOSSIL_MV_RM_FILE; | |
| 478 | -#endif | |
| 479 | 580 | } |
| 480 | 581 | db_multi_exec("CREATE TEMP TABLE sfile(pathname TEXT PRIMARY KEY %s)", |
| 481 | 582 | filename_collation()); |
| 482 | 583 | for(i=2; i<g.argc; i++){ |
| 483 | 584 | Blob treeName; |
| @@ -588,22 +689,22 @@ | ||
| 588 | 689 | /* |
| 589 | 690 | ** COMMAND: addremove |
| 590 | 691 | ** |
| 591 | 692 | ** Usage: %fossil addremove ?OPTIONS? |
| 592 | 693 | ** |
| 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: | |
| 595 | 696 | ** |
| 596 | 697 | ** * All files in the checkout but not in the repository (that is, |
| 597 | 698 | ** all files displayed using the "extras" command) are added as |
| 598 | -** if by the "add" command. | |
| 699 | +** if by the "[[add]]" command. | |
| 599 | 700 | ** |
| 600 | 701 | ** * All files in the repository but missing from the checkout (that is, |
| 601 | 702 | ** 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. | |
| 603 | 704 | ** |
| 604 | -** The command does not "commit". You must run the "commit" separately | |
| 705 | +** The command does not "[[commit]]". You must run the "[[commit]]" separately | |
| 605 | 706 | ** as a separate step. |
| 606 | 707 | ** |
| 607 | 708 | ** Files and directories whose names begin with "." are ignored unless |
| 608 | 709 | ** the --dotfiles option is used. |
| 609 | 710 | ** |
| @@ -616,25 +717,33 @@ | ||
| 616 | 717 | ** anything. |
| 617 | 718 | ** |
| 618 | 719 | ** This command can be used to track third party software. |
| 619 | 720 | ** |
| 620 | 721 | ** Options: |
| 621 | -** --case-sensitive <BOOL> Override the case-sensitive setting. | |
| 722 | +** --case-sensitive BOOL Override the case-sensitive setting. | |
| 622 | 723 | ** --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 | |
| 627 | 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. | |
| 628 | 737 | ** |
| 629 | -** See also: add, rm | |
| 738 | +** See also: [[add]], [[rm]] | |
| 630 | 739 | */ |
| 631 | 740 | void addremove_cmd(void){ |
| 632 | 741 | 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; | |
| 636 | 745 | int dryRunFlag = find_option("dry-run","n",0)!=0; |
| 637 | 746 | int n; |
| 638 | 747 | Stmt q; |
| 639 | 748 | int vid; |
| 640 | 749 | int nAdd = 0; |
| @@ -643,10 +752,23 @@ | ||
| 643 | 752 | |
| 644 | 753 | if( !dryRunFlag ){ |
| 645 | 754 | dryRunFlag = find_option("test",0,0)!=0; /* deprecated */ |
| 646 | 755 | } |
| 647 | 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 | + | |
| 648 | 770 | /* We should be done with options.. */ |
| 649 | 771 | verify_all_options(); |
| 650 | 772 | |
| 651 | 773 | /* Fail if unprocessed arguments are present, in case user expect the |
| 652 | 774 | ** addremove command to accept a list of file or directory. |
| @@ -710,11 +832,10 @@ | ||
| 710 | 832 | /* show command summary */ |
| 711 | 833 | fossil_print("added %d files, deleted %d files\n", nAdd, nDelete); |
| 712 | 834 | |
| 713 | 835 | db_end_transaction(dryRunFlag); |
| 714 | 836 | } |
| 715 | - | |
| 716 | 837 | |
| 717 | 838 | /* |
| 718 | 839 | ** Rename a single file. |
| 719 | 840 | ** |
| 720 | 841 | ** The original name of the file is zOrig. The new filename is zNew. |
| @@ -832,11 +953,11 @@ | ||
| 832 | 953 | ** Move or rename one or more files or directories within the repository tree. |
| 833 | 954 | ** You can either rename a file or directory or move it to another subdirectory. |
| 834 | 955 | ** |
| 835 | 956 | ** The 'mv' command does NOT normally rename or move the files on disk. |
| 836 | 957 | ** 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]]. | |
| 838 | 959 | ** However, the default behavior of this command may be overridden via |
| 839 | 960 | ** command line options listed below and/or the 'mv-rm-files' setting. |
| 840 | 961 | ** |
| 841 | 962 | ** The 'rename' command never renames or moves files on disk, even when the |
| 842 | 963 | ** command line options and/or the 'mv-rm-files' setting would otherwise |
| @@ -845,17 +966,17 @@ | ||
| 845 | 966 | ** WARNING: If the "--hard" option is specified -OR- the "mv-rm-files" |
| 846 | 967 | ** setting is non-zero, files WILL BE renamed or moved on disk |
| 847 | 968 | ** as well. This does NOT apply to the 'rename' command. |
| 848 | 969 | ** |
| 849 | 970 | ** 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. | |
| 855 | 976 | ** |
| 856 | -** See also: changes, status | |
| 977 | +** See also: [[changes]], [[status]] | |
| 857 | 978 | */ |
| 858 | 979 | void mv_cmd(void){ |
| 859 | 980 | int i; |
| 860 | 981 | int vid; |
| 861 | 982 | int moveFiles; |
| @@ -890,15 +1011,11 @@ | ||
| 890 | 1011 | }else if( softFlag ){ |
| 891 | 1012 | moveFiles = 0; |
| 892 | 1013 | }else if( hardFlag ){ |
| 893 | 1014 | moveFiles = 1; |
| 894 | 1015 | }else{ |
| 895 | -#if FOSSIL_ENABLE_LEGACY_MV_RM | |
| 896 | 1016 | moveFiles = db_get_boolean("mv-rm-files",0); |
| 897 | -#else | |
| 898 | - moveFiles = FOSSIL_MV_RM_FILE; | |
| 899 | -#endif | |
| 900 | 1017 | } |
| 901 | 1018 | file_tree_name(zDest, &dest, 0, 1); |
| 902 | 1019 | db_multi_exec( |
| 903 | 1020 | "UPDATE vfile SET origname=pathname WHERE origname IS NULL;" |
| 904 | 1021 | ); |
| @@ -947,11 +1064,11 @@ | ||
| 947 | 1064 | const char *zPath = db_column_text(&q, 0); |
| 948 | 1065 | int nPath = db_column_bytes(&q, 0); |
| 949 | 1066 | const char *zTail; |
| 950 | 1067 | if( nPath==nOrig ){ |
| 951 | 1068 | zTail = file_tail(zPath); |
| 952 | - }else if( destType==1 ){ | |
| 1069 | + }else if( origType!=0 && destType==1 ){ | |
| 953 | 1070 | zTail = &zPath[nOrig-strlen(file_tail(zOrig))]; |
| 954 | 1071 | }else{ |
| 955 | 1072 | zTail = &zPath[nOrig+1]; |
| 956 | 1073 | } |
| 957 | 1074 | db_multi_exec( |
| 958 | 1075 | |
| 959 | 1076 | 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 @@ | ||
| 46 | 46 | @ -- |
| 47 | 47 | @ -- The ssub field is a string where each character indicates a particular |
| 48 | 48 | @ -- type of event to subscribe to. Choices: |
| 49 | 49 | @ -- a - Announcements |
| 50 | 50 | @ -- c - Check-ins |
| 51 | +@ -- f - Forum posts | |
| 51 | 52 | @ -- t - Ticket changes |
| 52 | 53 | @ -- w - Wiki changes |
| 53 | 54 | @ -- Probably different codes will be added in the future. In the future |
| 54 | 55 | @ -- we might also add a separate table that allows subscribing to email |
| 55 | 56 | @ -- notifications for specific branches or tags or tickets. |
| @@ -114,11 +115,11 @@ | ||
| 114 | 115 | if( bOnlyIfEnabled |
| 115 | 116 | && fossil_strcmp(db_get("email-send-method",0),"off")==0 |
| 116 | 117 | ){ |
| 117 | 118 | return; /* Don't create table for disabled email */ |
| 118 | 119 | } |
| 119 | - db_multi_exec(zAlertInit/*works-like:""*/); | |
| 120 | + db_exec_sql(zAlertInit); | |
| 120 | 121 | alert_triggers_enable(); |
| 121 | 122 | }else if( !db_table_has_column("repository","pending_alert","sentMod") ){ |
| 122 | 123 | db_multi_exec( |
| 123 | 124 | "ALTER TABLE repository.pending_alert" |
| 124 | 125 | " ADD COLUMN sentMod BOOLEAN DEFAULT false;" |
| @@ -183,11 +184,11 @@ | ||
| 183 | 184 | ** is an administrator. |
| 184 | 185 | */ |
| 185 | 186 | void alert_submenu_common(void){ |
| 186 | 187 | if( g.perm.Admin ){ |
| 187 | 188 | if( fossil_strcmp(g.zPath,"subscribers") ){ |
| 188 | - style_submenu_element("List Subscribers","%R/subscribers"); | |
| 189 | + style_submenu_element("Subscribers","%R/subscribers"); | |
| 189 | 190 | } |
| 190 | 191 | if( fossil_strcmp(g.zPath,"subscribe") ){ |
| 191 | 192 | style_submenu_element("Add New Subscriber","%R/subscribe"); |
| 192 | 193 | } |
| 193 | 194 | } |
| @@ -238,10 +239,17 @@ | ||
| 238 | 239 | @ This is URL used as the basename for hyperlinks included in |
| 239 | 240 | @ email alert text. Omit the trailing "/". |
| 240 | 241 | @ Suggested value: "%h(g.zBaseURL)" |
| 241 | 242 | @ (Property: "email-url")</p> |
| 242 | 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> | |
| 243 | 251 | |
| 244 | 252 | entry_attribute("\"Return-Path\" email address", 20, "email-self", |
| 245 | 253 | "eself", "", 0); |
| 246 | 254 | @ <p><b>Required.</b> |
| 247 | 255 | @ This is the email to which email notification bounces should be sent. |
| @@ -297,17 +305,10 @@ | ||
| 297 | 305 | @ append a colon and TCP port number (ex: smtp.example.com:587). |
| 298 | 306 | @ The default TCP port number is 25. |
| 299 | 307 | @ (Property: "email-send-relayhost")</p> |
| 300 | 308 | @ <hr> |
| 301 | 309 | |
| 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 | 310 | @ <p><input type="submit" name="submit" value="Apply Changes" /></p> |
| 310 | 311 | @ </div></form> |
| 311 | 312 | db_end_transaction(0); |
| 312 | 313 | style_footer(); |
| 313 | 314 | } |
| @@ -574,22 +575,18 @@ | ||
| 574 | 575 | } |
| 575 | 576 | return 0; |
| 576 | 577 | } |
| 577 | 578 | |
| 578 | 579 | /* |
| 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){ | |
| 591 | 588 | int i; |
| 592 | 589 | int nAt = 0; |
| 593 | 590 | int nDot = 0; |
| 594 | 591 | char c; |
| 595 | 592 | if( z[0]=='.' ) return 0; /* Local part cannot begin with "." */ |
| @@ -619,13 +616,28 @@ | ||
| 619 | 616 | } |
| 620 | 617 | } |
| 621 | 618 | if( c!=cTerm ) return 0; /* Missing terminator */ |
| 622 | 619 | if( nAt==0 ) return 0; /* No "@" found anywhere */ |
| 623 | 620 | if( nDot==0 ) return 0; /* No "." in the domain */ |
| 621 | + return i; | |
| 622 | +} | |
| 624 | 623 | |
| 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); | |
| 627 | 639 | } |
| 628 | 640 | |
| 629 | 641 | /* |
| 630 | 642 | ** Scan the input string for a valid email address enclosed in <...> |
| 631 | 643 | ** If the string contains one or more email addresses, extract the first |
| @@ -659,10 +671,38 @@ | ||
| 659 | 671 | char *zOut = alert_find_emailaddr(zIn); |
| 660 | 672 | if( zOut ){ |
| 661 | 673 | sqlite3_result_text(context, zOut, -1, fossil_free); |
| 662 | 674 | } |
| 663 | 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 | +} | |
| 664 | 704 | |
| 665 | 705 | /* |
| 666 | 706 | ** Return the hostname portion of an email address - the part following |
| 667 | 707 | ** the @ |
| 668 | 708 | */ |
| @@ -762,11 +802,11 @@ | ||
| 762 | 802 | ** Date: |
| 763 | 803 | ** Message-Id: |
| 764 | 804 | ** Content-Type: |
| 765 | 805 | ** Content-Transfer-Encoding: |
| 766 | 806 | ** MIME-Version: |
| 767 | -** X-Fossil-From: | |
| 807 | +** Sender: | |
| 768 | 808 | ** |
| 769 | 809 | ** The caller maintains ownership of the input Blobs. This routine will |
| 770 | 810 | ** read the Blobs and send them onward to the email system, but it will |
| 771 | 811 | ** not free them. |
| 772 | 812 | ** |
| @@ -774,14 +814,14 @@ | ||
| 774 | 814 | ** in the pHdr parameter. |
| 775 | 815 | ** |
| 776 | 816 | ** If the zFromName argument is not NULL, then it should be a human-readable |
| 777 | 817 | ** name or handle for the sender. In that case, "From:" becomes a made-up |
| 778 | 818 | ** 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 | |
| 781 | 821 | ** 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 | |
| 783 | 823 | ** omitted. |
| 784 | 824 | */ |
| 785 | 825 | void alert_send( |
| 786 | 826 | AlertSender *p, /* Emailer context */ |
| 787 | 827 | Blob *pHdr, /* Email header (incomplete) */ |
| @@ -794,26 +834,26 @@ | ||
| 794 | 834 | fossil_print("Sending email\n"); |
| 795 | 835 | } |
| 796 | 836 | if( fossil_strcmp(p->zDest, "off")==0 ){ |
| 797 | 837 | return; |
| 798 | 838 | } |
| 839 | + blob_init(&all, 0, 0); | |
| 799 | 840 | if( fossil_strcmp(p->zDest, "blob")==0 ){ |
| 800 | 841 | pOut = &p->out; |
| 801 | 842 | if( blob_size(pOut) ){ |
| 802 | 843 | blob_appendf(pOut, "%.72c\n", '='); |
| 803 | 844 | } |
| 804 | 845 | }else{ |
| 805 | - blob_init(&all, 0, 0); | |
| 806 | 846 | pOut = &all; |
| 807 | 847 | } |
| 808 | 848 | blob_append(pOut, blob_buffer(pHdr), blob_size(pHdr)); |
| 809 | 849 | if( p->zFrom==0 || p->zFrom[0]==0 ){ |
| 810 | 850 | return; /* email-self is not set. Error will be reported separately */ |
| 811 | 851 | }else if( zFromName ){ |
| 812 | 852 | blob_appendf(pOut, "From: %s <%s@%s>\r\n", |
| 813 | 853 | 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); | |
| 815 | 855 | }else{ |
| 816 | 856 | blob_appendf(pOut, "From: <%s>\r\n", p->zFrom); |
| 817 | 857 | } |
| 818 | 858 | blob_appendf(pOut, "Date: %z\r\n", cgi_rfc822_datestamp(time(0))); |
| 819 | 859 | if( strstr(blob_str(pHdr), "\r\nMessage-Id:")==0 ){ |
| @@ -879,10 +919,26 @@ | ||
| 879 | 919 | fossil_print("%s", blob_str(&all)); |
| 880 | 920 | } |
| 881 | 921 | blob_reset(&all); |
| 882 | 922 | } |
| 883 | 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 | +*/ | |
| 884 | 940 | /* |
| 885 | 941 | ** SETTING: email-send-method width=5 default=off |
| 886 | 942 | ** Determine the method used to send email. Allowed values are |
| 887 | 943 | ** "off", "relay", "pipe", "dir", "db", and "stdout". The "off" value |
| 888 | 944 | ** means no email is ever sent. The "relay" value means emails are sent |
| @@ -1152,10 +1208,19 @@ | ||
| 1152 | 1208 | int i, j, n; |
| 1153 | 1209 | char c; |
| 1154 | 1210 | |
| 1155 | 1211 | *peErr = 0; |
| 1156 | 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 | + } | |
| 1157 | 1222 | |
| 1158 | 1223 | /* Check the validity of the email address. |
| 1159 | 1224 | ** |
| 1160 | 1225 | ** (1) Exactly one '@' character. |
| 1161 | 1226 | ** (2) No other characters besides [a-zA-Z0-9._+-] |
| @@ -1163,11 +1228,15 @@ | ||
| 1163 | 1228 | ** The local part is currently more restrictive than RFC 5322 allows: |
| 1164 | 1229 | ** https://stackoverflow.com/a/2049510/142454 We will expand this as |
| 1165 | 1230 | ** necessary. |
| 1166 | 1231 | */ |
| 1167 | 1232 | zEAddr = P("e"); |
| 1168 | - if( zEAddr==0 ) return 0; | |
| 1233 | + if( zEAddr==0 ){ | |
| 1234 | + *peErr = 1; | |
| 1235 | + *pzErr = mprintf("required"); | |
| 1236 | + return 0; | |
| 1237 | + } | |
| 1169 | 1238 | for(i=j=n=0; (c = zEAddr[i])!=0; i++){ |
| 1170 | 1239 | if( c=='@' ){ |
| 1171 | 1240 | n = i; |
| 1172 | 1241 | j++; |
| 1173 | 1242 | continue; |
| @@ -1193,14 +1262,13 @@ | ||
| 1193 | 1262 | *peErr = 1; |
| 1194 | 1263 | *pzErr = mprintf("email domain too short"); |
| 1195 | 1264 | return 0; |
| 1196 | 1265 | } |
| 1197 | 1266 | |
| 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"); | |
| 1202 | 1270 | return 0; |
| 1203 | 1271 | } |
| 1204 | 1272 | |
| 1205 | 1273 | /* Check to make sure the email address is available for reuse */ |
| 1206 | 1274 | if( db_exists("SELECT 1 FROM subscriber WHERE semail=%Q", zEAddr) ){ |
| @@ -1259,11 +1327,11 @@ | ||
| 1259 | 1327 | ** page. To allow anonymous passers-by to sign up for email |
| 1260 | 1328 | ** notification, set Email-Alerts on user "nobody" or "anonymous". |
| 1261 | 1329 | */ |
| 1262 | 1330 | void subscribe_page(void){ |
| 1263 | 1331 | int needCaptcha; |
| 1264 | - unsigned int uSeed; | |
| 1332 | + unsigned int uSeed = 0; | |
| 1265 | 1333 | const char *zDecoded; |
| 1266 | 1334 | char *zCaptcha = 0; |
| 1267 | 1335 | char *zErr = 0; |
| 1268 | 1336 | int eErr = 0; |
| 1269 | 1337 | int di; |
| @@ -1291,10 +1359,14 @@ | ||
| 1291 | 1359 | /* Everybody else jumps to the page to administer their own |
| 1292 | 1360 | ** account only. */ |
| 1293 | 1361 | cgi_redirectf("%R/alerts"); |
| 1294 | 1362 | return; |
| 1295 | 1363 | } |
| 1364 | + } | |
| 1365 | + if( !g.perm.Admin && !db_get_boolean("anon-subscribe",1) ){ | |
| 1366 | + register_page(); | |
| 1367 | + return; | |
| 1296 | 1368 | } |
| 1297 | 1369 | alert_submenu_common(); |
| 1298 | 1370 | needCaptcha = !login_is_individual(); |
| 1299 | 1371 | if( P("submit") |
| 1300 | 1372 | && cgi_csrf_safe(1) |
| @@ -1312,10 +1384,11 @@ | ||
| 1312 | 1384 | if( PB("sa") ) ssub[nsub++] = 'a'; |
| 1313 | 1385 | if( g.perm.Read && PB("sc") ) ssub[nsub++] = 'c'; |
| 1314 | 1386 | if( g.perm.RdForum && PB("sf") ) ssub[nsub++] = 'f'; |
| 1315 | 1387 | if( g.perm.RdTkt && PB("st") ) ssub[nsub++] = 't'; |
| 1316 | 1388 | if( g.perm.RdWiki && PB("sw") ) ssub[nsub++] = 'w'; |
| 1389 | + if( g.perm.RdForum && PB("sx") ) ssub[nsub++] = 'x'; | |
| 1317 | 1390 | ssub[nsub] = 0; |
| 1318 | 1391 | db_multi_exec( |
| 1319 | 1392 | "INSERT INTO subscriber(semail,suname," |
| 1320 | 1393 | " sverified,sdonotcall,sdigest,ssub,sctime,mtime,smip)" |
| 1321 | 1394 | "VALUES(%Q,%Q,%d,0,%d,%Q,now(),now(),%Q)", |
| @@ -1332,11 +1405,15 @@ | ||
| 1332 | 1405 | id); |
| 1333 | 1406 | if( !needCaptcha ){ |
| 1334 | 1407 | /* The new subscription has been added on behalf of a logged-in user. |
| 1335 | 1408 | ** No verification is required. Jump immediately to /alerts page. |
| 1336 | 1409 | */ |
| 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 | + } | |
| 1338 | 1415 | return; |
| 1339 | 1416 | }else{ |
| 1340 | 1417 | /* We need to send a verification email */ |
| 1341 | 1418 | Blob hdr, body; |
| 1342 | 1419 | AlertSender *pSender = alert_sender_new(0,0); |
| @@ -1354,11 +1431,11 @@ | ||
| 1354 | 1431 | @ <blockquote><pre> |
| 1355 | 1432 | @ %h(pSender->zErr) |
| 1356 | 1433 | @ </pre></blockquote> |
| 1357 | 1434 | }else{ |
| 1358 | 1435 | @ <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 | |
| 1360 | 1437 | @ subscription.</p> |
| 1361 | 1438 | } |
| 1362 | 1439 | alert_sender_free(pSender); |
| 1363 | 1440 | style_footer(); |
| 1364 | 1441 | } |
| @@ -1386,16 +1463,23 @@ | ||
| 1386 | 1463 | if( eErr==1 ){ |
| 1387 | 1464 | @ <tr><td><td><span class='loginError'>↑ %h(zErr)</span></td></tr> |
| 1388 | 1465 | } |
| 1389 | 1466 | @ </tr> |
| 1390 | 1467 | 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 | + } | |
| 1392 | 1475 | zDecoded = captcha_decode(uSeed); |
| 1393 | 1476 | zCaptcha = captcha_render(zDecoded); |
| 1394 | 1477 | @ <tr> |
| 1395 | 1478 | @ <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"); | |
| 1397 | 1481 | @ <input type="hidden" name="captchaseed" value="%u(uSeed)"></td> |
| 1398 | 1482 | @ </tr> |
| 1399 | 1483 | if( eErr==2 ){ |
| 1400 | 1484 | @ <tr><td><td><span class='loginError'>↑ %h(zErr)</span></td></tr> |
| 1401 | 1485 | } |
| @@ -1421,10 +1505,12 @@ | ||
| 1421 | 1505 | @ Check-ins</label><br> |
| 1422 | 1506 | } |
| 1423 | 1507 | if( g.perm.RdForum ){ |
| 1424 | 1508 | @ <label><input type="checkbox" name="sf" %s(PCK("sf"))> \ |
| 1425 | 1509 | @ Forum Posts</label><br> |
| 1510 | + @ <label><input type="checkbox" name="sx" %s(PCK("sx"))> \ | |
| 1511 | + @ Forum Edits</label><br> | |
| 1426 | 1512 | } |
| 1427 | 1513 | if( g.perm.RdTkt ){ |
| 1428 | 1514 | @ <label><input type="checkbox" name="st" %s(PCK("st"))> \ |
| 1429 | 1515 | @ Ticket changes</label><br> |
| 1430 | 1516 | } |
| @@ -1461,11 +1547,11 @@ | ||
| 1461 | 1547 | @ </table> |
| 1462 | 1548 | if( needCaptcha ){ |
| 1463 | 1549 | @ <div class="captcha"><table class="captcha"><tr><td><pre class="captcha"> |
| 1464 | 1550 | @ %h(zCaptcha) |
| 1465 | 1551 | @ </pre> |
| 1466 | - @ Enter the 8 characters above in the "Security Code" box | |
| 1552 | + @ Enter the 8 characters above in the "Security Code" box<br/> | |
| 1467 | 1553 | @ </td></tr></table></div> |
| 1468 | 1554 | } |
| 1469 | 1555 | @ </form> |
| 1470 | 1556 | fossil_free(zErr); |
| 1471 | 1557 | style_footer(); |
| @@ -1474,21 +1560,20 @@ | ||
| 1474 | 1560 | /* |
| 1475 | 1561 | ** Either shutdown or completely delete a subscription entry given |
| 1476 | 1562 | ** by the hex value zName. Then paint a webpage that explains that |
| 1477 | 1563 | ** the entry has been removed. |
| 1478 | 1564 | */ |
| 1479 | -static void alert_unsubscribe(const char *zName){ | |
| 1565 | +static void alert_unsubscribe(int sid){ | |
| 1480 | 1566 | char *zEmail; |
| 1481 | 1567 | zEmail = db_text(0, "SELECT semail FROM subscriber" |
| 1482 | - " WHERE subscriberCode=hextoblob(%Q)", zName); | |
| 1568 | + " WHERE subscriberId=%d", sid); | |
| 1483 | 1569 | if( zEmail==0 ){ |
| 1484 | 1570 | style_header("Unsubscribe Fail"); |
| 1485 | 1571 | @ <p>Unable to locate a subscriber with the requested key</p> |
| 1486 | 1572 | }else{ |
| 1487 | 1573 | db_multi_exec( |
| 1488 | - "DELETE FROM subscriber WHERE subscriberCode=hextoblob(%Q)", | |
| 1489 | - zName | |
| 1574 | + "DELETE FROM subscriber WHERE subscriberId=%d", sid | |
| 1490 | 1575 | ); |
| 1491 | 1576 | style_header("Unsubscribed"); |
| 1492 | 1577 | @ <p>The "%h(zEmail)" email address has been delisted. |
| 1493 | 1578 | @ All traces of that email address have been removed</p> |
| 1494 | 1579 | } |
| @@ -1499,108 +1584,149 @@ | ||
| 1499 | 1584 | /* |
| 1500 | 1585 | ** WEBPAGE: alerts |
| 1501 | 1586 | ** |
| 1502 | 1587 | ** Edit email alert and notification settings. |
| 1503 | 1588 | ** |
| 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); | |
| 1591 | 1715 | } |
| 1592 | 1716 | if( P("delete")!=0 && cgi_csrf_safe(1) ){ |
| 1593 | 1717 | if( !PB("dodelete") ){ |
| 1594 | 1718 | eErr = 9; |
| 1595 | 1719 | zErr = mprintf("Select this checkbox and press \"Unsubscribe\" again to" |
| 1596 | 1720 | " unsubscribe"); |
| 1597 | 1721 | }else{ |
| 1598 | - alert_unsubscribe(zName); | |
| 1599 | - return; | |
| 1722 | + alert_unsubscribe(sid); | |
| 1723 | + db_commit_transaction(); | |
| 1724 | + return; | |
| 1600 | 1725 | } |
| 1601 | 1726 | } |
| 1727 | + style_header("Update Subscription"); | |
| 1602 | 1728 | db_prepare(&q, |
| 1603 | 1729 | "SELECT" |
| 1604 | 1730 | " semail," /* 0 */ |
| 1605 | 1731 | " sverified," /* 1 */ |
| 1606 | 1732 | " sdonotcall," /* 2 */ |
| @@ -1607,52 +1733,92 @@ | ||
| 1607 | 1733 | " sdigest," /* 3 */ |
| 1608 | 1734 | " ssub," /* 4 */ |
| 1609 | 1735 | " smip," /* 5 */ |
| 1610 | 1736 | " suname," /* 6 */ |
| 1611 | 1737 | " 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); | |
| 1614 | 1741 | if( db_step(&q)!=SQLITE_ROW ){ |
| 1615 | 1742 | db_finalize(&q); |
| 1743 | + db_commit_transaction(); | |
| 1616 | 1744 | 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 | + } | |
| 1625 | 1757 | sa = strchr(ssub,'a')!=0; |
| 1626 | 1758 | sc = strchr(ssub,'c')!=0; |
| 1627 | 1759 | sf = strchr(ssub,'f')!=0; |
| 1628 | 1760 | st = strchr(ssub,'t')!=0; |
| 1629 | 1761 | sw = strchr(ssub,'w')!=0; |
| 1762 | + sx = strchr(ssub,'x')!=0; | |
| 1630 | 1763 | smip = db_column_text(&q, 5); |
| 1631 | - suname = db_column_text(&q, 6); | |
| 1632 | 1764 | mtime = db_column_text(&q, 7); |
| 1633 | 1765 | sctime = db_column_text(&q, 8); |
| 1634 | 1766 | 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 | + } | |
| 1642 | 1794 | }else{ |
| 1643 | 1795 | @ <p>Make changes to the email subscription shown below and |
| 1644 | 1796 | @ press "Submit".</p> |
| 1645 | 1797 | } |
| 1646 | 1798 | 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)"> | |
| 1648 | 1802 | @ <table class="subscribe"> |
| 1649 | 1803 | @ <tr> |
| 1650 | 1804 | @ <td class="form_label">Email 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'>← not a valid email address!</span> | |
| 1809 | + }else if( g.perm.Admin ){ | |
| 1810 | + @ <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 | + } | |
| 1652 | 1817 | @ </tr> |
| 1653 | 1818 | if( g.perm.Admin ){ |
| 1819 | + int uid; | |
| 1654 | 1820 | @ <tr> |
| 1655 | 1821 | @ <td class='form_label'>Created:</td> |
| 1656 | 1822 | @ <td>%h(sctime)</td> |
| 1657 | 1823 | @ </tr> |
| 1658 | 1824 | @ <tr> |
| @@ -1662,13 +1828,21 @@ | ||
| 1662 | 1828 | @ <tr> |
| 1663 | 1829 | @ <td class='form_label'>IP Address:</td> |
| 1664 | 1830 | @ <td>%h(smip)</td> |
| 1665 | 1831 | @ </tr> |
| 1666 | 1832 | @ <tr> |
| 1833 | + @ <td class='form_label'>Subscriber Code:</td> | |
| 1834 | + @ <td>%h(db_column_text(&q,9))</td> | |
| 1835 | + @ <tr> | |
| 1667 | 1836 | @ <td class="form_label">User:</td> |
| 1668 | 1837 | @ <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 | + @ <a href='%R/setup_uedit?id=%d(uid)'>\ | |
| 1842 | + @ (login info for %h(suname))</a>\ | |
| 1843 | + } | |
| 1670 | 1844 | @ </tr> |
| 1671 | 1845 | } |
| 1672 | 1846 | @ <tr> |
| 1673 | 1847 | @ <td class="form_label">Topics:</td> |
| 1674 | 1848 | @ <td><label><input type="checkbox" name="sa" %s(sa?"checked":"")>\ |
| @@ -1678,10 +1852,12 @@ | ||
| 1678 | 1852 | @ Check-ins</label><br> |
| 1679 | 1853 | } |
| 1680 | 1854 | if( g.perm.RdForum ){ |
| 1681 | 1855 | @ <label><input type="checkbox" name="sf" %s(sf?"checked":"")>\ |
| 1682 | 1856 | @ Forum Posts</label><br> |
| 1857 | + @ <label><input type="checkbox" name="sx" %s(sx?"checked":"")>\ | |
| 1858 | + @ Forum Edits</label><br> | |
| 1683 | 1859 | } |
| 1684 | 1860 | if( g.perm.RdTkt ){ |
| 1685 | 1861 | @ <label><input type="checkbox" name="st" %s(st?"checked":"")>\ |
| 1686 | 1862 | @ Ticket changes</label><br> |
| 1687 | 1863 | } |
| @@ -1695,19 +1871,15 @@ | ||
| 1695 | 1871 | @ <td><select size="1" name="sdigest"> |
| 1696 | 1872 | @ <option value="0" %s(sdigest?"":"selected")>Individual Emails</option> |
| 1697 | 1873 | @ <option value="1" %s(sdigest?"selected":"")>Daily Digest</option> |
| 1698 | 1874 | @ </select></td> |
| 1699 | 1875 | @ </tr> |
| 1700 | -#if 0 | |
| 1701 | - @ <label><input type="checkbox" name="sdigest" %s(sdigest?"checked":"")>\ | |
| 1702 | - @ Daily digest only</label><br> | |
| 1703 | -#endif | |
| 1704 | 1876 | if( g.perm.Admin ){ |
| 1705 | 1877 | @ <tr> |
| 1706 | 1878 | @ <td class="form_label">Admin Options:</td><td> |
| 1707 | 1879 | @ <label><input type="checkbox" name="sdonotcall" \ |
| 1708 | - @ %s(sdonotcall?"checked":"")> Do not call</label><br> | |
| 1880 | + @ %s(sdonotcall?"checked":"")> Do not disturb</label><br> | |
| 1709 | 1881 | @ <label><input type="checkbox" name="sverified" \ |
| 1710 | 1882 | @ %s(sverified?"checked":"")>\ |
| 1711 | 1883 | @ Verified</label></td></tr> |
| 1712 | 1884 | } |
| 1713 | 1885 | if( eErr==9 ){ |
| @@ -1726,10 +1898,12 @@ | ||
| 1726 | 1898 | @ </table> |
| 1727 | 1899 | @ </form> |
| 1728 | 1900 | fossil_free(zErr); |
| 1729 | 1901 | db_finalize(&q); |
| 1730 | 1902 | style_footer(); |
| 1903 | + db_commit_transaction(); | |
| 1904 | + return; | |
| 1731 | 1905 | } |
| 1732 | 1906 | |
| 1733 | 1907 | /* This is the message that gets sent to describe how to change |
| 1734 | 1908 | ** or modify a subscription |
| 1735 | 1909 | */ |
| @@ -1760,25 +1934,26 @@ | ||
| 1760 | 1934 | */ |
| 1761 | 1935 | void unsubscribe_page(void){ |
| 1762 | 1936 | const char *zName = P("name"); |
| 1763 | 1937 | char *zErr = 0; |
| 1764 | 1938 | int eErr = 0; |
| 1765 | - unsigned int uSeed; | |
| 1939 | + unsigned int uSeed = 0; | |
| 1766 | 1940 | const char *zDecoded; |
| 1767 | 1941 | char *zCaptcha = 0; |
| 1768 | 1942 | int dx; |
| 1769 | 1943 | int bSubmit; |
| 1770 | 1944 | const char *zEAddr; |
| 1771 | 1945 | char *zCode = 0; |
| 1946 | + int sid = 0; | |
| 1772 | 1947 | |
| 1773 | 1948 | /* If a valid subscriber code is supplied, then unsubscribe immediately. |
| 1774 | 1949 | */ |
| 1775 | 1950 | 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 | |
| 1778 | 1953 | ){ |
| 1779 | - alert_unsubscribe(zName); | |
| 1954 | + alert_unsubscribe(sid); | |
| 1780 | 1955 | return; |
| 1781 | 1956 | } |
| 1782 | 1957 | |
| 1783 | 1958 | /* Logged in users are redirected to the /alerts page */ |
| 1784 | 1959 | login_check_credentials(); |
| @@ -1855,10 +2030,11 @@ | ||
| 1855 | 2030 | zDecoded = captcha_decode(uSeed); |
| 1856 | 2031 | zCaptcha = captcha_render(zDecoded); |
| 1857 | 2032 | @ <tr> |
| 1858 | 2033 | @ <td class="form_label">Security Code:</td> |
| 1859 | 2034 | @ <td><input type="text" name="captcha" value="" size="30"> |
| 2035 | + captcha_speakit_button(uSeed, "Speak the code"); | |
| 1860 | 2036 | @ <input type="hidden" name="captchaseed" value="%u(uSeed)"></td> |
| 1861 | 2037 | if( eErr==2 ){ |
| 1862 | 2038 | @ <td><span class="loginError">← %h(zErr)</span></td> |
| 1863 | 2039 | } |
| 1864 | 2040 | @ </tr> |
| @@ -1874,11 +2050,11 @@ | ||
| 1874 | 2050 | @ </tr> |
| 1875 | 2051 | @ </table> |
| 1876 | 2052 | @ <div class="captcha"><table class="captcha"><tr><td><pre class="captcha"> |
| 1877 | 2053 | @ %h(zCaptcha) |
| 1878 | 2054 | @ </pre> |
| 1879 | - @ Enter the 8 characters above in the "Security Code" box | |
| 2055 | + @ Enter the 8 characters above in the "Security Code" box<br/> | |
| 1880 | 2056 | @ </td></tr></table></div> |
| 1881 | 2057 | @ </form> |
| 1882 | 2058 | fossil_free(zErr); |
| 1883 | 2059 | style_footer(); |
| 1884 | 2060 | } |
| @@ -1885,37 +2061,69 @@ | ||
| 1885 | 2061 | |
| 1886 | 2062 | /* |
| 1887 | 2063 | ** WEBPAGE: subscribers |
| 1888 | 2064 | ** |
| 1889 | 2065 | ** This page, accessible to administrators only, |
| 1890 | -** shows a list of email notification email addresses. | |
| 2066 | +** shows a list of subscriber email addresses. | |
| 1891 | 2067 | ** Clicking on an email takes one to the /alerts page |
| 1892 | 2068 | ** for that email where the delivery settings can be |
| 1893 | 2069 | ** modified. |
| 1894 | 2070 | */ |
| 1895 | 2071 | void subscriber_list_page(void){ |
| 1896 | 2072 | Blob sql; |
| 1897 | 2073 | Stmt q; |
| 1898 | 2074 | sqlite3_int64 iNow; |
| 2075 | + int nTotal; | |
| 2076 | + int nPending; | |
| 2077 | + int nDel = 0; | |
| 1899 | 2078 | if( alert_webpages_disabled() ) return; |
| 1900 | 2079 | login_check_credentials(); |
| 1901 | 2080 | if( !g.perm.Admin ){ |
| 1902 | 2081 | login_needed(0); |
| 1903 | 2082 | return; |
| 1904 | 2083 | } |
| 1905 | 2084 | alert_submenu_common(); |
| 2085 | + style_submenu_element("Users","setup_ulist"); | |
| 1906 | 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 | + } | |
| 1907 | 2114 | blob_init(&sql, 0, 0); |
| 1908 | 2115 | blob_append_sql(&sql, |
| 1909 | - "SELECT hex(subscriberCode)," /* 0 */ | |
| 2116 | + "SELECT subscriberId," /* 0 */ | |
| 1910 | 2117 | " semail," /* 1 */ |
| 1911 | 2118 | " ssub," /* 2 */ |
| 1912 | 2119 | " suname," /* 3 */ |
| 1913 | 2120 | " sverified," /* 4 */ |
| 1914 | 2121 | " sdigest," /* 5 */ |
| 1915 | 2122 | " mtime," /* 6 */ |
| 1916 | - " date(sctime,'unixepoch')" /* 7 */ | |
| 2123 | + " date(sctime,'unixepoch')," /* 7 */ | |
| 2124 | + " (SELECT uid FROM user WHERE login=subscriber.suname)" /* 8 */ | |
| 1917 | 2125 | " FROM subscriber" |
| 1918 | 2126 | ); |
| 1919 | 2127 | if( P("only")!=0 ){ |
| 1920 | 2128 | blob_append_sql(&sql, " WHERE ssub LIKE '%%%q%%'", P("only")); |
| 1921 | 2129 | style_submenu_element("Show All","%R/subscribers"); |
| @@ -1937,16 +2145,22 @@ | ||
| 1937 | 2145 | @ </tr> |
| 1938 | 2146 | @ </thead><tbody> |
| 1939 | 2147 | while( db_step(&q)==SQLITE_ROW ){ |
| 1940 | 2148 | sqlite3_int64 iMtime = db_column_int64(&q, 6); |
| 1941 | 2149 | double rAge = (iNow - iMtime)/86400.0; |
| 2150 | + int uid = db_column_int(&q, 8); | |
| 2151 | + const char *zUname = db_column_text(&q, 3); | |
| 1942 | 2152 | @ <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))'>\ | |
| 1944 | 2154 | @ %h(db_column_text(&q,1))</a></td> |
| 1945 | 2155 | @ <td>%h(db_column_text(&q,2))</td> |
| 1946 | 2156 | @ <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 | + } | |
| 1948 | 2162 | @ <td>%s(db_column_int(&q,4)?"yes":"pending")</td> |
| 1949 | 2163 | @ <td data-sortkey='%010llx(iMtime)'>%z(human_readable_age(rAge))</td> |
| 1950 | 2164 | @ <td>%h(db_column_text(&q,7))</td> |
| 1951 | 2165 | @ </tr> |
| 1952 | 2166 | } |
| @@ -1958,13 +2172,21 @@ | ||
| 1958 | 2172 | |
| 1959 | 2173 | #if LOCAL_INTERFACE |
| 1960 | 2174 | /* |
| 1961 | 2175 | ** A single event that might appear in an alert is recorded as an |
| 1962 | 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 | |
| 1963 | 2185 | */ |
| 1964 | 2186 | struct EmailEvent { |
| 1965 | - int type; /* 'c', 'f', 'm', 't', 'w' */ | |
| 2187 | + int type; /* 'c', 'f', 't', 'w', 'x' */ | |
| 1966 | 2188 | int needMod; /* Pending moderator approval */ |
| 1967 | 2189 | Blob hdr; /* Header content, for forum entries */ |
| 1968 | 2190 | Blob txt; /* Text description to appear in an alert */ |
| 1969 | 2191 | char *zFromName; /* Human name of the sender */ |
| 1970 | 2192 | EmailEvent *pNext; /* Next in chronological order */ |
| @@ -2039,20 +2261,20 @@ | ||
| 2039 | 2261 | p->needMod = db_column_int(&q, 4); |
| 2040 | 2262 | p->zFromName = 0; |
| 2041 | 2263 | p->pNext = 0; |
| 2042 | 2264 | switch( p->type ){ |
| 2043 | 2265 | case 'c': zType = "Check-In"; break; |
| 2044 | - case 'f': zType = "Forum post"; break; | |
| 2266 | + /* case 'f': -- forum posts omitted from this loop. See below */ | |
| 2045 | 2267 | case 't': zType = "Ticket Change"; break; |
| 2046 | 2268 | case 'w': zType = "Wiki Edit"; break; |
| 2047 | 2269 | } |
| 2048 | 2270 | blob_init(&p->hdr, 0, 0); |
| 2049 | 2271 | blob_init(&p->txt, 0, 0); |
| 2050 | 2272 | blob_appendf(&p->txt,"== %s %s ==\n%s\n%s/info/%.20s\n", |
| 2051 | 2273 | db_column_text(&q,1), |
| 2052 | 2274 | zType, |
| 2053 | - db_column_text(&q,2), | |
| 2275 | + db_column_text(&q, 2), | |
| 2054 | 2276 | zUrl, |
| 2055 | 2277 | db_column_text(&q,0) |
| 2056 | 2278 | ); |
| 2057 | 2279 | if( p->needMod ){ |
| 2058 | 2280 | blob_appendf(&p->txt, |
| @@ -2078,17 +2300,28 @@ | ||
| 2078 | 2300 | ** is a normal email alert. Construct full-text forum post alerts |
| 2079 | 2301 | ** using a format that enables them to be sent as separate emails. |
| 2080 | 2302 | */ |
| 2081 | 2303 | db_prepare(&q, |
| 2082 | 2304 | "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 */ | |
| 2090 | 2323 | " FROM temp.wantalert, event, forumpost" |
| 2091 | 2324 | " LEFT JOIN user ON (login=coalesce(euser,user))" |
| 2092 | 2325 | " WHERE event.objid=substr(wantalert.eventId,2)+0" |
| 2093 | 2326 | " AND eventId GLOB 'f*'" |
| 2094 | 2327 | " AND forumpost.fpid=event.objid" |
| @@ -2104,11 +2337,11 @@ | ||
| 2104 | 2337 | const char *z; |
| 2105 | 2338 | if( pPost==0 ) continue; |
| 2106 | 2339 | p = fossil_malloc( sizeof(EmailEvent) ); |
| 2107 | 2340 | pLast->pNext = p; |
| 2108 | 2341 | pLast = p; |
| 2109 | - p->type = 'f'; | |
| 2342 | + p->type = db_column_int(&q,7) ? 'f' : 'x'; | |
| 2110 | 2343 | p->needMod = db_column_int(&q, 5); |
| 2111 | 2344 | z = db_column_text(&q,6); |
| 2112 | 2345 | p->zFromName = z && z[0] ? fossil_strdup(z) : 0; |
| 2113 | 2346 | p->pNext = 0; |
| 2114 | 2347 | blob_init(&p->hdr, 0, 0); |
| @@ -2321,13 +2554,14 @@ | ||
| 2321 | 2554 | ** the process malfunctions or crashes, some notifications may never |
| 2322 | 2555 | ** be sent. But that is better than some recurring bug causing |
| 2323 | 2556 | ** subscribers to be flooded with repeated notifications every 60 |
| 2324 | 2557 | ** seconds! |
| 2325 | 2558 | */ |
| 2326 | -void alert_send_alerts(u32 flags){ | |
| 2559 | +int alert_send_alerts(u32 flags){ | |
| 2327 | 2560 | EmailEvent *pEvents, *p; |
| 2328 | 2561 | int nEvent = 0; |
| 2562 | + int nSent = 0; | |
| 2329 | 2563 | Stmt q; |
| 2330 | 2564 | const char *zDigest = "false"; |
| 2331 | 2565 | Blob hdr, body; |
| 2332 | 2566 | const char *zUrl; |
| 2333 | 2567 | const char *zRepoName; |
| @@ -2436,13 +2670,13 @@ | ||
| 2436 | 2670 | ** if the recipient is a moderator for that type of event. Setup |
| 2437 | 2671 | ** and Admin users always get notified. */ |
| 2438 | 2672 | char xType = '*'; |
| 2439 | 2673 | if( strpbrk(zCap,"as")==0 ){ |
| 2440 | 2674 | 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; | |
| 2444 | 2678 | } |
| 2445 | 2679 | if( strchr(zCap,xType)==0 ) continue; |
| 2446 | 2680 | } |
| 2447 | 2681 | }else if( strchr(zCap,'s')!=0 || strchr(zCap,'a')!=0 ){ |
| 2448 | 2682 | /* Setup and admin users can get any notification that does not |
| @@ -2450,14 +2684,14 @@ | ||
| 2450 | 2684 | }else{ |
| 2451 | 2685 | /* Other users only see the alert if they have sufficient |
| 2452 | 2686 | ** privilege to view the event itself */ |
| 2453 | 2687 | char xType = '*'; |
| 2454 | 2688 | 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; | |
| 2459 | 2693 | } |
| 2460 | 2694 | if( strchr(zCap,xType)==0 ) continue; |
| 2461 | 2695 | } |
| 2462 | 2696 | if( blob_size(&p->hdr)>0 ){ |
| 2463 | 2697 | /* This alert should be sent as a separate email */ |
| @@ -2467,10 +2701,11 @@ | ||
| 2467 | 2701 | blob_append(&fhdr, blob_buffer(&p->hdr), blob_size(&p->hdr)); |
| 2468 | 2702 | blob_init(&fbody, blob_buffer(&p->txt), blob_size(&p->txt)); |
| 2469 | 2703 | blob_appendf(&fbody, "\n-- \nSubscription info: %s/alerts/%s\n", |
| 2470 | 2704 | zUrl, zCode); |
| 2471 | 2705 | alert_send(pSender,&fhdr,&fbody,p->zFromName); |
| 2706 | + nSent++; | |
| 2472 | 2707 | blob_reset(&fhdr); |
| 2473 | 2708 | blob_reset(&fbody); |
| 2474 | 2709 | }else{ |
| 2475 | 2710 | /* Events other than forum posts are gathered together into |
| 2476 | 2711 | ** a single email message */ |
| @@ -2490,10 +2725,11 @@ | ||
| 2490 | 2725 | } |
| 2491 | 2726 | if( nHit==0 ) continue; |
| 2492 | 2727 | blob_appendf(&body,"\n-- \nSubscription info: %s/alerts/%s\n", |
| 2493 | 2728 | zUrl, zCode); |
| 2494 | 2729 | alert_send(pSender,&hdr,&body,0); |
| 2730 | + nSent++; | |
| 2495 | 2731 | blob_truncate(&hdr, 0); |
| 2496 | 2732 | blob_truncate(&body, 0); |
| 2497 | 2733 | } |
| 2498 | 2734 | blob_reset(&hdr); |
| 2499 | 2735 | blob_reset(&body); |
| @@ -2506,10 +2742,11 @@ | ||
| 2506 | 2742 | db_multi_exec("DELETE FROM pending_alert WHERE sentDigest AND sentSep;"); |
| 2507 | 2743 | |
| 2508 | 2744 | send_alert_done: |
| 2509 | 2745 | alert_sender_free(pSender); |
| 2510 | 2746 | if( g.fSqlTrace ) fossil_trace("-- END alert_send_alerts(%u)\n", flags); |
| 2747 | + return nSent; | |
| 2511 | 2748 | } |
| 2512 | 2749 | |
| 2513 | 2750 | /* |
| 2514 | 2751 | ** Do backoffice processing for email notifications. In other words, |
| 2515 | 2752 | ** check to see if any email notifications need to occur, and then |
| @@ -2519,19 +2756,21 @@ | ||
| 2519 | 2756 | ** |
| 2520 | 2757 | ** The mFlags option is zero or more of the SENDALERT_* flags. Normally |
| 2521 | 2758 | ** this flag is zero, but the test-set-alert command sets it to |
| 2522 | 2759 | ** SENDALERT_TRACE. |
| 2523 | 2760 | */ |
| 2524 | -void alert_backoffice(u32 mFlags){ | |
| 2761 | +int alert_backoffice(u32 mFlags){ | |
| 2525 | 2762 | 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); | |
| 2528 | 2766 | iJulianDay = db_int(0, "SELECT julianday('now')"); |
| 2529 | 2767 | if( iJulianDay>db_get_int("email-last-digest",0) ){ |
| 2530 | 2768 | db_set_int("email-last-digest",iJulianDay,0); |
| 2531 | - alert_send_alerts(SENDALERT_DIGEST|mFlags); | |
| 2769 | + nSent += alert_send_alerts(SENDALERT_DIGEST|mFlags); | |
| 2532 | 2770 | } |
| 2771 | + return nSent; | |
| 2533 | 2772 | } |
| 2534 | 2773 | |
| 2535 | 2774 | /* |
| 2536 | 2775 | ** WEBPAGE: contact_admin |
| 2537 | 2776 | ** |
| @@ -2594,10 +2833,11 @@ | ||
| 2594 | 2833 | @ <table class="subscribe"> |
| 2595 | 2834 | if( zCaptcha ){ |
| 2596 | 2835 | @ <tr> |
| 2597 | 2836 | @ <td class="form_label">Security Code:</td> |
| 2598 | 2837 | @ <td><input type="text" name="captcha" value="" size="10"> |
| 2838 | + captcha_speakit_button(uSeed, "Speak the code"); | |
| 2599 | 2839 | @ <input type="hidden" name="captchaseed" value="%u(uSeed)"></td> |
| 2600 | 2840 | @ </tr> |
| 2601 | 2841 | } |
| 2602 | 2842 | @ <tr> |
| 2603 | 2843 | @ <td class="form_label">Your Email Address:</td> |
| @@ -2620,11 +2860,11 @@ | ||
| 2620 | 2860 | @ </table> |
| 2621 | 2861 | if( zCaptcha ){ |
| 2622 | 2862 | @ <div class="captcha"><table class="captcha"><tr><td><pre class="captcha"> |
| 2623 | 2863 | @ %h(zCaptcha) |
| 2624 | 2864 | @ </pre> |
| 2625 | - @ Enter the 8 characters above in the "Security Code" box | |
| 2865 | + @ Enter the 8 characters above in the "Security Code" box<br/> | |
| 2626 | 2866 | @ </td></tr></table></div> |
| 2627 | 2867 | } |
| 2628 | 2868 | @ </form> |
| 2629 | 2869 | style_footer(); |
| 2630 | 2870 | } |
| @@ -2638,10 +2878,11 @@ | ||
| 2638 | 2878 | char *zErr; |
| 2639 | 2879 | const char *zTo = PT("to"); |
| 2640 | 2880 | char *zSubject = PT("subject"); |
| 2641 | 2881 | int bAll = PB("all"); |
| 2642 | 2882 | int bAA = PB("aa"); |
| 2883 | + int bMods = PB("mods"); | |
| 2643 | 2884 | const char *zSub = db_get("email-subname", "[Fossil Repo]"); |
| 2644 | 2885 | int bTest2 = fossil_strcmp(P("name"),"test2")==0; |
| 2645 | 2886 | Blob hdr, body; |
| 2646 | 2887 | blob_init(&body, 0, 0); |
| 2647 | 2888 | blob_init(&hdr, 0, 0); |
| @@ -2649,17 +2890,29 @@ | ||
| 2649 | 2890 | pSender = alert_sender_new(bTest2 ? "blob" : 0, 0); |
| 2650 | 2891 | if( zTo[0] ){ |
| 2651 | 2892 | blob_appendf(&hdr, "To: <%s>\r\nSubject: %s %s\r\n", zTo, zSub, zSubject); |
| 2652 | 2893 | alert_send(pSender, &hdr, &body, 0); |
| 2653 | 2894 | } |
| 2654 | - if( bAll || bAA ){ | |
| 2895 | + if( bAll || bAA || bMods ){ | |
| 2655 | 2896 | Stmt q; |
| 2656 | 2897 | int nUsed = blob_size(&body); |
| 2657 | 2898 | 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 | + } | |
| 2661 | 2914 | while( db_step(&q)==SQLITE_ROW ){ |
| 2662 | 2915 | const char *zCode = db_column_text(&q, 1); |
| 2663 | 2916 | zTo = db_column_text(&q, 0); |
| 2664 | 2917 | blob_truncate(&hdr, 0); |
| 2665 | 2918 | blob_appendf(&hdr, "To: <%s>\r\nSubject: %s %s\r\n", zTo, zSub, zSubject); |
| @@ -2716,11 +2969,12 @@ | ||
| 2716 | 2969 | @ <p>The following error was reported by the system: |
| 2717 | 2970 | @ <blockquote><pre> |
| 2718 | 2971 | @ %h(zErr) |
| 2719 | 2972 | @ </pre></blockquote> |
| 2720 | 2973 | }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> | |
| 2722 | 2976 | } |
| 2723 | 2977 | style_footer(); |
| 2724 | 2978 | return; |
| 2725 | 2979 | } else if( !alert_enabled() ){ |
| 2726 | 2980 | style_header("Cannot Send Announcement"); |
| @@ -2734,21 +2988,26 @@ | ||
| 2734 | 2988 | @ <form method="POST"> |
| 2735 | 2989 | @ <table class="subscribe"> |
| 2736 | 2990 | if( g.perm.Admin ){ |
| 2737 | 2991 | int aa = PB("aa"); |
| 2738 | 2992 | int all = PB("all"); |
| 2993 | + int aMod = PB("mods"); | |
| 2739 | 2994 | const char *aack = aa ? "checked" : ""; |
| 2740 | 2995 | const char *allck = all ? "checked" : ""; |
| 2996 | + const char *modck = aMod ? "checked" : ""; | |
| 2741 | 2997 | @ <tr> |
| 2742 | 2998 | @ <td class="form_label">To:</td> |
| 2743 | 2999 | @ <td><input type="text" name="to" value="%h(PT("to"))" size="30"><br> |
| 2744 | 3000 | @ <label><input type="checkbox" name="aa" %s(aack)> \ |
| 2745 | 3001 | @ All "announcement" subscribers</label> \ |
| 2746 | 3002 | @ <a href="%R/subscribers?only=a" target="_blank">(list)</a><br> |
| 2747 | 3003 | @ <label><input type="checkbox" name="all" %s(allck)> \ |
| 2748 | 3004 | @ 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> | |
| 2750 | 3009 | @ </tr> |
| 2751 | 3010 | } |
| 2752 | 3011 | @ <tr> |
| 2753 | 3012 | @ <td class="form_label">Subject:</td> |
| 2754 | 3013 | @ <td><input type="text" name="subject" value="%h(PT("subject"))"\ |
| @@ -2759,11 +3018,15 @@ | ||
| 2759 | 3018 | @ <td><textarea name="msg" cols="80" rows="10" wrap="virtual">\ |
| 2760 | 3019 | @ %h(PT("msg"))</textarea> |
| 2761 | 3020 | @ </tr> |
| 2762 | 3021 | @ <tr> |
| 2763 | 3022 | @ <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 | + } | |
| 2765 | 3028 | @ </tr> |
| 2766 | 3029 | @ </table> |
| 2767 | 3030 | @ </form> |
| 2768 | 3031 | style_footer(); |
| 2769 | 3032 | } |
| 2770 | 3033 |
| --- 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'>↑ %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'>↑ %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 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">← %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 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 Email 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'>↑ %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'>↑ %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 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'>← not a valid email address!</span> |
| 1809 | }else if( g.perm.Admin ){ |
| 1810 | @ <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 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 | @ <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">← %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 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 Email 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 @@ | ||
| 19 | 19 | */ |
| 20 | 20 | #include "config.h" |
| 21 | 21 | #include "allrepo.h" |
| 22 | 22 | #include <assert.h> |
| 23 | 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 | 24 | /* |
| 51 | 25 | ** Build a string that contains all of the command-line options |
| 52 | 26 | ** specified as arguments. If the option name begins with "+" then |
| 53 | 27 | ** it takes an argument. Without the "+" it does not. |
| 54 | 28 | */ |
| 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){ | |
| 56 | 30 | const char *z = find_option(zArg, zShort, 0); |
| 57 | 31 | if( z!=0 ){ |
| 58 | 32 | blob_appendf(pExtra, " %s", z); |
| 59 | 33 | } |
| 60 | 34 | } |
| 61 | 35 | static void collect_argument_value(Blob *pExtra, const char *zArg){ |
| 62 | 36 | const char *zValue = find_option(zArg, 0, 1); |
| 63 | 37 | if( zValue ){ |
| 64 | 38 | if( zValue[0] ){ |
| 65 | - blob_appendf(pExtra, " --%s %s", zArg, zValue); | |
| 39 | + blob_appendf(pExtra, " --%s %$", zArg, zValue); | |
| 66 | 40 | }else{ |
| 67 | 41 | blob_appendf(pExtra, " --%s \"\"", zArg); |
| 68 | 42 | } |
| 69 | 43 | } |
| 70 | 44 | } |
| @@ -88,10 +62,13 @@ | ||
| 88 | 62 | ** On Win32 systems, the file is named "_fossil" and is located in |
| 89 | 63 | ** %LOCALAPPDATA%, %APPDATA% or %HOMEPATH%. |
| 90 | 64 | ** |
| 91 | 65 | ** Available operations are: |
| 92 | 66 | ** |
| 67 | +** backup Backup all repositories. The argument must the name of | |
| 68 | +** a directory into which all backup repositories are written. | |
| 69 | +** | |
| 93 | 70 | ** cache Manages the cache used for potentially expensive web |
| 94 | 71 | ** pages. Any additional arguments are passed on verbatim |
| 95 | 72 | ** to the cache command. |
| 96 | 73 | ** |
| 97 | 74 | ** changes Shows all local checkouts that have uncommitted changes. |
| @@ -128,15 +105,15 @@ | ||
| 128 | 105 | ** supported by the rebuild command itself, if any are |
| 129 | 106 | ** present, are passed along verbatim. The --force and |
| 130 | 107 | ** --randomize options are not supported. |
| 131 | 108 | ** |
| 132 | 109 | ** sync Run a "sync" on all repositories. Only the --verbose |
| 133 | -** option is supported. | |
| 110 | +** and --unversioned options are supported. | |
| 134 | 111 | ** |
| 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 | |
| 138 | 115 | ** otherwise be set globally. |
| 139 | 116 | ** |
| 140 | 117 | ** server Run the "ui" or "server" commands on all repositories. |
| 141 | 118 | ** ui The root URI gives a listing of all repos. |
| 142 | 119 | ** |
| @@ -169,12 +146,10 @@ | ||
| 169 | 146 | void all_cmd(void){ |
| 170 | 147 | int n; |
| 171 | 148 | Stmt q; |
| 172 | 149 | const char *zCmd; |
| 173 | 150 | char *zSyscmd; |
| 174 | - char *zFossil; | |
| 175 | - char *zQFilename; | |
| 176 | 151 | Blob extra; |
| 177 | 152 | int useCheckouts = 0; |
| 178 | 153 | int quiet = 0; |
| 179 | 154 | int dryRunFlag = 0; |
| 180 | 155 | int showFile = find_option("showfile",0,0)!=0; |
| @@ -202,10 +177,20 @@ | ||
| 202 | 177 | return; |
| 203 | 178 | } |
| 204 | 179 | if( strncmp(zCmd, "list", n)==0 || strncmp(zCmd,"ls",n)==0 ){ |
| 205 | 180 | zCmd = "list"; |
| 206 | 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); | |
| 207 | 192 | }else if( strncmp(zCmd, "clean", n)==0 ){ |
| 208 | 193 | zCmd = "clean --chdir"; |
| 209 | 194 | collect_argument(&extra, "allckouts",0); |
| 210 | 195 | collect_argument_value(&extra, "case-sensitive"); |
| 211 | 196 | collect_argument_value(&extra, "clean"); |
| @@ -283,11 +268,13 @@ | ||
| 283 | 268 | }else if( strncmp(zCmd, "sync", n)==0 ){ |
| 284 | 269 | zCmd = "sync -autourl -R"; |
| 285 | 270 | collect_argument(&extra, "verbose","v"); |
| 286 | 271 | collect_argument(&extra, "unversioned","u"); |
| 287 | 272 | }else if( strncmp(zCmd, "test-integrity", n)==0 ){ |
| 273 | + collect_argument(&extra, "db-only", "d"); | |
| 288 | 274 | collect_argument(&extra, "parse", 0); |
| 275 | + collect_argument(&extra, "quick", "q"); | |
| 289 | 276 | zCmd = "test-integrity"; |
| 290 | 277 | }else if( strncmp(zCmd, "test-orphans", n)==0 ){ |
| 291 | 278 | zCmd = "test-orphans -R"; |
| 292 | 279 | }else if( strncmp(zCmd, "test-missing", n)==0 ){ |
| 293 | 280 | zCmd = "test-missing -q -R"; |
| @@ -368,11 +355,10 @@ | ||
| 368 | 355 | fossil_fatal("\"all\" subcommand should be one of: " |
| 369 | 356 | "add cache changes clean dbstat extras fts-config ignore " |
| 370 | 357 | "info list ls pull push rebuild server setting sync ui unset"); |
| 371 | 358 | } |
| 372 | 359 | verify_all_options(); |
| 373 | - zFossil = quoteFilename(g.nameOfExe); | |
| 374 | 360 | db_multi_exec("CREATE TEMP TABLE repolist(name,tag);"); |
| 375 | 361 | if( useCheckouts ){ |
| 376 | 362 | db_multi_exec( |
| 377 | 363 | "INSERT INTO repolist " |
| 378 | 364 | "SELECT DISTINCT substr(name, 7), name COLLATE nocase" |
| @@ -410,13 +396,12 @@ | ||
| 410 | 396 | continue; |
| 411 | 397 | }else if( showFile ){ |
| 412 | 398 | fossil_print("%s: %s\n", useCheckouts ? "checkout" : "repository", |
| 413 | 399 | zFilename); |
| 414 | 400 | } |
| 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)); | |
| 418 | 403 | if( showLabel ){ |
| 419 | 404 | int len = (int)strlen(zFilename); |
| 420 | 405 | int nStar = 80 - (len + 15); |
| 421 | 406 | if( nStar<2 ) nStar = 1; |
| 422 | 407 | fossil_print("%.13c %s %.*c\n", '*', zFilename, nStar, '*'); |
| @@ -426,11 +411,10 @@ | ||
| 426 | 411 | fossil_print("%s\n", zSyscmd); |
| 427 | 412 | fflush(stdout); |
| 428 | 413 | } |
| 429 | 414 | rc = dryRunFlag ? 0 : fossil_system(zSyscmd); |
| 430 | 415 | free(zSyscmd); |
| 431 | - free(zQFilename); | |
| 432 | 416 | if( stopOnError && rc ){ |
| 433 | 417 | break; |
| 434 | 418 | } |
| 435 | 419 | } |
| 436 | 420 | db_finalize(&q); |
| 437 | 421 |
| --- 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 @@ | ||
| 23 | 23 | |
| 24 | 24 | /* |
| 25 | 25 | ** WEBPAGE: attachlist |
| 26 | 26 | ** List attachments. |
| 27 | 27 | ** |
| 28 | -** tkt=TICKETUUID | |
| 28 | +** tkt=HASH | |
| 29 | 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. | |
| 30 | 36 | ** |
| 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. | |
| 37 | 40 | */ |
| 38 | 41 | void attachlist_page(void){ |
| 39 | 42 | const char *zPage = P("page"); |
| 40 | 43 | const char *zTkt = P("tkt"); |
| 41 | 44 | const char *zTechNote = P("technote"); |
| @@ -152,15 +155,16 @@ | ||
| 152 | 155 | ** WEBPAGE: attachdownload |
| 153 | 156 | ** WEBPAGE: attachimage |
| 154 | 157 | ** WEBPAGE: attachview |
| 155 | 158 | ** |
| 156 | 159 | ** Download or display an attachment. |
| 160 | +** | |
| 157 | 161 | ** Query parameters: |
| 158 | 162 | ** |
| 159 | -** tkt=TICKETUUID | |
| 163 | +** tkt=HASH | |
| 160 | 164 | ** page=WIKIPAGE |
| 161 | -** technote=TECHNOTEUUID | |
| 165 | +** technote=HASH | |
| 162 | 166 | ** file=FILENAME |
| 163 | 167 | ** attachid=ID |
| 164 | 168 | ** |
| 165 | 169 | */ |
| 166 | 170 | void attachview_page(void){ |
| @@ -250,11 +254,11 @@ | ||
| 250 | 254 | /* |
| 251 | 255 | ** Commit a new attachment into the repository |
| 252 | 256 | */ |
| 253 | 257 | void attach_commit( |
| 254 | 258 | 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 */ | |
| 256 | 260 | const char *aContent, /* The content of the attachment */ |
| 257 | 261 | int szContent, /* The length of the attachment */ |
| 258 | 262 | int needModerator, /* Moderate the attachment? */ |
| 259 | 263 | const char *zComment /* The comment for the attachment */ |
| 260 | 264 | ){ |
| @@ -305,13 +309,13 @@ | ||
| 305 | 309 | |
| 306 | 310 | /* |
| 307 | 311 | ** WEBPAGE: attachadd |
| 308 | 312 | ** Add a new attachment. |
| 309 | 313 | ** |
| 310 | -** tkt=TICKETUUID | |
| 314 | +** tkt=HASH | |
| 311 | 315 | ** page=WIKIPAGE |
| 312 | -** technote=TECHNOTEUUID | |
| 316 | +** technote=HASH | |
| 313 | 317 | ** from=URL |
| 314 | 318 | ** |
| 315 | 319 | */ |
| 316 | 320 | void attachadd_page(void){ |
| 317 | 321 | const char *zPage = P("page"); |
| @@ -420,14 +424,14 @@ | ||
| 420 | 424 | */ |
| 421 | 425 | void ainfo_page(void){ |
| 422 | 426 | int rid; /* RID for the control artifact */ |
| 423 | 427 | int ridSrc; /* RID for the attached file */ |
| 424 | 428 | char *zDate; /* Date attached */ |
| 425 | - const char *zUuid; /* UUID of the control artifact */ | |
| 429 | + const char *zUuid; /* Hash of the control artifact */ | |
| 426 | 430 | Manifest *pAttach; /* Parse of the control artifact */ |
| 427 | 431 | 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 */ | |
| 429 | 433 | const char *zName; /* Name of the attached file */ |
| 430 | 434 | const char *zDesc; /* Description of the attached file */ |
| 431 | 435 | const char *zWikiName = 0; /* Wiki page name when attached to Wiki */ |
| 432 | 436 | const char *zTNUuid = 0; /* Tech Note ID when attached to tech note */ |
| 433 | 437 | const char *zTktUuid = 0; /* Ticket ID when attached to a ticket */ |
| @@ -545,11 +549,11 @@ | ||
| 545 | 549 | cgi_redirectf("%R/wiki?name=%t", zWikiName); |
| 546 | 550 | } |
| 547 | 551 | return; |
| 548 | 552 | } |
| 549 | 553 | if( strcmp(zModAction,"approve")==0 ){ |
| 550 | - moderation_approve(rid); | |
| 554 | + moderation_approve('a', rid); | |
| 551 | 555 | } |
| 552 | 556 | } |
| 553 | 557 | style_header("Attachment Details"); |
| 554 | 558 | style_submenu_element("Raw", "%R/artifact/%s", zUuid); |
| 555 | 559 | if(fShowContent){ |
| @@ -681,22 +685,23 @@ | ||
| 681 | 685 | /* |
| 682 | 686 | ** COMMAND: attachment* |
| 683 | 687 | ** |
| 684 | 688 | ** Usage: %fossil attachment add ?PAGENAME? FILENAME ?OPTIONS? |
| 685 | 689 | ** |
| 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. | |
| 698 | 703 | ** |
| 699 | 704 | ** DATETIME may be "now" or "YYYY-MM-DDTHH:MM:SS.SSS". If in |
| 700 | 705 | ** year-month-day form, it may be truncated, the "T" may be replaced by |
| 701 | 706 | ** a space, and it may also name a timezone offset from UTC as "-HH:MM" |
| 702 | 707 | ** (westward) or "+HH:MM" (eastward). Either no timezone suffix or "Z" |
| @@ -763,11 +768,11 @@ | ||
| 763 | 768 | } |
| 764 | 769 | blob_read_from_file(&content, zFile, ExtFILE); |
| 765 | 770 | user_select(); |
| 766 | 771 | attach_commit( |
| 767 | 772 | zFile, /* The filename of the attachment */ |
| 768 | - zTarget, /* The artifact uuid to attach to */ | |
| 773 | + zTarget, /* The artifact hash to attach to */ | |
| 769 | 774 | blob_buffer(&content), /* The content of the attachment */ |
| 770 | 775 | blob_size(&content), /* The length of the attachment */ |
| 771 | 776 | 0, /* No need to moderate the attachment */ |
| 772 | 777 | "" /* Empty attachment comment */ |
| 773 | 778 | ); |
| 774 | 779 | |
| 775 | 780 | 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 |
+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 |
| --- 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 @@ | ||
| 19 | 19 | ** occur after user interaction with the repository. Examples of |
| 20 | 20 | ** backoffice processing includes: |
| 21 | 21 | ** |
| 22 | 22 | ** * Sending alerts and notifications |
| 23 | 23 | ** * Processing the email queue |
| 24 | +** * Handling post-receive hooks | |
| 24 | 25 | ** * Automatically syncing to peer repositories |
| 25 | 26 | ** |
| 26 | 27 | ** Backoffice processing is automatically started whenever there are |
| 27 | 28 | ** changes to the repository. The backoffice process dies off after |
| 28 | 29 | ** a period of inactivity. |
| @@ -77,10 +78,12 @@ | ||
| 77 | 78 | #else |
| 78 | 79 | # include <unistd.h> |
| 79 | 80 | # include <sys/types.h> |
| 80 | 81 | # include <signal.h> |
| 81 | 82 | # include <errno.h> |
| 83 | +# include <sys/time.h> | |
| 84 | +# include <sys/resource.h> | |
| 82 | 85 | # include <fcntl.h> |
| 83 | 86 | # define GETPID getpid |
| 84 | 87 | #endif |
| 85 | 88 | #include <time.h> |
| 86 | 89 | |
| @@ -121,13 +124,37 @@ | ||
| 121 | 124 | ** should run if backoffice process is needed. It is set by the |
| 122 | 125 | ** backoffice_check_if_needed() routine which must be run while the database |
| 123 | 126 | ** file is open. Later, after the database is closed, the |
| 124 | 127 | ** backoffice_run_if_needed() will consult this variable to see if it |
| 125 | 128 | ** should be a no-op. |
| 129 | +** | |
| 130 | +** The magic string "x" in this variable means "do not run the backoffice". | |
| 126 | 131 | */ |
| 127 | 132 | static char *backofficeDb = 0; |
| 128 | 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 | + | |
| 129 | 156 | /* End of state variables |
| 130 | 157 | ****************************************************************************/ |
| 131 | 158 | |
| 132 | 159 | /* |
| 133 | 160 | ** This function emits a diagnostic message related to the processing in |
| @@ -277,11 +304,11 @@ | ||
| 277 | 304 | } |
| 278 | 305 | #endif |
| 279 | 306 | |
| 280 | 307 | /* |
| 281 | 308 | ** 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. | |
| 283 | 310 | */ |
| 284 | 311 | static int backofficeProcessExists(sqlite3_uint64 pid){ |
| 285 | 312 | #if defined(_WIN32) |
| 286 | 313 | return pid>0 && backofficeWin32ProcessExists((DWORD)pid)!=0; |
| 287 | 314 | #else |
| @@ -289,11 +316,11 @@ | ||
| 289 | 316 | #endif |
| 290 | 317 | } |
| 291 | 318 | |
| 292 | 319 | /* |
| 293 | 320 | ** 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. | |
| 295 | 322 | */ |
| 296 | 323 | static int backofficeProcessDone(sqlite3_uint64 pid){ |
| 297 | 324 | #if defined(_WIN32) |
| 298 | 325 | return pid<=0 || backofficeWin32ProcessExists((DWORD)pid)==0; |
| 299 | 326 | #else |
| @@ -514,73 +541,178 @@ | ||
| 514 | 541 | } |
| 515 | 542 | } |
| 516 | 543 | } |
| 517 | 544 | return; |
| 518 | 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 | + | |
| 519 | 589 | |
| 520 | 590 | /* |
| 521 | 591 | ** This routine runs to do the backoffice processing. When adding new |
| 522 | 592 | ** backoffice processing tasks, add them here. |
| 523 | 593 | */ |
| 524 | 594 | void backoffice_work(void){ |
| 525 | 595 | /* Log the backoffice run for testing purposes. For production deployments |
| 526 | 596 | ** the "backoffice-logfile" property should be unset and the following code |
| 527 | 597 | ** 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); | |
| 536 | 626 | } |
| 537 | 627 | |
| 538 | 628 | /* 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 | + } | |
| 541 | 648 | } |
| 542 | 649 | |
| 543 | 650 | /* |
| 544 | 651 | ** COMMAND: backoffice* |
| 545 | 652 | ** |
| 546 | -** Usage: backoffice [OPTIONS...] [REPOSITORIES...] | |
| 653 | +** Usage: %fossil backoffice [OPTIONS...] [REPOSITORIES...] | |
| 547 | 654 | ** |
| 548 | 655 | ** Run backoffice processing on the repositories listed. If no |
| 549 | 656 | ** repository is specified, run it on the repository of the local checkout. |
| 550 | 657 | ** |
| 551 | 658 | ** This might be done by a cron job or similar to make sure backoffice |
| 552 | 659 | ** processing happens periodically. Or, the --poll option can be used |
| 553 | 660 | ** 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. | |
| 555 | 667 | ** |
| 556 | -** OPTIONS: | |
| 668 | +** Standard options: | |
| 557 | 669 | ** |
| 558 | 670 | ** --debug Show what this command is doing. |
| 559 | 671 | ** |
| 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). | |
| 565 | 678 | ** |
| 566 | 679 | ** --poll N Repeat backoffice calls for repositories that |
| 567 | 680 | ** change in appoximately N-second intervals. |
| 568 | 681 | ** N less than 1 turns polling off (the default). |
| 682 | +** Recommended polling interval: 60 seconds. | |
| 569 | 683 | ** |
| 570 | 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. | |
| 571 | 697 | */ |
| 572 | 698 | void backoffice_command(void){ |
| 573 | 699 | int nPoll; |
| 700 | + int nMin; | |
| 574 | 701 | const char *zPoll; |
| 575 | 702 | int bDebug = 0; |
| 703 | + int bNoLease = 0; | |
| 576 | 704 | unsigned int nCmd = 0; |
| 577 | 705 | if( find_option("trace",0,0)!=0 ) g.fAnyTrace = 1; |
| 578 | 706 | if( find_option("nodelay",0,0)!=0 ) backofficeNoDelay = 1; |
| 707 | + backofficeLogfile = find_option("logfile",0,1); | |
| 579 | 708 | zPoll = find_option("poll",0,1); |
| 580 | 709 | nPoll = zPoll ? atoi(zPoll) : 0; |
| 710 | + zPoll = find_option("min",0,1); | |
| 711 | + nMin = zPoll ? atoi(zPoll) : 3600; | |
| 581 | 712 | bDebug = find_option("debug",0,0)!=0; |
| 713 | + bNoLease = find_option("nolease",0,0)!=0; | |
| 582 | 714 | |
| 583 | 715 | /* Silently consume the -R or --repository flag, leaving behind its |
| 584 | 716 | ** argument. This is for legacy compatibility. Older versions of the |
| 585 | 717 | ** backoffice command only ran on a single repository that was specified |
| 586 | 718 | ** using the -R option. */ |
| @@ -592,28 +724,48 @@ | ||
| 592 | 724 | ** or we are polling. In either case, each backoffice should be run |
| 593 | 725 | ** using a separate sub-process */ |
| 594 | 726 | int i; |
| 595 | 727 | time_t iNow = 0; |
| 596 | 728 | time_t ix; |
| 729 | + i64 *aLastRun = fossil_malloc( sizeof(i64)*g.argc ); | |
| 730 | + memset(aLastRun, 0, sizeof(i64)*g.argc ); | |
| 597 | 731 | while( 1 /* exit via "break;" */){ |
| 598 | 732 | time_t iNext = time(0); |
| 599 | 733 | for(i=2; i<g.argc; i++){ |
| 600 | 734 | 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 | + } | |
| 603 | 744 | blob_init(&cmd, 0, 0); |
| 604 | 745 | blob_append_escaped_arg(&cmd, g.nameOfExe); |
| 605 | 746 | blob_append(&cmd, " backoffice --nodelay", -1); |
| 606 | 747 | if( g.fAnyTrace ){ |
| 607 | 748 | blob_append(&cmd, " --trace", -1); |
| 608 | 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 | + } | |
| 609 | 760 | blob_append_escaped_arg(&cmd, g.argv[i]); |
| 610 | 761 | nCmd++; |
| 611 | 762 | if( bDebug ){ |
| 612 | 763 | fossil_print("COMMAND[%u]: %s\n", nCmd, blob_str(&cmd)); |
| 613 | 764 | } |
| 614 | 765 | fossil_system(blob_str(&cmd)); |
| 766 | + aLastRun[i] = iNext; | |
| 615 | 767 | blob_reset(&cmd); |
| 616 | 768 | } |
| 617 | 769 | if( nPoll<1 ) break; |
| 618 | 770 | iNow = iNext; |
| 619 | 771 | ix = time(0); |
| @@ -622,16 +774,25 @@ | ||
| 622 | 774 | if( bDebug )fossil_print("SLEEP: %lld\n", nMS); |
| 623 | 775 | sqlite3_sleep((int)nMS); |
| 624 | 776 | } |
| 625 | 777 | } |
| 626 | 778 | }else{ |
| 779 | + /* Not polling and only one repository named. Backoffice is run | |
| 780 | + ** once by this process, which then exits */ | |
| 627 | 781 | if( g.argc==3 ){ |
| 628 | 782 | g.zRepositoryOption = g.argv[2]; |
| 629 | 783 | g.argc--; |
| 630 | 784 | } |
| 631 | 785 | 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 | + } | |
| 633 | 794 | } |
| 634 | 795 | } |
| 635 | 796 | |
| 636 | 797 | /* |
| 637 | 798 | ** This is the main interface to backoffice from the rest of the system. |
| 638 | 799 |
| --- 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 @@ | ||
| 37 | 37 | void bisect_path(void){ |
| 38 | 38 | PathNode *p; |
| 39 | 39 | bisect.bad = db_lget_int("bisect-bad", 0); |
| 40 | 40 | bisect.good = db_lget_int("bisect-good", 0); |
| 41 | 41 | 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); | |
| 43 | 43 | }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); | |
| 45 | 45 | }else if( bisect.bad==0 && bisect.good==0 ){ |
| 46 | 46 | fossil_fatal("neither \"good\" nor \"bad\" versions have been identified"); |
| 47 | 47 | }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); | |
| 49 | 62 | if( p==0 ){ |
| 50 | 63 | char *zBad = db_text(0,"SELECT uuid FROM blob WHERE rid=%d",bisect.bad); |
| 51 | 64 | char *zGood = db_text(0,"SELECT uuid FROM blob WHERE rid=%d",bisect.good); |
| 52 | 65 | fossil_fatal("no path from good ([%S]) to bad ([%S]) or back", |
| 53 | 66 | zGood, zBad); |
| @@ -78,11 +91,16 @@ | ||
| 78 | 91 | unsigned int i; |
| 79 | 92 | int r = -1; |
| 80 | 93 | for(i=0; i<count(aBisectOption); i++){ |
| 81 | 94 | if( fossil_strcmp(zName, aBisectOption[i].zName)==0 ){ |
| 82 | 95 | 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 | + } | |
| 84 | 102 | if( is_truth(z) ) r = 1; |
| 85 | 103 | if( is_false(z) ) r = 0; |
| 86 | 104 | if( r<0 ) r = is_truth(aBisectOption[i].zDefault); |
| 87 | 105 | free(zLabel); |
| 88 | 106 | break; |
| @@ -167,29 +185,51 @@ | ||
| 167 | 185 | db_multi_exec( |
| 168 | 186 | "REPLACE INTO vvar(name,value) VALUES('bisect-log'," |
| 169 | 187 | "COALESCE((SELECT value||' ' FROM vvar WHERE name='bisect-log'),'')" |
| 170 | 188 | " || '%d')", rid); |
| 171 | 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 | +} | |
| 172 | 199 | |
| 173 | 200 | /* |
| 174 | 201 | ** Create a TEMP table named "bilog" that contains the complete history |
| 175 | 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. | |
| 176 | 213 | */ |
| 177 | -int bisect_create_bilog_table(int iCurrent, const char *zDesc){ | |
| 214 | +int bisect_create_bilog_table(int iCurrent, const char *zDesc, int bDetail){ | |
| 178 | 215 | char *zLog; |
| 179 | 216 | Blob log, id; |
| 180 | 217 | Stmt q; |
| 181 | 218 | int cnt = 0; |
| 219 | + int lastGood = -1; | |
| 220 | + int lastBad = -1; | |
| 182 | 221 | |
| 183 | 222 | if( zDesc!=0 ){ |
| 184 | 223 | blob_init(&log, 0, 0); |
| 185 | - while( zDesc[0]=='y' || zDesc[0]=='n' ){ | |
| 224 | + while( zDesc[0]=='y' || zDesc[0]=='n' || zDesc[0]=='s' ){ | |
| 186 | 225 | int i; |
| 187 | 226 | char c; |
| 188 | 227 | int rid; |
| 189 | 228 | if( blob_size(&log) ) blob_append(&log, " ", 1); |
| 190 | 229 | if( zDesc[0]=='n' ) blob_append(&log, "-", 1); |
| 230 | + if( zDesc[0]=='s' ) blob_append(&log, "s", 1); | |
| 191 | 231 | for(i=1; ((c = zDesc[i])>='0' && c<='9') || (c>='a' && c<='f'); i++){} |
| 192 | 232 | if( i==1 ) break; |
| 193 | 233 | rid = db_int(0, |
| 194 | 234 | "SELECT rid FROM blob" |
| 195 | 235 | " WHERE uuid LIKE '%.*q%%'" |
| @@ -204,30 +244,58 @@ | ||
| 204 | 244 | zLog = db_lget("bisect-log",""); |
| 205 | 245 | blob_init(&log, zLog, -1); |
| 206 | 246 | } |
| 207 | 247 | db_multi_exec( |
| 208 | 248 | "CREATE TEMP TABLE bilog(" |
| 209 | - " seq INTEGER PRIMARY KEY," /* Sequence of events */ | |
| 249 | + " rid INTEGER PRIMARY KEY," /* Sequence of events */ | |
| 210 | 250 | " stat TEXT," /* Type of occurrence */ |
| 211 | - " rid INTEGER UNIQUE" /* Check-in number */ | |
| 251 | + " seq INTEGER UNIQUE" /* Check-in number */ | |
| 212 | 252 | ");" |
| 213 | 253 | ); |
| 214 | 254 | db_prepare(&q, "INSERT OR IGNORE INTO bilog(seq,stat,rid)" |
| 215 | 255 | " VALUES(:seq,:stat,:rid)"); |
| 216 | 256 | while( blob_token(&log, &id) ){ |
| 217 | - int rid = atoi(blob_str(&id)); | |
| 257 | + int rid; | |
| 218 | 258 | 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 | + } | |
| 221 | 275 | db_step(&q); |
| 222 | 276 | db_reset(&q); |
| 223 | 277 | } |
| 224 | 278 | if( iCurrent>0 ){ |
| 225 | 279 | db_bind_int(&q, ":seq", ++cnt); |
| 226 | 280 | db_bind_text(&q, ":stat", "CURRENT"); |
| 227 | 281 | db_bind_int(&q, ":rid", iCurrent); |
| 228 | 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(); | |
| 229 | 297 | } |
| 230 | 298 | db_finalize(&q); |
| 231 | 299 | return 1; |
| 232 | 300 | } |
| 233 | 301 | |
| @@ -244,14 +312,25 @@ | ||
| 244 | 312 | Blob log; |
| 245 | 313 | Blob link = BLOB_INITIALIZER; |
| 246 | 314 | Blob id; |
| 247 | 315 | blob_init(&log, zLog, -1); |
| 248 | 316 | 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); | |
| 253 | 332 | } |
| 254 | 333 | zResult = mprintf("%s", blob_str(&link)); |
| 255 | 334 | blob_reset(&link); |
| 256 | 335 | blob_reset(&log); |
| 257 | 336 | blob_reset(&id); |
| @@ -263,11 +342,11 @@ | ||
| 263 | 342 | ** sorted either chronologically by bisect time, or by check-in time. |
| 264 | 343 | */ |
| 265 | 344 | static void bisect_chart(int sortByCkinTime){ |
| 266 | 345 | Stmt q; |
| 267 | 346 | int iCurrent = db_lget_int("checkout",0); |
| 268 | - bisect_create_bilog_table(iCurrent, 0); | |
| 347 | + bisect_create_bilog_table(iCurrent, 0, 0); | |
| 269 | 348 | db_prepare(&q, |
| 270 | 349 | "SELECT bilog.seq, bilog.stat," |
| 271 | 350 | " substr(blob.uuid,1,16), datetime(event.mtime)," |
| 272 | 351 | " blob.rid==%d" |
| 273 | 352 | " FROM bilog, blob, event" |
| @@ -302,77 +381,72 @@ | ||
| 302 | 381 | /* |
| 303 | 382 | ** COMMAND: bisect |
| 304 | 383 | ** |
| 305 | 384 | ** Usage: %fossil bisect SUBCOMMAND ... |
| 306 | 385 | ** |
| 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. | |
| 366 | 440 | */ |
| 367 | 441 | void bisect_cmd(void){ |
| 368 | 442 | int n; |
| 369 | 443 | const char *zCmd; |
| 370 | 444 | int foundCmd = 0; |
| 371 | 445 | db_must_be_within_tree(); |
| 372 | 446 | 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"); | |
| 374 | 448 | } |
| 375 | 449 | zCmd = g.argv[2]; |
| 376 | 450 | n = strlen(zCmd); |
| 377 | 451 | if( n==0 ) zCmd = "-"; |
| 378 | 452 | if( strncmp(zCmd, "bad", n)==0 ){ |
| @@ -399,10 +473,28 @@ | ||
| 399 | 473 | ridGood = name_to_typed_rid(g.argv[3], "ci"); |
| 400 | 474 | } |
| 401 | 475 | if( ridGood>0 ){ |
| 402 | 476 | bisect_append_log(ridGood); |
| 403 | 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 | + ){ | |
| 404 | 496 | zCmd = "next"; |
| 405 | 497 | n = 4; |
| 406 | 498 | } |
| 407 | 499 | } |
| 408 | 500 | }else if( strncmp(zCmd, "undo", n)==0 ){ |
| @@ -448,11 +540,11 @@ | ||
| 448 | 540 | bisect_path(); |
| 449 | 541 | pMid = path_midpoint(); |
| 450 | 542 | if( pMid==0 ){ |
| 451 | 543 | fossil_print("bisect complete\n"); |
| 452 | 544 | }else{ |
| 453 | - int nSpan = path_length(); | |
| 545 | + int nSpan = path_length_not_hidden(); | |
| 454 | 546 | int nStep = path_search_depth(); |
| 455 | 547 | g.argv[1] = "update"; |
| 456 | 548 | g.argv[2] = db_text(0, "SELECT uuid FROM blob WHERE rid=%d", pMid->rid); |
| 457 | 549 | g.argc = 3; |
| 458 | 550 | g.fNoSync = 1; |
| 459 | 551 |
| --- 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 @@ | ||
| 477 | 477 | void blob_resize(Blob *pBlob, unsigned int newSize){ |
| 478 | 478 | pBlob->xRealloc(pBlob, newSize+1); |
| 479 | 479 | pBlob->nUsed = newSize; |
| 480 | 480 | pBlob->aData[newSize] = 0; |
| 481 | 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 | +} | |
| 482 | 501 | |
| 483 | 502 | /* |
| 484 | 503 | ** Make sure a blob is nul-terminated and is not a pointer to unmanaged |
| 485 | 504 | ** space. Return a pointer to the data. |
| 486 | 505 | */ |
| @@ -1167,11 +1186,10 @@ | ||
| 1167 | 1186 | blob_reset(&b3); |
| 1168 | 1187 | } |
| 1169 | 1188 | fossil_print("ok\n"); |
| 1170 | 1189 | } |
| 1171 | 1190 | |
| 1172 | -#if defined(_WIN32) || defined(__CYGWIN__) | |
| 1173 | 1191 | /* |
| 1174 | 1192 | ** Convert every \n character in the given blob into \r\n. |
| 1175 | 1193 | */ |
| 1176 | 1194 | void blob_add_cr(Blob *p){ |
| 1177 | 1195 | char *z = p->aData; |
| @@ -1191,11 +1209,10 @@ | ||
| 1191 | 1209 | if( (z[--j] = z[--i]) =='\n' ){ |
| 1192 | 1210 | z[--j] = '\r'; |
| 1193 | 1211 | } |
| 1194 | 1212 | } |
| 1195 | 1213 | } |
| 1196 | -#endif | |
| 1197 | 1214 | |
| 1198 | 1215 | /* |
| 1199 | 1216 | ** Remove every \r character from the given blob, replacing each one with |
| 1200 | 1217 | ** a \n character if it was not already part of a \r\n pair. |
| 1201 | 1218 | */ |
| @@ -1284,35 +1301,88 @@ | ||
| 1284 | 1301 | char c; |
| 1285 | 1302 | int needEscape = 0; |
| 1286 | 1303 | int n = blob_size(pBlob); |
| 1287 | 1304 | char *z = blob_buffer(pBlob); |
| 1288 | 1305 | #if defined(_WIN32) |
| 1306 | + const char cDirSep = '\\'; /* Use \ as directory separator */ | |
| 1289 | 1307 | const char cQuote = '"'; /* Use "..." quoting on windows */ |
| 1308 | + const char cEscape = '^'; /* Use ^X escaping on windows */ | |
| 1290 | 1309 | #else |
| 1310 | + const char cDirSep = '/'; /* Use / as directory separator */ | |
| 1291 | 1311 | const char cQuote = '\''; /* Use '...' quoting on unix */ |
| 1312 | + const char cEscape = '\\'; /* Use \X escaping on unix */ | |
| 1292 | 1313 | #endif |
| 1293 | 1314 | |
| 1294 | 1315 | for(i=0; (c = zIn[i])!=0; i++){ |
| 1295 | 1316 | if( c==cQuote || (unsigned char)c<' ' || |
| 1296 | - c=='\\' || c==';' || c=='*' || c=='?' || c=='[' ){ | |
| 1317 | + c==cEscape || c==';' || c=='*' || c=='?' || c=='[' ){ | |
| 1297 | 1318 | Blob bad; |
| 1298 | 1319 | blob_token(pBlob, &bad); |
| 1299 | 1320 | fossil_fatal("the [%s] argument to the \"%s\" command contains " |
| 1300 | 1321 | "a character (ascii 0x%02x) that is a security risk", |
| 1301 | 1322 | zIn, blob_str(&bad), c); |
| 1302 | 1323 | } |
| 1303 | - if( !needEscape && !fossil_isalnum(c) && c!='/' && c!='.' && c!='_' ){ | |
| 1324 | + if( !needEscape && !fossil_isalnum(c) && c!=cDirSep && c!='.' && c!='_' ){ | |
| 1304 | 1325 | needEscape = 1; |
| 1305 | 1326 | } |
| 1306 | 1327 | } |
| 1307 | 1328 | if( n>0 && !fossil_isspace(z[n-1]) ){ |
| 1308 | 1329 | blob_append_char(pBlob, ' '); |
| 1309 | 1330 | } |
| 1310 | 1331 | 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 | |
| 1312 | 1350 | 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 | + } | |
| 1314 | 1384 | } |
| 1315 | 1385 | |
| 1316 | 1386 | /* |
| 1317 | 1387 | ** A read(2)-like impl for the Blob class. Reads (copies) up to nLen |
| 1318 | 1388 | ** bytes from pIn, starting at position pIn->iCursor, and copies them |
| 1319 | 1389 |
| --- 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 @@ | ||
| 18 | 18 | ** This file contains code used to create new branches within a repository. |
| 19 | 19 | */ |
| 20 | 20 | #include "config.h" |
| 21 | 21 | #include "branch.h" |
| 22 | 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 | +} | |
| 23 | 37 | |
| 24 | 38 | /* |
| 25 | 39 | ** If RID refers to a check-in, return the name of the branch for that |
| 26 | 40 | ** check-in. |
| 27 | 41 | ** |
| @@ -144,11 +158,10 @@ | ||
| 144 | 158 | blob_appendf(&branch, "T *bgcolor * %F\n", zColor); |
| 145 | 159 | } |
| 146 | 160 | blob_appendf(&branch, "T *branch * %F\n", zBranch); |
| 147 | 161 | blob_appendf(&branch, "T *sym-%F *\n", zBranch); |
| 148 | 162 | if( isPrivate ){ |
| 149 | - blob_appendf(&branch, "T +private *\n"); | |
| 150 | 163 | noSign = 1; |
| 151 | 164 | } |
| 152 | 165 | |
| 153 | 166 | /* Cancel all other symbolic tags */ |
| 154 | 167 | db_prepare(&q, |
| @@ -245,11 +258,11 @@ | ||
| 245 | 258 | @ GROUP BY 1; |
| 246 | 259 | ; |
| 247 | 260 | |
| 248 | 261 | /* Call this routine to create the TEMP table */ |
| 249 | 262 | static void brlist_create_temp_table(void){ |
| 250 | - db_multi_exec(createBrlistQuery/*works-like:""*/); | |
| 263 | + db_exec_sql(createBrlistQuery); | |
| 251 | 264 | } |
| 252 | 265 | |
| 253 | 266 | |
| 254 | 267 | #if INTERFACE |
| 255 | 268 | /* |
| @@ -334,27 +347,27 @@ | ||
| 334 | 347 | ** Usage: %fossil branch SUBCOMMAND ... ?OPTIONS? |
| 335 | 348 | ** |
| 336 | 349 | ** Run various subcommands to manage branches of the open repository or |
| 337 | 350 | ** of the repository identified by the -R or --repository option. |
| 338 | 351 | ** |
| 339 | -** fossil branch current | |
| 352 | +** > fossil branch current | |
| 340 | 353 | ** |
| 341 | 354 | ** Print the name of the branch for the current check-out |
| 342 | 355 | ** |
| 343 | -** fossil branch info BRANCH-NAME | |
| 356 | +** > fossil branch info BRANCH-NAME | |
| 344 | 357 | ** |
| 345 | 358 | ** Print information about a branch |
| 346 | 359 | ** |
| 347 | -** fossil branch list|ls ?OPTIONS? | |
| 360 | +** > fossil branch list|ls ?OPTIONS? | |
| 348 | 361 | ** |
| 349 | 362 | ** List all branches. Options: |
| 350 | 363 | ** -a|--all List all branches. Default show only open branches |
| 351 | 364 | ** -c|--closed List closed branches. |
| 352 | 365 | ** -r Reverse the sort order |
| 353 | 366 | ** -t Show recently changed branches first |
| 354 | 367 | ** |
| 355 | -** fossil branch new BRANCH-NAME BASIS ?OPTIONS? | |
| 368 | +** > fossil branch new BRANCH-NAME BASIS ?OPTIONS? | |
| 356 | 369 | ** |
| 357 | 370 | ** Create a new branch BRANCH-NAME off of check-in BASIS. |
| 358 | 371 | ** Supported options for this subcommand include: |
| 359 | 372 | ** --private branch is private (i.e., remains local) |
| 360 | 373 | ** --bgcolor COLOR use COLOR instead of automatic background |
| @@ -366,18 +379,13 @@ | ||
| 366 | 379 | ** year-month-day form, it may be truncated, the "T" may be |
| 367 | 380 | ** replaced by a space, and it may also name a timezone offset |
| 368 | 381 | ** from UTC as "-HH:MM" (westward) or "+HH:MM" (eastward). |
| 369 | 382 | ** Either no timezone suffix or "Z" means UTC. |
| 370 | 383 | ** |
| 371 | -** Options: | |
| 372 | -** -R|--repository FILE Run commands on repository FILE | |
| 384 | +** Options valid for all subcommands: | |
| 373 | 385 | ** |
| 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 | |
| 379 | 387 | */ |
| 380 | 388 | void branch_cmd(void){ |
| 381 | 389 | int n; |
| 382 | 390 | const char *zCmd = "list"; |
| 383 | 391 | db_find_and_open_repository(0, 0); |
| 384 | 392 |
| --- 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 @@ | ||
| 59 | 59 | zOut = sqlite3_mprintf("/%.*s", i-n, &z[n]); |
| 60 | 60 | sqlite3_result_text(context, zOut, i-n+1, sqlite3_free); |
| 61 | 61 | } |
| 62 | 62 | } |
| 63 | 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 | + | |
| 64 | 72 | /* |
| 65 | 73 | ** Given a pathname which is a relative path from the root of |
| 66 | 74 | ** the repository to a file or directory, compute a string which |
| 67 | 75 | ** is an HTML rendering of that path with hyperlinks on each |
| 68 | 76 | ** directory component of the path where the hyperlink redirects |
| @@ -76,29 +84,36 @@ | ||
| 76 | 84 | void hyperlinked_path( |
| 77 | 85 | const char *zPath, /* Path to render */ |
| 78 | 86 | Blob *pOut, /* Write into this blob */ |
| 79 | 87 | const char *zCI, /* check-in name, or NULL */ |
| 80 | 88 | 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 */ | |
| 82 | 91 | ){ |
| 83 | 92 | int i, j; |
| 84 | 93 | char *zSep = ""; |
| 85 | 94 | |
| 86 | 95 | for(i=0; zPath[i]; i=j){ |
| 87 | 96 | 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]); | |
| 100 | 115 | } |
| 101 | 116 | zSep = "/"; |
| 102 | 117 | while( zPath[j]=='/' ){ j++; } |
| 103 | 118 | } |
| 104 | 119 | } |
| @@ -122,33 +137,29 @@ | ||
| 122 | 137 | */ |
| 123 | 138 | void page_dir(void){ |
| 124 | 139 | char *zD = fossil_strdup(P("name")); |
| 125 | 140 | int nD = zD ? strlen(zD)+1 : 0; |
| 126 | 141 | int mxLen; |
| 127 | - int n; | |
| 128 | 142 | char *zPrefix; |
| 129 | 143 | Stmt q; |
| 130 | 144 | const char *zCI = P("ci"); |
| 131 | 145 | int rid = 0; |
| 132 | 146 | char *zUuid = 0; |
| 133 | - Blob dirname; | |
| 134 | 147 | Manifest *pM = 0; |
| 135 | 148 | const char *zSubdirLink; |
| 136 | 149 | int linkTrunk = 1; |
| 137 | 150 | int linkTip = 1; |
| 138 | 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; | |
| 139 | 155 | |
| 156 | + if( zCI && strlen(zCI)==0 ){ zCI = 0; } | |
| 140 | 157 | if( strcmp(PD("type","flat"),"tree")==0 ){ page_tree(); return; } |
| 141 | 158 | login_check_credentials(); |
| 142 | 159 | if( !g.perm.Read ){ login_needed(g.anon.Read); return; } |
| 143 | 160 | 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 | 161 | |
| 151 | 162 | /* If the name= parameter is an empty string, make it a NULL pointer */ |
| 152 | 163 | if( zD && strlen(zD)==0 ){ zD = 0; } |
| 153 | 164 | |
| 154 | 165 | /* If a specific check-in is requested, fetch and parse it. If the |
| @@ -160,53 +171,80 @@ | ||
| 160 | 171 | if( pM ){ |
| 161 | 172 | int trunkRid = symbolic_name_to_rid("tag:trunk", "ci"); |
| 162 | 173 | linkTrunk = trunkRid && rid != trunkRid; |
| 163 | 174 | linkTip = rid != symbolic_name_to_rid("tip", "ci"); |
| 164 | 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); | |
| 165 | 179 | }else{ |
| 166 | 180 | zCI = 0; |
| 167 | 181 | } |
| 168 | 182 | } |
| 169 | 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 | + | |
| 170 | 206 | /* Compute the title of the page */ |
| 171 | - blob_zero(&dirname); | |
| 172 | 207 | 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); | |
| 175 | 213 | zPrefix = mprintf("%s/", zD); |
| 176 | 214 | style_submenu_element("Top-Level", "%s", |
| 177 | 215 | url_render(&sURI, "name", 0, 0, 0)); |
| 178 | 216 | }else{ |
| 179 | - blob_append(&dirname, "in the top-level directory", -1); | |
| 217 | + @ <h2>Files in the top-level directory \ | |
| 180 | 218 | zPrefix = ""; |
| 181 | 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 | + } | |
| 182 | 237 | if( linkTrunk ){ |
| 183 | 238 | style_submenu_element("Trunk", "%s", |
| 184 | 239 | url_render(&sURI, "ci", "trunk", 0, 0)); |
| 185 | 240 | } |
| 186 | 241 | if( linkTip ){ |
| 187 | 242 | style_submenu_element("Tip", "%s", url_render(&sURI, "ci", "tip", 0, 0)); |
| 188 | 243 | } |
| 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 | - @ %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 | - @ %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); | |
| 208 | 246 | } |
| 209 | 247 | style_submenu_element("All", "%s", url_render(&sURI, "ci", 0, 0, 0)); |
| 210 | 248 | style_submenu_element("Tree-View", "%s", |
| 211 | 249 | url_render(&sURI, "type", "tree", 0, 0)); |
| 212 | 250 | |
| @@ -269,15 +307,14 @@ | ||
| 269 | 307 | |
| 270 | 308 | /* Generate a multi-column table listing the contents of zD[] |
| 271 | 309 | ** directory. |
| 272 | 310 | */ |
| 273 | 311 | mxLen = db_int(12, "SELECT max(length(x)) FROM localfiles /*scan*/"); |
| 274 | - n = db_int(1,"SELECT count(*) FROM localfiles; /*scan*/"); | |
| 275 | 312 | if( mxLen<12 ) mxLen = 12; |
| 276 | 313 | mxLen += (mxLen+9)/10; |
| 277 | 314 | 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"> | |
| 279 | 316 | @ <ul class="browser"> |
| 280 | 317 | while( db_step(&q)==SQLITE_ROW ){ |
| 281 | 318 | const char *zFN; |
| 282 | 319 | zFN = db_column_text(&q, 0); |
| 283 | 320 | if( zFN[0]=='/' ){ |
| @@ -284,12 +321,11 @@ | ||
| 284 | 321 | zFN++; |
| 285 | 322 | @ <li class="dir">%z(href("%s%T",zSubdirLink,zFN))%h(zFN)</a></li> |
| 286 | 323 | }else{ |
| 287 | 324 | const char *zLink; |
| 288 | 325 | 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); | |
| 291 | 327 | }else{ |
| 292 | 328 | zLink = href("%R/finfo?name=%T%T",zPrefix,zFN); |
| 293 | 329 | } |
| 294 | 330 | @ <li class="%z(fileext_class(zFN))">%z(zLink)%h(zFN)</a></li> |
| 295 | 331 | } |
| @@ -354,10 +390,11 @@ | ||
| 354 | 390 | @ </iframe> |
| 355 | 391 | }else{ |
| 356 | 392 | Blob content; |
| 357 | 393 | const char *zMime = mimetype_from_name(zName); |
| 358 | 394 | content_get(rid, &content); |
| 395 | + safe_html_context(DOCSRC_FILE); | |
| 359 | 396 | wiki_render_by_mimetype(&content, zMime); |
| 360 | 397 | } |
| 361 | 398 | } |
| 362 | 399 | } |
| 363 | 400 | db_finalize(&q); |
| @@ -614,11 +651,15 @@ | ||
| 614 | 651 | HQuery sURI; /* Hyperlink */ |
| 615 | 652 | int startExpanded; /* True to start out with the tree expanded */ |
| 616 | 653 | int showDirOnly; /* Show directories only. Omit files */ |
| 617 | 654 | int nDir = 0; /* Number of directories. Used for ID attributes */ |
| 618 | 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; | |
| 619 | 659 | |
| 660 | + if( zCI && strlen(zCI)==0 ){ zCI = 0; } | |
| 620 | 661 | if( strcmp(PD("type","flat"),"flat")==0 ){ page_dir(); return; } |
| 621 | 662 | memset(&sTree, 0, sizeof(sTree)); |
| 622 | 663 | login_check_credentials(); |
| 623 | 664 | if( !g.perm.Read ){ login_needed(g.anon.Read); return; } |
| 624 | 665 | while( nD>1 && zD[nD-2]=='/' ){ zD[(--nD)-1] = 0; } |
| @@ -626,14 +667,12 @@ | ||
| 626 | 667 | pathelementFunc, 0, 0); |
| 627 | 668 | url_initialize(&sURI, "tree"); |
| 628 | 669 | cgi_query_parameters_to_url(&sURI); |
| 629 | 670 | if( PB("nofiles") ){ |
| 630 | 671 | showDirOnly = 1; |
| 631 | - style_header("Folder Hierarchy"); | |
| 632 | 672 | }else{ |
| 633 | 673 | showDirOnly = 0; |
| 634 | - style_header("File Tree"); | |
| 635 | 674 | } |
| 636 | 675 | style_adunit_config(ADUNIT_RIGHT_OK); |
| 637 | 676 | if( PB("expand") ){ |
| 638 | 677 | startExpanded = 1; |
| 639 | 678 | }else{ |
| @@ -662,37 +701,55 @@ | ||
| 662 | 701 | linkTip = rid != symbolic_name_to_rid("tip", "ci"); |
| 663 | 702 | zUuid = db_text(0, "SELECT uuid FROM blob WHERE rid=%d", rid); |
| 664 | 703 | rNow = db_double(0.0, "SELECT mtime FROM event WHERE objid=%d", rid); |
| 665 | 704 | zNow = db_text("", "SELECT datetime(mtime,toLocal())" |
| 666 | 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); | |
| 667 | 709 | }else{ |
| 668 | 710 | zCI = 0; |
| 669 | 711 | } |
| 670 | 712 | } |
| 671 | 713 | if( zCI==0 ){ |
| 672 | 714 | rNow = db_double(0.0, "SELECT max(mtime) FROM event"); |
| 673 | 715 | zNow = db_text("", "SELECT datetime(max(mtime),toLocal()) FROM event"); |
| 674 | 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); | |
| 675 | 734 | |
| 676 | 735 | /* Compute the title of the page */ |
| 677 | 736 | blob_zero(&dirname); |
| 678 | 737 | if( zD ){ |
| 679 | 738 | blob_append(&dirname, "within directory ", -1); |
| 680 | - hyperlinked_path(zD, &dirname, zCI, "tree", zREx); | |
| 739 | + hyperlinked_path(zD, &dirname, zCI, "tree", zREx, 0); | |
| 681 | 740 | if( zRE ) blob_appendf(&dirname, " matching \"%s\"", zRE); |
| 682 | 741 | style_submenu_element("Top-Level", "%s", |
| 683 | 742 | 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); | |
| 688 | 745 | } |
| 689 | 746 | style_submenu_binary("mtime","Sort By Time","Sort By Filename", 0); |
| 690 | 747 | if( zCI ){ |
| 691 | 748 | style_submenu_element("All", "%s", url_render(&sURI, "ci", 0, 0, 0)); |
| 692 | 749 | 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); | |
| 694 | 751 | } |
| 695 | 752 | } |
| 696 | 753 | if( linkTrunk ){ |
| 697 | 754 | style_submenu_element("Trunk", "%s", |
| 698 | 755 | url_render(&sURI, "ci", "trunk", 0, 0)); |
| @@ -747,10 +804,11 @@ | ||
| 747 | 804 | tree_add_node(&sTree, zName, zUuid, mtime); |
| 748 | 805 | nFile++; |
| 749 | 806 | } |
| 750 | 807 | db_finalize(&q); |
| 751 | 808 | } |
| 809 | + style_submenu_checkbox("nofiles", "Folders Only", 0, 0); | |
| 752 | 810 | |
| 753 | 811 | if( showDirOnly ){ |
| 754 | 812 | for(nFile=0, p=sTree.pFirst; p; p=p->pNext){ |
| 755 | 813 | if( p->pChild!=0 && p->nFullName>nD ) nFile++; |
| 756 | 814 | } |
| @@ -757,18 +815,24 @@ | ||
| 757 | 815 | zObjType = "Folders"; |
| 758 | 816 | }else{ |
| 759 | 817 | zObjType = "Files"; |
| 760 | 818 | } |
| 761 | 819 | |
| 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 | + } | |
| 770 | 834 | }else{ |
| 771 | 835 | int n = db_int(0, "SELECT count(*) FROM plink"); |
| 772 | 836 | @ <h2>%s(zObjType) from all %d(n) check-ins %s(blob_str(&dirname)) |
| 773 | 837 | } |
| 774 | 838 | if( useMtime ){ |
| @@ -826,11 +890,11 @@ | ||
| 826 | 890 | nDir++; |
| 827 | 891 | }else if( !showDirOnly ){ |
| 828 | 892 | const char *zFileClass = fileext_class(p->zName); |
| 829 | 893 | char *zLink; |
| 830 | 894 | if( zCI ){ |
| 831 | - zLink = href("%R/artifact/%!S",p->zUuid); | |
| 895 | + zLink = href("%R/file?name=%T&ci=%T",p->zFullName,zCI); | |
| 832 | 896 | }else{ |
| 833 | 897 | zLink = href("%R/finfo?name=%T",p->zFullName); |
| 834 | 898 | } |
| 835 | 899 | @ <li class="%z(zFileClass)%s(zLastClass)"><div class="filetreeline"> |
| 836 | 900 | @ %z(zLink)%h(p->zName)</a> |
| @@ -847,11 +911,11 @@ | ||
| 847 | 911 | } |
| 848 | 912 | } |
| 849 | 913 | } |
| 850 | 914 | @ </ul> |
| 851 | 915 | @ </ul></div> |
| 852 | - style_load_one_js_file("tree.js"); | |
| 916 | + builtin_request_js("tree.js"); | |
| 853 | 917 | style_footer(); |
| 854 | 918 | |
| 855 | 919 | /* We could free memory used by sTree here if we needed to. But |
| 856 | 920 | ** the process is about to exit, so doing so would not really accomplish |
| 857 | 921 | ** anything useful. */ |
| @@ -920,11 +984,11 @@ | ||
| 920 | 984 | ** mtime on that check-in. If zGlob and *zGlob then only files matching |
| 921 | 985 | ** the given glob are computed. |
| 922 | 986 | */ |
| 923 | 987 | int compute_fileage(int vid, const char* zGlob){ |
| 924 | 988 | Stmt q; |
| 925 | - db_multi_exec(zComputeFileAgeSetup /*works-like:"constant"*/); | |
| 989 | + db_exec_sql(zComputeFileAgeSetup); | |
| 926 | 990 | db_prepare(&q, zComputeFileAgeRun /*works-like:"constant"*/); |
| 927 | 991 | db_bind_int(&q, ":ckin", vid); |
| 928 | 992 | db_bind_text(&q, ":glob", zGlob && zGlob[0] ? zGlob : "*"); |
| 929 | 993 | db_exec(&q); |
| 930 | 994 | db_finalize(&q); |
| @@ -1003,10 +1067,11 @@ | ||
| 1003 | 1067 | int rid; |
| 1004 | 1068 | const char *zName; |
| 1005 | 1069 | const char *zGlob; |
| 1006 | 1070 | const char *zUuid; |
| 1007 | 1071 | const char *zNow; /* Time of check-in */ |
| 1072 | + int isBranchCI; /* name= is a branch name */ | |
| 1008 | 1073 | int showId = PB("showid"); |
| 1009 | 1074 | Stmt q1, q2; |
| 1010 | 1075 | double baseTime; |
| 1011 | 1076 | login_check_credentials(); |
| 1012 | 1077 | if( !g.perm.Read ){ login_needed(g.anon.Read); return; } |
| @@ -1016,28 +1081,34 @@ | ||
| 1016 | 1081 | rid = symbolic_name_to_rid(zName, "ci"); |
| 1017 | 1082 | if( rid==0 ){ |
| 1018 | 1083 | fossil_fatal("not a valid check-in: %s", zName); |
| 1019 | 1084 | } |
| 1020 | 1085 | zUuid = db_text("", "SELECT uuid FROM blob WHERE rid=%d", rid); |
| 1086 | + isBranchCI = branch_includes_uuid(zName,zUuid); | |
| 1021 | 1087 | baseTime = db_double(0.0,"SELECT mtime FROM event WHERE objid=%d", rid); |
| 1022 | 1088 | zNow = db_text("", "SELECT datetime(mtime,toLocal()) FROM event" |
| 1023 | 1089 | " WHERE objid=%d", rid); |
| 1024 | 1090 | style_submenu_element("Tree-View", "%R/tree?ci=%T&mtime=1&type=tree", zName); |
| 1025 | 1091 | style_header("File Ages"); |
| 1026 | 1092 | zGlob = P("glob"); |
| 1027 | 1093 | compute_fileage(rid,zGlob); |
| 1028 | 1094 | db_multi_exec("CREATE INDEX fileage_ix1 ON fileage(mid,pathname);"); |
| 1029 | 1095 | |
| 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 | + } | |
| 1032 | 1104 | if( zGlob && zGlob[0] ){ |
| 1033 | 1105 | @ that match "%h(zGlob)" |
| 1034 | 1106 | } |
| 1035 | 1107 | @ ordered by age</h1> |
| 1036 | 1108 | @ |
| 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 | |
| 1039 | 1110 | @ %z(href("%R/timeline?c=%t",zNow))%s(zNow)</a>.</p> |
| 1040 | 1111 | @ |
| 1041 | 1112 | @ <div class='fileage'><table> |
| 1042 | 1113 | @ <tr><th>Age</th><th>Files</th><th>Check-in</th></tr> |
| 1043 | 1114 | db_prepare(&q1, |
| @@ -1052,14 +1123,13 @@ | ||
| 1052 | 1123 | " AND blob.rid=event.objid\n" |
| 1053 | 1124 | " ORDER BY event.mtime DESC;", |
| 1054 | 1125 | TAG_BRANCH |
| 1055 | 1126 | ); |
| 1056 | 1127 | 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" | |
| 1059 | 1130 | " WHERE fileage.mid=:mid AND filename.fnid=fileage.fnid" |
| 1060 | - " AND blob.rid=fileage.fid;" | |
| 1061 | 1131 | ); |
| 1062 | 1132 | while( db_step(&q1)==SQLITE_ROW ){ |
| 1063 | 1133 | double age = baseTime - db_column_double(&q1, 0); |
| 1064 | 1134 | int mid = db_column_int(&q1, 1); |
| 1065 | 1135 | const char *zUuid = db_column_text(&q1, 2); |
| @@ -1069,24 +1139,24 @@ | ||
| 1069 | 1139 | char *zAge = human_readable_age(age); |
| 1070 | 1140 | @ <tr><td>%s(zAge)</td> |
| 1071 | 1141 | @ <td> |
| 1072 | 1142 | db_bind_int(&q2, ":mid", mid); |
| 1073 | 1143 | 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> \ | |
| 1077 | 1146 | 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 /> | |
| 1079 | 1149 | }else{ |
| 1080 | - @ %z(href("%R/artifact/%!S",zFUuid))%h(zFile)</a><br /> | |
| 1150 | + @ </a><br /> | |
| 1081 | 1151 | } |
| 1082 | 1152 | } |
| 1083 | 1153 | db_reset(&q2); |
| 1084 | 1154 | @ </td> |
| 1085 | 1155 | @ <td> |
| 1086 | 1156 | @ %W(zComment) |
| 1087 | - @ (check-in: %z(href("%R/ci/%!S",zUuid))%S(zUuid)</a>, | |
| 1157 | + @ (check-in: %z(href("%R/info/%!S",zUuid))%S(zUuid)</a>, | |
| 1088 | 1158 | if( showId ){ |
| 1089 | 1159 | @ id: %d(mid) |
| 1090 | 1160 | } |
| 1091 | 1161 | @ user: %z(href("%R/timeline?u=%t&c=%!S&nd",zUser,zUuid))%h(zUser)</a>, |
| 1092 | 1162 | @ branch: \ |
| 1093 | 1163 |
| --- 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 | @ %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 | @ %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: %z(href("%R/ci/%!S",zUuid))%S(zUuid)</a>, |
| 1088 | if( showId ){ |
| 1089 | @ id: %d(mid) |
| 1090 | } |
| 1091 | @ user: %z(href("%R/timeline?u=%t&c=%!S&nd",zUser,zUuid))%h(zUser)</a>, |
| 1092 | @ branch: \ |
| 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: %z(href("%R/info/%!S",zUuid))%S(zUuid)</a>, |
| 1158 | if( showId ){ |
| 1159 | @ id: %d(mid) |
| 1160 | } |
| 1161 | @ user: %z(href("%R/timeline?u=%t&c=%!S&nd",zUser,zUuid))%h(zUser)</a>, |
| 1162 | @ branch: \ |
| 1163 |
+251
-11
| --- src/builtin.c | ||
| +++ src/builtin.c | ||
| @@ -28,13 +28,15 @@ | ||
| 28 | 28 | ** builtin_data.h file. Include that information here: |
| 29 | 29 | */ |
| 30 | 30 | #include "builtin_data.h" |
| 31 | 31 | |
| 32 | 32 | /* |
| 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. | |
| 34 | 36 | */ |
| 35 | -const unsigned char *builtin_file(const char *zFilename, int *piSize){ | |
| 37 | +static int builtin_file_index(const char *zFilename){ | |
| 36 | 38 | int lwr, upr, i, c; |
| 37 | 39 | lwr = 0; |
| 38 | 40 | upr = count(aBuiltinFiles) - 1; |
| 39 | 41 | while( upr>=lwr ){ |
| 40 | 42 | i = (upr+lwr)/2; |
| @@ -42,30 +44,50 @@ | ||
| 42 | 44 | if( c<0 ){ |
| 43 | 45 | lwr = i+1; |
| 44 | 46 | }else if( c>0 ){ |
| 45 | 47 | upr = i-1; |
| 46 | 48 | }else{ |
| 47 | - if( piSize ) *piSize = aBuiltinFiles[i].nByte; | |
| 48 | - return aBuiltinFiles[i].pData; | |
| 49 | + return i; | |
| 49 | 50 | } |
| 50 | 51 | } |
| 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 | + } | |
| 53 | 67 | } |
| 54 | 68 | const char *builtin_text(const char *zFilename){ |
| 55 | 69 | return (char*)builtin_file(zFilename, 0); |
| 56 | 70 | } |
| 57 | 71 | |
| 58 | 72 | /* |
| 59 | 73 | ** 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. | |
| 60 | 77 | ** |
| 61 | 78 | ** List the names and sizes of all built-in resources. |
| 62 | 79 | */ |
| 63 | 80 | void test_builtin_list(void){ |
| 64 | - int i; | |
| 81 | + int i, size = 0;; | |
| 65 | 82 | 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); | |
| 67 | 89 | } |
| 68 | 90 | } |
| 69 | 91 | |
| 70 | 92 | /* |
| 71 | 93 | ** WEBPAGE: test-builtin-files |
| @@ -73,16 +95,18 @@ | ||
| 73 | 95 | ** Show all built-in text files. |
| 74 | 96 | */ |
| 75 | 97 | void test_builtin_list_page(void){ |
| 76 | 98 | int i; |
| 77 | 99 | style_header("Built-in Text Files"); |
| 78 | - @ <ul> | |
| 100 | + @ <ol> | |
| 79 | 101 | for(i=0; i<count(aBuiltinFiles); i++){ |
| 80 | 102 | 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> | |
| 82 | 106 | } |
| 83 | - @ </ul> | |
| 107 | + @ </ol> | |
| 84 | 108 | style_footer(); |
| 85 | 109 | } |
| 86 | 110 | |
| 87 | 111 | /* |
| 88 | 112 | ** COMMAND: test-builtin-get |
| @@ -102,5 +126,221 @@ | ||
| 102 | 126 | } |
| 103 | 127 | blob_init(&x, (const char*)pData, nByte); |
| 104 | 128 | blob_write_to_file(&x, g.argc==4 ? g.argv[3] : "-"); |
| 105 | 129 | blob_reset(&x); |
| 106 | 130 | } |
| 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 |